// TODO: exploit a better algorithm, use vertex hash table/map. // void mxRenderMesh::WeldVertices() { TArray< mxVertex > newVerts; newVerts.Resize( GetVertexCount() ); for ( u32 triIdx = 0; triIdx < GetTriangleCount(); triIdx++ ) { IndexTriple & rTri = Triangles[ triIdx ]; for ( TIndex i = 0; i < 3; i++ ) { const mxVertex & rCurrVertex = Vertices[ rTri[i] ]; s32 iExistingVertex = -1; for ( TIndex iVtx = 0; iVtx < newVerts.Num(); iVtx++ ) { if ( VectorsEqual( newVerts[ iVtx ].Pos, rCurrVertex.Pos ) ) { iExistingVertex = iVtx; break; } } if ( iExistingVertex != -1 ) { rTri[ i ] = iExistingVertex; } else { rTri[ i ] = newVerts.Append( mxVertex( rCurrVertex ) ); } } } Vertices = newVerts; }
void BatchRenderer::DrawSolidAABB( const rxAABB& box, const FColor& color ) { SetBatchState( this, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ); Unimplemented; #if 0 enum { NUM_CORNERS = 8 }; enum { NUM_INDICES = 6*2*3 }; static const XMVECTOR verts[NUM_CORNERS] = { { -1, -1, -1, 0 }, { 1, -1, -1, 0 }, { 1, -1, 1, 0 }, { -1, -1, 1, 0 }, { -1, 1, -1, 0 }, { 1, 1, -1, 0 }, { 1, 1, 1, 0 }, { -1, 1, 1, 0 } }; static const Index indices[NUM_INDICES]= { // }; enum { NUM_VERTICES = 24 }; enum { NUM_INDICES = 36 }; // Create vertex buffer. mxVertex vertices[ NUM_VERTICES ]; // Fill in the front face vertex data. vertices[0] = mxVertex( Vec3D( -0.5f, -0.5f, -0.5f ), Vec2D( 0.0f, 1.0f ), Vec3D( 0.0f, 0.0f, -1.0f ), Vec3D( 1.0f, 0.0f, 0.0f ) ); vertices[1] = mxVertex( Vec3D( -0.5f, 0.5f, -0.5f ), Vec2D( 0.0f, 0.0f ), Vec3D( 0.0f, 0.0f, -1.0f ), Vec3D( 1.0f, 0.0f, 0.0f ) ); vertices[2] = mxVertex( Vec3D( 0.5f, 0.5f, -0.5f ), Vec2D( 1.0f, 0.0f ), Vec3D( 0.0f, 0.0f, -1.0f ), Vec3D( 1.0f, 0.0f, 0.0f ) ); vertices[3] = mxVertex( Vec3D( 0.5f, -0.5f, -0.5f ), Vec2D( 1.0f, 1.0f ), Vec3D( 0.0f, 0.0f, -1.0f ), Vec3D( 1.0f, 0.0f, 0.0f ) ); // Fill in the back face vertex data. vertices[4] = mxVertex( Vec3D( -0.5f, -0.5f, 0.5f ), Vec2D( 1.0f, 1.0f ), Vec3D( 0.0f, 0.0f, 1.0f ), Vec3D( -1.0f, 0.0f, 0.0f ) ); vertices[5] = mxVertex( Vec3D( 0.5f, -0.5f, 0.5f ), Vec2D( 0.0f, 1.0f ), Vec3D( 0.0f, 0.0f, 1.0f ), Vec3D( -1.0f, 0.0f, 0.0f ) ); vertices[6] = mxVertex( Vec3D( 0.5f, 0.5f, 0.5f ), Vec2D( 0.0f, 0.0f ), Vec3D( 0.0f, 0.0f, 1.0f ), Vec3D( -1.0f, 0.0f, 0.0f ) ); vertices[7] = mxVertex( Vec3D( -0.5f, 0.5f, 0.5f ), Vec2D( 1.0f, 0.0f ), Vec3D( 0.0f, 0.0f, 1.0f ), Vec3D( -1.0f, 0.0f, 0.0f ) ); // Fill in the top face vertex data. vertices[8] = mxVertex( Vec3D( -0.5f, 0.5f, -0.5f ), Vec2D( 0.0f, 1.0f ), Vec3D( 0.0f, 1.0f, 0.0f ), Vec3D( 1.0f, 0.0f, 0.0f ) ); vertices[9] = mxVertex( Vec3D( -0.5f, 0.5f, 0.5f ), Vec2D( 0.0f, 0.0f ), Vec3D( 0.0f, 1.0f, 0.0f ), Vec3D( 1.0f, 0.0f, 0.0f ) ); vertices[10] = mxVertex( Vec3D( 0.5f, 0.5f, 0.5f ), Vec2D( 1.0f, 0.0f ), Vec3D( 0.0f, 1.0f, 0.0f ), Vec3D( 1.0f, 0.0f, 0.0f ) ); vertices[11] = mxVertex( Vec3D( 0.5f, 0.5f, -0.5f ), Vec2D( 1.0f, 1.0f ), Vec3D( 0.0f, 1.0f, 0.0f ), Vec3D( 1.0f, 0.0f, 0.0f ) ); // Fill in the bottom face vertex data. vertices[12] = mxVertex( Vec3D( -0.5f, -0.5f, -0.5f ), Vec2D( 1.0f, 1.0f ), Vec3D( 0.0f, -1.0f, 0.0f ), Vec3D( -1.0f, 0.0f, 0.0f ) ); vertices[13] = mxVertex( Vec3D( 0.5f, -0.5f, -0.5f ), Vec2D( 0.0f, 1.0f ), Vec3D( 0.0f, -1.0f, 0.0f ), Vec3D( -1.0f, 0.0f, 0.0f ) ); vertices[14] = mxVertex( Vec3D( 0.5f, -0.5f, 0.5f ), Vec2D( 0.0f, 0.0f ), Vec3D( 0.0f, -1.0f, 0.0f ), Vec3D( -1.0f, 0.0f, 0.0f ) ); vertices[15] = mxVertex( Vec3D( -0.5f, -0.5f, 0.5f ), Vec2D( 1.0f, 0.0f ), Vec3D( 0.0f, -1.0f, 0.0f ), Vec3D( -1.0f, 0.0f, 0.0f ) ); // Fill in the left face vertex data. vertices[16] = mxVertex( Vec3D( -0.5f, -0.5f, 0.5f ), Vec2D( 0.0f, 1.0f ), Vec3D( -1.0f, 0.0f, 0.0f ), Vec3D( 0.0f, 0.0f, -1.0f ) ); vertices[17] = mxVertex( Vec3D( -0.5f, 0.5f, 0.5f ), Vec2D( 0.0f, 0.0f ), Vec3D( -1.0f, 0.0f, 0.0f ), Vec3D( 0.0f, 0.0f, -1.0f ) ); vertices[18] = mxVertex( Vec3D( -0.5f, 0.5f, -0.5f ), Vec2D( 1.0f, 0.0f ), Vec3D( -1.0f, 0.0f, 0.0f ), Vec3D( 0.0f, 0.0f, -1.0f ) ); vertices[19] = mxVertex( Vec3D( -0.5f, -0.5f, -0.5f ), Vec2D( 1.0f, 1.0f ), Vec3D( -1.0f, 0.0f, 0.0f ), Vec3D( 0.0f, 0.0f, -1.0f ) ); // Fill in the right face vertex data. vertices[20] = mxVertex( Vec3D( 0.5f, -0.5f, -0.5f ), Vec2D( 0.0f, 1.0f ), Vec3D( 1.0f, 0.0f, 0.0f ), Vec3D( 0.0f, 0.0f, 1.0f ) ); vertices[21] = mxVertex( Vec3D( 0.5f, 0.5f, -0.5f ), Vec2D( 0.0f, 0.0f ), Vec3D( 1.0f, 0.0f, 0.0f ), Vec3D( 0.0f, 0.0f, 1.0f ) ); vertices[22] = mxVertex( Vec3D( 0.5f, 0.5f, 0.5f ), Vec2D( 1.0f, 0.0f ), Vec3D( 1.0f, 0.0f, 0.0f ), Vec3D( 0.0f, 0.0f, 1.0f ) ); vertices[23] = mxVertex( Vec3D( 0.5f, -0.5f, 0.5f ), Vec2D( 1.0f, 1.0f ), Vec3D( 1.0f, 0.0f, 0.0f ), Vec3D( 0.0f, 0.0f, 1.0f ) ); // Scale the box. { const Vec3D vScale( length, height, depth ); Matrix4 scaleMat( Matrix4::CreateScale( vScale ) ); Matrix4 invTranspose( scaleMat.Inverse().Transpose() ); for(UINT i = 0; i < NUM_VERTICES; ++i) { vertices[i].xyz = scaleMat.TransformVector( vertices[i].xyz ); vertices[i].N = invTranspose.TransformNormal( vertices[i].N ); vertices[i].T = invTranspose.TransformNormal( vertices[i].T ); } } // Create the index buffer. rxIndex indices[ NUM_INDICES ]; // Fill in the front face index data indices[0] = 0; indices[1] = 1; indices[2] = 2; indices[3] = 0; indices[4] = 2; indices[5] = 3; // Fill in the back face index data indices[6] = 4; indices[7] = 5; indices[8] = 6; indices[9] = 4; indices[10] = 6; indices[11] = 7; // Fill in the top face index data indices[12] = 8; indices[13] = 9; indices[14] = 10; indices[15] = 8; indices[16] = 10; indices[17] = 11; // Fill in the bottom face index data indices[18] = 12; indices[19] = 13; indices[20] = 14; indices[21] = 12; indices[22] = 14; indices[23] = 15; // Fill in the left face index data indices[24] = 16; indices[25] = 17; indices[26] = 18; indices[27] = 16; indices[28] = 18; indices[29] = 19; // Fill in the right face index data indices[30] = 20; indices[31] = 21; indices[32] = 22; indices[33] = 20; indices[34] = 22; indices[35] = 23; newMesh->vertices.SetNum( NUM_VERTICES ); MemCopy( newMesh->vertices.ToPtr(), vertices, sizeof(vertices) ); newMesh->indices.SetNum( NUM_INDICES ); MemCopy( newMesh->indices.ToPtr(), indices, sizeof(indices) ); #endif }