# simulate **Repository Path**: mirrors_huggingface/simulate ## Basic Information - **Project Name**: simulate - **Description**: π’ Creating and sharing simulation environments for embodied and synthetic data research - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-10-24 - **Last Updated**: 2026-01-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README
### Creating a Scene and adding/managing Objects in the scene Basic example of creating a scene with a plane and a sphere above it: ``` import simulate as sm scene = sm.Scene() scene += sm.Plane() + sm.Sphere(position=[0, 1, 0], radius=0.2) >>> scene >>> Scene(dimensionality=3, engine='PyVistaEngine') >>> βββ plane_01 (Plane - Mesh: 121 points, 100 cells) >>> βββ sphere_02 (Sphere - Mesh: 842 points, 870 cells) scene.show() ``` An object (as well as the Scene) is just a node in a tree provided with optional mesh (under the hood created/stored/edited as a [`pyvista.PolyData`](https://docs.pyvista.org/api/core/_autosummary/pyvista.PolyData.html#pyvista-polydata) or [`pyvista.MultiBlock`](https://docs.pyvista.org/api/core/_autosummary/pyvista.MultiBlock.html#pyvista-multiblock) objects) and material and/or light, camera, agents special objects. The following objects creation helpers are currently provided: - `Object3D` any object with a mesh and/or material - `Plane` - `Sphere` - `Capsule` - `Cylinder` - `Box` - `Cone` - `Line` - `MultipleLines` - `Tube` - `Polygon` - `Ring` - `Text3D` - `Triangle` - `Rectangle` - `Circle` - `StructuredGrid` - ... (see the doc) Many of these objects can be visualized by running the following [example](https://github.com/huggingface/simulate/tree/main/examples/objects.py): ``` python examples/basic/objects.py ```
### Objects are organized in a tree structure Adding/removing objects: - Using the addition (`+`) operator (or alternatively the method `.add(object)`) will add an object as a child of a previous object. - Objects can be removed with the subtraction (`-`) operator or the `.remove(object)` command. - Several objects can be added at once by adding a list/tuple to the scene. - The whole scene can be cleared with `.clear()`. - To add a nested object, just add it to the object under which it should be nested, e.g. `scene.sphere += sphere_child`. Accessing objects: - Objects can be directly accessed as attributes of their parents using their names (given with `name` attribute at creation or automatically generated from the class name + creation counter). - Objects can also be accessed from their names with `.get_node(name)`. - The names of the object are enforced to be unique (on save/show). - Various `tree_*` attributes are available on any node to quickly navegate or list part of the tree of nodes. Here are a couple of examples of manipulations: ``` # Add two copy of the sphere to the scene as children of the root node (using list will add all objects on the same level) # Using `.copy()` will create a copy of an object (the copy doesn't have any parent or children) scene += [scene.plane_01.sphere_02.copy(), scene.plane_01.sphere_02.copy()] >>> scene >>> Scene(dimensionality=3, engine='pyvista') >>> βββ plane_01 (Plane - Mesh: 121 points, 100 cells) >>> β βββ sphere_02 (Sphere - Mesh: 842 points, 870 cells) >>> βββ sphere_03 (Sphere - Mesh: 842 points, 870 cells) >>> βββ sphere_04 (Sphere - Mesh: 842 points, 870 cells) # Remove the last added sphere >>> scene.remove(scene.sphere_04) >>> Scene(dimensionality=3, engine='pyvista') >>> βββ plane_01 (Plane - Mesh: 121 points, 100 cells) >>> β βββ sphere_02 (Sphere - Mesh: 842 points, 870 cells) >>> βββ sphere_03 (Sphere - Mesh: 842 points, 870 cells) ``` ### Editing and moving objects Objects can be easily translated, rotated, scaled Here are a couple of examples: ``` # Let's translate our floor (with the first sphere, it's child) scene.plane_01.translate_x(1) # Let's scale the second sphere uniformly scene.sphere_03.scale(0.1) # Inspect the current position and scaling values print(scene.plane_01.position) >>> array([1., 0., 0.]) print(scene.sphere_03.scaling) >>> array([0.1, 0.1, 0.1]) # We can also translate from a vector and rotate from a quaternion or along the various axis ``` Editing objects: - mesh of the object can be edited with all the manipulation operator provided by [pyvista](https://docs.pyvista.org/user-guide/index.html) ## Visualization engine A default visualization engine is provided with the vtk backend of [`pyvista`](https://docs.pyvista.org/user-guide/index.html). Starting the visualization engine can be done simply with `.show()`. ``` scene.show() ``` You can find bridges to other rendering/simulation engines in the `integrations` directory. ## Tips If you are running on GCP, remember not to install `pyvistaqt`, and if you did so, uninstall it in your environment, since QT doesn't work well on GCP. ## Citation ```bibtex @misc{simulate, author = {Thomas Wolf, Edward Beeching, Carl Cochet, Dylan Ebert, Alicia Machado, Nathan Lambert, ClΓ©ment Romac}, title = {Simulate}, year = {2022}, publisher = {GitHub}, journal = {GitHub repository}, howpublished = {\url{https://github.com/huggingface/simulate}} } ```