diff --git a/engine/core/subsystem/PhysicsSystem.cpp b/engine/core/subsystem/PhysicsSystem.cpp index 80fa1a07..409d3e49 100644 --- a/engine/core/subsystem/PhysicsSystem.cpp +++ b/engine/core/subsystem/PhysicsSystem.cpp @@ -490,23 +490,42 @@ void PhysicsSystem::createMeshShape3D(Entity entity, MeshComponent& mesh){ if (body){ - JPH::VertexList jvertices; - int verticesize = int(mesh.buffer.getCount()); - jvertices.resize(verticesize); - Attribute* attVertex = mesh.buffer.getAttribute(AttributeType::POSITION); - for (int i = 0; i < verticesize; i++){ - Vector3 vertice = mesh.buffer.getVector3(attVertex, i); - jvertices[i] = JPH::Float3(vertice.x, vertice.y, vertice.z); + std::map buffers; + + if (mesh.buffer.getSize() > 0){ + buffers["vertices"] = &mesh.buffer; + } + if (mesh.indices.getSize() > 0){ + buffers["indices"] = &mesh.indices; + } + for (int i = 0; i < mesh.numExternalBuffers; i++){ + buffers[mesh.eBuffers[i].getName()] = &mesh.eBuffers[i]; } JPH::IndexedTriangleList jindices; - int indicesize = int(mesh.indices.getCount() / 3); - jindices.resize(indicesize); - Attribute* attIndex = mesh.indices.getAttribute(AttributeType::INDEX); - for (int i = 0; i < indicesize; i++){ - for (int j = 0; j < 3; j++){ - uint16_t indice = mesh.indices.getUInt16(attIndex, (3*i)+j); - jindices[i].mIdx[j] = indice; + JPH::VertexList jvertices; + + for (auto const& buf : buffers){ + if (buf.second->isRenderAttributes()) { + if (buf.second->getType() == BufferType::INDEX_BUFFER){ + int indicesize = int(buf.second->getCount() / 3); + jindices.resize(indicesize); + Attribute* attIndex = buf.second->getAttribute(AttributeType::INDEX); + for (int i = 0; i < indicesize; i++){ + for (int j = 0; j < 3; j++){ + uint16_t indice = buf.second->getUInt16(attIndex, (3*i)+j); + jindices[i].mIdx[j] = indice; + } + } + }else{ + int verticesize = int(buf.second->getCount()); + jvertices.resize(verticesize); + Attribute* attVertex = buf.second->getAttribute(AttributeType::POSITION); + for (int i = 0; i < verticesize; i++){ + Vector3 vertice = buf.second->getVector3(attVertex, i); + jvertices[i] = JPH::Float3(vertice.x, vertice.y, vertice.z); + } + } } }