I noticed that three.js possibly doesn’t include /src/shaders/ and there’s no /js/nodes/ but /jsm/nodes/ exists.
I created index.html with three.js scene and it works fine:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Game</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="importmap">
{
"imports": {
"three": "./jsm/three.module.js",
"three-nodes/": "./jsm/nodes/"
}
}
</script>
</head>
<body>
<div class="game"></div>
<script src="js/three.js"></script>
<script src="js/loaders/GLTFLoader.js"></script>
<script src="js/game.js"></script>
<script src="js/my-shader.js" type="module"></script>
</body>
</html>
game.js contains something along the lines of:
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
let geometry = new THREE.BoxGeometry(1, 1, 1);
let object3d = new THREE.Mesh(geometry, new THREE.MeshLambertMaterial());
scene.add(object3d);
function animate(){
object3d.rotation.x += 0.01;
object3d.rotation.y += 0.01;
renderer.render(scene, camera);
requestAnimationFrame(animate);
};
animate();
In my-shader.js I wanted to only add a single node material and be able to apply it to the objects from the scene:
import * as THREE from '../jsm/three.module.js';
import * as Nodes from '../jsm/nodes/Nodes.js';
import { nodeFrame } from '../jsm/renderers/webgl/nodes/WebGLNodes.js';
window.Nodes = Nodes;
window.nodeFrame = nodeFrame;
let material = new Nodes.MeshStandardNodeMaterial();
object3d.material = material;
nodeFrame.update();
But it doesn’t work because three.js doesn’t have some shader chunk from /src/ folder, which three.module.js has:
So, the question is: can I have both three.js and three.module.js in the same HTML document and only use jsm version to add a single node material?
My app is already pretty large so I’d like to avoid converting everything to modules if possible.