-
Hi, I'm trying to use this project to perform boolean operations on 3D models rendered in three.js. The boolean operations work perfectly, it's absolutely great! I've tried to follow the three.js example (and the editor) and I've got to the point where I can render models but the lighting is off, and I suspect something is wrong in the way I convert the manifold mesh to the three.js geometry. Here's an example, where the cube on the right is from a Screen.Recording.2024-03-19.at.23.24.09.movThe light points to the origin (between the cube) from the above. This is the code I'm using: const material = new THREE.MeshLambertMaterial({
color: 0x00ddff,
});
const { Manifold: { cube } } = await ManifoldModule;
const geom1 = mesh2geometry(cube(20));
geom1.computeVertexNormals();
const mesh1 = new THREE.Mesh(geom1, material);
mesh1.position.x = -20;
scene.add(mesh1);
const geom2 = new THREE.BoxGeometry( 20, 20, 20 );
const mesh2 = new THREE.Mesh(geom2, material);
mesh2.position.x = 20;
mesh2.position.y = 10;
mesh2.position.z = 10;
scene.add(mesh2); The This is the translation code I stole from one of the examples but I suspect something got lost in translation: export function mesh2geometry(manifold: Manifold): THREE.BufferGeometry {
const mesh = manifold.getMesh();
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(mesh.vertProperties, 3),
);
geometry.setIndex(new THREE.BufferAttribute(mesh.triVerts, 1));
return geometry;
} I'm pretty sure I fixed this exact issue many times in OpenGL many years ago which is terribly frustrating! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
I'm not sure what Three's As for the translation code, you'll notice that it doesn't save normals at all - hence black. I'm just in the process of building some APIs into Manifold to help handle normals, see |
Beta Was this translation helpful? Give feedback.
-
Thank you for the quick answer!
Yup, makes sense!
That's a weird coincidence, but I'll take it! Is this ready to use or should I wait a bit for further work/polishing/release? I'm happy to do some alpha testing if necessary if you give me the nix invocations to get a library I can just
Here I get a bit lost. Would I not be using this new API you are developing to compute normals in Manifold to then pass to Three.js (i.e. the other way around)? And out of curiosity, what is the fundamental difference between what I'm doing here and these beautiful normals you got going in the editor? Even when using |
Beta Was this translation helpful? Give feedback.
I'm not sure what Three's
computeVertexNormals
is doing, but it's probably not what you want - I'd guess they're just computing average normals for each vert, thus giving a weirdly smoothed appearance.As for the translation code, you'll notice that it doesn't save normals at all - hence black. I'm just in the process of building some APIs into Manifold to help handle normals, see
ComputeNormals()
in #771. You'll need to use our properties API, which is agnostic to what kind of data you store in it, so you'll need to choose some channels for normals and then read them into Three.js. You can also copy normals from Three.js into amesh
to pass to Manifold.