Skip to content

Commit 6a7d930

Browse files
authored
Merge pull request #267 from donmccurdy/feat/weld-default
fix(transform): Updates to support glTF Transform v4
2 parents 70a7b77 + c998baf commit 6a7d930

File tree

5 files changed

+27
-39
lines changed

5 files changed

+27
-39
lines changed

cli.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@ const cli = meow(
3131
--exportdefault, -E Use default export
3232
--transform, -T Transform the asset for the web (draco, prune, resize)
3333
--resolution, -R Resolution for texture resizing (default: 1024)
34-
--keepmeshes, -j Do not join compatible meshes
34+
--keepmeshes, -j Do not join compatible meshes
3535
--keepmaterials, -M Do not palette join materials
3636
--format, -f Texture format (default: "webp")
3737
--simplify, -S Mesh simplification (default: false)
38-
--weld Weld tolerance (default: 0.00005)
3938
--ratio Simplifier ratio (default: 0)
4039
--error Simplifier error threshold (default: 0.0001)
4140
--console, -c Log JSX to console, won't produce a file
@@ -66,7 +65,6 @@ const cli = meow(
6665
keepmaterials: { type: 'boolean', shortFlag: 'M', default: false },
6766
format: { type: 'string', shortFlag: 'f', default: 'webp' },
6867
exportdefault: { type: 'boolean', shortFlag: 'E' },
69-
weld: { type: 'number', default: 0.0001 },
7068
ratio: { type: 'number', default: 0.75 },
7169
error: { type: 'number', default: 0.001 },
7270
console: { type: 'boolean', shortFlag: 'c' },

package.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
"node": ">=16"
3939
},
4040
"dependencies": {
41-
"@gltf-transform/core": "4.0.4",
42-
"@gltf-transform/extensions": "4.0.4",
43-
"@gltf-transform/functions": "4.0.4",
41+
"@gltf-transform/core": "4.0.8",
42+
"@gltf-transform/extensions": "4.0.8",
43+
"@gltf-transform/functions": "4.0.8",
4444
"@node-loader/babel": "^2.0.1",
4545
"draco3dgltf": "^1.5.7",
4646
"is-var-name": "^2.0.0",
@@ -59,7 +59,10 @@
5959
"sharp": "<0.33.0"
6060
},
6161
"resolutions": {
62-
"sharp": "<0.33.0"
62+
"sharp": "<0.33.0",
63+
"@gltf-transform/core": "4.0.8",
64+
"@gltf-transform/extensions": "4.0.8",
65+
"@gltf-transform/functions": "4.0.8"
6366
},
6467
"devDependencies": {
6568
"@babel/core": "7.23.6",

readme.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ A small command-line tool that turns GLTF assets into declarative and re-usable
1818

1919
### GLTFJSX fixes that
2020

21-
- 🧑‍💻 It creates a virtual graph of all objects and materials. Now you can easily alter contents and re-use.
21+
- 🧑‍💻 It creates a virtual graph of all objects and materials. Now you can easily alter contents and re-use.
2222
- 🏎️ The graph gets pruned (empty groups, unnecessary transforms, ...) and will perform better.
2323
- ⚡️ It will optionally compress your model with up to 70%-90% size reduction.
2424

@@ -45,11 +45,10 @@ Options
4545
--exportdefault, -E Use default export
4646
--transform, -T Transform the asset for the web (draco, prune, resize)
4747
--resolution, -R Resolution for texture resizing (default: 1024)
48-
--keepmeshes, -j Do not join compatible meshes
48+
--keepmeshes, -j Do not join compatible meshes
4949
--keepmaterials, -M Do not palette join materials
5050
--format, -f Texture format (default: "webp")
5151
--simplify, -S Mesh simplification (default: false)
52-
--weld Weld tolerance (default: 0.00005)
5352
--ratio Simplifier ratio (default: 0)
5453
--error Simplifier error threshold (default: 0.0001)
5554
--console, -c Log JSX to console, won't produce a file
@@ -81,7 +80,7 @@ export function Model(props) {
8180
const { nodes, materials } = useGLTF('/model-transformed.glb')
8281
return (
8382
<group {...props} dispose={null}>
84-
<PerspectiveCamera name="camera" fov={40} near={10} far={1000} position={[10, 0, 50]} />
83+
<PerspectiveCamera name="camera" fov={40} near={10} far={1000} position={[10, 0, 50]} />
8584
<pointLight intensity={10} position={[100, 50, 100]} rotation={[-Math.PI / 2, 0, 0]} />
8685
<group position={[10, -5, 0]}>
8786
<mesh geometry={nodes.robot.geometry} material={materials.metal} />
@@ -110,7 +109,7 @@ import { Model } from './Model'
110109
function App() {
111110
return (
112111
<Canvas>
113-
<Model />
112+
<Model />
114113
```
115114
116115
You can re-use it, it will re-use geometries and materials out of the box:
@@ -208,7 +207,7 @@ useEffect(() => {
208207
209208
#### ⚡️ Auto-instancing
210209
211-
Use the `--instance` flag and it will look for similar geometry and create instances of them. Look into [drei/Merged](https://github.com/pmndrs/drei#instances) to understand how it works. It does not matter if you instanced the model previously in Blender, it creates instances for each mesh that has a specific geometry and/or material.
210+
Use the `--instance` flag and it will look for similar geometry and create instances of them. Look into [drei/Merged](https://github.com/pmndrs/drei#instances) to understand how it works. It does not matter if you instanced the model previously in Blender, it creates instances for each mesh that has a specific geometry and/or material.
212211
213212
`--instanceall` will create instances of all the geometry. This allows you to re-use the model with the smallest amount of drawcalls.
214213
@@ -287,7 +286,7 @@ it('should have a scene with a blue mesh', async () => {
287286
const { scene } = await new Promise((res) => loader.parse(data, '', res))
288287
expect(() => scene.children.length).toEqual(1)
289288
expect(() => scene.children[0].type).toEqual('mesh')
290-
expect(() => scene.children[0].material.color).toEqual('blue')
289+
expect(() => scene.children[0].material.color).toEqual('blue')
291290
})
292291
```
293292

src/utils/transform.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,13 @@ async function transform(file, output, config = {}) {
5656
)
5757
}
5858

59+
functions.push(
60+
// Weld vertices
61+
weld(),
62+
)
63+
5964
if (config.simplify) {
6065
functions.push(
61-
// Weld vertices
62-
weld({ tolerance: config.weld ?? 0.0001 / 2 }),
6366
// Simplify meshes
6467
simplify({ simplifier: MeshoptSimplifier, ratio: config.ratio ?? 0, error: config.error ?? 0.0001 })
6568
)

yarn.lock

+8-23
Original file line numberDiff line numberDiff line change
@@ -1094,43 +1094,28 @@
10941094
"@babel/helper-validator-identifier" "^7.24.7"
10951095
to-fast-properties "^2.0.0"
10961096

1097-
"@gltf-transform/[email protected]":
1098-
version "4.0.4"
1099-
resolved "https://registry.yarnpkg.com/@gltf-transform/core/-/core-4.0.4.tgz#71d9465fb12f656c97506fe85ef54e3ae96e927c"
1100-
integrity sha512-SsIL8vAMjXZBEJR3gI6OhGejK+ck4KKDSswYtShpXLylFAVke2EmITRA7CbzwmgZzbFc3a+appjhBhjRdb7v5A==
1101-
dependencies:
1102-
property-graph "^2.0.0"
1103-
1104-
"@gltf-transform/core@^4.0.4", "@gltf-transform/core@^4.0.8":
1097+
"@gltf-transform/[email protected]", "@gltf-transform/core@^4.0.8":
11051098
version "4.0.8"
11061099
resolved "https://registry.yarnpkg.com/@gltf-transform/core/-/core-4.0.8.tgz#cf5699cb05e62a33bb68dbf9e1438186f992cac5"
11071100
integrity sha512-8oSLSw+t+wxPvKC2qm0n3EOoR6Ql2DMuagimjWjGz8sC4MtCqbo6kS6dCeissYrkgP2fj/k8dzRWiWQZRatGMg==
11081101
dependencies:
11091102
property-graph "^2.0.0"
11101103

1111-
"@gltf-transform/[email protected]":
1112-
version "4.0.4"
1113-
resolved "https://registry.yarnpkg.com/@gltf-transform/extensions/-/extensions-4.0.4.tgz#f4cbd658969ca012f6a5c2e6565133f90d6bb0e4"
1114-
integrity sha512-hFdH9Rp7EeNKGjie+OSlw/OHGb10+AlN1e9VLWGzQjNc7Oco9+ZIja5pqEENxYw5WjOS6sX07E6eyOAZUcbF4A==
1115-
dependencies:
1116-
"@gltf-transform/core" "^4.0.4"
1117-
ktx-parse "^0.7.0"
1118-
1119-
"@gltf-transform/extensions@^4.0.4":
1104+
"@gltf-transform/[email protected]", "@gltf-transform/extensions@^4.0.8":
11201105
version "4.0.8"
11211106
resolved "https://registry.yarnpkg.com/@gltf-transform/extensions/-/extensions-4.0.8.tgz#4f099841df3b2f28a7974e048c7a65f9abb03618"
11221107
integrity sha512-ZbpSV+tHIIYZySwkt5/GLiTvfhvO/4ff7frSmdAG8nE3xRsLyxd2cuYcYHSqN7PP3Ch8NxLSBxvd9/MHNQmMYw==
11231108
dependencies:
11241109
"@gltf-transform/core" "^4.0.8"
11251110
ktx-parse "^0.7.0"
11261111

1127-
"@gltf-transform/[email protected].4":
1128-
version "4.0.4"
1129-
resolved "https://registry.yarnpkg.com/@gltf-transform/functions/-/functions-4.0.4.tgz#8e3b68a8b30a637fc1a0e4bc0e7038655e88d55c"
1130-
integrity sha512-9RLdwSqyBQGbY3dPq7JDXkGJfCo29X5MlXX8UJLjse8SBB53ketvJvcnKD2yEg6XiIso+ee126uB8MXdQuw4pg==
1112+
"@gltf-transform/[email protected].8":
1113+
version "4.0.8"
1114+
resolved "https://registry.yarnpkg.com/@gltf-transform/functions/-/functions-4.0.8.tgz#2b5d653e327d6c27c4011774561d4828b14f3956"
1115+
integrity sha512-v6yVtqh82iBoIz4PiEX9SWu9GEsrCyMclhzBMh6A6X2ezb823QBg1jOWdP+tB7KgetWZna4hALppwpsMQwS1ZQ==
11311116
dependencies:
1132-
"@gltf-transform/core" "^4.0.4"
1133-
"@gltf-transform/extensions" "^4.0.4"
1117+
"@gltf-transform/core" "^4.0.8"
1118+
"@gltf-transform/extensions" "^4.0.8"
11341119
ktx-parse "^0.7.0"
11351120
ndarray "^1.0.19"
11361121
ndarray-lanczos "^0.3.0"

0 commit comments

Comments
 (0)