diff --git a/cli.js b/cli.js index 2fa4ec5..3efdc99 100755 --- a/cli.js +++ b/cli.js @@ -31,11 +31,10 @@ const cli = meow( --exportdefault, -E Use default export --transform, -T Transform the asset for the web (draco, prune, resize) --resolution, -R Resolution for texture resizing (default: 1024) - --keepmeshes, -j Do not join compatible meshes + --keepmeshes, -j Do not join compatible meshes --keepmaterials, -M Do not palette join materials --format, -f Texture format (default: "webp") --simplify, -S Mesh simplification (default: false) - --weld Weld tolerance (default: 0.00005) --ratio Simplifier ratio (default: 0) --error Simplifier error threshold (default: 0.0001) --console, -c Log JSX to console, won't produce a file @@ -66,7 +65,6 @@ const cli = meow( keepmaterials: { type: 'boolean', shortFlag: 'M', default: false }, format: { type: 'string', shortFlag: 'f', default: 'webp' }, exportdefault: { type: 'boolean', shortFlag: 'E' }, - weld: { type: 'number', default: 0.0001 }, ratio: { type: 'number', default: 0.75 }, error: { type: 'number', default: 0.001 }, console: { type: 'boolean', shortFlag: 'c' }, diff --git a/package.json b/package.json index edcead7..abedeed 100644 --- a/package.json +++ b/package.json @@ -38,9 +38,9 @@ "node": ">=16" }, "dependencies": { - "@gltf-transform/core": "4.0.4", - "@gltf-transform/extensions": "4.0.4", - "@gltf-transform/functions": "4.0.4", + "@gltf-transform/core": "4.0.8", + "@gltf-transform/extensions": "4.0.8", + "@gltf-transform/functions": "4.0.8", "@node-loader/babel": "^2.0.1", "draco3dgltf": "^1.5.7", "is-var-name": "^2.0.0", @@ -59,7 +59,10 @@ "sharp": "<0.33.0" }, "resolutions": { - "sharp": "<0.33.0" + "sharp": "<0.33.0", + "@gltf-transform/core": "4.0.8", + "@gltf-transform/extensions": "4.0.8", + "@gltf-transform/functions": "4.0.8" }, "devDependencies": { "@babel/core": "7.23.6", diff --git a/readme.md b/readme.md index 629a7eb..731d335 100644 --- a/readme.md +++ b/readme.md @@ -18,7 +18,7 @@ A small command-line tool that turns GLTF assets into declarative and re-usable ### GLTFJSX fixes that -- 🧑‍💻 It creates a virtual graph of all objects and materials. Now you can easily alter contents and re-use. +- 🧑‍💻 It creates a virtual graph of all objects and materials. Now you can easily alter contents and re-use. - 🏎️ The graph gets pruned (empty groups, unnecessary transforms, ...) and will perform better. - ⚡️ It will optionally compress your model with up to 70%-90% size reduction. @@ -45,11 +45,10 @@ Options --exportdefault, -E Use default export --transform, -T Transform the asset for the web (draco, prune, resize) --resolution, -R Resolution for texture resizing (default: 1024) - --keepmeshes, -j Do not join compatible meshes + --keepmeshes, -j Do not join compatible meshes --keepmaterials, -M Do not palette join materials --format, -f Texture format (default: "webp") --simplify, -S Mesh simplification (default: false) - --weld Weld tolerance (default: 0.00005) --ratio Simplifier ratio (default: 0) --error Simplifier error threshold (default: 0.0001) --console, -c Log JSX to console, won't produce a file @@ -81,7 +80,7 @@ export function Model(props) { const { nodes, materials } = useGLTF('/model-transformed.glb') return ( - + @@ -110,7 +109,7 @@ import { Model } from './Model' function App() { return ( - + ``` You can re-use it, it will re-use geometries and materials out of the box: @@ -208,7 +207,7 @@ useEffect(() => { #### ⚡️ Auto-instancing -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. +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. `--instanceall` will create instances of all the geometry. This allows you to re-use the model with the smallest amount of drawcalls. @@ -287,7 +286,7 @@ it('should have a scene with a blue mesh', async () => { const { scene } = await new Promise((res) => loader.parse(data, '', res)) expect(() => scene.children.length).toEqual(1) expect(() => scene.children[0].type).toEqual('mesh') - expect(() => scene.children[0].material.color).toEqual('blue') + expect(() => scene.children[0].material.color).toEqual('blue') }) ``` diff --git a/src/utils/transform.js b/src/utils/transform.js index 4c98986..25c7005 100644 --- a/src/utils/transform.js +++ b/src/utils/transform.js @@ -56,10 +56,13 @@ async function transform(file, output, config = {}) { ) } + functions.push( + // Weld vertices + weld(), + ) + if (config.simplify) { functions.push( - // Weld vertices - weld({ tolerance: config.weld ?? 0.0001 / 2 }), // Simplify meshes simplify({ simplifier: MeshoptSimplifier, ratio: config.ratio ?? 0, error: config.error ?? 0.0001 }) ) diff --git a/yarn.lock b/yarn.lock index 657a9c7..6250ae3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1094,29 +1094,14 @@ "@babel/helper-validator-identifier" "^7.24.7" to-fast-properties "^2.0.0" -"@gltf-transform/core@4.0.4": - version "4.0.4" - resolved "https://registry.yarnpkg.com/@gltf-transform/core/-/core-4.0.4.tgz#71d9465fb12f656c97506fe85ef54e3ae96e927c" - integrity sha512-SsIL8vAMjXZBEJR3gI6OhGejK+ck4KKDSswYtShpXLylFAVke2EmITRA7CbzwmgZzbFc3a+appjhBhjRdb7v5A== - dependencies: - property-graph "^2.0.0" - -"@gltf-transform/core@^4.0.4", "@gltf-transform/core@^4.0.8": +"@gltf-transform/core@4.0.8", "@gltf-transform/core@^4.0.8": version "4.0.8" resolved "https://registry.yarnpkg.com/@gltf-transform/core/-/core-4.0.8.tgz#cf5699cb05e62a33bb68dbf9e1438186f992cac5" integrity sha512-8oSLSw+t+wxPvKC2qm0n3EOoR6Ql2DMuagimjWjGz8sC4MtCqbo6kS6dCeissYrkgP2fj/k8dzRWiWQZRatGMg== dependencies: property-graph "^2.0.0" -"@gltf-transform/extensions@4.0.4": - version "4.0.4" - resolved "https://registry.yarnpkg.com/@gltf-transform/extensions/-/extensions-4.0.4.tgz#f4cbd658969ca012f6a5c2e6565133f90d6bb0e4" - integrity sha512-hFdH9Rp7EeNKGjie+OSlw/OHGb10+AlN1e9VLWGzQjNc7Oco9+ZIja5pqEENxYw5WjOS6sX07E6eyOAZUcbF4A== - dependencies: - "@gltf-transform/core" "^4.0.4" - ktx-parse "^0.7.0" - -"@gltf-transform/extensions@^4.0.4": +"@gltf-transform/extensions@4.0.8", "@gltf-transform/extensions@^4.0.8": version "4.0.8" resolved "https://registry.yarnpkg.com/@gltf-transform/extensions/-/extensions-4.0.8.tgz#4f099841df3b2f28a7974e048c7a65f9abb03618" integrity sha512-ZbpSV+tHIIYZySwkt5/GLiTvfhvO/4ff7frSmdAG8nE3xRsLyxd2cuYcYHSqN7PP3Ch8NxLSBxvd9/MHNQmMYw== @@ -1124,13 +1109,13 @@ "@gltf-transform/core" "^4.0.8" ktx-parse "^0.7.0" -"@gltf-transform/functions@4.0.4": - version "4.0.4" - resolved "https://registry.yarnpkg.com/@gltf-transform/functions/-/functions-4.0.4.tgz#8e3b68a8b30a637fc1a0e4bc0e7038655e88d55c" - integrity sha512-9RLdwSqyBQGbY3dPq7JDXkGJfCo29X5MlXX8UJLjse8SBB53ketvJvcnKD2yEg6XiIso+ee126uB8MXdQuw4pg== +"@gltf-transform/functions@4.0.8": + version "4.0.8" + resolved "https://registry.yarnpkg.com/@gltf-transform/functions/-/functions-4.0.8.tgz#2b5d653e327d6c27c4011774561d4828b14f3956" + integrity sha512-v6yVtqh82iBoIz4PiEX9SWu9GEsrCyMclhzBMh6A6X2ezb823QBg1jOWdP+tB7KgetWZna4hALppwpsMQwS1ZQ== dependencies: - "@gltf-transform/core" "^4.0.4" - "@gltf-transform/extensions" "^4.0.4" + "@gltf-transform/core" "^4.0.8" + "@gltf-transform/extensions" "^4.0.8" ktx-parse "^0.7.0" ndarray "^1.0.19" ndarray-lanczos "^0.3.0"