|
1 | 1 | import os |
| 2 | +import pickle |
| 3 | +import time |
2 | 4 |
|
3 | 5 | import numpy as np |
4 | 6 | import torch |
5 | | -import pickle |
6 | | -import time |
7 | 7 | import taichi as ti |
| 8 | +from numpy.typing import ArrayLike |
8 | 9 |
|
9 | 10 | import genesis as gs |
10 | 11 | import genesis.utils.geom as gu |
@@ -434,95 +435,84 @@ def link_entities( |
434 | 435 |
|
435 | 436 | if child_link._parent_idx != -1: |
436 | 437 | gs.logger.warning( |
437 | | - "Child entity already has a parent link. This may cause the entity to break into parts. Make sure this operation is intended." |
| 438 | + "Child entity already has a parent link. This may cause the entity to break into parts. Make sure " |
| 439 | + "this operation is intended." |
438 | 440 | ) |
439 | 441 | child_link._parent_idx = parent_link.idx |
440 | 442 | parent_link._child_idxs.append(child_link.idx) |
441 | 443 |
|
442 | 444 | @gs.assert_unbuilt |
443 | 445 | def add_light( |
444 | 446 | self, |
445 | | - morph: Morph, |
446 | | - color=(1.0, 1.0, 1.0, 1.0), |
447 | | - intensity=20.0, |
448 | | - revert_dir=False, |
449 | | - double_sided=False, |
450 | | - beam_angle=180.0, |
| 447 | + *, |
| 448 | + morph: Morph | None = None, |
| 449 | + color: ArrayLike | None = (1.0, 1.0, 1.0, 1.0), |
| 450 | + intensity: float = 20.0, |
| 451 | + revert_dir: bool | None = False, |
| 452 | + double_sided: bool | None = False, |
| 453 | + beam_angle: float | None = 180.0, |
| 454 | + pos: ArrayLike | None = None, |
| 455 | + dir: ArrayLike | None = None, |
| 456 | + directional: bool | None = None, |
| 457 | + castshadow: bool | None = None, |
| 458 | + cutoff: float | None = None, |
451 | 459 | ): |
452 | 460 | """ |
453 | | - Add a light to the scene. Note that lights added this way can be instantiated from morphs |
454 | | - (supporting `gs.morphs.Primitive` or `gs.morphs.Mesh`), and will only be used by the RayTracer renderer. |
| 461 | + Add a light to the scene. |
| 462 | +
|
| 463 | + Warning |
| 464 | + ------- |
| 465 | + The signature of this method is different depending on the renderer being used, i.e.: |
| 466 | + - RayTracer: 'add_light(self, morph, color, intensity, revert_dir, double_sided, beam_angle)' |
| 467 | + - BatchRender: 'add_ligth(self, pos, dir, intensity, directional, castshadow, cutoff)' |
| 468 | + - Rasterizer: **Unsupported** |
455 | 469 |
|
456 | 470 | Parameters |
457 | 471 | ---------- |
458 | 472 | morph : gs.morphs.Morph |
459 | | - The morph of the light. Must be an instance of `gs.morphs.Primitive` or `gs.morphs.Mesh`. |
| 473 | + The morph of the light. Must be an instance of `gs.morphs.Primitive` or `gs.morphs.Mesh`. Only supported by |
| 474 | + RayTracer. |
460 | 475 | color : tuple of float, shape (3,) |
461 | | - The color of the light, specified as (r, g, b). |
| 476 | + The color of the light, specified as (r, g, b). Only supported by RayTracer. |
462 | 477 | intensity : float |
463 | 478 | The intensity of the light. |
464 | 479 | revert_dir : bool |
465 | 480 | Whether to revert the direction of the light. If True, the light will be emitted towards the mesh's inside. |
| 481 | + Only supported by RayTracer. |
466 | 482 | double_sided : bool |
467 | | - Whether to emit light from both sides of surface. |
| 483 | + Whether to emit light from both sides of surface. Only supported by RayTracer. |
468 | 484 | beam_angle : float |
469 | | - The beam angle of the light. |
470 | | - """ |
471 | | - if isinstance(self.renderer_options, gs.renderers.BatchRenderer): |
472 | | - gs.logger.warning( |
473 | | - "This add_light() function is only supported when NOT using BatchRenderer." |
474 | | - "Please use add_light(self, pos, dir, intensity, directional, castshadow, cutoff) instead." |
475 | | - ) |
476 | | - return |
477 | | - |
478 | | - if self.visualizer.raytracer is None: |
479 | | - gs.logger.warning("Light is only supported by RayTracer renderer.") |
480 | | - return |
481 | | - |
482 | | - if not isinstance(morph, (gs.morphs.Primitive, gs.morphs.Mesh)): |
483 | | - gs.raise_exception("Light morph only supports `gs.morphs.Primitive` or `gs.morphs.Mesh`.") |
484 | | - |
485 | | - mesh = gs.Mesh.from_morph_surface(morph, gs.surfaces.Plastic(smooth=False)) |
486 | | - self.visualizer.raytracer.add_mesh_light( |
487 | | - mesh, color, intensity, morph.pos, morph.quat, revert_dir, double_sided, beam_angle |
488 | | - ) |
489 | | - |
490 | | - @gs.assert_unbuilt |
491 | | - def add_light( |
492 | | - self, |
493 | | - pos, |
494 | | - dir, |
495 | | - intensity, |
496 | | - directional, |
497 | | - castshadow, |
498 | | - cutoff, |
499 | | - ): |
500 | | - """ |
501 | | - Add a light to the scene for batch renderer. |
502 | | -
|
503 | | - Parameters |
504 | | - ---------- |
| 485 | + The beam angle of the light. Only supported by RayTracer. |
505 | 486 | pos : tuple of float, shape (3,) |
506 | | - The position of the light, specified as (x, y, z). |
| 487 | + The position of the light, specified as (x, y, z). Only supported by BatchRenderer. |
507 | 488 | dir : tuple of float, shape (3,) |
508 | | - The direction of the light, specified as (x, y, z). |
| 489 | + The direction of the light, specified as (x, y, z). Only supported by BatchRenderer. |
509 | 490 | intensity : float |
510 | | - The intensity of the light. |
| 491 | + The intensity of the light. Only supported by BatchRenderer. |
511 | 492 | directional : bool |
512 | | - Whether the light is directional. |
| 493 | + Whether the light is directional. Only supported by BatchRenderer. |
513 | 494 | castshadow : bool |
514 | | - Whether the light casts shadows. |
| 495 | + Whether the light casts shadows. Only supported by BatchRenderer. |
515 | 496 | cutoff : float |
516 | | - The cutoff angle of the light in degrees. |
| 497 | + The cutoff angle of the light in degrees. Only supported by BatchRenderer. |
517 | 498 | """ |
518 | | - if not isinstance(self.renderer_options, gs.renderers.BatchRenderer): |
519 | | - gs.logger.warning( |
520 | | - "This add_light() function is only supported when using BatchRenderer." |
521 | | - "Please use add_light(self, morph, color, intensity, revert_dir, double_sided, beam_angle) instead." |
| 499 | + if self._visualizer.batch_renderer is not None: |
| 500 | + if any(map(lambda e: e is None, (pos, dir, intensity, directional, castshadow, cutoff))): |
| 501 | + gs.raise_exception("Input arguments do not complain with expected signature when using 'BatchRenderer'") |
| 502 | + |
| 503 | + self.visualizer.add_light(pos, dir, intensity, directional, castshadow, cutoff) |
| 504 | + elif self.visualizer.raytracer is not None: |
| 505 | + if any(map(lambda e: e is None, (morph, color, intensity, revert_dir, double_sided, beam_angle))): |
| 506 | + gs.raise_exception("Input arguments do not complain with expected signature when using 'RayTracer'") |
| 507 | + if not isinstance(morph, (gs.morphs.Primitive, gs.morphs.Mesh)): |
| 508 | + gs.raise_exception("Light morph only supports `gs.morphs.Primitive` or `gs.morphs.Mesh`.") |
| 509 | + |
| 510 | + mesh = gs.Mesh.from_morph_surface(morph, gs.surfaces.Plastic(smooth=False)) |
| 511 | + self.visualizer.raytracer.add_mesh_light( |
| 512 | + mesh, color, intensity, morph.pos, morph.quat, revert_dir, double_sided, beam_angle |
522 | 513 | ) |
523 | | - return |
524 | | - |
525 | | - self.visualizer.add_light(pos, dir, intensity, directional, castshadow, cutoff) |
| 514 | + else: |
| 515 | + gs.raise_exception("Adding lights is only supported by 'RayTracer' and 'BatchRenderer'.") |
526 | 516 |
|
527 | 517 | @gs.assert_unbuilt |
528 | 518 | def add_camera( |
@@ -1110,7 +1100,7 @@ def render_all_cameras(self, rgb=True, depth=False, normal=False, segmentation=F |
1110 | 1100 | Returns: |
1111 | 1101 | A tuple of tensors of shape (n_envs, H, W, 3) if rgb is not None, |
1112 | 1102 | otherwise a list of tensors of shape (n_envs, H, W, 1) if depth is not None. |
1113 | | - If n_envs ==0, the first dimension of the tensor is squeezed. |
| 1103 | + If n_envs == 0, the first dimension of the tensor is squeezed. |
1114 | 1104 | """ |
1115 | 1105 | return self._visualizer.batch_renderer.render(rgb, depth, normal, segmentation, force_render) |
1116 | 1106 |
|
|
0 commit comments