vHavokDisplayGeometry::vHavokDisplayGeometry(hkDisplayGeometry* geometry, const hkTransform &transform, hkUlong id, int tag) { // Set id m_ID = id; // Create mesh instance if (geometry->getGeometry() == NULL) geometry->buildGeometry(); // Create mesh buffer VisMBVertexDescriptor_t desc; desc.m_iStride = sizeof(SimpleMesh_t); desc.m_iPosOfs = offsetof(SimpleMesh_t,pos); UINT iVertices = geometry->getGeometry()->m_vertices.getSize(); UINT iTriangles = geometry->getGeometry()->m_triangles.getSize(); VisMeshBuffer_cl *pMesh = new VisMeshBuffer_cl(); // Copy vertices pMesh->AllocateVertices(desc, iVertices); SimpleMesh_t *pVertex = (SimpleMesh_t *)pMesh->LockVertices(VIS_LOCKFLAG_DISCARDABLE); for (UINT i = 0; i < iVertices; i++, pVertex++) { hkVector4 vPos; vPos.setMul(geometry->getGeometry()->m_vertices[i], vHavokConversionUtils::GetHavok2VisionScaleSIMD()); vPos.store<3,HK_IO_NATIVE_ALIGNED>(&pVertex->pos[0]); } pMesh->UnLockVertices(); // Copy indices pMesh->AllocateIndexList(iTriangles*3); unsigned short *pIndex = (unsigned short *)pMesh->LockIndices(VIS_LOCKFLAG_DISCARDABLE); for (UINT i = 0; i < iTriangles; i++, pIndex+=3) { pIndex[0] = geometry->getGeometry()->m_triangles[i].m_a; pIndex[1] = geometry->getGeometry()->m_triangles[i].m_b; pIndex[2] = geometry->getGeometry()->m_triangles[i].m_c; } pMesh->UnLockIndices(); pMesh->SetPrimitiveType(VisMeshBuffer_cl::MB_PRIMTYPE_INDEXED_TRILIST ); // Create mesh instance m_spMeshInstance = new VisMeshBufferObject_cl(pMesh); // Mesh instance created if (m_spMeshInstance == NULL) return; // Apply highlighting shader m_spMeshInstance->SetTechnique(CreateHighlightEffect(VColorRef(55, 255, 55))); // Set transform. Add the transform of the actual shape to the transform of the Vision mesh. // This is needed for shapes that come from HKT files where they can have custom pivots. hkTransform finalTransform = transform; finalTransform.setMulEq(geometry->getTransform()); vHavokConversionUtils::PhysTransformToVisMatVecWorld(finalTransform, m_vRot, m_vPos); m_spMeshInstance->SetUseEulerAngles(FALSE); m_spMeshInstance->SetPosition(m_vPos); m_spMeshInstance->SetRotationMatrix(m_vRot); m_spMeshInstance->SetVisible(false); m_spMeshInstance->SetObjectFlag(VObjectFlag_AutoDispose); }