Scenegraph/es: Difference between revisions

From FreeCAD Documentation
(Created page with "Una escena gráfica de openInventor describe todo lo que es parte de una escena 3D, como la geometría, colores, materiales, luces, etc, y organiza todos los datos en una estr...")
(Created page with "Como puedes ver, la estructura es muy simple. Utiliza separadores para organizar los datos en bloques, parecido a como harías al organizar tus archivos en carpetas. Cada decl...")
Line 39: Line 39:
</syntaxhighlight>
</syntaxhighlight>


Como puedes ver, la estructura es muy simple. Utiliza separadores para organizar los datos en bloques, parecido a como harías al organizar tus archivos en carpetas. Cada declaración afecta a lo que viene después, por ejemplo los dos primeros puntos de nuestro separador raíz son una rotación y una traslación, todo ello afectará al siguiente elemento, que es un separador. En ese separador, se define un material y otra transformación. Nuestro cilindro por lo tanto se verá afectado por las dos transformaciones, la que le fue aplicada directamente, y la que se aplicó al separador que le contiene.
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 who was 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 color, textures, shading modes and transparency. We can also define lights, cameras, and even movement. It is even possible to embed pieces of scripting in openInventor files, to define more complex behaviours.
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 color, textures, shading modes and transparency. We can also define lights, cameras, and even movement. It is even possible to embed pieces of scripting in openInventor files, to define more complex behaviours.

Revision as of 20:15, 1 October 2014

FreeCAD es, en esencia, un collage de varias bibliotecas muy potentes, siendo las más importantes openCascade, para la gestión y construcción de la geometría, Coin3d para visualizar esa geometría, y Qt para poner todo esto en una bonita interfaz gráfica de usuario (GUI).

La geometría que aparece en las vistas 3D de FreeCAD son renderizadas por la biblioteca Coin3D. Coin3D es una implementación del estandard OpenInventor. El software OpenCascade también proporciona la misma funcionalidad, pero se decidió, al comenzar el desarrollo de FreeCAD, no utilizar el visor de OpenCascade, sino cambiar al software Coin3D, por tener mejor rendimiento. Un buen modo de aprender sobre esa librería es el libro Open Inventor Mentor.

OpenInventor es en realidad un lenguaje de descripción de escena 3D. La escena descrita en openInventor es seguidamente renderizada en la pantalla con OpenGL. Coin3d se encarga de hacer esto, por lo que el programador no tiene que lidiar con complejas llamadas a OpenGL, bastará con que le proporcione código OpenInventor válido. La gran ventaja es que openInventor es un estándard muy bien conocido y bien documentado.

Uno de los trabajos mas inportantes que FreeCAD hace por ti es, básicamente, traducir la información de geometría OpenCascade al idioma de openInventor.

OpenInventor describe una escena 3D en forma de una escena gráfica (scenegraph), como la siguiente:

image from Inventor mentor

Una escena gráfica de openInventor describe todo lo que es parte de una escena 3D, como la geometría, colores, materiales, luces, etc, y organiza todos los datos en una estructura cómoda y clara. Todo puede agruparse en sub-estructuras, lo que te permite organizar los contenidos de tu escena más o menos de la forma que quiera. He aquí un ejemplo de un archivo de openInventor:

 #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 {
        }
     }
 }

Como puedes ver, la estructura es muy simple. Utiliza separadores para organizar los datos en bloques, parecido a como harías al organizar tus archivos en carpetas. Cada declaración afecta a lo que viene después, por ejemplo los dos primeros puntos de nuestro separador raíz son una rotación y una traslación, todo ello afectará al siguiente elemento, que es un separador. En ese separador, se define un material y otra transformación. Nuestro cilindro por lo tanto se verá afectado por las dos transformaciones, la que le fue aplicada directamente, y la que se aplicó al separador que le contiene.

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 color, textures, shading modes and transparency. We can also define lights, cameras, and even movement. It is even possible to embed pieces of scripting in openInventor files, to define more complex behaviours.

If you are interested in learning more about openInventor, head directly to its most famous reference, the Inventor mentor.

In FreeCAD, normally, we don't need to interact directly with the openInventor scenegraph. Every object in a FreeCAD document, being a mesh, a part shape or anything else, gets automatically converted to openInventor code and inserted in the main scenegraph that you see in a 3D view. That scenegraph gets updated continuously when you do modifications, add or remove objects to the document. In fact, every object (in App space) has a view provider (a corresponding object in Gui space), responsible for issuing openInventor code.

But there are many advantages to be able to access the scenegraph directly. For example, we can temporarily change the appearence 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 openInventor code. For example, the following python code will show the openInventor 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.

Mesh to Part
Pivy