From 427ef0874bd47cec134bbde65228e8dbcaeff07f Mon Sep 17 00:00:00 2001 From: Garux Date: Sat, 8 May 2021 14:15:17 +0300 Subject: [PATCH] * improve ase export compatibility write normals after faces write vertex normals right after their face normal --- plugins/assmodel/plugin.cpp | 2 +- tools/quake3/q3map2/convert_ase.cpp | 38 +++++++++++++---------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/plugins/assmodel/plugin.cpp b/plugins/assmodel/plugin.cpp index 6623d48c..af5c0217 100644 --- a/plugins/assmodel/plugin.cpp +++ b/plugins/assmodel/plugin.cpp @@ -366,7 +366,7 @@ ___q3map2 ?support non vertex anim frames test failed model loading ?is PicoFixSurfaceNormals needed? -shaderlab_terrain.ase great error spam +shaderlab_terrain.ase great error spam, table2.ase split to smaller meshes aiProcess_SplitLargeMeshes is inefficient handle nodes transformations; or aiProcess_PreTransformVertices -> applies them (but also removes animations) diff --git a/tools/quake3/q3map2/convert_ase.cpp b/tools/quake3/q3map2/convert_ase.cpp index 9f42fd2f..8a34c3ef 100644 --- a/tools/quake3/q3map2/convert_ase.cpp +++ b/tools/quake3/q3map2/convert_ase.cpp @@ -93,27 +93,6 @@ static void ConvertSurface( FILE *f, bspModel_t *model, int modelNum, bspDrawSur } fprintf( f, "\t\t}\r\n" ); - /* export vertex normals */ - fprintf( f, "\t\t*MESH_NORMALS\t{\r\n" ); - for ( i = 0; i < ds->numIndexes; i += 3 ) - { - face = ( i / 3 ); - a = bspDrawIndexes[ i + ds->firstIndex ]; - b = bspDrawIndexes[ i + ds->firstIndex + 1 ]; - c = bspDrawIndexes[ i + ds->firstIndex + 2 ]; - Vector3 normal = bspDrawVerts[ a ].normal + bspDrawVerts[ b ].normal + bspDrawVerts[ c ].normal; - if ( VectorNormalize( normal ) != 0 ) { - fprintf( f, "\t\t\t*MESH_FACENORMAL\t%d\t%f\t%f\t%f\r\n", face, normal[ 0 ], normal[ 1 ], normal[ 2 ] ); - } - } - for ( i = 0; i < ds->numVerts; i++ ) - { - v = i + ds->firstVert; - dv = &bspDrawVerts[ v ]; - fprintf( f, "\t\t\t*MESH_VERTEXNORMAL\t%d\t%f\t%f\t%f\r\n", i, dv->normal[ 0 ], dv->normal[ 1 ], dv->normal[ 2 ] ); - } - fprintf( f, "\t\t}\r\n" ); - /* export faces */ fprintf( f, "\t\t*MESH_FACE_LIST\t{\r\n" ); for ( i = 0; i < ds->numIndexes; i += 3 ) @@ -156,6 +135,23 @@ static void ConvertSurface( FILE *f, bspModel_t *model, int modelNum, bspDrawSur } fprintf( f, "\t\t}\r\n" ); + /* export vertex normals */ + fprintf( f, "\t\t*MESH_NORMALS\t{\r\n" ); + for ( i = 0; i < ds->numIndexes; i += 3 ) + { + face = ( i / 3 ); + a = bspDrawIndexes[ i + ds->firstIndex ]; + b = bspDrawIndexes[ i + ds->firstIndex + 1 ]; + c = bspDrawIndexes[ i + ds->firstIndex + 2 ]; + const Vector3 normal = VectorNormalized( bspDrawVerts[ a ].normal + bspDrawVerts[ b ].normal + bspDrawVerts[ c ].normal ); + fprintf( f, "\t\t\t*MESH_FACENORMAL\t%d\t%f\t%f\t%f\r\n", face, normal[ 0 ], normal[ 1 ], normal[ 2 ] ); + for( const auto idx : { a, b, c } ){ + dv = &bspDrawVerts[ idx ]; + fprintf( f, "\t\t\t\t*MESH_VERTEXNORMAL\t%d\t%f\t%f\t%f\r\n", idx, dv->normal[ 0 ], dv->normal[ 1 ], dv->normal[ 2 ] ); + } + } + fprintf( f, "\t\t}\r\n" ); + /* print mesh footer */ fprintf( f, "\t}\r\n" );