Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when I try to use --transform #282

Open
alanmun opened this issue Jan 3, 2025 · 6 comments
Open

Error when I try to use --transform #282

alanmun opened this issue Jan 3, 2025 · 6 comments

Comments

@alanmun
Copy link

alanmun commented Jan 3, 2025

npx gltfjsx --transform .\frontend\assets\models\bedroom.glb
TypeError: Cannot read properties of null (reading 'createAccessor')
at compactPrimitive (file:///C:/Users/red/Repositories/horragame/node_modules/@gltf-transform/functions/dist/functions.modern.js:2408:31)
at _joinLevel (file:///C:/Users/red/Repositories/horragame/node_modules/@gltf-transform/functions/dist/functions.modern.js:4104:7)
at join (file:///C:/Users/red/Repositories/horragame/node_modules/@gltf-transform/functions/dist/functions.modern.js:4066:7)
at Document.transform (file:///C:/Users/red/Repositories/horragame/node_modules/gltfjsx/node_modules/@gltf-transform/core/dist/index.modern.js:4005:13)
at async transform (file:///C:/Users/red/Repositories/horragame/node_modules/gltfjsx/src/utils/transform.js:114:3)
at async run (file:///C:/Users/red/Repositories/horragame/node_modules/gltfjsx/src/gltfjsx.js:54:9)

Using without --transform works fine, but I'd really like to compress my models so they load faster while developing.

I am using:
"@react-three/drei": "^9.120.4",
"@react-three/fiber": "^8.17.10",
"@react-three/postprocessing": "^2.16.3",
"react": "18",
"react-dom": "18",
"three": "^0.171.0",
"gltfjsx": "^6.5.3",

@donmccurdy
Copy link
Member

@alanmun are you able to share the .glb, and your Node.js version?

@alanmun
Copy link
Author

alanmun commented Jan 3, 2025

@donmccurdy Node v21.7.3

@donmccurdy
Copy link
Member

donmccurdy commented Jan 3, 2025

Looks strongly like a case of dual package hazard. Somehow @gltf-transform/functions is installed directly in your project...

horragame/node_modules/@gltf-transform/functions/

... while @gltf-transform/core has been installed under gltfjsx:

horragame/node_modules/gltfjsx/node_modules/@gltf-transform/core

Probably there's a second copy of @gltf-transform/core in your project's own node_modules and the two copies are conflicting. I'm not sure how that might have happened but removing the copies from your project might solve it.

Or, instead of using --transform, you can use the glTF Transform CLI (https://gltf-transform.dev/cli) directly, which gives you more configuration options. gltfjsx has a somewhat custom configuration, but roughly comparable usage would be...

npx @gltf-transform/cli optimize in.glb out.glb --compress draco --texture-compress webp --texture-size 2048 --no-instance

... and then you can use the output model in gltfjsx without --transform (it's already optimized).

@donmccurdy
Copy link
Member

donmccurdy commented Jan 3, 2025

More info about why the dual package hazard would affect these particular dependencies in donmccurdy/glTF-Transform#1594, but an upstream fix isn't likely to arrive soon.

@alanmun
Copy link
Author

alanmun commented Jan 3, 2025

You were right, I do have two copies somehow. Which is the erroneous one?

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@gltf-transform/functions' imported from C:\Users\red\Repositories\horragame\node_modules\gltfjsx\src\utils\transform.js
at packageResolve (node:internal/modules/esm/resolve:845:9)
at moduleResolve (node:internal/modules/esm/resolve:918:18)
at defaultResolve (node:internal/modules/esm/resolve:1148:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:390:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:359:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:234:38)
at ModuleWrap. (node:internal/modules/esm/module_job:87:39)
at link (node:internal/modules/esm/module_job:86:36) {
code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v21.7.3

When I tried deleting the first mentioned one

@alanmun
Copy link
Author

alanmun commented Jan 3, 2025

I ended up trying your equivalent command, works except I get:

Could not load /models/bedroom-draco.glb: THREE.GLTFLoader: WebP required by asset but unsupported.
at http://localhost:3000/main_window/index.js:3047:36
at _onError (http://localhost:3000/main_window/index.js:93315:9)

So I'll look into removing webp usage from your command. Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants