1+ # 01.simple_scene.py
2+ #
3+ # This shows a sphere on top of a mirror floor.
4+ # You should see how to set up a simple scene with visii, where light is
5+ # provided by the dome.
6+
17import visii
28
3- SAMPLES_PER_PIXEL = 50
4- WIDTH = 500
5- HEIGHT = 500
6- USE_DENOISER = True
7- FILE_NAME = "tmp .png"
9+ opt = lambda : None
10+ opt . spp = 50
11+ opt . width = 512
12+ opt . height = 512
13+ opt . out = '01_simple_scene .png'
814
915# headless - no window
1016# verbose - output number of frames rendered, etc..
1117visii .initialize (headless = True , verbose = True )
1218
13- # Uses a neural network to denoise ray traced
14- if USE_DENOISER : visii .enable_denoiser ()
19+ # Use a neural network to denoise ray traced
20+ visii .enable_denoiser ()
1521
1622# First, lets create an entity that will serve as our camera.
1723camera = visii .entity .create (name = "camera" )
1824
19- # To place the camera into our scene, we'll add a "transform" component
20- # Note that all visii objects have a "name" that can be used for easy lookup later.
21- # These names must be unique per component-type, but can be reused across types.
25+ # To place the camera into our scene, we'll add a "transform" component.
26+ # (All visii objects have a "name" that can be used for easy lookup later.)
2227camera .set_transform (visii .transform .create (name = "camera_transform" ))
2328
2429# To make our camera entity act like a "camera", we'll add a camera component
2530camera .set_camera (
2631 visii .camera .create_from_fov (
2732 name = "camera_camera" ,
2833 field_of_view = 0.785398 , # note, this is in radians
29- aspect = float ( WIDTH ) / float (HEIGHT )
34+ aspect = opt . width / float (opt . height )
3035 )
3136)
3237
3338# Finally, we'll select this entity to be the current camera entity.
3439# (visii can only use one camera at the time)
3540visii .set_camera_entity (camera )
3641
37- # Lets place our camera in the scene to look at an object
38-
39- # All positions and vectors are defined through a sequence of three numbers.
40- # That sequence can be specified using lists, tuples, through numpy,
41- # or using the built in visii.vec3 type:
42- # transform.set_position([x, y, z]) <- lists
43- # transform.set_position((x, y, z)) <- tuples
44- # transform.set_position(np.array([x, y, z])) <- numpy arrays
45- # transform.set_position(visii.vec3(x, y, z)) <- visii vec3 object
46-
47- # note that visii quaternions are slightly out of order from a normal list
48- # transform.set_rotation([x, y, z, w]) <- lists
49- # transform.set_rotation(visii.quat(w, x, y, z)) <- visii quat object
50-
5142# Lets set the camera to look at an object.
52- # We'll do this by editing the transform component,
53- # which functionally acts like the camera's "view" transform.
54- # (Note that any of the below three vectors can match any of
55- # the above mentioned patterns)
56- camera .get_transform ().look_at (
57- at = (0 , 0 , 0.9 ), # at position
58- up = (0 , 0 , 1 ), # up vector
59- eye = (0 , 5 , 1 ) # eye position
60- )
43+ # We'll do this by editing the transform component.
44+ camera .get_transform ().look_at (at = (0 , 0 , .9 ), up = (0 , 0 , 1 ), eye = (0 , 5 , 1 ))
6145
6246# Next, lets at an object (a floor).
63- # For an entity to be visible to a camera, that entity
64- # must have a mesh component, a transform component, and a
65- # material component.
66- visii .entity .create (
47+ floor = visii .entity .create (
6748 name = "floor" ,
6849 mesh = visii .mesh .create_plane ("mesh_floor" ),
6950 transform = visii .transform .create ("transform_floor" ),
7051 material = visii .material .create ("material_floor" )
7152)
7253
7354# Lets make our floor act as a mirror
74- # we first get the material associated with our floor entity
75- # if you do not have a direct handler to the entity, you
76- # search for a specific entity, material, transform, etc.
77- # name.
78- mat = visii .material .get ("material_floor" )
79-
80- # Lets change the color
81- # the colors are RGB and the values are expected to be between
82- # 0 and 1.
55+ mat = floor .get_material ()
56+ # mat = visii.material.get("material_floor") # <- this also works
57+
58+ # Mirrors are smooth and "metallic".
8359mat .set_base_color ((0.19 ,0.16 ,0.19 ))
84- # Lets now change the metallic propreties for shinyness
8560mat .set_metallic (1 )
86- # to make sure we get a perfect mirror lets change the roughness
8761mat .set_roughness (0 )
8862
89- # we want to make sure our floor is large so let's update the
90- # scale of the object.
91- trans = visii .transform .get ("transform_floor" )
92-
93- # the scale takes as input a vector of 3 numbers
63+ # Make the floor large by scaling it
64+ trans = floor .get_transform ()
9465trans .set_scale ((5 ,5 ,1 ))
9566
9667# Let's also add a sphere
10071 transform = visii .transform .create ("sphere" ),
10172 material = visii .material .create ("sphere" )
10273)
103- # lets set the sphere up
10474sphere .get_transform ().set_position ((0 ,0 ,0.41 ))
10575sphere .get_transform ().set_scale ((0.4 , 0.4 , 0.4 ))
10676sphere .get_material ().set_base_color ((0.1 ,0.9 ,0.08 ))
10777sphere .get_material ().set_roughness (0.7 )
108- sphere .get_material ().set_specular (1 )
109-
11078
111- # # # # # # # # # # # # # # # # # # # # # # # # #
112- # now that we have a simple scene set up let's render it
113- print ("rendering to" , FILE_NAME )
114- visii .render_to_png (
115- width = WIDTH ,
116- height = HEIGHT ,
117- samples_per_pixel = SAMPLES_PER_PIXEL ,
118- image_path = FILE_NAME
79+ # Now that we have a simple scene, let's render it
80+ print ("rendering to" , "01_simple_scene.png" )
81+ visii .render_to_file (
82+ width = opt .width ,
83+ height = opt .height ,
84+ samples_per_pixel = opt .spp ,
85+ file_path = "01_simple_scene.png"
11986)
12087
121- # let's clean up the GPU
12288visii .deinitialize ()
123- print ("done!" )
0 commit comments