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
+82-94Lines changed: 82 additions & 94 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,6 +29,7 @@
29
29
-[useProps](#useprops)
30
30
5.[Utilities](#utilities)
31
31
-[Raycasters](#raycasters)
32
+
-[LoaderCache](#loadercache)
32
33
-[autodispose](#autodispose)
33
34
-[Metadata Utilities](#metadata-utilities)
34
35
-[Testing Utilities](#testing-utilities)
@@ -408,6 +409,7 @@ const App = () => {
408
409
Declarative component for loading Three.js resources with automatic caching and Suspense integration. When no children are provided, the loaded resource is automatically rendered with any additional props passed through.
`LoaderCache` is the built-in implementation of the `LoaderRegistry` interface that `solid-three` exports. It's automatically set as the default cache for `useLoader`, providing a sophisticated caching system with automatic memory management for Three.js loader resources.
828
-
829
-
**Features:**
830
-
831
-
-**Automatic Reference Counting**: Tracks how many components are using each resource
832
-
-**Solid.js Integration**: Automatically decrements reference counts when components unmount
833
-
-**Deferred Disposal**: Resources are added to a "free list" when no longer referenced
834
-
-**Memory Management**: Call `emptyFreeList()` to dispose of unused resources
835
-
-**Multi-Loader Support**: Each Three.js loader gets its own isolated cache namespace
836
-
-**Path-based Storage**: Hierarchical storage using paths for efficient lookups
// When this component unmounts, the reference count decreases
882
-
// If it reaches zero, the texture is added to the free list
883
-
return (
884
-
<T.Mesh>
885
-
<T.BoxGeometry />
886
-
<T.MeshBasicMaterialmap={texture()} />
887
-
</T.Mesh>
888
-
)
889
-
}
890
-
891
-
// Multiple components can share the same cached resource
892
-
const Scene = () => (
893
-
<>
894
-
<TexturedBox /> {/* ref count: 1 */}
895
-
<TexturedBox /> {/* ref count: 2 */}
896
-
<TexturedBox /> {/* ref count: 3 */}
897
-
</>
898
-
)
899
-
```
900
-
901
827
**Advanced Usage with Multiple Loaders:**
902
828
903
829
```tsx
@@ -1086,6 +1012,68 @@ const App = () => {
1086
1012
}
1087
1013
```
1088
1014
1015
+
### LoaderCache
1016
+
1017
+
`LoaderCache` is the default cache-manager for `useLoader`. It implements the `LoaderRegistry` interface and adds additional methods to simplify managing the cached resources.
1018
+
1019
+
**Features:**
1020
+
1021
+
-**Automatic Reference Counting**: Tracks if a resource is currently actively in-use
1022
+
-**Deferred Disposal**: Resources are added to a free list when no longer referenced
1023
+
-**Disposal Methods**: Several methods to ease managing disposal of resources
1024
+
-**dispose(loader, path)**: dispose a resource based on loader and path
1025
+
-**disposeResource(resource)**: dispose a resource by passing the resource directly
1026
+
-**disposeFreeList()**: dispose all currently not referenced resources
1027
+
1028
+
**Example:**
1029
+
1030
+
```tsx
1031
+
const TexturedBox = () => {
1032
+
// This increments the reference count for 'texture.jpg'
// These will be disposed when ConditionalMesh unmounts
@@ -1171,23 +1159,7 @@ const MyTest = () => {
1171
1159
1172
1160
## Event Handling
1173
1161
1174
-
`solid-three` provides a comprehensive event system that integrates `three.js` pointer and mouse events with `solid-js`' reactivity. Events are automatically handled through raycasting and support stopping propagation.
1175
-
1176
-
### Controlling Raycasting with raycastable
1177
-
1178
-
The `raycastable` prop controls whether an Object3D can be targeted by raycasting:
1179
-
1180
-
-**raycastable** (`boolean`): When set to `false`, the object will not be hit by rays, but can still receive events through propagation from its descendants. Default is `true`.
`solid-three` provides a custom event system inspired by [`react-three-fiber`](https://github.com/pmndrs/react-three-fiber). Events are automatically handled through raycasting and support DOM-like propagation.
1191
1163
1192
1164
### Supported Events
1193
1165
@@ -1413,6 +1385,22 @@ solid-three's hover event handling differs from react-three-fiber in several key
1413
1385
-**react-three-fiber**: When moving from child to parent, the parent receives both leave and immediate re-enter events
1414
1386
</details>
1415
1387
1388
+
### Controlling Raycasting with raycastable
1389
+
1390
+
The `raycastable` prop controls whether an Object3D can be targeted by raycasting:
1391
+
1392
+
-**raycastable** (`boolean`): When set to `false`, the object will not be hit by rays, but can still receive events through propagation from its descendants. Default is `true`.
0 commit comments