Scenegraph: Difference between revisions
mNo edit summary |
(replace OpenInventor by Open Inventor) |
||
(15 intermediate revisions by 5 users not shown) | |||
Line 4: | Line 4: | ||
<!--T:17--> |
<!--T:17--> |
||
{{Docnav |
{{Docnav |
||
|[[Scripted_objects|Scripted objects]] |
|||
|[[Mesh_to_Part|Mesh to Part]] |
|||
|[[Pivy|Pivy]] |
|[[Pivy|Pivy]] |
||
}} |
}} |
||
Line 15: | Line 15: | ||
<!--T:2--> |
<!--T:2--> |
||
The geometry that appears in the [[3D_view|3D views]] of FreeCAD is rendered by the [https://en.wikipedia.org/wiki/Coin3D |
The geometry that appears in the [[3D_view|3D views]] of FreeCAD is rendered by the [https://en.wikipedia.org/wiki/Coin3D Coin3D] library. Coin3D is an implementation of the [https://en.wikipedia.org/wiki/Open_Inventor Open Inventor] standard. The [https://en.wikipedia.org/wiki/Open_Cascade_Technology OpenCASCADE] software also provides the same functionality, but it was decided at the very early stages of FreeCAD not to use the built-in OpenCASCADE viewer, but rather switch to the more performant Coin3D software. A good way to learn about that library is the book [http://www-evasion.imag.fr/Membres/Francois.Faure/doc/inventorMentor/sgi_html/ Open Inventor Mentor]. |
||
==Description== <!--T:20--> |
==Description== <!--T:20--> |
||
<!--T:3--> |
<!--T:3--> |
||
[https://en.wikipedia.org/wiki/Open_Inventor |
[https://en.wikipedia.org/wiki/Open_Inventor Open Inventor] is a 3D scene description language. The scene described in Open Inventor is then rendered in OpenGL on your screen. Coin3D takes care of doing this, so programmers do not need to deal with complex OpenGL calls, and may just provide valid Open Inventor code. The big advantage is that Open Inventor is a very well-known and well documented standard. |
||
<!--T:4--> |
<!--T:4--> |
||
One of the big jobs FreeCAD does for you is translating OpenCASCADE geometry information into |
One of the big jobs FreeCAD does for you is translating OpenCASCADE geometry information into Open Inventor language. |
||
<!--T:5--> |
<!--T:5--> |
||
Open Inventor describes a 3D scene in the form of a [https://en.wikipedia.org/wiki/Scene_graph scene graph], like the one below: |
|||
</translate> |
</translate> |
||
Line 32: | Line 32: | ||
<translate> |
<translate> |
||
<!--T:6--> |
<!--T:6--> |
||
{{Caption|Image taken from [http://www-evasion.imag.fr/~Francois.Faure/doc/inventorMentor/sgi_html/ Inventor mentor]}} |
{{Caption|Image taken from [https://web.archive.org/web/20190807185912/http://www-evasion.imag.fr/~Francois.Faure/doc/inventorMentor/sgi_html/ Inventor mentor]}} |
||
<!--T:7--> |
<!--T:7--> |
||
An |
An Open Inventor scenegraph describes everything that is part of a 3D scene, such as geometry, colors, materials, lights, etc, and organizes all that data in a convenient and clear structure. Everything can be grouped into sub-structures, allowing you to organize your scene contents pretty much the way you like. Here is an example of an Open Inventor file: |
||
</translate> |
</translate> |
||
{{Code|lang=bash|code= |
{{Code|lang=bash|code= |
||
Line 60: | Line 61: | ||
} |
} |
||
} |
} |
||
}} |
}} |
||
<translate> |
<translate> |
||
<!--T:8--> |
<!--T:8--> |
||
As you can see, the structure is very simple. You use separators to organize your data into blocks, a bit like you would organize your files into folders. Each statement affects what comes next, for example the first two items of our root separator are a rotation and a translation, both will affect the next item, which is a separator. In that separator |
As you can see, the structure is very simple. You use separators to organize your data into blocks, a bit like you would organize your files into folders. Each statement affects what comes next, for example the first two items of our root separator are a rotation and a translation, both will affect the next item, which is a separator. In that separator a material is defined and another transformation. Our cylinder will therefore be affected by both transformations, the one applied directly to it and the one that was applied to its parent separator. |
||
<!--T:9--> |
<!--T:9--> |
||
We also have many other types of elements to organize our scene, such as groups, switches or annotations. We can define very complex materials for our objects, with |
We also have many other types of elements to organize our scene, such as groups, switches or annotations. We can define very complex materials for our objects, with colors, textures, shading modes and transparency. We can also define lights, cameras, and even movement. It is even possible to embed pieces of scripting in Open Inventor files to define more complex behaviors. |
||
<!--T:10--> |
<!--T:10--> |
||
If you are interested in learning more about |
If you are interested in learning more about Open Inventor head directly to its most famous reference: the [http://www-evasion.imag.fr/~Francois.Faure/doc/inventorMentor/sgi_html/ Inventor mentor]. |
||
<!--T:11--> |
<!--T:11--> |
||
In FreeCAD, normally, we don't need to interact directly with the |
In FreeCAD, normally, we don't need to interact directly with the Open Inventor scenegraph. Every object in a FreeCAD document, being a mesh, a part shape or anything else, gets automatically converted to Open Inventor code and inserted in the main scenegraph that you see in a [[3D_view|3D view]]. That scenegraph gets updated continuously when you modify, add or remove objects. In fact every object (in App space) has a view provider (a corresponding object in Gui space) responsible for issuing Open Inventor code. |
||
<!--T:12--> |
<!--T:12--> |
||
But there are many advantages to |
But there are many advantages to being able to access the scenegraph directly. For example, we can temporarily change the appearance of an object, or we can add objects to the scene that have no real existence in the FreeCAD document, such as construction geometry, helpers, graphical hints or tools such as manipulators or on-screen information. |
||
<!--T:13--> |
<!--T:13--> |
||
FreeCAD itself features several tools to see or modify |
FreeCAD itself features several tools to see or modify Open Inventor code. For example, the following Python code will show the Open Inventor representation of a selected object: |
||
</translate> |
</translate> |
||
{{Code|code= |
{{Code|code= |
||
Line 89: | Line 90: | ||
}} |
}} |
||
<translate> |
<translate> |
||
<!--T:14--> |
<!--T:14--> |
||
But we also have a |
But we also have a Python module that allows complete access to anything managed by Coin3D, such as our FreeCAD scenegraph. So, read on to [[Pivy|Pivy]]. |
||
== Coding examples == <!--T:22--> |
|||
<!--T:23--> |
|||
See [[Coin3d_snippets|Coin3d snippets]] courtesy of MariwanJ's research for the [[Design456_Workbench|Design456 Workbench]]. The code repository can be found at https://github.com/MariwanJ/COIN3D_Snippet. |
|||
</translate>{{Top}}<translate> |
|||
<!--T:15--> |
<!--T:15--> |
||
{{Docnav |
{{Docnav |
||
|[[Scripted_objects|Scripted objects]] |
|||
|[[Mesh_to_Part|Mesh to Part]] |
|||
|[[Pivy|Pivy]] |
|[[Pivy|Pivy]] |
||
}} |
}} |
||
Line 101: | Line 111: | ||
{{Powerdocnavi{{#translation:}}}} |
{{Powerdocnavi{{#translation:}}}} |
||
[[Category:Developer Documentation{{#translation:}}]] |
[[Category:Developer Documentation{{#translation:}}]] |
||
{{clear}} |
Latest revision as of 20:31, 17 November 2022
Introduction
The geometry that appears in the 3D views of FreeCAD is rendered by the Coin3D library. Coin3D is an implementation of the Open Inventor standard. The OpenCASCADE software also provides the same functionality, but it was decided at the very early stages of FreeCAD not to use the built-in OpenCASCADE viewer, but rather switch to the more performant Coin3D software. A good way to learn about that library is the book Open Inventor Mentor.
Description
Open Inventor is a 3D scene description language. The scene described in Open Inventor is then rendered in OpenGL on your screen. Coin3D takes care of doing this, so programmers do not need to deal with complex OpenGL calls, and may just provide valid Open Inventor code. The big advantage is that Open Inventor is a very well-known and well documented standard.
One of the big jobs FreeCAD does for you is translating OpenCASCADE geometry information into Open Inventor language.
Open Inventor describes a 3D scene in the form of a scene graph, like the one below:
Image taken from Inventor mentor
An Open Inventor scenegraph describes everything that is part of a 3D scene, such as geometry, colors, materials, lights, etc, and organizes all that data in a convenient and clear structure. Everything can be grouped into sub-structures, allowing you to organize your scene contents pretty much the way you like. Here is an example of an Open Inventor file:
#Inventor V2.0 ascii
Separator {
RotationXYZ {
axis Z
angle 0
}
Transform {
translation 0 0 0.5
}
Separator {
Material {
diffuseColor 0.05 0.05 0.05
}
Transform {
rotation 1 0 0 1.5708
scaleFactor 0.2 0.5 0.2
}
Cylinder {
}
}
}
As you can see, the structure is very simple. You use separators to organize your data into blocks, a bit like you would organize your files into folders. Each statement affects what comes next, for example the first two items of our root separator are a rotation and a translation, both will affect the next item, which is a separator. In that separator a material is defined and another transformation. Our cylinder will therefore be affected by both transformations, the one applied directly to it and the one that was applied to its parent separator.
We also have many other types of elements to organize our scene, such as groups, switches or annotations. We can define very complex materials for our objects, with colors, textures, shading modes and transparency. We can also define lights, cameras, and even movement. It is even possible to embed pieces of scripting in Open Inventor files to define more complex behaviors.
If you are interested in learning more about Open Inventor head directly to its most famous reference: the Inventor mentor.
In FreeCAD, normally, we don't need to interact directly with the Open Inventor scenegraph. Every object in a FreeCAD document, being a mesh, a part shape or anything else, gets automatically converted to Open Inventor code and inserted in the main scenegraph that you see in a 3D view. That scenegraph gets updated continuously when you modify, add or remove objects. In fact every object (in App space) has a view provider (a corresponding object in Gui space) responsible for issuing Open Inventor code.
But there are many advantages to being able to access the scenegraph directly. For example, we can temporarily change the appearance of an object, or we can add objects to the scene that have no real existence in the FreeCAD document, such as construction geometry, helpers, graphical hints or tools such as manipulators or on-screen information.
FreeCAD itself features several tools to see or modify Open Inventor code. For example, the following Python code will show the Open Inventor representation of a selected object:
obj = FreeCAD.ActiveDocument.ActiveObject
viewprovider = obj.ViewObject
print viewprovider.toString()
But we also have a Python module that allows complete access to anything managed by Coin3D, such as our FreeCAD scenegraph. So, read on to Pivy.
Coding examples
See Coin3d snippets courtesy of MariwanJ's research for the Design456 Workbench. The code repository can be found at https://github.com/MariwanJ/COIN3D_Snippet.
![](/images/thumb/8/8f/Power_user_hub.png/24px-Power_user_hub.png)
- FreeCAD scripting: Python, Introduction to Python, Python scripting tutorial, FreeCAD Scripting Basics
- Modules: Builtin modules, Units, Quantity
- Workbenches: Workbench creation, Gui Commands, Commands, Installing more workbenches
- Meshes and Parts: Mesh Scripting, Topological data scripting, Mesh to Part, PythonOCC
- Parametric objects: Scripted objects, Viewproviders (Custom icon in tree view)
- Scenegraph: Coin (Inventor) scenegraph, Pivy
- Graphical interface: Interface creation, Interface creation completely in Python (1, 2, 3, 4, 5), PySide, PySide examples beginner, intermediate, advanced
- Macros: Macros, How to install macros
- Embedding: Embedding FreeCAD, Embedding FreeCADGui
- Other: Expressions, Code snippets, Line drawing function, FreeCAD vector math library (deprecated)
- Hubs: User hub, Power users hub, Developer hub