You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+70-75Lines changed: 70 additions & 75 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,55 +6,40 @@
6
6
7
7
`solid-three` is a port of [react-three-fiber](https://github.com/pmndrs/react-three-fiber) to [solid-js](https://www.solidjs.com/). It allows you to declaratively construct a [Three.js](https://threejs.org/) scene, with reactive primitives, just as you would construct a DOM tree in `solid-js`.
8
8
9
+
-**Declarative `three.js` Components**: Utilize `three.js` objects as JSX components.
10
+
-**Reactive Prop Updates**: Properties of 3D objects update reactively, promoting efficient re-renders.
11
+
-**Integrated Animation Loop**: `useFrame` hook allows for easy animations.
12
+
-**Comprehensive Event System**: Enhanced event handling with support for `three.js` pointer and mouse events.
13
+
-**Extensible and Customizable**: Easily extendable with additional `three.js` entities or custom behaviors.
14
+
-**Optimized for `solid-js`**: Leverages `solid-js`' fine-grained reactivity for optimal performance.
15
+
9
16
## Table of Contents
10
17
11
-
1.[Features](#features)
12
-
2.[Differences from React-Three-Fiber](#differences-from-react-three-fiber)
-**Declarative `three.js` Components**: Utilize `three.js` objects as JSX components.
42
-
-**Reactive Prop Updates**: Properties of 3D objects update reactively, promoting efficient re-renders.
43
-
-**Integrated Animation Loop**: `useFrame` hook allows for easy animations.
44
-
-**Comprehensive Event System**: Enhanced event handling with support for `three.js` pointer and mouse events.
45
-
-**Extensible and Customizable**: Easily extendable with additional `three.js` entities or custom behaviors.
46
-
-**Optimized for `solid-js`**: Leverages `solid-js`' fine-grained reactivity for optimal performance.
47
-
48
-
## Differences from React-Three-Fiber
49
-
50
-
While `solid-three` is heavily inspired by– and initially shared a lot of code with– react-three-fiber, there are currently several key differences:
51
-
52
-
-**No `performance` Prop**: The `Canvas` component does not support a `performance` prop as optimization is handled differently in `solid-js`.
53
-
-**Simplified Event Objects**: The event object provided to event handlers is more minimalistic.
54
-
-**Minimal `useThree` Hook**: Returns a more concise context object, focusing on essential properties.
55
-
-**Missed Events**: Implements `onClickMissed`, `onDoubleClickMissed`, and `onContextMenuMissed` for handling events on empty space or stopped propagation.
56
-
-**TODO**:
57
-
-**No Pointer Capture**: Pointer events do not support pointer capture management.
10.[Differences from React-Three-Fiber](#differences-from-react-three-fiber)
41
+
11.[Contributing](#contributing)
42
+
12.[License](#license)
58
43
59
44
## Installation
60
45
@@ -72,43 +57,20 @@ yarn add solid-three three
72
57
73
58
Ensure that `solid-js` is installed in your environment, as it is a peer dependency of `solid-three`.
74
59
75
-
## Setup with `extend()`
76
-
77
-
Before using solid-three components, you must register THREE.js objects with the `extend()` function:
78
-
79
-
```tsx
80
-
import { extend } from"solid-three"
81
-
import*asTHREEfrom"three"
82
-
83
-
// Register all THREE.js objects (required step)
84
-
extend(THREE)
85
-
```
86
-
87
-
This registration step is required and must be done before rendering any `<T.*>` components. You can also register specific objects, allowing for treeshaking:
//Required: Register THREE.js objects before using them
108
-
extend(THREE)
69
+
//Create the T namespace with THREE.js objects
70
+
const T =createT(THREE)
109
71
110
72
const Box = () => {
111
-
let mesh:Mesh|undefined
73
+
let mesh:THREE.Mesh|undefined
112
74
const [hovered, setHovered] =createSignal(false)
113
75
114
76
useFrame(() => (mesh!.rotation.y+=0.01))
@@ -183,19 +145,36 @@ Example with all props:
183
145
</Canvas>
184
146
```
185
147
186
-
### Primitive Components (`<T/>`)
148
+
### T Namespace (`<T/>`)
187
149
188
-
`<T/>` components are wrappers around `three.js` objects, allowing you to insert these objects into your scene declaratively. These components are created dynamically based on the `three.js` classes you've registered with `extend()`.
189
-
190
-
Example:
150
+
The `T` namespace contains components that wrap `three.js` objects, allowing you to insert them into your scene declaratively. Before using these components, you must create the namespace using the `createT()` function:
191
151
192
152
```tsx
153
+
import { createT } from"solid-three"
154
+
import*asTHREEfrom"three"
155
+
156
+
// Create T namespace with all THREE.js objects
157
+
const T =createT(THREE)
158
+
159
+
// Now you can use T components
193
160
<T.Mesh>
194
161
<T.BoxGeometryargs={[1, 1, 1]} />
195
162
<T.MeshBasicMaterialcolor="hotpink" />
196
163
</T.Mesh>
197
164
```
198
165
166
+
You can also create a namespace with specific objects for better tree-shaking:
const T =createT({ Mesh, BoxGeometry, MeshBasicMaterial })
174
+
```
175
+
176
+
The `T` namespace can be created once and imported throughout your application, or created locally in each file as needed. The components are typed based on the objects you pass to `createT()`, providing full TypeScript support and autocomplete.
177
+
199
178
#### Advanced Prop Patterns
200
179
201
180
`solid-three` supports advanced prop attachment patterns for precise control:
@@ -231,7 +210,6 @@ const AdvancedProps = () => {
231
210
232
211
These patterns automatically trigger `needsUpdate` flags on materials and geometries when necessary.
233
212
234
-
235
213
### Portal
236
214
237
215
The `Portal` component allows you to place children outside the regular scene graph while maintaining reactive updates. This is useful for rendering objects into different scenes or bypassing the normal parent-child relationships.
@@ -394,7 +372,7 @@ function useLoader<TLoader, TArgs>(
394
372
395
373
```tsx
396
374
import { createSignal } from "solid-js"
397
-
import { Canvas, T, useLoader } from "solid-three"
375
+
import { Canvas, useLoader } from "solid-three"
398
376
import { TextureLoader } from "three"
399
377
400
378
const TexturedSphere = () => {
@@ -421,7 +399,7 @@ export const App = () => {
421
399
### Multipletextures
422
400
423
401
```tsx
424
-
import { Canvas, T, useLoader } from "solid-three"
402
+
import { Canvas, useLoader } from "solid-three"
425
403
import { TextureLoader } from "three"
426
404
427
405
const TexturedPlanes = () => {
@@ -716,13 +694,14 @@ solid-three's hover event handling differs from react-three-fiber in several key
716
694
717
695
```tsx
718
696
import type { S3 } from "solid-three"
697
+
import type * as THREE from "three"
719
698
720
699
// Component types
721
-
type MeshComponent = S3.Component<Mesh>
722
-
type BoxProps = S3.ClassProps<BoxGeometry>
700
+
type MeshComponent = S3.Component<THREE.Mesh>
701
+
type BoxProps = S3.Props<THREE.BoxGeometry>
723
702
724
703
// Instance types - `three.js` objects augmented with solid-three metadata
725
-
type AugmentedMesh = S3.Instance<Mesh>
704
+
type AugmentedMesh = S3.Instance<THREE.Mesh>
726
705
727
706
// Generic Three instance
728
707
type AnyInstance = S3.ThreeInstance
@@ -734,9 +713,11 @@ type Camera = S3.CameraType // PerspectiveCamera | OrthographicCamera
734
713
### PropsTypes
735
714
736
715
```tsx
716
+
import type { S3 } from "solid-three"
717
+
737
718
// Get props type for a specific `three.js` class
738
-
type MeshProps = S3.Props<"Mesh">
739
-
type MaterialProps = S3.Props<"MeshStandardMaterial">
719
+
type MeshProps = S3.Props<THREE.Mesh>
720
+
type MaterialProps = S3.Props<THREE.MeshStandardMaterial>
0 commit comments