Multiple geometries#

A Scene may consist of more than one geometry object. For fast performance, try to condense the scene down to as few geometries with as many primitives as possible. Multiple geometries allow for different materials to be applied to the same type of geometry and for different types of geometry in the same scene.

[1]:
import fresnel
scene = fresnel.Scene()

Create multiple geometries#

To create multiple geometries, instantiate several instances of the geometry class.

[2]:
geom1 = fresnel.geometry.Sphere(scene, position = [[-3.2, 1, 0], [-3.2, -1, 0], [-1.2, 1, 0], [-1.2, -1, 0]], radius=1.0)
geom1.material = fresnel.material.Material(solid=1.0, color=fresnel.color.linear([0.42,0.267,1]))
geom1.outline_width = 0.12
[3]:
geom2 = fresnel.geometry.Sphere(scene, position = [[3.2, 1, 0], [3.2, -1, 0], [1.2, 1, 0], [1.2, -1, 0]], radius=1.0)
geom2.material = fresnel.material.Material(solid=0.0, color=fresnel.color.linear([1,0.874,0.169]))
[4]:
scene.camera = fresnel.camera.Orthographic.fit(scene)
fresnel.preview(scene, w=900, h=370)
[4]:
../../_images/examples_02-Advanced-topics_00-Multiple-geometries_5_0.png

Disable geometries#

disable a geometry to prevent it from appearing in the scene.

[5]:
geom1.disable()
[6]:
fresnel.preview(scene, w=900, h=370)
[6]:
../../_images/examples_02-Advanced-topics_00-Multiple-geometries_8_0.png

enable the geometry to make it appear again.

[7]:
geom1.enable()
[8]:
fresnel.preview(scene, w=900, h=370)
[8]:
../../_images/examples_02-Advanced-topics_00-Multiple-geometries_11_0.png

Remove geometry#

Call remove to completely remove a geometry instance from the scene. It cannot be added back.

[9]:
geom2.remove()
[10]:
fresnel.preview(scene, w=900, h=370)
[10]:
../../_images/examples_02-Advanced-topics_00-Multiple-geometries_14_0.png

This page was generated from a jupyter notebook. You can download and run the notebook locally from the fresnel-examples repository.