Closed anderslanglands closed 2 years ago
Hi @anderslanglands ,
Could you try rendering with another variant, e.g. scalar_rgb
? I suspect it could be an issue on how you create/upload the mesh buffers on the GPU.
Hi @Speierers, I get the same result with scalar_rgb
I would suggest you try to rotate the object / camera by 90 degree, it could be that you are looking at the rectangle from the side.
The vertices I have there should be a match for the default "rectangle" shape right? (i.e. rectangle in the XY plane). If I change "dyn" to "rectangle" in the script above I get the attached image
One way to debug this further would be to use the Mesh::write_ply()
method and open the output file (e.g. in blender) to see what's going on.
Taking a quick look at your code, it could be that InputVector3f
doesn't have the size that you expect. IIRC it allocates an extra float (e.g. padding).
Thanks, I ended up writing the ply out and inspecting it directly. Turns out there were a couple of problems: 1) Both InputVector3f and ScalarIndex3 are padded 2) When I was creating the triangles list:
std::vector<ScalarIndex3> triangles{ 0, 1, 2, 0, 2, 3 };
This was actually creating a vector of 6 triangles. I guess ScalarIndex3 has a constructor that implicitly converts from a single int?
The working constructor, for posterity's sake:
DynMesh(const Properties &props) : Base(props) {
std::vector<ScalarIndex3> triangles{ {0, 1, 2}, {0, 2, 3} };
std::vector<InputPoint3f> vertices{
{ -1, -1, 0 }, { 1, -1, 0 }, { 1, 1, 0 }, { -1, 1, 0 }
};
std::vector<InputNormal3f> normals;
m_name = "blah";
m_vertex_count = vertices.size();
m_face_count = triangles.size();
m_disable_vertex_normals = true;
m_faces_buf = empty<UInt32>(m_face_count * 3);
m_vertex_positions_buf = empty<FloatStorage>(m_vertex_count * 3);
if (!m_disable_vertex_normals)
m_vertex_normals_buf = empty<FloatStorage>(m_vertex_count * 3);
m_faces_buf.managed();
m_vertex_positions_buf.managed();
m_vertex_normals_buf.managed();
m_vertex_texcoords_buf.managed();
if constexpr (is_cuda_array_v<Float>)
cuda_sync();
for (size_t i = 0; i < triangles.size(); ++i) {
for (int e = 0; e < 3; ++e) {
m_faces_buf.data()[i*3+e] = triangles[i][e];
}
}
for (size_t i = 0; i < vertices.size(); ++i) {
m_bbox.expand(vertices[i]);
InputFloat *dst_v = m_vertex_positions_buf.data() + i * 3;
store_unaligned(dst_v+0, vertices[i].x());
store_unaligned(dst_v+1, vertices[i].y());
store_unaligned(dst_v+2, vertices[i].z());
}
set_children();
}
Great to hear that it works now. I will close this issue.
Summary
I'm trying to create a new Shape plugin, inheriting from Mesh. I've taken the OBJ as a starting point and stripped it down to a minimum and am just trying to manually create a rect at the origin for now, only nothing renders. I know the camera is pointed the right way because if I replace the mesh with a sphere in the test script below, I see it. The plugin is loading ok and prints out as part of the scene, and everything looks ok there, no errors. I just don't see my mesh.
Description
Here's the plugin source:
and here's a test script:
Steps to reproduce