Skip to content

Commit a225230

Browse files
Tinooooalvarosabu
andauthored
feat: make some of the utility methods available to users (#1068)
* refactor: reorganize HTML tag handling and utility functions - Moved the `HTML_TAGS` constant and `isHTMLTag` function from `src/utils/index.ts` to `src/utils/is.ts` for better modularity. - Removed the `makeMap` function from `index.ts` and imported it in `is.ts`, enhancing code clarity and separation of concerns. - Cleaned up unused code in `index.ts` to streamline the utility functions. * fix: fixed import * refactor: made use of radashis type guards and removed unused ones. * refactor: structured type guards and made them smaller and more readable * refactor: remove unused type guard tests and consolidate exports in utility files * refactor: Refactor utility functions and improve equality checks in node operations, removed unused methods * refactor: removed more unused code; added string util * refactor: moved noop * refactor: moved pixelRatio stuff * refactor: replaced shuffle * refactor: separated getObjectByUuid * refactor: removed unused highlight material methods, moved used one * chore: removed unused dependency * refactor: moved filterInPlace * moved extractBindingPosition * refactor: moved hasMap * chore: removed comment * Add exports for three and tres utility modules Export utility functions from utils/is/three and utils/is/tres to make them available for external use. * fix: added null check * chore: made use of isMesh in docs * made use of type guards * chore: beautified code a bit * docs: added type guard docs --------- Co-authored-by: alvarosabu <[email protected]>
1 parent ba83f0d commit a225230

34 files changed

+789
-1030
lines changed

docs/app/components/examples/web-gpu/HologramCube.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
2+
import { isMesh } from '@tresjs/core'
23
import { useGLTF } from '@tresjs/cientos'
34
import { add, cameraProjectionMatrix, cameraViewMatrix, color, Fn, hash, mix, normalView, positionWorld, sin, timerGlobal, uniform, varying, vec3, vec4 } from 'three/tsl'
4-
import type { Mesh, Object3D } from 'three/webgpu'
55
import { AdditiveBlending, DoubleSide, MeshBasicNodeMaterial } from 'three/webgpu'
66
77
const { nodes } = useGLTF('https://raw.githubusercontent.com/Tresjs/assets/main/models/gltf/blender-cube.glb', { draco: true })
@@ -46,8 +46,6 @@ material.colorNode = Fn(() => {
4646
})()
4747
4848
watch(model, (newModel) => {
49-
const isMesh = (child: Object3D): child is Mesh => 'isMesh' in child && !!(child.isMesh)
50-
5149
newModel?.traverse((child) => {
5250
if (isMesh(child)) {
5351
child.material = material
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
title: Utils
2+
icon: i-lucide-wrench
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
title: Type Guards
3+
description: TresJS provides type guard methods to help you determine the type of a Three.js object.
4+
---
5+
6+
To help you work with Three.js objects more effectively, TresJS provides a set of type guard methods. These methods allow you to determine the type of a Three.js object, making your code more robust and easier to maintain.
7+
The supported type guards are:
8+
9+
- `isBufferGeometry`
10+
- `isCamera`
11+
- `isColor`
12+
- `isColorRepresentation`
13+
- `isFog`
14+
- `isGroup`
15+
- `isLayers`
16+
- `isLight`
17+
- `isMaterial`
18+
- `isMesh`
19+
- `isObject3D`
20+
- `isOrthographicCamera`
21+
- `isPerspectiveCamera`
22+
- `isScene`
File renamed without changes.
File renamed without changes.

docs/content/3.api/4.advanced/web-gpu.md renamed to docs/content/3.api/5.advanced/web-gpu.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const createWebGPURenderer = (ctx: TresRendererSetupContext) => {
7272

7373
```vue [components/HologramCube.vue]
7474
<script setup lang="ts">
75+
import { isMesh } from '@tesjs/core'
7576
import { useGLTF } from '@tresjs/cientos'
7677
import { add, cameraProjectionMatrix, cameraViewMatrix, color, Fn, hash, mix, normalView, positionWorld, sin, timerGlobal, uniform, varying, vec3, vec4 } from 'three/tsl'
7778
import { AdditiveBlending, DoubleSide, MeshBasicNodeMaterial } from 'three/webgpu'
@@ -119,7 +120,7 @@ const createWebGPURenderer = (ctx: TresRendererSetupContext) => {
119120
120121
watch(model, (newModel) => {
121122
newModel.traverse((child) => {
122-
if (child.isMesh) {
123+
if (isMesh(child)) {
123124
child.material = material
124125
}
125126
})

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@
7878
"vue": ">=3.4"
7979
},
8080
"dependencies": {
81-
"@alvarosabu/utils": "^3.2.0",
8281
"@pmndrs/pointer-events": "^6.6.17",
8382
"@vue/devtools-api": "^7.7.2",
84-
"@vueuse/core": "^12.5.0"
83+
"@vueuse/core": "^12.5.0",
84+
"radashi": "^12.6.0"
8585
},
8686
"devDependencies": {
8787
"@release-it/conventional-changelog": "^10.0.0",

playground/vue/src/pages/advanced/webGPU/HologramCube.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script setup lang="ts">
2+
import { isMesh } from '@tresjs/core'
23
import { useGLTF } from '@tresjs/cientos'
34
import { add, cameraProjectionMatrix, cameraViewMatrix, color, Fn, hash, mix, normalView, positionWorld, sin, timerGlobal, uniform, varying, vec3, vec4 } from 'three/tsl'
45
import { AdditiveBlending, DoubleSide, MeshBasicNodeMaterial } from 'three/webgpu'
@@ -46,7 +47,7 @@ material.colorNode = Fn(() => {
4647
4748
watch(model, (newModel) => {
4849
newModel.traverse((child) => {
49-
if (child.isMesh) {
50+
if (isMesh(child)) {
5051
child.material = material
5152
}
5253
})

pnpm-lock.yaml

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)