VisualStyle
Customize what to render on screen
Description
VisualStyle component controls the DisplayFlags state embedded in the VisualParams for the current subgraph. It merges the DisplayFlags conveyed by the VisualParams with its own DisplayFlags. Example Taken from examples/Component/Visual/VisualStyle.scn
[caption id="attachment_1566" align="aligncenter" width="533"]{.size-full .wp-image-1566 width="533" height="400"} Resulting View from the previous XML scene[/caption]
XML Usage
allowed values for displayFlags data are a combination of the following:
showAll, hideAll,
showVisual, hideVisual,
showVisualModels, hideVisualModels,
showBehavior, hideBehavior,
showBehaviorModels, hideBehaviorModels,
showForceFields, hideForceFields,
showInteractionForceFields, hideInteractionForceFields
showMapping, hideMapping
showMappings, hideMappings
showMechanicalMappings, hideMechanicalMappings
showCollision, hideCollision
showCollisionModels, hideCollisionModels
showBoundingCollisionModels, hideBoundingCollisionModels
showOptions hideOptions
showNormals hideNormals
showWireframe hideWireframe
C++ Usage
In C++, to set the visual style in a node, you have to create a VisualStyle component, attach it to the node, create and tune a !DisplayFlags object and set the !VisualStyle with it, as shown in the following example:
VisualStyle::SPtr visualStyle = New();
root->addObject(visualStyle);
VisualStyle::DisplayFlags displayFlags;
displayFlags.setShowAll();
visualStyle->displayFlags.setValue(displayFlags);
You can also use method component::visualmodel::addVisualStyle( simulation::Node::SPtr ) to insert a VisualStyle component at the given node and return a WriteAccessor on the display flags:
Edit the visual style. Allowed values for displayFlags data are a combination of the following: showAll, hideAll, showVisual, hideVisual, showVisualModels, hideVisualModels, showBehavior, hideBehavior, showBehaviorModels, hideBehaviorModels, showForceFields, hideForceFields, showInteractionForceFields, hideInteractionForceFields showMapping, hideMapping showMappings, hideMappings showMechanicalMappings, hideMechanicalMappings showCollision, hideCollision showCollisionModels, hideCollisionModels showBoundingCollisionModels, hideBoundingCollisionModels showOptions hideOptions showRendering hideRendering showNormals hideNormals showWireframe hideWireframe
Target: Sofa.Component.Visual
namespace: sofa::component::visual
parents:
- VisualModel
Data
Name | Description | Default value |
---|---|---|
name | object name | unnamed |
printLog | if true, emits extra messages at runtime. | 0 |
tags | list of the subsets the object belongs to | |
bbox | this object bounding box | |
componentState | The state of the component among (Dirty, Valid, Undefined, Loading, Invalid). | Undefined |
listening | if true, handle the events, otherwise ignore the events | 0 |
enable | Display the object or not | 1 |
displayFlags | Display Flags |
Links
Name | Description | Destination type name |
---|---|---|
context | Graph Node containing this object (or BaseContext::getDefault() if no graph is used) | BaseContext |
slaves | Sub-objects used internally by this object | BaseObject |
master | nullptr for regular objects, or master object for which this object is one sub-objects | BaseObject |
Examples
VisualStyle.scn
<?xml version="1.0"?>
<Node name="root" gravity="0 -9.81 0" dt="0.02">
<RequiredPlugin name="Sofa.Component.Collision.Geometry"/> <!-- Needed to use components [SphereCollisionModel] -->
<RequiredPlugin name="Sofa.Component.Constraint.Projective"/> <!-- Needed to use components [FixedProjectiveConstraint] -->
<RequiredPlugin name="Sofa.Component.IO.Mesh"/> <!-- Needed to use components [MeshGmshLoader MeshOBJLoader SphereLoader] -->
<RequiredPlugin name="Sofa.Component.Mapping.Linear"/> <!-- Needed to use components [BarycentricMapping] -->
<RequiredPlugin name="Sofa.Component.Mass"/> <!-- Needed to use components [DiagonalMass] -->
<RequiredPlugin name="Sofa.Component.SolidMechanics.FEM.Elastic"/> <!-- Needed to use components [TetrahedralCorotationalFEMForceField] -->
<RequiredPlugin name="Sofa.Component.StateContainer"/> <!-- Needed to use components [MechanicalObject] -->
<RequiredPlugin name="Sofa.Component.Topology.Container.Dynamic"/> <!-- Needed to use components [TetrahedronSetGeometryAlgorithms TetrahedronSetTopologyContainer] -->
<RequiredPlugin name="Sofa.Component.Visual"/> <!-- Needed to use components [VisualStyle] -->
<RequiredPlugin name="Sofa.GL.Component.Rendering3D"/> <!-- Needed to use components [OglModel] -->
<!-- Using the VisualStyle choose your visual options! -->
<!-- ACTIVATE: showVisual showBehavior showForceFields showInteractionForceFields showCollision showCollisionModels showWireFrame -->
<!-- DE-ACTIVATE: hideVisual hideBehavior hideForceFields hideInteractionForceFields hideCollision hideCollisionModels hideWireFrame -->
<VisualStyle displayFlags="showVisual showCollisionModels" />
<DefaultAnimationLoop/>
<Node name="Liver" >
<MeshGmshLoader name="meshLoader" filename="mesh/liver.msh" />
<TetrahedronSetTopologyContainer name="topo" src="@meshLoader" />
<MechanicalObject name="dofs" src="@meshLoader" />
<TetrahedronSetGeometryAlgorithms name="GeomAlgo" />
<DiagonalMass name="computed using mass density" massDensity="1" />
<TetrahedralCorotationalFEMForceField template="Vec3" name="FEM" method="large" poissonRatio="0.3" youngModulus="3000" computeGlobalMatrix="0" />
<FixedProjectiveConstraint name="FixedProjectiveConstraint" indices="3 39 64" />
<Node name="WireframeVisu" >
<VisualStyle displayFlags="showVisual showWireframe" />
<MeshOBJLoader name="meshLoader_1" filename="mesh/liver-smooth.obj" handleSeams="1" />
<OglModel name="VisualModel" src="@meshLoader_1" />
<BarycentricMapping name="visual mapping" input="@../dofs" output="@VisualModel" />
</Node>
<Node name="Sphere" >
<VisualStyle displayFlags="hideBehavior showCollision showWireframe" />
<SphereLoader filename="mesh/liver.sph" />
<MechanicalObject name="spheres" position="@[-1].position" />
<SphereCollisionModel name="CollisionModel" listRadius="@[-2].listRadius" />
<BarycentricMapping name="sphere mapping" input="@../dofs" output="@spheres" />
</Node>
<Node name="TranslatedSurface" gravity="0 -9.81 0">
<!-- default rendering should be flat rendered and not wireframed -->
<MeshOBJLoader name="meshLoader_0" filename="mesh/liver.obj" translation="5 0 0" handleSeams="1" />
<OglModel src="@meshLoader_0" />
</Node>
</Node>
</Node>
def createScene(root_node):
root = root_node.addChild('root', gravity="0 -9.81 0", dt="0.02")
root.addObject('RequiredPlugin', name="Sofa.Component.Collision.Geometry")
root.addObject('RequiredPlugin', name="Sofa.Component.Constraint.Projective")
root.addObject('RequiredPlugin', name="Sofa.Component.IO.Mesh")
root.addObject('RequiredPlugin', name="Sofa.Component.Mapping.Linear")
root.addObject('RequiredPlugin', name="Sofa.Component.Mass")
root.addObject('RequiredPlugin', name="Sofa.Component.SolidMechanics.FEM.Elastic")
root.addObject('RequiredPlugin', name="Sofa.Component.StateContainer")
root.addObject('RequiredPlugin', name="Sofa.Component.Topology.Container.Dynamic")
root.addObject('RequiredPlugin', name="Sofa.Component.Visual")
root.addObject('RequiredPlugin', name="Sofa.GL.Component.Rendering3D")
root.addObject('VisualStyle', displayFlags="showVisual showCollisionModels")
root.addObject('DefaultAnimationLoop', )
liver = root.addChild('Liver')
liver.addObject('MeshGmshLoader', name="meshLoader", filename="mesh/liver.msh")
liver.addObject('TetrahedronSetTopologyContainer', name="topo", src="@meshLoader")
liver.addObject('MechanicalObject', name="dofs", src="@meshLoader")
liver.addObject('TetrahedronSetGeometryAlgorithms', name="GeomAlgo")
liver.addObject('DiagonalMass', name="computed using mass density", massDensity="1")
liver.addObject('TetrahedralCorotationalFEMForceField', template="Vec3", name="FEM", method="large", poissonRatio="0.3", youngModulus="3000", computeGlobalMatrix="0")
liver.addObject('FixedProjectiveConstraint', name="FixedProjectiveConstraint", indices="3 39 64")
wireframe_visu = Liver.addChild('WireframeVisu')
wireframe_visu.addObject('VisualStyle', displayFlags="showVisual showWireframe")
wireframe_visu.addObject('MeshOBJLoader', name="meshLoader_1", filename="mesh/liver-smooth.obj", handleSeams="1")
wireframe_visu.addObject('OglModel', name="VisualModel", src="@meshLoader_1")
wireframe_visu.addObject('BarycentricMapping', name="visual mapping", input="@../dofs", output="@VisualModel")
sphere = Liver.addChild('Sphere')
sphere.addObject('VisualStyle', displayFlags="hideBehavior showCollision showWireframe")
sphere.addObject('SphereLoader', filename="mesh/liver.sph")
sphere.addObject('MechanicalObject', name="spheres", position="@[-1].position")
sphere.addObject('SphereCollisionModel', name="CollisionModel", listRadius="@[-2].listRadius")
sphere.addObject('BarycentricMapping', name="sphere mapping", input="@../dofs", output="@spheres")
translated_surface = Liver.addChild('TranslatedSurface', gravity="0 -9.81 0")
translated_surface.addObject('MeshOBJLoader', name="meshLoader_0", filename="mesh/liver.obj", translation="5 0 0", handleSeams="1")
translated_surface.addObject('OglModel', src="@meshLoader_0")