Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 3 deletions genesis/engine/entities/hybrid_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ def default_func_instantiate_rigid_from_soft(
pos=pos_rigid,
quat=quat_rigid,
scale=scale_rigid,
fixed=material_hybrid.fixed,
fixed=morph.fixed,
)
part_rigid = scene.add_entity(
material=material_rigid,
Expand Down Expand Up @@ -715,15 +715,14 @@ def default_func_instantiate_rigid_soft_association_from_soft(
line_length = np.linalg.norm(line_vec)

positions_proj_on_line_t = (positions - p0) @ line_vec / (line_length**2)
positions_proj_on_line = p0 + positions_proj_on_line_t[:, None] * line_vec

dist_to_p0 = np.linalg.norm(positions - p0, axis=-1)
dist_to_p1 = np.linalg.norm(positions - p1, axis=-1)
dist_to_line = np.sqrt(dist_to_p0**2 - ((positions_proj_on_line_t[:, None] * line_vec) ** 2).sum(-1))

is_clipped_low = positions_proj_on_line_t < 0.0
is_clipped_high = positions_proj_on_line_t > 1.0
is_valid = not (is_clipped_low or is_clipped_high)
is_valid = ~(is_clipped_low | is_clipped_high)
dist_to_link = dist_to_p0 * is_clipped_low + dist_to_p1 * is_clipped_high + dist_to_line * is_valid

trans, quat = gu.transform_pos_quat_by_trans_quat(
Expand Down
12 changes: 8 additions & 4 deletions genesis/engine/entities/particle_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import gstaichi as ti
import torch
import trimesh
from scipy.spatial import KDTree

import genesis as gs
import genesis.utils.geom as gu
Expand Down Expand Up @@ -191,10 +190,15 @@ def _add_particles_to_solver(self):

def _add_vverts_to_solver(self):
# Compute supports for rendering vverts using neighboring particles
kdtree = KDTree(self._particles)
_, support_idxs = kdtree.query(self._vverts, k=self.solver._n_vvert_supports)
support_idxs = support_idxs.astype(gs.np_int)
dist2 = np.sum(np.square(self._vverts[:, None, :] - self._particles[None, :, :]), axis=2)
support_idxs = np.argpartition(dist2, self.solver._n_vvert_supports - 1, axis=1)[
:, : self.solver._n_vvert_supports
]
row_indices = np.arange(dist2.shape[0])[:, None]
sorted_order = np.lexsort((support_idxs, dist2[row_indices, support_idxs]))
support_idxs = support_idxs[row_indices, sorted_order].astype(gs.np_int)
support_idxs = np.clip(support_idxs, 0, len(self._particles) - 1)

all_ps = self._particles[support_idxs]
Ps = all_ps[:, :-1].swapaxes(-2, -1) - np.expand_dims(all_ps[:, -1], axis=-1)
P_invs = np.linalg.pinv(Ps)
Expand Down
7 changes: 0 additions & 7 deletions genesis/engine/entities/sf_entity.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import numpy as np
import gstaichi as ti
from scipy.spatial import KDTree

import genesis as gs
import genesis.utils.geom as gu
import genesis.utils.mesh as mu
from genesis.engine.entities.base_entity import Entity
from genesis.engine.entities.particle_entity import ParticleEntity
import trimesh


@ti.data_oriented
Expand Down
13 changes: 7 additions & 6 deletions genesis/ext/isaacgym/terrain_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.


import numpy as np
from scipy import interpolate

import genesis as gs
import genesis.utils.geom as gu


def fractal_terrain(terrain, levels=8, scale=1.0):
"""
Generates a fractal terrain

Parameters
terrain (SubTerrain): the terrain
levels (int, optional): granurarity of the fractal terrain. Defaults to 8.
levels (int, optional): granularity of the fractal terrain. Defaults to 8.
scale (float, optional): scales vertical variation. Defaults to 1.0.
"""
width = terrain.width
Expand Down Expand Up @@ -79,11 +80,11 @@ def random_uniform_terrain(
x = np.linspace(0, scaled_width, height_field_downsampled.shape[0])
y = np.linspace(0, scaled_length, height_field_downsampled.shape[1])

f = interpolate.RectBivariateSpline(x, y, height_field_downsampled)

x_upsampled = np.linspace(0, scaled_width, terrain.width)
y_upsampled = np.linspace(0, scaled_length, terrain.length)
z_upsampled = np.rint(f(x_upsampled, y_upsampled))
z_upsampled = np.rint(
gu.cubic_spline_1d(x, gu.cubic_spline_1d(y, height_field_downsampled.T, y_upsampled).T, x_upsampled)
)

terrain.height_field_raw += z_upsampled
return terrain
Expand Down
4 changes: 2 additions & 2 deletions genesis/ext/pyrender/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ def render(self, scene, flags, seg_node_map=None, *, is_first_pass=True, force_s
self._shadow_mapping_pass(scene, ln, flags, env_idx=env_idx)
glBindFramebuffer(GL_FRAMEBUFFER, 0)

# Make forward pass
if flags & RenderFlags.REFLECTIVE_FLOOR:
self._floor_pass(scene, flags, env_idx=env_idx)

Expand All @@ -190,7 +189,8 @@ def render(self, scene, flags, seg_node_map=None, *, is_first_pass=True, force_s
for idx, val in enumerate(retval):
retval_list[idx].append(val)

# If necessary, make normals pass
# Render normal visualization on screen only if requested, ie after reading frame buffer and without
# cleaning first.
if flags & (RenderFlags.VERTEX_NORMALS | RenderFlags.FACE_NORMALS):
self._normal_pass(scene, flags, env_idx=env_idx)

Expand Down
18 changes: 3 additions & 15 deletions genesis/ext/urdfpy/urdf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import copy
import io
import os
import time
import xml.etree.ElementTree as ET
Expand All @@ -10,15 +9,8 @@
import numpy as np
import PIL
import trimesh
from scipy.spatial.transform import Rotation

from .utils import (
configure_origin,
get_filename,
load_meshes,
parse_origin,
unparse_origin,
)
from .utils import configure_origin, get_filename, load_meshes, parse_origin, unparse_origin


class URDFType(object):
Expand Down Expand Up @@ -4025,12 +4017,8 @@ def from_nxgraph(
for grandchild_node in G.successors(child_node):
joint_edge_vec1 = norm_vec(G_pos[parent_node] - G_pos[child_node])
joint_edge_vec2 = norm_vec(G_pos[grandchild_node] - G_pos[child_node])
joint_rotmat = rotation_matrix_from_vectors(
joint_edge_vec1, joint_edge_vec2
) # broken down into joint axis and initial pose
joint_rotvec = Rotation.from_matrix(joint_rotmat).as_rotvec()
joint_init_ang = np.linalg.norm(joint_rotvec)
joint_axis = joint_rotvec / joint_init_ang # the same as np.cross(joint_edge_vec2, joint_edge_vec1)
joint_axis = np.cross(joint_edge_vec1, joint_edge_vec2)
joint_axis /= np.linalg.norm(joint_axis)
joint_origin_rotmat = np.eye(3)
joint_origin = xyz_rotmat_to_matrix(joint_xyz, joint_origin_rotmat)
joint = Joint(
Expand Down
Loading
Loading