Ver código fonte

Use .includes to check for value instead of strict comparison. Update useSeek documentation to include these 2 new functions

Garrett Walker 1 ano atrás
pai
commit
23f8c7e214
2 arquivos alterados com 16 adições e 4 exclusões
  1. 15 3
      docs/api/composables.md
  2. 1 1
      src/composables/useSeek/index.ts

+ 15 - 3
docs/api/composables.md

@@ -152,10 +152,10 @@ Similar to above composable, the `useTexture` composable returns a promise, you
 
 
 ## useSeek
 ## useSeek
 
 
-The `useSeek` composable provides utilities to easily traverse and navigate through complex ThreeJS scenes and object children graphs. It exports two functions, `seek` and `seekByName`, which allow you to find child objects based on specific properties.
+The `useSeek` composable provides utilities to easily traverse and navigate through complex ThreeJS scenes and object children graphs. It exports 4 functions which allow you to find child objects based on specific properties.
 
 
 ```ts
 ```ts
-const { seek, seekbyName } = useSeek()
+const { seek, seekByName, seekAll, seekAllByName } = useSeek()
 ```
 ```
 
 
 The seek function accepts three parameters:
 The seek function accepts three parameters:
@@ -164,7 +164,7 @@ The seek function accepts three parameters:
 - `property`: The property to be used in the search condition.
 - `property`: The property to be used in the search condition.
 - `value`: The value of the property to match.
 - `value`: The value of the property to match.
 
 
-Both function traverses the object and returns the child object with the specified property and value. If no child with the given property and value is found, it returns null and logs a warning.
+The `seek` and `seekByName` function traverses the object and returns the child object with the specified property and value. If no child with the given property and value is found, it returns null and logs a warning.
 
 
 ```ts
 ```ts
 const carRef = ref(null)
 const carRef = ref(null)
@@ -179,6 +179,18 @@ watch(carRef, ({ model }) => {
 })
 })
 ```
 ```
 
 
+Similarly, the `seekAll` and `seekAllByName` functions return an array of child objects whose property includes the given value. If no matches are found, then they return an empty array and a warning is logged.
+
+```ts
+const character = ref(null)
+
+watch(character, ({ model }) => {
+  if (model) {
+    const bones = seekAll(character, type, 'Bone')
+  }
+})
+```
+
 ## useTresContext
 ## useTresContext
 This composable aims to provide access to the state model which contains multiple useful properties.
 This composable aims to provide access to the state model which contains multiple useful properties.
 
 

+ 1 - 1
src/composables/useSeek/index.ts

@@ -58,7 +58,7 @@ export function useSeek(): UseSeekReturn {
     const foundChildren: THREE.Object3D[] = []
     const foundChildren: THREE.Object3D[] = []
 
 
     parent.traverse((child) => {
     parent.traverse((child) => {
-      if ((child as any)[property] === value) {
+      if ((child as any)[property].includes(value)) {
         foundChildren.push(child)
         foundChildren.push(child)
       }
       }
     })
     })