6-SOFA视觉模型Visual Model
6-visual-model.scn
<?xml version="1.0"?> <!-- Adding a visual model to our object --> <Node name="root" dt="0.01" gravity="0 0 0"> <Node name="plugins"> <RequiredPlugin name="Sofa.Component.IO.Mesh"/> <!-- Needed to use components [MeshGmshLoader] --> <RequiredPlugin name="Sofa.Component.LinearSolver.Iterative"/> <!-- Needed to use components [CGLinearSolver] --> <RequiredPlugin name="Sofa.Component.Mass"/> <!-- Needed to use components [MeshMatrixMass] --> <RequiredPlugin name="Sofa.Component.MechanicalLoad"/> <!-- Needed to use components [ConstantForceField] --> <RequiredPlugin name="Sofa.Component.StateContainer"/> <!-- Needed to use components [MechanicalObject] --> <RequiredPlugin name="Sofa.Component.ODESolver.Backward"/> <!-- Needed to use components [EulerImplicitSolver] --> <RequiredPlugin name="Sofa.Component.SolidMechanics.FEM.Elastic"/> <!-- Needed to use components [TetrahedronFEMForceField] --> <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] --> </Node> <DefaultAnimationLoop computeBoundingBox="false"/> <!-- 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="showForceFields" /> <MeshGmshLoader name="meshLoaderCoarse" filename="mesh/liver.msh" /> <Node name="Liver"> <EulerImplicitSolver /> <CGLinearSolver iterations="200" tolerance="1e-09" threshold="1e-09"/> <TetrahedronSetTopologyContainer name="topo" src="@../meshLoaderCoarse" /> <TetrahedronSetGeometryAlgorithms template="Vec3d" name="GeomAlgo" /> <MechanicalObject template="Vec3d" name="MechanicalModel" showObject="1" showObjectScale="3" /> <TetrahedronFEMForceField name="FEM" youngModulus="1000" poissonRatio="0.4" method="large" /> <MeshMatrixMass massDensity="1" topology="@topo" /> <ConstantForceField totalForce="1 0 0" /> <OglModel name="VisualModel" src="@../meshLoaderCoarse" /> </Node> </Node>1.视觉模型
到这里我们已经完成了一个 full mechanical model,完整力学模型。现在这个对象已经不只是“能显示的东西”,而是真正有质量、有材料、有外力、有求解器、能运动和变形的力学对象。
现在我们要加另一个 representation,也就是另一种“表示”。
前面已经学过 SOFA 里可以把一个对象拆成几种表示:
- Mechanical model:力学模型,负责计算运动和变形
- Visual model / Rendering model:视觉模型,负责显示给你看
- Collision model:碰撞模型,负责碰撞检测
这一段加的是:Visual model / Rendering model 视觉模型 / 渲染模型
2.可变性对象
现在和之前的代码5最大的区别是,我们有了constitutive model,本构模型,它来自连续介质力学。
continuum的意思是“连续对象”。虽然我们在计算机里把它离散成很多节点和四面体,但它在物理意义上是一个整体。一个节点上发生的事情会影响其他节点。
按住Shift + 鼠标左键,会出现绿色箭头,这些绿色箭头表示:在鼠标和物体之间创建一个临时弹簧,拖动物体上的一个点。你会看到整个 lever 发生形变。
这说明它不是一堆互相独立的点,而是一个连续的可变形物体 deformable object 。
3.刚体点云 vs 可变形体
前面的点云/刚体 frame:
- 每个点是独立的 rigid frame
- 点和点之间没有材料连接
- 你拖一个点,不会影响其他点
现在的可变形体:
- 节点之间通过 3D 网格和材料模型连接
- 拖一个节点,会影响整个物体
原因是:现在有 3D 空间积分、有材料模型、有内部弹性力。某处发生变形,会通过连续体模型传递到整个 domain。
4.加入visual model
现在要添加另一种 representation,也就是visual/rendering representation,视觉/渲染表示。
<OglModel name="VisualModel" src="@../meshLoaderCoarse" />它的作用是:把 meshLoaderCoarse 读入的网格,用作可视化显示模型。
注意:MechanicalObject是力学状态,OglModel是显示外观。它们不是同一个东西。
5.渲染模型没有力学计算
点 Animate 后开始引出核心问题:我们现在虽然有了另一个 representation,也就是OglModel,但是我们忘了一件事——没有把 rendering 和 mechanics 连接起来。
渲染模型只负责显示。它不计算力;它不解方程;它不知道每个节点的新位置和新速度。
现在的rendering 上没有任何 mechanics computation,渲染模型只负责渲染。
所以OglModel需要一个东西来告诉它:力学模型现在变成什么形状了、每个节点现在在哪里、速度是多少。缺的东西就是 mapping。
