Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions genesis/options/morphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,13 @@ class Plane(Primitive):
Whether the entity needs to be visualized. Set it to False if you need a invisible object only for collision purposes. Defaults to True. `visualization` and `collision` cannot both be False. **This is only used for RigidEntity.**
collision : bool, optional
Whether the entity needs to be considered for collision checking. Defaults to True. `visualization` and `collision` cannot both be False. **This is only used for RigidEntity.**
double_sided : bool, optional
Whether the entity needs to be rendered as a one-sided or two-sided plane.
"""

fixed: bool = True
normal: tuple = (0, 0, 1)
double_sided: bool = False

def __init__(self, **data):
super().__init__(**data)
Expand All @@ -348,6 +351,8 @@ def __init__(self, **data):
if self.requires_jac_and_IK:
gs.raise_exception("`requires_jac_and_IK` must be False for `Plane`.")

self.double_sided = self.double_sided

self.normal = tuple(np.array(self.normal) / np.linalg.norm(self.normal))


Expand Down
40 changes: 26 additions & 14 deletions genesis/utils/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,24 +860,36 @@ def create_box(extents=None, color=(1.0, 1.0, 1.0, 1.0), bounds=None, wireframe=

def create_plane(size=1e3, color=None, normal=(0.0, 0.0, 1.0)):
thickness = 1e-2 # for safety
mesh = trimesh.creation.box(extents=[size, size, thickness])
half = size * 0.5
verts = np.array(
[
[-half, -half, 0.0],
[half, -half, 0.0],
[half, half, 0.0],
[-half, -half, 0.0],
[half, half, 0.0],
[-half, half, 0.0],
],
dtype=np.float32,
)
faces = np.arange(6, dtype=np.int32).reshape(-1, 3)
uv = np.array(
[
[0, 0],
[size, 0],
[size, size],
[0, 0],
[size, size],
[0, size],
],
dtype=np.float32,
)
mesh = trimesh.Trimesh(verts, faces, process=False)
mesh.vertices[:, 2] -= thickness / 2
mesh.vertices = gu.transform_by_R(mesh.vertices, gu.z_up_to_R(np.asarray(normal, dtype=np.float32)))
if color is None: # use checkerboard texture
mesh.visual = trimesh.visual.TextureVisuals(
uv=np.array(
[
[0, 0],
[0, 0],
[0, size],
[0, size],
[size, 0],
[size, 0],
[size, size],
[size, size],
],
dtype=np.float32,
),
uv=uv,
material=trimesh.visual.material.SimpleMaterial(
image=Image.open(os.path.join(get_assets_dir(), "textures/checker.png")),
),
Expand Down
4 changes: 1 addition & 3 deletions genesis/vis/rasterizer_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,7 @@ def on_rigid(self):
mesh=mesh,
poses=geom_T,
smooth=geom.surface.smooth if "collision" not in rigid_entity.surface.vis_mode else False,
double_sided=(
geom.surface.double_sided if "collision" not in rigid_entity.surface.vis_mode else False
),
double_sided=rigid_entity.morph.double_sided,
is_floor=isinstance(rigid_entity._morph, gs.morphs.Plane),
env_shared=not self.env_separate_rigid,
)
Expand Down
Loading