Skip to content

Commit

Permalink
Mesh shape 3D creation improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardodoria committed Oct 27, 2023
1 parent b63b81d commit 2c70d65
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions engine/core/subsystem/PhysicsSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, Buffer*> 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);
}
}
}
}

Expand Down

0 comments on commit 2c70d65

Please sign in to comment.