Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _m_from_tqs(t, q, s):
S = np.eye(4)
S[:3,:3] = np.diag(s)
R = np.eye(4)
R[:3,:3] = Node._r_from_q(q)
T = np.eye(4)
T[:3,3] = t
return T.dot(R.dot(S))
def matrix(self, value):
value = np.asanyarray(value)
if value.shape != (4, 4):
raise ValueError('Matrix must be a 4x4 numpy ndarray')
if not np.allclose(value[3, :], np.array([0.0, 0.0, 0.0, 1.0])):
raise ValueError('Bottom row of matrix must be [0,0,0,1]')
self._matrix = value
self.rotation = Node._q_from_m(value)
self.scale = Node._s_from_m(value)
self.translation = Node._t_from_m(value)
def _q_from_m(m):
M = np.eye(4)
M[:3,:3] = Node._r_from_m(m)
q_wxyz = transformations.quaternion_from_matrix(M)
return np.roll(q_wxyz, -1)
The parent of this Node. If None, the new node is a root node.
parent_name : str
The name of the parent node, can be specified instead of
`parent_node`.
Returns
-------
node : :class:`Node`
The newly-created and inserted node.
"""
if isinstance(obj, Mesh):
node = Node(name=name, matrix=pose, mesh=obj)
elif isinstance(obj, Light):
node = Node(name=name, matrix=pose, light=obj)
elif isinstance(obj, Camera):
node = Node(name=name, matrix=pose, camera=obj)
else:
raise TypeError('Unrecognized object type')
if parent_node is None and parent_name is not None:
parent_nodes = self.get_nodes(name=parent_name)
if len(parent_nodes) == 0:
raise ValueError('No parent node with name {} found'
.format(parent_name))
elif len(parent_nodes) > 1:
raise ValueError('More than one parent node with name {} found'
.format(parent_name))
parent_node = list(parent_nodes)[0]
self.add_node(node, parent_node=parent_node)
return node
xmag = ymag = 1.0
self._default_orth_cam = OrthographicCamera(
xmag=xmag, ymag=ymag,
znear=znear,
zfar=zfar
)
if self._default_camera_pose is None:
self._default_camera_pose = self._compute_initial_camera_pose()
# Pick camera
if self.viewer_flags['use_perspective_cam']:
camera = self._default_persp_cam
else:
camera = self._default_orth_cam
self._camera_node = Node(
matrix=self._default_camera_pose, camera=camera
)
scene.add_node(self._camera_node)
scene.main_camera_node = self._camera_node
self._reset_view()
#######################################################################
# Initialize OpenGL context and renderer
#######################################################################
self._renderer = Renderer(
self._viewport_size[0], self._viewport_size[1],
self.render_flags['point_size']
)
self._is_active = True
if self.run_in_thread:
The local pose of this node relative to its parent node.
parent_node : :class:`Node`
The parent of this Node. If None, the new node is a root node.
parent_name : str
The name of the parent node, can be specified instead of
`parent_node`.
Returns
-------
node : :class:`Node`
The newly-created and inserted node.
"""
if isinstance(obj, Mesh):
node = Node(name=name, matrix=pose, mesh=obj)
elif isinstance(obj, Light):
node = Node(name=name, matrix=pose, light=obj)
elif isinstance(obj, Camera):
node = Node(name=name, matrix=pose, camera=obj)
else:
raise TypeError('Unrecognized object type')
if parent_node is None and parent_name is not None:
parent_nodes = self.get_nodes(name=parent_name)
if len(parent_nodes) == 0:
raise ValueError('No parent node with name {} found'
.format(parent_name))
elif len(parent_nodes) > 1:
raise ValueError('More than one parent node with name {} found'
.format(parent_name))
parent_node = list(parent_nodes)[0]
self.add_node(node, parent_node=parent_node)
def matrix(self, value):
value = np.asanyarray(value)
if value.shape != (4, 4):
raise ValueError('Matrix must be a 4x4 numpy ndarray')
if not np.allclose(value[3, :], np.array([0.0, 0.0, 0.0, 1.0])):
raise ValueError('Bottom row of matrix must be [0,0,0,1]')
self._matrix = value
self.rotation = Node._q_from_m(value)
self.scale = Node._s_from_m(value)
self.translation = Node._t_from_m(value)
def _m_from_tqs(t, q, s):
S = np.eye(4)
S[:3, :3] = np.diag(s)
R = np.eye(4)
R[:3, :3] = Node._r_from_q(q)
T = np.eye(4)
T[:3, 3] = t
return T.dot(R.dot(S))