mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 07:37:20 +02:00
don't forget to use the transform of child shapes
This commit is contained in:
parent
1e95e489cb
commit
06d40afeac
1 changed files with 53 additions and 49 deletions
|
@ -20,67 +20,71 @@
|
||||||
|
|
||||||
float verts[3 * MAX_HULL_POINTS];
|
float verts[3 * MAX_HULL_POINTS];
|
||||||
|
|
||||||
void copyHullToMesh(const btShapeHull& hull, model::MeshPointer mesh) {
|
void copyShapeToMesh(const btTransform& transform, const btConvexShape* shape, model::MeshPointer mesh) {
|
||||||
if ((bool)mesh) {
|
assert((bool)mesh);
|
||||||
const uint32_t* hullIndices = hull.getIndexPointer();
|
assert(shape);
|
||||||
int32_t numIndices = hull.numIndices();
|
|
||||||
assert(numIndices <= 6 * MAX_HULL_POINTS);
|
|
||||||
|
|
||||||
{ // new part
|
btShapeHull hull(shape);
|
||||||
model::Mesh::Part part;
|
const btScalar MARGIN = 0.0f;
|
||||||
part._startIndex = mesh->getIndexBuffer().getNumElements();
|
hull.buildHull(MARGIN);
|
||||||
part._numIndices = (model::Index)numIndices;
|
|
||||||
part._baseVertex = mesh->getVertexBuffer().getNumElements();
|
|
||||||
|
|
||||||
gpu::BufferView::Size numBytes = sizeof(model::Mesh::Part);
|
const uint32_t* hullIndices = hull.getIndexPointer();
|
||||||
const gpu::Byte* data = reinterpret_cast<const gpu::Byte*>(&part);
|
int32_t numIndices = hull.numIndices();
|
||||||
mesh->getPartBuffer()._buffer->append(numBytes, data);
|
assert(numIndices <= 6 * MAX_HULL_POINTS);
|
||||||
|
|
||||||
|
{ // new part
|
||||||
|
model::Mesh::Part part;
|
||||||
|
part._startIndex = mesh->getIndexBuffer().getNumElements();
|
||||||
|
part._numIndices = (model::Index)numIndices;
|
||||||
|
part._baseVertex = mesh->getVertexBuffer().getNumElements();
|
||||||
|
|
||||||
|
gpu::BufferView::Size numBytes = sizeof(model::Mesh::Part);
|
||||||
|
const gpu::Byte* data = reinterpret_cast<const gpu::Byte*>(&part);
|
||||||
|
mesh->getPartBuffer()._buffer->append(numBytes, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
{ // new vertices
|
||||||
|
const btVector3* hullVertices = hull.getVertexPointer();
|
||||||
|
int32_t numVertices = hull.numVertices();
|
||||||
|
assert(numVertices <= MAX_HULL_POINTS);
|
||||||
|
for (int32_t i = 0; i < numVertices; ++i) {
|
||||||
|
btVector3 transformedPoint = transform * hullVertices[i];
|
||||||
|
memcpy(transformedPoint.m_floats, verts + 3 * i, 3 * sizeof(float));
|
||||||
|
//data[0] = transformedPoint.getX();
|
||||||
|
//data[1] = transformedPoint.getY();
|
||||||
|
//data[2] = transformedPoint.getZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // new vertices
|
gpu::BufferView::Size numBytes = sizeof(float) * (3 * numVertices);
|
||||||
const btVector3* hullVertices = hull.getVertexPointer();
|
const gpu::Byte* data = reinterpret_cast<const gpu::Byte*>(verts);
|
||||||
int32_t numVertices = hull.numVertices();
|
mesh->getVertexBuffer()._buffer->append(numBytes, data);
|
||||||
assert(numVertices <= MAX_HULL_POINTS);
|
}
|
||||||
for (int32_t i = 0; i < numVertices; ++i) {
|
|
||||||
float* data = verts + 3 * i;
|
|
||||||
data[0] = hullVertices[i].getX();
|
|
||||||
data[1] = hullVertices[i].getY();
|
|
||||||
data[2] = hullVertices[i].getZ();
|
|
||||||
}
|
|
||||||
|
|
||||||
gpu::BufferView::Size numBytes = sizeof(float) * (3 * numVertices);
|
{ // new indices
|
||||||
const gpu::Byte* data = reinterpret_cast<const gpu::Byte*>(verts);
|
gpu::BufferView::Size numBytes = (gpu::BufferView::Size)(sizeof(uint32_t) * hull.numIndices());
|
||||||
mesh->getVertexBuffer()._buffer->append(numBytes, data);
|
const gpu::Byte* data = reinterpret_cast<const gpu::Byte*>(hullIndices);
|
||||||
}
|
mesh->getIndexBuffer()._buffer->append(numBytes, data);
|
||||||
|
|
||||||
{ // new indices
|
|
||||||
gpu::BufferView::Size numBytes = (gpu::BufferView::Size)(sizeof(uint32_t) * hull.numIndices());
|
|
||||||
const gpu::Byte* data = reinterpret_cast<const gpu::Byte*>(hullIndices);
|
|
||||||
mesh->getIndexBuffer()._buffer->append(numBytes, data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
model::MeshPointer createMeshFromShape(const btCollisionShape* shape) {
|
model::MeshPointer createMeshFromShape(const btCollisionShape* shape) {
|
||||||
if (!shape) {
|
|
||||||
return std::make_shared<model::Mesh>();
|
|
||||||
}
|
|
||||||
model::MeshPointer mesh = std::make_shared<model::Mesh>();
|
model::MeshPointer mesh = std::make_shared<model::Mesh>();
|
||||||
int32_t shapeType = shape->getShapeType();
|
if (shape) {
|
||||||
if (shapeType == (int32_t)COMPOUND_SHAPE_PROXYTYPE) {
|
int32_t shapeType = shape->getShapeType();
|
||||||
const btScalar MARGIN = 0.0f;
|
if (shapeType == (int32_t)COMPOUND_SHAPE_PROXYTYPE) {
|
||||||
const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(shape);
|
const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(shape);
|
||||||
int32_t numSubShapes = compoundShape->getNumChildShapes();
|
int32_t numSubShapes = compoundShape->getNumChildShapes();
|
||||||
for (int i = 0; i < numSubShapes; ++i) {
|
for (int i = 0; i < numSubShapes; ++i) {
|
||||||
const btCollisionShape* childShape = compoundShape->getChildShape(i);
|
const btCollisionShape* childShape = compoundShape->getChildShape(i);
|
||||||
if (childShape->isConvex()) {
|
if (childShape->isConvex()) {
|
||||||
const btConvexShape* convexShape = static_cast<const btConvexShape*>(childShape);
|
const btConvexShape* convexShape = static_cast<const btConvexShape*>(childShape);
|
||||||
btShapeHull shapeHull(convexShape);
|
copyShapeToMesh(compoundShape->getChildTransform(i), convexShape, mesh);
|
||||||
shapeHull.buildHull(MARGIN);
|
}
|
||||||
copyHullToMesh(shapeHull, mesh);
|
|
||||||
}
|
}
|
||||||
|
} else if (shape->isConvex()) {
|
||||||
|
const btConvexShape* convexShape = static_cast<const btConvexShape*>(shape);
|
||||||
|
copyShapeToMesh(btTransform(), convexShape, mesh);
|
||||||
}
|
}
|
||||||
} else if (shape->isConvex()) {
|
|
||||||
}
|
}
|
||||||
return mesh;
|
return mesh;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue