File: three.js/webgl_nodes_loader_gltf_transmission.html at 31d84e8cd349ac68d4f3c22a2a50c60cb73201b5 · mrdoob/three.js · GitHub
<script type="importmap">
{
"imports": {
"three": "../build/three.module.js",
"three/addons/": "./jsm/",
"three/nodes": "./jsm/nodes/Nodes.js"
}
}
</script>
Why have /three/nodes/
instead of loading nodes by import { NodeMaterial, float } from '/three/addons/nodes/Nodes.js';
, like everything else is loaded?
Also, why "three/addons/"
has forward slash and "three/nodes"
doesn’t? Does it make a difference?
Also, Node.js is using node:fs
convention, so isn’t three:nodes
better?
three/addons/
is a prefix, and individual things are imported from specific paths underneath that folder, like three/addons/loaders/GLTFLoader.js
.
three/nodes
is an entrypoint, i.e. everything in the node-based shader system can be imported directly from three/nodes
. That codebase is still in active development, it may change, and it’s a large module containing many files (unlike most addons) so importing from a single entrypoint is helpful.
Also, the exact Import Map syntax above is not a requirement, you can use bundlers, and there may be other ways of achieving the same thing in your development environment. This is just what three.js has set up.
the node:fs
is a Node.js-specific convention, not common in the wider JS ecosystem, the slashes are more common for multiple entrypoints in a package.
Thank you for a very detailed answer.
But I still don’t see any benefit of using import { NodeMaterial, float } from 'three/nodes';
over import { NodeMaterial, float } from '/three/addons/nodes/Nodes.js';
.
It’s the same thing.
Yes, those are the same thing for now. You can use either. Using three/nodes
is just a convention in the codebase.