Problem creating custom mesh from txt files

Hey! I am having some trouble creating a custom mesh from txt files. In the playground linked at the bottom of this post you will see that I load in two txt files, one containing vertices of the mesh and the other containing the indices of the faces which each vertex belongs to. We are able to load the txt files into Blender, where it looks correct, and export it as an stl file, which I have also loaded into the playground. The stl file loads as expected and this is how we want the mesh to look when created using the txt files.

As you can see there are two obvious problems:

  • The first is that vertices are arranged in a different pattern than the stl file. They might be loading in in the wrong order, but I am not sure about that. This also might be causing the second issue.
  • The second is that the meshes are not complete. We believe it might be a problem with the material but are not too sure how to go about fixing this.

Also, we believe that the coordinates of the txt file vertices are correct, and it is possible that the stl file coordinates are flipped in some way. (ex: xzy instead of xyz).

Any help would be greatly appreciated, thanks so much!

Playground: https://playground.babylonjs.com/#EQ46H3#4

Edit: the playground now has two stl files. The first (which is uncommented) is an stl file created using numpy-stl · PyPI
The second (which is currently commented) was created by exporting from Blender.

This is what the mesh looks like in Blender:

1 Like

Hi,

I guess some of the faces have incorrect ordering of indices. I.e. You are actually showing the back of the faces. You need to change the order of the indices for these faces.

Take this PG as example. It has two triangles. One facing front, and the other facing back. You can rotate the camera to see the triangle that is back facing.
https://playground.babylonjs.com/#VKBJN#8

If you modified the order of indices (see line 16), you can see the back facing triangle is now also front facing.
https://playground.babylonjs.com/#VKBJN#1433

This is a screenshot I took from your PG. I moved the camera inside the brain and look out. The missing faces look solid when look inside out.

2 Likes

The winding is wrong indeed, you can fix it by inverting index 1 and index 2 for each triangles:

https://playground.babylonjs.com/#EQ46H3#6

2 Likes