-
Notifications
You must be signed in to change notification settings - Fork 29
/
08.obj_scene_loader.py
83 lines (67 loc) · 2.19 KB
/
08.obj_scene_loader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import nvisii
import noise
import random
import numpy as np
opt = lambda : None
opt.spp = 512
opt.width = 1024
opt.height = 1024
opt.out = "08_obj_scene_loader.png"
# # # # # # # # # # # # # # # # # # # # # # # # #
nvisii.initialize(headless=True, verbose=True)
nvisii.enable_denoiser()
camera = nvisii.entity.create(
name = "camera",
transform = nvisii.transform.create("camera"),
camera = nvisii.camera.create(
name = "camera",
aspect = float(opt.width)/float(opt.height)
)
)
camera.get_transform().look_at(
at = (-5,0,12), # look at (world coordinate)
up = (0,0,1), # up vector
eye = (5,-15,18)
)
nvisii.set_camera_entity(camera)
# # # # # # # # # # # # # # # # # # # # # # # # #
sdb = nvisii.import_scene(
file_path = 'content/salle_de_bain_separated/salle_de_bain_separated.obj',
position = (1,0,0),
scale = (1.0, 1.0, 1.0),
rotation = nvisii.angleAxis(3.14 * .5, (1,0,0)),
args = ["verbose"] # list assets as they are loaded
)
# Using the above function,
# nvisii loads each obj model as its own entity.
# You can find them by name (with an optional prefix added
# to front of each generated component name)
# nvisii generates the same naming pattern for the different
# materials defined in the mtl file
# since obj/mtl do not have definition for metallic properties
# lets add them manually to the material
mirror = nvisii.material.get('Mirror')
mirror.set_roughness(0)
mirror.set_metallic(1)
mirror.set_base_color((1,1,1))
# When loading the obj scene, nvisii returns a list of entities
# you can loop them to find specific objects or add physical
# collisions.
# Since obj/mtl do not define lights, lets add one to the mesh
# named light
for i_s, s in enumerate(sdb.entities):
if "light" in s.get_name().lower():
s.set_light(nvisii.light.create('light'))
s.get_light().set_intensity(1)
s.get_light().set_exposure(15)
s.get_light().set_temperature(5000)
s.clear_material()
# # # # # # # # # # # # # # # # # # # # # # # # #
nvisii.render_to_file(
width=opt.width,
height=opt.height,
samples_per_pixel=opt.spp,
file_path=opt.out
)
# let's clean up the GPU
nvisii.deinitialize()