Jump to content

how to use addTriangles


photo

Recommended Posts

i want to load obj file which is made by maya.

and i use the addTriangles to load vertices there are a lot block on the surface.

the left one is smooth using index but cannot add texture because vertices_size and texcoords_size is not equal.

 

left 

object->allocateIndices(indices_size);
object->allocateVertex(vertices_size);

 for (int i = 0; i < vertices_size; i++){
        float x = mesh->attrib.vertices[3 * i + 0];
        float y = mesh->attrib.vertices[3 * i + 1];
       float z = mesh->attrib.vertices[3 * i + 2];

       object->addVertex(vec3(x, y, z));
 }
  for (int i = 0; i < shapes_size; i++){
       size_t index_offset = 0;
         for (size_t f = 0; f < mesh->shapes.mesh.num_face_vertices.size(); f++) {
              size_t fnum = mesh->shapes.mesh.num_face_vertices[f];
                for (size_t v = 0; v < fnum; v++) {
                   tinyobj::index_t idx = mesh->shapes.mesh.indices[index_offset + v];
                    object->addIndex(idx.vertex_index);
                    }
                    index_offset += fnum;
                }
            }

right

int total_indices = 0;
            for (int i = 0; i < mesh->shapes.size(); i++){
                total_indices += mesh->shapes.mesh.indices.size();
            }
            object->addTriangles(total_indices / 3);      
                    for (size_t v = 0; v < fv; v++) {
                        tinyobj::index_t idx = mesh->shapes.mesh.indices[index_offset + v];
                        tinyobj::real_t vx = mesh->attrib.vertices[3 * idx.vertex_index + 0];
                        tinyobj::real_t vy = mesh->attrib.vertices[3 * idx.vertex_index + 1];
                        tinyobj::real_t vz = mesh->attrib.vertices[3 * idx.vertex_index + 2];
                        object->addVertex(vec3(vx, vy, vz));

                        tinyobj::real_t tx = mesh->attrib.texcoords[2 * idx.texcoord_index + 0];
                        tinyobj::real_t ty = 1.0f - mesh->attrib.texcoords[2 * idx.texcoord_index + 1];
                        object->addTexCoord(vec4(tx, ty, 0.0f, 0.0f));
                    }
                    index_offset += fv;
                }
            }

TIM截图20180424144219.jpg

Edited by shichao
Link to comment

Hi!

There is a meshimport tool available with SDK (<SDK>/bin/meshimport_**.exe) that can convert obj files to unigine .mesh format. Can you check that you have the same results with it? You also can use ResourceEditor to smooth the surface normals.

Please, don't hesitate to contact our Chinese support team via china-support@unigine.com. I believe they can help you much faster :)

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

i add the index it works

but i dont know how to add normals in the ObjectMeshDynamicPtr object

i only found addTangent in ObjectMeshDynamicPtr

not sure how to transfrom normal to tangent?

Link to comment
×
×
  • Create New...