Jump to content

How to build a mesh manually?


photo

Recommended Posts

I try to create a mesh manually, and saved the mesh, but it can't be display in the scene. I can only see the outline of the mesh which I create.

this my c# code:

        Mesh mesh = new Mesh();

        mesh.AddSurface("0");

        mesh.AddVertex(new vec3(0.0f, 0.0f, 0.0f), 0);
        mesh.AddVertex(new vec3(0.0f, 0.0f, 1.0f), 0);
        mesh.AddVertex(new vec3(0.0f, 1.0f, 0.0f), 0);
        mesh.AddVertex(new vec3(0.0f, 1.0f, 1.0f), 0);

        mesh.AddVertex(new vec3(-1.0f, 0.0f, 0.0f), 0);
        mesh.AddVertex(new vec3(-1.0f, 0.0f, 1.0f), 0);
        mesh.AddVertex(new vec3(-1.0f, 1.0f, 0.0f), 0);
        mesh.AddVertex(new vec3(-1.0f, 1.0f, 1.0f), 0);

        mesh.AddIndex(0, 0);
        mesh.AddIndex(1, 0);
        mesh.AddIndex(2, 0);

        mesh.AddIndex(3, 0);
        mesh.AddIndex(2, 0);
        mesh.AddIndex(1, 0);

        mesh.AddIndex(4, 0);
        mesh.AddIndex(5, 0);
        mesh.AddIndex(6, 0);

        mesh.AddIndex(7, 0);
        mesh.AddIndex(6, 0);
        mesh.AddIndex(5, 0);

        mesh.AddIndex(7, 0);
        mesh.AddIndex(3, 0);
        mesh.AddIndex(6, 0);

        mesh.AddIndex(2, 0);
        mesh.AddIndex(6, 0);
        mesh.AddIndex(3, 0);

        mesh.AddIndex(5, 0);
        mesh.AddIndex(1, 0);
        mesh.AddIndex(7, 0);

        mesh.AddIndex(3, 0);
        mesh.AddIndex(7, 0);
        mesh.AddIndex(1, 0);

        mesh.AddIndex(0, 0);
        mesh.AddIndex(1, 0);
        mesh.AddIndex(4, 0);

        mesh.AddIndex(5, 0);
        mesh.AddIndex(4, 0);
        mesh.AddIndex(1, 0);

        mesh.AddIndex(4, 0);
        mesh.AddIndex(6, 0);
        mesh.AddIndex(0, 0);

        mesh.AddIndex(2, 0);
        mesh.AddIndex(0, 0);
        mesh.AddIndex(6, 0);

        mesh.CreateNormals(0);

        mesh.CreateTangents();

        ObjectMeshStatic om = new ObjectMeshStatic(mesh);
        om.WorldPosition = new vec3(0, 0, 1);
        om.SetMaterial(mat, 0);
        om.SaveMesh("test.mesh");
        mesh.Clear();

It's so strange that I can see it in the editor preview panel, but in the scene I can't see it except the outline.

1.png.5d7cfe40cf3aa25ddc8f00ece6bd9960.png2.png.e2c96ff12ea9ac930cd1ee3c1040599f.png

please point out of the mistake of my code, thanks!

 

Link to comment
  • 1 year later...
×
×
  • Create New...