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
Show camera as mesh #262
Show camera as mesh #262
Conversation
wkentaro
commented
Nov 26, 2018
•
edited
edited
# this transform is necessary to get correct image
transform = transform @ tf.rotation_matrix(np.deg2rad(-180), [1, 0, 0]) Actually this is necessary because z axis is other way around in trimesh. |
Nice! I think this probably makes most sense in
|
8de709f
to
29ae6ce
Compare
Updated example: #!/usr/bin/env python
import numpy as np
import trimesh
import trimesh.transformations as tf
trimesh.util.attach_to_log(level='WARNING')
def get_homography_rpy(roll, pitch, yaw, distance, center):
translation = tf.translation_matrix(center)
translation[2][3] += distance # z from center
rotation = (
tf.rotation_matrix(roll, [1, 0, 0], point=center) @
tf.rotation_matrix(pitch, [0, 1, 0], point=center) @
tf.rotation_matrix(yaw, [0, 0, 1], point=center)
)
transform = translation @ rotation
return transform
def get_homography_lookat(eye, lookat):
# both are positions
assert len(eye) == 3
assert len(lookat) == 3
if __name__ == '__main__':
extents = (0.5, 0.5, 0.5)
box = trimesh.creation.box(extents)
box.visual.face_colors = [255, 0, 0, 127]
scene = trimesh.Scene()
scene.add_geometry(box, node_name='box')
scene.add_geometry(trimesh.creation.axis())
roll, pitch, yaw = 0, 0, np.deg2rad(45)
distance = 0.9
center = (0, 0, 0)
transform = get_homography_rpy(roll, pitch, yaw, distance, center)
print('Using RPY (Red)')
print('Distance:', distance)
print('RPY:', (roll, pitch, yaw))
scene_camera = scene.copy()
camera = trimesh.scene.Camera(
resolution=(320, 240),
fov=(60, 45),
transform=transform
)
scene_camera.set_camera(camera=camera)
scene_camera.show(start_loop=False)
# this transform is necessary to get correct image
transform = transform @ tf.rotation_matrix(np.deg2rad(-180), [1, 0, 0])
camera.transform = transform
mesh = trimesh.creation.camera_marker(camera=camera)
scene.add_geometry(mesh)
scene.show() |
I addressed all of your comments. Could you review again? |
Awesome! Merged to master in ef90ebc and should release as soon as the build finishes. I made some minor changes, the main thing was moving the import into the function and a Thanks for the PR's!! It's great to get your work into the master branch and releases 😄 |
Thanks for your help! |
…ctm-support * upstream/master: (60 commits) add test failing any function returning NaN or inf fix strict DXF test on python2 DXF export whitespace fix bump for mikedh#268 update radius calculation fallback logic in nsphere further nsphere speedup test for remove_unreferenced Fix missing arg in call to unique_bincount in docker builds check certs and sha256 add checksums to docker builds and fix align_vectors test freeze miniconda version align_vectors to more robust method and tests bump for mikedh#265 use unique_bincount and unify slice_plane with slice_plane add unit test for unique_bincount creation docstring add unique_bincount slice with multiple planes and performance tweaks readme, comments, and bump for mikedh#262 and mikedh#264 wrap load_path import in camera marker ...