Question Regarding Concave Meshes Documentation #448
-
|
Hello all, I have been using this library to incorporate physics into my game and want to start using concave meshes for my world. But, when I look at the documentation it doesn't seem to match up with the "modern usage". For example take a look at this snippet in the documentation. reactphysics3d::PhysicsCommon physicsCommon;
//create phys world
reactphysics3d::PhysicsWorld* physWorld = physicsCommon.createPhysicsWorld();
// Create the TriangleVertexArray
const int nbVertices = 8;
const int nbTriangles = 12;
float vertices[3 * nbVertices] = ...;
int indices[3 * nbTriangles] = ...;
TriangleVertexArray* triangleArray =
new TriangleVertexArray(nbVertices, vertices, 3 * sizeof(float), nbTriangles,
indices, 3 * sizeof(int),
TriangleVertexArray::VertexDataType::VERTEX_FLOAT_TYPE,
TriangleVertexArray::IndexDataType::INDEX_INTEGER_TYPE);
// Create the TriangleMesh
std::vector<rp3d::Message> messages;
TriangleMesh* triangleMesh = physicsCommon.createTriangleMesh(vertexArray, messages);
// Display the messages (info, warning and errors)
if (messages.size() > 0) {
for (const rp3d::Message& message : messages) {
std::string messageType;
switch (message.type) {
case rp3d::Message::Type::Information:
messageType = "info";
break;
case rp3d::Message::Type::Warning:
messageType = "warning";
break;
case rp3d::Message::Type::Error:
messageType = "error";
break;
}
std::cout << "Message (" << messageType << "): " << message.text << std::endl;
}
}
// Make sure there was no errors during mesh creation
assert(triangleMesh != nullptr);
Firstly, when I replicate this in my IDE As well as where is Secondly, when I follow the compiler and use the right argument for the Here is some example code to what I'm trying to do: #include <iostream>
#include <reactphysics3d/reactphysics3d.h>
#include <glm/glm.hpp>
int main()
{
reactphysics3d::PhysicsCommon physCom;
//create phys world
reactphysics3d::PhysicsWorld* physWorld = physCom.createPhysicsWorld();
const int num_of_plane_vertices = 6;
const int num_of_plane_triangles = 6;
float plane_vertices[3 * num_of_plane_vertices] =
{
25.0f, -0.5f, 25.0f,
-25.0f, -0.5f, 25.0f,
-25.0f, -0.5f, -25.0f,
25.0f, -0.5f, 25.0f,
-25.0f, -0.5f, -25.0f,
25.0f, -0.5f, -25.0f
};
reactphysics3d::TriangleVertexArray plane_vertex_array = reactphysics3d::TriangleVertexArray(num_of_plane_vertices, plane_vertices, 3 * sizeof(float), num_of_plane_vertices, 0, 3 * sizeof(int), reactphysics3d::TriangleVertexArray::VertexDataType::VERTEX_FLOAT_TYPE, reactphysics3d::TriangleVertexArray::IndexDataType::INDEX_INTEGER_TYPE);
std::vector<reactphysics3d::Message> plane_messages;
reactphysics3d::TriangleMesh* plane_mesh = physCom.createTriangleMesh(plane_vertex_array, plane_messages);
return 0;
}I really like this library and it's been pretty seamless to integrate into my game. Just some small issues here and there and this one I'm pretty stuck on. Any help would be greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Yes, that's a real documentation bug, not a typo on your end. I pulled the current live docs page, and the example as published literally creates a pointer named But even fixing that name wouldn't make it compile, which is the deeper issue: the actual current signature, per the API reference, is TriangleMesh * createTriangleMesh(const TriangleVertexArray &triangleVertexArray, std::vector< Message > &messages) - it takes a The crash is also explainable, and it's a different bug in your own code, not the library. Looking at the actual constructor signature:
The fix is to supply an actual index array. Since your 6 vertices already represent 2 sequential triangles, the simplest fix: unsigned int plane_indices[6] = { 0, 1, 2, 3, 4, 5 };
reactphysics3d::TriangleVertexArray plane_vertex_array = reactphysics3d::TriangleVertexArray(
num_of_plane_vertices, plane_vertices, 3 * sizeof(float),
2 /* nbTriangles, not num_of_plane_vertices */,
plane_indices /* not 0 */, 3 * sizeof(unsigned int),
reactphysics3d::TriangleVertexArray::VertexDataType::VERTEX_FLOAT_TYPE,
reactphysics3d::TriangleVertexArray::IndexDataType::INDEX_INTEGER_TYPE);That should resolve the access violation. Worth filing the documentation typo as a separate, quick issue against the docs site if you want it fixed for the next person - it's a one line fix ( |
Beta Was this translation helpful? Give feedback.
Yes, that's a real documentation bug, not a typo on your end. I pulled the current live docs page, and the example as published literally creates a pointer named
triangleArray, then references an undefinedvertexArrayin the next line: TriangleVertexArray* triangleArray = new TriangleVertexArray(nbVertices, vertices, 3 * sizeof(float), nbTriangles, indices, 3 * sizeof(int), TriangleVertexArray::VertexDataType::VERTEX_FLOAT_TYPE, TriangleVertexArray::IndexDataType::INDEX_INTEGER_TYPE); ... TriangleMesh* triangleMesh = physicsCommon.createTriangleMesh(vertexArray, messages); That's an unrelated, never declared variable - confirmed stale/broken sample.But even fixing that name wouldn't make…