User Tools

Site Tools


tutorials:import-object-in-groimp

GroIMP can import objects from several 3d or graph formats into the project graph. The imported objects can then be used similar to any other part of the graph.

In the following different way of adding a file will be shown based on this dtd file.

Using the Gui

Add directly

The easiest way is to add the object directly, using the main menu: Objects, there you can find the options insert File and insert File to RGG.

They both work very similar, starting with a file dialog to choose which file to import and then turning this file into a graph and adding it. The only difference is that 'Insert File' adds the loaded graph to the root of the scene and 'Insert File to RGG' to the RGG root. This leads to the difference that a file inserted to RGG will be removed when the model is rested or recompiled.

In order to remove a object added to the root of the scene the function 'clear project graph' in the main menu: Edit can be used. Additionally it is always possible to select and object in the 2d or 3d view and use the delte key.

In a new RGG project using the file from above the following result should be appearing:

Since this little tree is added to the GroIMP Graph it can now be queried and manipulated using XL rules. For example to add the following query to the XL console should return 344.

count((*F*)); 

Or remove stepwise the last internodes:

	[f:F,(empty((*f --> Node*)))==>;]

Using the Object explorer

A second more reusable way is to add the external objects to the Object explorer. The explorer can be found on the main menu on Panels/Explorers/Objects. In the newly opened panel a menu with the item Object should be visible. Under this item following the path '/new/insert File' we can select the same file as above. After selecting the file with the file dialog a popup asks “How should the file be added?” the three options mean:

Add the file: the file is copied to a folder objects in the GSZ or the project directory, this means the file is added to the project and will also be available if the project is moved.

Link the file: only the path to the current file is added, this can be useful in a more complex pipeline where the external file is updated by another softare or another GroIMP project. Yet this relays on the the file path to the external object.

Embed the file: The file is read and added to the meta Graph. Doing so makes it independent from the format, the file or the import process. Yet it is then part of the GroImp Graph and for bigger files this could slow down the simulation.

The choice really depends on the use case, but in our case the easiest is to add the file. After the file was loaded it can be reference from the RGG using 'Reference(“cherry_new.dtd”);'. Using this in a XL query will create an instance of the imported object, in the Graph. Meaning it is not importing the graph structure but only one node representing the 3d structure.

For example the following code would create three time the same tree in a row:

protected void init ()
[
	Axiom ==> for(int i=0; i<3; i++)(
	Translate(0,1,0)
		[
			Reference("cherry_new.dtd")
		]
	);
]

It is also possible to access the graph structure of this referenced objects using the code below but it is more recommended to use the GraphExplorer to do so.

	{
	Reference ref = new Reference("cherry_new.dtd");
	Node refRoot = ref.resolveNode();
	}
tutorials/import-object-in-groimp.txt · Last modified: 2024/09/27 16:22 by tim