Replies: 2 comments
-
vsg::Builder was created to generate primitive shapes, it's been my intention to eventually expand support to include meshes, but there are many other tasks on my TODO list so it's not been something I've tackled. You are welcome to add an implementation for meshes, it's potentially quite an open ended tasks so getting the API right might be something that takes a few tries. |
Beta Was this translation helpful? Give feedback.
-
I tried adding a ref_ptr<Node> Builder::createMesh(ref_ptr<vec3Array> vertices, ref_ptr<vec3Array> normals, ref_ptr<ushortArray> indices, const GeometryInfo& info, const StateInfo& stateInfo)
{
// currently assume no subgraph
uint32_t instanceCount = 1;
auto positions = instancePositions(info, instanceCount);
auto colors = instanceColors(info, instanceCount);
if (info.transform != identity)
{
transform(info.transform, vertices, normals);
}
// setup geometry
auto vid = VertexIndexDraw::create();
DataList arrays;
arrays.push_back(vertices);
if (normals) arrays.push_back(normals);
if (colors) arrays.push_back(colors);
if (positions) arrays.push_back(positions);
vid->assignArrays(arrays);
vid->assignIndices(indices);
vid->indexCount = static_cast<uint32_t>(indices->size());
vid->instanceCount = instanceCount;
return decorateAndCompileIfRequired(info, stateInfo, vid);
} I then created a small test based on vsgExample int main(int argc, char **argv)
{
auto windowTraits = vsg::WindowTraits::create();
windowTraits->windowTitle = "hello-mesh-builder";
auto builder = vsg::Builder::create();
auto scene = vsg::Group::create();
vsg::GeometryInfo geomInfo;
vsg::StateInfo stateInfo;
// Change box color to red
geomInfo.color = vsg::vec4 {1.0f, 0.0f, 0.0f, 1.0f};
// Create a mesh by primitives
auto vertices = vsg::vec3Array::create(
{{-0.5f, -0.5f, 0.0f},
{0.5f, -0.5f, 0.0f},
{0.5f, 0.5f, 0.0f},
});
auto indices = vsg::ushortArray::create({0, 1, 2});
auto normals = vsg::vec3Array::create(
{{0.0f, 0.0f, 1.0f},
{0.0f, 0.0f, 1.0f},
{0.0f, 0.0f, 1.0f}});
auto node = builder->createMesh(vertices, normals, indices, geomInfo, stateInfo);
scene->addChild(node);
// compute the bounds of the scene graph to help position the camera
vsg::ComputeBounds computeBounds;
scene->accept(computeBounds);
vsg::dvec3 centre = (computeBounds.bounds.min + computeBounds.bounds.max) * 0.5;
: However, when running the result I get a black window, and my whole the system becomes unresponsive. Any idea of what I did wrong? Should I create a minimum reproducible example? |
Beta Was this translation helpful? Give feedback.
-
I'm curious why the
vsg::Builder()
does not have acreateMesh()
method that creates a mesh from a list of vertices and faces? Is it simply that nobody has had any need for it, or is there some deeper reason? If the answer is the former, I might try to create a PR to add such a function.Thanks!
Beta Was this translation helpful? Give feedback.
All reactions