MeshShape serialization issues #1647
-
|
So I have the function below, it takes in lists of vertices and indices and converts them to the format expected by MeshShapeSettings, and I also have the serialization function shown as well, However when i do do the saving/serialization, nothing pops out. Most of this I lifted pretty much straight from the saving shapes section of the docs. Let me know if theres any other data I should provide. JPH::Ref<JPH::Shape> mesh;
inline void Create(std::vector<glm::vec3> verts, std::vector<unsigned int> indices) {
JPH::VertexList vertices;
JPH::IndexedTriangleList indicesList;
for (int i = 0; i < verts.size(); i++) {
auto vert = verts[i];
vertices.push_back(JPH::Float3(vert.x, vert.y, vert.z));
}
for (int i = 0; i < indices.size(); i += 3) {
indicesList.push_back(JPH::IndexedTriangle(indices[i], indices[i + 1], indices[i + 2]));
}
{
JPH::MeshShapeSettings meshSettings(vertices, indicesList);
JPH::Shape::ShapeResult result = meshSettings.Create();
mesh = result.Get();
std::cout << result.HasError() << std::endl;
if (result.HasError()) {
std::cout << "MeshCollider creation failed" + result.GetError() << std::endl;
return;
}
}
std::cout << "MeshCollider created" << std::endl;
}
void save(Archive& archive) const {
std::stringstream ShapeData;
JPH::StreamOutWrapper stream(ShapeData);
JPH::Shape::ShapeToIDMap shape_to_id;
JPH::Shape::MaterialToIDMap material_to_id;
mesh->SaveWithChildren(stream, shape_to_id, material_to_id);
cereal::make_nvp("MeshShape", ShapeData.str()); // copys data inside ShapeData.str to a json file, nothing is outputted
Save(archive); // function part of the PhysicsComponent base class, saves data like mass, type of object (RigidBody, Trigger, etc)
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
I think the confusion is probably that |
Beta Was this translation helpful? Give feedback.
-
|
no yeah, your right, the size of the string is 413, thanks for pointing me in the right direction. |
Beta Was this translation helpful? Give feedback.
I think the confusion is probably that
ShapeData.str()is not an ASCII string. It's a binary stream of bytes that could start with a 0-byte. If you treat it as text and output it to JSON you would end up with an empty string. CheckShapeData.str().size(), I think it will be bigger than 0.