Skip to content
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

Add parent_node and transform to add_geometry #257

Closed
wants to merge 2 commits into from

Conversation

wkentaro
Copy link
Contributor

@wkentaro wkentaro commented Nov 22, 2018

This and #256 helps to build scene more easily.

Scene

screen shot 2018-11-22 at 00 53 39

Before (without this and #256)

#!/usr/bin/env python

import numpy as np
import trimesh
import trimesh.transformations as tf


scene = trimesh.Scene()

# plane
plane = trimesh.creation.box(extents=[1, 1, 0.01])
plane.visual.face_colors = [0.5, 0.5, 0.5, 0.5]
scene.add_geometry(plane)
scene.add_geometry(trimesh.creation.axis())

# object-1 (box)
box = trimesh.creation.box(extents=[0.3, 0.3, 0.3])
box.visual.face_colors = [0, 1., 0, 0.5]
axis = trimesh.creation.axis(origin_color=[1., 0, 0])
translation = [-0.2, 0, 0.15 + 0.01]  # box offset + plane offset
box.apply_translation(translation)
axis.apply_translation(translation)
rotation = tf.rotation_matrix(np.deg2rad(30), [0, 0, 1], point=box.centroid)
box.apply_transform(rotation)
axis.apply_transform(rotation)
scene.add_geometry(box)
scene.add_geometry(axis)

# object-2 (cylinder)
cylinder = trimesh.creation.cylinder(radius=0.1, height=0.3)
cylinder.visual.face_colors = [0, 0, 1., 0.5]
axis = trimesh.creation.axis(origin_color=[1., 0, 0])
translation = [0.1, -0.2, 0.15 + 0.01]  # cylinder offset + plane offset
cylinder.apply_translation(translation)
axis.apply_translation(translation)
scene.add_geometry(cylinder)
scene.add_geometry(axis)

scene.show()

After

#!/usr/bin/env python

import numpy as np
import trimesh
import trimesh.transformations as tf


scene = trimesh.Scene()

# plane
plane = trimesh.creation.box(
    extents=[1, 1, 0.01], face_colors=[0.5, 0.5, 0.5, 0.5]
)
node_name = scene.add_geometry(plane)
scene.add_geometry(trimesh.creation.axis(), parent_node_name=node_name)

# object-1 (box)
box = trimesh.creation.box(extents=[0.3, 0.3, 0.3], face_colors=[0, 1, 0, 0.5])
translation = tf.translation_matrix([-0.2, 0, 0.15 + 0.01])
rotation = tf.rotation_matrix(np.deg2rad(30), [0, 0, 1], point=box.centroid)
transform = rotation @ translation
node_name = scene.add_geometry(box, transform=transform)
axis = trimesh.creation.axis(origin_color=[1., 0, 0])
scene.add_geometry(axis, parent_node_name=node_name)

# object-2 (cylinder)
cylinder = trimesh.creation.cylinder(
    radius=0.1, height=0.3, face_colors=[0, 0, 1., 0.5]
)
axis = trimesh.creation.axis(origin_color=[1., 0, 0])
translation = tf.translation_matrix([0.1, -0.2, 0.15 + 0.01])
node_name = scene.add_geometry(cylinder, transform=translation)
scene.add_geometry(axis, parent_node_name=node_name)

scene.show()

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.04%) to 84.336% when pulling 3d08af2 on wkentaro:parent_node_transform into 6665426 on mikedh:master.

@wkentaro
Copy link
Contributor Author

Will be merged with https://github.com/mikedh/trimesh/tree/camera_merge

@wkentaro wkentaro closed this Nov 22, 2018
@wkentaro wkentaro deleted the parent_node_transform branch November 22, 2018 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants