sergey.shandar Posted June 20, 2012 Posted June 20, 2012 Hi, I'm generating a trackbed and rails for rail track using ObjectMeshDynamic. So I use such functions as addVertex, addTextCoords. After that I call update functions for all generated meshes in such order: mesh.updateIndices(); mesh.updateSurfaces(); mesh.updateBounds(); mesh.updateNormals(); mesh.updateTangents(); mesh.flush(); And the result looks not as I would expect, see the attached screenshoot. V is continuous on rails but you can still see the breaks. I suspect it something related with normals/tangents. The question is how should I calculate properly normals/tangents for my rails?
Guest shane.ploenges Posted June 20, 2012 Posted June 20, 2012 Hey Sergey.. maybe make a tick box "make it good" ;).. sorry, could not resist :)
ulf.schroeter Posted June 20, 2012 Posted June 20, 2012 So I use such functions as addVertex, addTextCoords. Dumb question: do you also specify calculated vertex normals via addNormal() ? Also normal length is always 1 ? Also by saving your ObjectMeshDynamic as static mesh file you can use ResourceEditorx86.exe to view your normals. 1
sergey.shandar Posted June 21, 2012 Author Posted June 21, 2012 I did call addNormal but it looks like it has no effect if you later call updateNormals(), I've tried different normals, even constants such as dvec(0, 0, 1). It looks like updateNormals() recalculate normals. As far as I understood, there are also no functions addTangents(), clearNormals().
ulf.schroeter Posted June 21, 2012 Posted June 21, 2012 Hm, the following code excerpt works for us just with updateBounds() and updateTangents(), maybe helpful /** * create connector mesh * * @param event event data record */ void createConnector( Event event ) { .... .... ObjectMeshDynamic mesh = batch.mesh(); mesh.addStrip( vertexCount ); mesh.addVertex( xyzStart * 1.0025f ); mesh.addNormal( xyzStart ); mesh.addTexCoord( vec4(0.0f, 0.5f, timestamp, 0.0f) ); for( int i=0; i<=segmentCount; i++ ) { // create segment vertices vec3 xyzSegmentNormal = rotate( xyzNormal, segmentAngle ) * xyzStart; vec3 xyzSegmentCenter = xyzSegmentNormal * 1.0025f; vec3 xyzSegmentWidth = xyzNormal * segmentWidth * DEG2RAD; vec3 xyzSegmentLeft = xyzSegmentCenter - xyzSegmentWidth; vec3 xyzSegmentRight = xyzSegmentCenter + xyzSegmentWidth; mesh.addVertex( xyzSegmentLeft ); mesh.addNormal( xyzSegmentNormal ); mesh.addTexCoord( vec4( segmentTexCoord, 0.0f, timestamp, 0.0f) ); mesh.addVertex( xyzSegmentRight ); mesh.addNormal( xyzSegmentNormal ); mesh.addTexCoord( vec4( segmentTexCoord, 1.0f, timestamp, 0.0f) ); // next segment values segmentAngle += segmentAngleStep; segmentWidth += segmentWidthStep; segmentTexCoord += segmentTexCoordStep; } mesh.addVertex( xyzEnd * 1.0025f ); mesh.addNormal( xyzEnd ); mesh.addTexCoord( vec4(total_angle * texcoord_per_angle, 0.5f, timestamp, 0.0f) ); // update mesh mesh.updateBounds(); mesh.updateTangents(); mesh.flush(); .... ... } 1
unclebob Posted June 21, 2012 Posted June 21, 2012 You're right, updateNormals() will recalculate normals even if you set them before. As Ulf said, you can save your dynamic mesh and open it in resource editor for troubleshooting. Also, updateIndices() will optimize your mesh, so it'll have optimized vertex buffer with less vertices. Don't call this if you want preserve your initial vertices. 1
Recommended Posts