I’m trying to export my threejs mesh (imported from obj file) to be used inside rhino. I’m using rhino3dm for that however the file I receive is corrupted. My procedure is:
Import the .OBJ file onto ThreeJS mesh
Join all child mesh geometries onto single one one (this step can be ommited, it works properly)
Export the combined mesh into .obj file (works correctly)
Create new rhino mesh using rhino.Mesh.createFromThreejsJSON({ data: exportGeometry })
Export this to the new 3dm file using doc = rhino.File3dm(); doc.objects().add(mesh, null); fs.writeFileSync('name.3dm', doc.toByteArray());
The result is that rhino cannot open this and says that the file is broken (not an m_archive format). What am I doing wrong?
I’m using rhino3dm@0.13.0 version, nodejs@12 and three.js@r0.125.2export_rhino.txt (908 Bytes)
@gorny.adrian the rhino.Mesh.createFromThreejsJSON() method takes a THREE.BufferGeometry as the input, not the obj format. After you import the obj with threejs, the resulting BufferGeometry from the THREE.Mesh object is what you want.
Yeah I already know that and in the attached code you can see we’re using mesh.geometry inside. Perhaps our call is wrong? We use rhino.Mesh.createFromThreejsJSON({ data: mesh.geometry }) to simplify it.
This sample in node works for me with a different file: src
Not sure how you referenced three and the obj loader, so I took a crack at it. Maybe there is a better way?
Well I’ve used ESM imports for that. Perhaps the issue is that I’m not actually rendering the scene anywhere and calculations/updates are not made. I’ll clean-up the script, take another look on that and if it won’t work I’ll create a reproducible case.
Ok so @fraguada I’ve added the sphere code and it magically started working. What’s more I’ve also tried that with adding an arc and surprise - it also starts working. Performed test that uses deleteItem afterward and the error returns. So it seems that the only case it’s working is when you have normal mesh and some kind of nurb-based stuff like arc, circle, sphere or whatever.
After analyzing the code underneath from WASM lib source I’d guess that it has to do something with NURBs actually. Whenever you add an object that bases upon NURBs instead of standard geometry (I hope it makes any sense to you), all other meshes starts working. Not sure if it helps you in any way tho.
Yes, but the example I link to has an obj, and converts just fine. Like I mention, we have another case where we’ve seen this behaviour, so there is a bug we need to track down and fix.