Rhino3dm file.3dm not an m_archive when adding 6 or more vertices to mesh

Hi guys,

I’m trying to create a .3dm file from a set of vertices and faces and ran into a problem where the file gave the “file.3dm is not a Rhino m_archive” error when opening in Rhino. Upon further investigation it seems as if this error occurs only when creating a mesh and adding 6 or more vertices with the mesh.vertices().add() function. It’s probably worth noting that sending the resulting file to a rhino.compute instance successfully produces an output, making me guess that there could be an issue in the filewrite.

I used the following code:

rhino3dm().then((r) => {
  rhino = r;
  let doc = new rhino.File3dm();
  let mesh = new rhino.Mesh();
  
  let vert0 = mesh.vertices().add(1.0,1.0,1.0);
  let vert1 = mesh.vertices().add(2.0,1.0,1.0);
  let vert2 = mesh.vertices().add(3.0,1.0,1.0);
  let vert3 = mesh.vertices().add(4.0,1.0,1.0);
  let vert4 = mesh.vertices().add(2.0,1.0,1.0);
  let vert5 = mesh.vertices().add(6.0,1.0,1.0);
  let vert6 = mesh.vertices().add(7.0,1.0,1.0);

  doc.objects().add(mesh, null);
  fs.writeFileSync(__dirname + '/mesh.3dm', doc.toByteArray());
  commonSolve(inputs);
})

and these dependencies:
“compute-rhino3d”: “^0.13.0-beta”,
“rhino3dm”: “^0.14.0”

When you run it with vert5 & 6 commented out, it should result in a perfectly fine file, but with 5 and/or 6 active, your file should not be usable.

It’s my first post here, so I hope I explained everything clearly enough!

Hi @williambvl.franck,

I don’t see where you’ve added any faces.

– Dale

I left that bit out since adding or not adding faces appeared to be irrelevant to whether or not the file was valid. I attempted both with adding a single face through “mesh.faces().addFace(0,1,2);” as well as filling them out from an array through a for loop.
Is there perhaps any reason related to faces that could cause the file to become unusable after adding 6 or more vertices?

Without a sample that I can run here, I can’t really speculate.

Does this work any better?

function createMeshBox() {
  var mesh = new rhino.Mesh();
  // add vertices
  mesh.vertices().add(0.5,  0.5,  0.5);
  mesh.vertices().add(0.5, 0.5, -0.5);
  mesh.vertices().add(0.5, -0.5, 0.5);
  mesh.vertices().add(0.5, -0.5, -0.5);
  mesh.vertices().add(-0.5, 0.5, 0.5);
  mesh.vertices().add(-0.5, 0.5, -0.5);
  mesh.vertices().add(-0.5, -0.5, 0.5);
  mesh.vertices().add(-0.5, -0.5, -0.5);
  // add faces
  mesh.faces().addFace(0, 1, 5, 4);
  mesh.faces().addFace(0, 4, 6, 2);
  mesh.faces().addFace(0, 2, 3, 1);
  mesh.faces().addFace(7, 3, 2, 6);
  mesh.faces().addFace(7, 6, 4, 5);
  mesh.faces().addFace(7, 5, 1, 3);
  // finish...
  mesh.normals().computeNormals();
  return mesh;
}

– Dale

This sounds a lot like this bug…

Sadly not, it’s still giving me the “not a rhino m_archive” error when I open the resulting file.

and as for the bug that as linked, looks like it could indeed be a related issue…