Hello all!
I’m trying to use rhino.compute and rhino3dm.js to create a three.js mesh from a rhino mesh. This works fine, but I haven’t figured out how to include the materials from the rhino mesh to the three mesh yet.
Here is the relevant part of the code that I’m using at the moment:
_threeMaterial = new THREE.MeshNormalMaterial() //basic material
let mesh = rhino.DracoCompression.decompressBase64String(data) //data is the draco compressed mesh
let threeMesh = meshToThreejs(mesh, _threeMaterial)
//conversion function
function meshToThreejs (mesh, material) {
let loader = new THREE.BufferGeometryLoader()
var geometry = loader.parse(mesh.toThreejsJSON())
return new THREE.Mesh(geometry, material
}
As I see it there’s two parts to the equation here.
- To acquire the color information from the rhino mesh in the js environment
- To convert the rhino mesh material (rgb values in my case) into
THREE.MeshBasicMaterials()
or similar and apply it to the mesh.
For the first part I’ve tried to store the data in the compressed mesh, but it seems like some of the color information gets lost in the process even when I’m using IncludeVertexColors = true
in the DracoCompressionOptions when compressing the mesh. For certain colors it works but other times it is completely off (see image below).
So I was thinking that maybe it could be a good idea to just output the list of vertex colors as a RH_OUT:
parameter instead of saving it as part of the compressed mesh. Is this a good idea or am I missing something?
For the second part I have no clue how to do it. My initial ideas was to just loop through every item in the list of vertex colors and create a ‘new THREE.MeshBasicMaterials(vertexColors[i])’ from it that I then apply to the mesh. Do you have any suggestions here?
Thank you!
Best regards,
Erik