carl.sutton Posted November 3, 2011 Posted November 3, 2011 Hello, I have found that both my own code that calls engine.editor.saveMesh function and the mesh export button in the editor will cause unigine to crash and will fail to make a combined mesh file when trying to export using ObjectMeshDynamic nodes that have more than one surface. Just to make sure I havn't done anything stupid, here is the code I used to make my multi surface dynamic object which then refuses to export to a mesh; ObjectMeshDynamic CreateCylinder(ObjectMeshDynamic mesh,float radius,float height, vec4 texCoord, int stacks = 1,int slices = 32,Mat4 transform = Mat4_identity) { height /= 2.0f; float k = floor(PI * radius / height); Mat4 rtransform = rotation(transform); mesh.addFan(slices + 2); mesh.addVertex(transform * vec3(0.0f,0.0f,height)); mesh.addTexCoord(vec4(0.5f,0.5f,0.0f,0.0f)); mesh.addNormal(rtransform * vec3(0.0f,0.0f,1.0f)); for(int j = 0; j <= slices; j++) { float s = float(j) / slices; float theta = PI2 * s - PI05; vec3 normal = vec3(cos(theta),sin(theta),0.0f); mesh.addVertex(transform * (vec3(0.0f,0.0f,height) + normal * radius)); mesh.addTexCoord(vec4(normal.x * 0.5f + 0.5f,0.5f - normal.y * 0.5f,0.0f,0.0f)); mesh.addNormal(rtransform * vec3(0.0f,0.0f,1.0f)); } mesh.addFan(slices + 2); mesh.addVertex(transform * vec3(0.0f,0.0f,-height)); mesh.addTexCoord(vec4(0.5f,0.5f,0.0f,0.0f)); mesh.addNormal(rtransform * vec3(0.0f,0.0f,-1.0f)); for(int j = 0; j <= slices; j++) { float s = float(j) / slices; float theta = PI2 * s - PI; vec3 normal = vec3(sin(theta),cos(theta),0.0f); mesh.addVertex(transform * (vec3(0.0f,0.0f,-height) + normal * radius)); mesh.addTexCoord(vec4(normal.x * 0.5f + 0.5f,normal.y * 0.5f + 0.5f,0.0f,0.0f)); mesh.addNormal(rtransform * vec3(0.0f,0.0f,-1.0f)); } mesh.addSurface("end"); //SURFACE 1 int num_vertex = mesh.getNumVertex(); for(int i = 0; i < stacks; i++) { for(int j = 0; j < slices; j++) { int offset = num_vertex + (slices + 1) * i + j; mesh.addIndex(offset + 0); mesh.addIndex(offset + slices + 1); mesh.addIndex(offset + 1); mesh.addIndex(offset + slices + 2); mesh.addIndex(offset + 1); mesh.addIndex(offset + slices + 1); } } for(int i = 0; i <= stacks; i++) { float t = float(i) / stacks; for(int j = 0; j <= slices; j++) { float s = float(j) / slices; float theta = PI2 * s - PI05; vec3 normal = vec3(cos(theta),sin(theta),0.0f); mesh.addVertex(transform * (vec3(0.0f,0.0f,height - height * t * 2.0f) + normal * radius)); //mesh.addTexCoord(vec4(s * k,t,0.0f,0.0f)); mesh.addTexCoord(vec4(texCoord.x,lerp(texCoord.y, texCoord.w, t),0.0f,0.0f)); //FIXME texcoords are incorrect mesh.addNormal(rtransform * normal); } } mesh.addSurface("body"); //SURFACE 2 mesh.updateBounds(); mesh.updateTangents(); return mesh; } }; I have tried the above code without making it multi surfaced and the problem does not occur. It will be much appreciated if a fix could be found for this as I would prefer not to have to make a seperate mesh for each surface or use some other workaround that converts dynamic to a node type that will export. Thanks
Recommended Posts