news 2026/7/14 19:10:46

6-SOFA视觉模型Visual Model

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
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 里可以把一个对象拆成几种表示:

  1. Mechanical model:力学模型,负责计算运动和变形
  2. Visual model / Rendering model:视觉模型,负责显示给你看
  3. 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。

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/7/13 16:31:27

大数据毕设项目:基于 Python Django 的旅游用户画像构建与景点推荐系统的设计与实现 (源码+文档,讲解、调试运行,定制等)

博主介绍&#xff1a;✌️码农一枚 &#xff0c;专注于大学生项目实战开发、讲解和毕业&#x1f6a2;文撰写修改等。全栈领域优质创作者&#xff0c;博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java、小程序技术领域和毕业项目实战 ✌️技术范围&#xff1a;&am…

作者头像 李华
网站建设 2026/7/13 16:24:39

c++秋招必刷:上百道c/c++面试八股文,含答案讲解Linux开发架构之路

1.讲一讲封装、继承、多态是什么&#xff1f;封装&#xff1a;将具体实现过程和数据封装成一个类&#xff0c;只能通过接口进行访问&#xff0c;降低耦合性&#xff0c;使类成为一个具有内部数据的自我隐藏能力、功能独立的软件模块。意义&#xff1a;保护或防止代码在无意之中…

作者头像 李华