Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add normals to a MeshBuilder<VertexPosition> #25

Closed
tongbong opened this issue Sep 24, 2019 · 2 comments
Closed

Add normals to a MeshBuilder<VertexPosition> #25

tongbong opened this issue Sep 24, 2019 · 2 comments

Comments

@tongbong
Copy link

Hello and thank you for this library,

I am trying to convert a STL file into a GLTF file.

So I create a mesh like this :

            var mesh = new MeshBuilder<VertexPosition>();
            var prim = mesh.UsePrimitive(material, 3);

            foreach (var stlMesh in reader.ReadFile())
            {
                var vertice1 = VERTEX.Create(new System.Numerics.Vector3(stlMesh.vert1.x, stlMesh.vert1.y, stlMesh.vert1.z));
                var vertice2 = VERTEX.Create(new System.Numerics.Vector3(stlMesh.vert2.x, stlMesh.vert2.y, stlMesh.vert2.z));
                var vertice3 = VERTEX.Create(new System.Numerics.Vector3(stlMesh.vert3.x, stlMesh.vert3.y, stlMesh.vert3.z));
                prim.AddTriangle(vertice1, vertice2, vertice3);
            }

So far so good, the conversion is ok and I am able to see the 3D object in a gltf viewer (https://gltf-viewer.donmccurdy.com/).

But now I would like to add normals to the mesh and I am stuck here.
Is there any way to do it?

@vpenades
Copy link
Owner

Yes, you can use VertexPositionNormal instead of VertexPosition

If you check the Geometry/VertexTypes namespace, you'll see there's many vertex combinations already defined.

Furthermore, if at some point you need vertex colors or texture coodinates, you define them like this:

new MeshBuilder<VertexPositionNormal, VertexColor1Texture1>();

@tongbong
Copy link
Author

Yes, I saw that, but I came to understand it just now!
Thanks for the quick answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants