-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to construct a subset scene from existing scene objects? #1328
Comments
Hi @ebhrz, One option would be to construct a dictionary from all the objects in your scene i.e. shapes, emitters, sensors and integrators. def to_dict(scene: mi.Scene):
assert isinstance(scene, mi.Scene)
children = [
*scene.shapes(),
*scene.emitters(),
*scene.sensors(),
scene.integrator(),
]
return {
"type": "scene",
**{child.id(): child for child in children},
} Note, that this will not construct the same dict from which the scene has been created, but it will create the same scene when calling |
Hi @ebhrz, (1) AFAIK, we cannot dynamically maintain an initialized scene. |
@DoeringChristian Thanks so much for your solution! I think it will work well, let me have a try. |
@ziyi-zhang Hi Ziyi, sorry for bothering again. I've resolved the previous issue with optixPipelineCreate failing. It was due to an out-of-memory error because TensorFlow was consuming a substantial amount of memory. Additionally, I suspect there might be a memory leak, as memory usage increases progressively during program execution. I’m uncertain whether this is due to Mitsuba or TensorFlow. To address this, I've implemented a memory growth strategy in TensorFlow to ensure that Mitsuba has sufficient memory available. However, I’ve encountered another issue: Critical Dr.Jit compiler failure: cuda_check(): API error 0700 (CUDA_ERROR_ILLEGAL_ADDRESS): "an illegal memory access was encountered" in /project/ext/drjit-core/src/init.cpp:454. This error does not consistently reproduce; it only appears after the program has run numerous epochs. Running a specific epoch in isolation does not trigger the error. Could you provide any insights or suggestions on how to tackle this problem? Thank you for your assistance. |
I use it in this way: for depth in range(max_depth):
si = scene.ray_intersect(rays)
active &= si.is_valid()
# Record which primitives were hit
shape_i = dr.gather(mi.Int32, shape_indices,
dr.reinterpret_array_v(mi.UInt32, si.shape),
active)
offsets = dr.gather(mi.Int32, prim_offsets, shape_i,
active)
prims_i = dr.select(active, offsets + si.prim_index, -1)
candidates.append(prims_i)
# Record the hit point
hit_p = rays.o + si.t*rays.d
t_all[depth] = si.t.numpy()
hit_points.append(hit_p.numpy())
clos = ~active.numpy()
los[depth] = clos
# Prepare the next interaction, assuming purely specular
# reflection
rays = si.spawn_ray(si.to_world(mi.reflect(si.wi)))
direct[depth+1] = rays.d.numpy() |
A quick tip about this particular problem: if your application allows, enclosing your shapes in a |
Thanks @merlinND, yes, I'll not use BSDF. In fact I'm not doing rendering, but just the ray tracing. Besides, sorry for my stupid question, how can I enclose these shapes? I can't find the related api in the document. Currently I use the solution from Christian. |
Hi @ziyi-zhang , I've solved the issue by adding a dr. eval() expression. Thanks for your kind assistant. |
@ebhrz The idea is simply to have the shapes in your scene nested inside of a <shape type="merge">
<shape type="obj" ...>
....
</shape> Or with @DoeringChristian's solution, something like: def to_dict(scene: mi.Scene):
assert isinstance(scene, mi.Scene)
children = [
*scene.emitters(),
*scene.sensors(),
scene.integrator(),
]
return {
"type": "scene",
"merged_shape": dict({ "type": "merge",
**{child.id(): child for child in scene.shapes()}),
**{child.id(): child for child in children},
} |
I have a very big scene, including thousands of shapes and I need to do the ray tracing. I found that the ray tracing speed seems relate to the size of the scenario. I want to write an octree to coarsely query the surrounding shapes. But once I get all the shapes, how can I use these shapes to construct a new scene? I can't find any API to create a scene from the object, but only load_file, load_dict and load_string
The text was updated successfully, but these errors were encountered: