Replies: 3 comments
-
STL files are loaded via vsgXchange::assimp, this by uses either the PBR ShaderSet or Phong ShaderSet, both of which fully support lighting and shadows, just like the vsg::Builder generated meshes do. However, lighting depends upon the dataset having normals, and it could be that assimp isn't creating normals - if there are no normals on the original model then this would be correct. assimp does have support for generating normals. You can enable options like generating normals using vsg::Options class, and there is support for parsing command line args to map to these vsg::Options. You can list the supported options using vsgconv --features vsgXchange::assimp: $ vsgconv --features vsgXchange::assimp
vsgXchange::assimp provides support for 70 extensions, and 0 protocols.
Extensions Supported ReaderWriter methods
---------- ------------------------------
.3d read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.3ds read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.3mf read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.ac read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.ac3d read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.acc read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.amf read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.ase read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.ask read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.assbin read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.b3d read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.blend read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.bsp read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.bvh read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.cob read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.csm read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.dae read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.dxf read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.enff read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.fbx read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.glb read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.gltf read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.hmp read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.ifc read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.ifczip read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.iqm read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.irr read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.irrmesh read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.lwo read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.lws read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.lxo read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.md2 read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.md3 read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.md5anim read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.md5camera read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.md5mesh read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.mdc read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.mdl read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.mesh read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.mesh.xml read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.mot read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.ms3d read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.ndo read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.nff read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.obj read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.off read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.ogex read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.pk3 read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.ply read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.pmx read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.prj read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.q3o read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.q3s read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.raw read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.scn read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.sib read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.smd read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.step read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.stl read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.stp read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.ter read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.uc read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.vta read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.x read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.x3d read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.x3db read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.xgl read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.xml read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.zae read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
.zgl read(vsg::Path, ..) read(std::istream, ..) read(uint8_t* ptr, size_t size, ..)
vsg::Options::Value type
------------------- ----
crease_angle float
culling bool
discard_empty_nodes bool
external_texture_format vsgXchange::TextureFormat
external_textures bool
generate_sharp_normals bool
generate_smooth_normals bool
print_assimp int
sRGBTextures bool
two_sided bool |
Beta Was this translation helpful? Give feedback.
-
How to change the color of STL nodes? |
Beta Was this translation helpful? Give feedback.
-
Answer to @keiler2018 IntroThis note describes how to change the color, or any other material property, from a model loaded by vsgXchange. The code in this note is based on the vsghelloworld.cpp from the vsgExamples repo. Locating the property to changeThe first step is to locate the property to change. One simple way of doing that is to save the model in the vsgt ascii format immediately after loading. This may be done by adding the following lines immediately after // Save the scene to a vsgt file for manual inspection
vsg::write(vsg_scene, "vsg-scene.vsgt", options); So, e.g if you have an stl 3DBenchy.stl, you run your modified helloworld program:
You can then inspect the vsgt file in any editor and look for the properties you want to change. After modifying the properties manually, you can save the file and then reloade it into myvsghelloworld.
After some probing you can will find that the color of the is controlled by the property
Editing the color programaticallyTo change the diffuseColor value in your C++ program, you need to get a pointer to // Extract a pointer to the materialValue
vsg::PbrMaterialValue *extractMaterialValue(vsg::Node* node, bool makeDynamic=true)
{
struct ExtractMaterialVisitor : public vsg::Visitor
{
ExtractMaterialVisitor() {}
void apply(vsg::Object& object) override
{
object.traverse(*this);
}
// Find and return the PbrMaterial value
void apply(vsg::DescriptorBuffer& db) override
{
for (auto& bfi : db.bufferInfoList)
{
auto data = bfi->data;
print("Found bfi of type {}\n", data->type_info().name());
if (data->is_compatible(typeid(vsg::PbrMaterialValue))) {
if (makeDynamic)
data->properties.dataVariance = vsg::DYNAMIC_DATA;
// Store the materialValue so that it can be returned to the user
this->materialValue = data->cast<vsg::PbrMaterialValue>();
}
}
}
bool makeDynamic = true;
vsg::PbrMaterialValue *materialValue = nullptr;
};
ExtractMaterialVisitor emv;
emv.makeDynamic = makeDynamic;
node->accept(emv);
if (!emv.materialValue)
throw std::runtime_error("Failed finding the material value!");
return emv.materialValue;
} Calling this function returns a pointer to the MaterialValue and you can then change it. // Extract the materialValue which can be used to change the property
auto materialValue = extractMaterialValue(vsg_scene);
auto material = (vsg::PbrMaterial*)(materialValue->dataPointer(0));
material->diffuseFactor = vsg::vec4{1.0,0.0,0.0,1.0}; Dynamic changing of the colorThis is all that is needed for changing the color before the scene graph is compiled. But if you want to change the color dynamically, e.g. when picking the part, you need to do the following:
Here is a modified render loop that switches the color between green and red once a second: // rendering main loop
int frameId = 0;
int colorId = 0;
while (viewer->advanceToNextFrame())
{
// pass any events into EventHandlers assigned to the Viewer
viewer->handleEvents();
viewer->update();
viewer->recordAndSubmit();
viewer->present();
// Toggle the material diffuse color once a second
if (frameId % 60 == 0)
{
if (colorId == 0)
material->diffuseFactor = vsg::vec4{1.0,0.0,0.0,1.0};
else
material->diffuseFactor = vsg::vec4{0.0,1.0,0.0,1.0};
colorId = (colorId+1)%2;
materialValue->dirty();
}
frameId++;
} My complete modified example may be found in the following gist: https://gist.github.com/dov/85e967bd0598edccac4a245893721858 I hope this helps. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
While learning vulkanscenegraph, I'm writing my own viewer program based on vsgviewer. I'd like to change the material appearance of an STL mesh loaded into the viewer through vsgXchange. Since an STL file is just pure geometry, I assume that
vsgXchange
fills in various default properties/nodes on its own. I had a look at the resulting vsgt as output by vsgconv, and tried to find a light/illumination node, but I could not find it. So what makes it visible?In contrast, if I create through a
vsg::Builder
, I have figured out that I must add a light on my own to the scene, e.g. byvsg::createHeadlight()
. Is there any way of making a model loaded by vsgXchange, behave the same, so that I have to add illumination on my own?Beta Was this translation helpful? Give feedback.
All reactions