コード例 #1
0
ファイル: gltf.py プロジェクト: rjodon-compas-forks/compas
 def get_matrix_from_trs(self, node):
     matrix = identity_matrix(4)
     if 'translation' in node:
         translation = matrix_from_translation(node['translation'])
         matrix = multiply_matrices(matrix, translation)
     if 'rotation' in node:
         rotation = matrix_from_quaternion(node['rotation'])
         matrix = multiply_matrices(matrix, rotation)
     if 'scale' in node:
         scale = matrix_from_scale_factors(node['scale'])
         matrix = multiply_matrices(matrix, scale)
     return matrix
コード例 #2
0
ファイル: gltf_node.py プロジェクト: rutvik-deshpande/compas
    def get_matrix_from_trs(self):
        """If the node's displacement from the origin is given by its translation, rotation and
        scale attributes, this method returns the matrix given by the composition of these
        attributes.

        Returns
        -------

        """
        matrix = identity_matrix(4)
        if self.translation:
            translation = matrix_from_translation(self.translation)
            matrix = multiply_matrices(matrix, translation)
        if self.rotation:
            rotation = matrix_from_quaternion(self.rotation)
            matrix = multiply_matrices(matrix, rotation)
        if self.scale:
            scale = matrix_from_scale_factors(self.scale)
            matrix = multiply_matrices(matrix, scale)
        return matrix
コード例 #3
0
def test_translation_from_matrix():
    t = [1, 2, 3]
    T = matrix_from_translation(t)
    assert translation_from_matrix(T) == t
コード例 #4
0
def test_matrix_from_translation():
    T = matrix_from_translation([1, 2, 3])
    t = [[1.0, 0.0, 0.0, 1.0], [0.0, 1.0, 0.0, 2.0], [0.0, 0.0, 1.0, 3.0],
         [0.0, 0.0, 0.0, 1.0]]
    assert allclose(T, t)
コード例 #5
0
    return network_copy


# ==============================================================================
# Main
# ==============================================================================

if __name__ == "__main__":

    from math import pi

    from compas.utilities import print_profile
    from compas.geometry import Box
    from compas.geometry import matrix_from_translation
    from compas.geometry import Translation
    from compas.geometry import Rotation
    from compas.datastructures import network

    network_transform = print_profile(network_transform)

    box = Box.from_corner_corner_height([0.0, 0.0, 0.0], [1.0, 1.0, 0.0], 1.0)
    network = network.from_vertices_and_faces(box.vertices, box.faces)

    T = matrix_from_translation([-2.0, 0.0, 3.0])
    T = Translation([-2.0, 0.0, 3.0])
    R = Rotation.from_axis_and_angle([0.0, 0.0, 1.0], pi / 2)

    network_transform(network, R)

    print(network.get_vertices_attribute('x'))
コード例 #6
0
ファイル: app.py プロジェクト: sehlstrom/compas
    # and adapt projection parameters to the size of the model

    import compas
    from compas.datastructures import Mesh
    from compas.geometry import transform_points
    from compas.geometry import matrix_from_translation

    class Mesh(Mesh):
        def apply_xform(self, M):
            key_index = self.key_index()
            points = self.get_vertices_attributes('xyz')
            points = transform_points(points, M)
            for key, attr in self.vertices(True):
                index = key_index[key]
                x, y, z = points[index]
                attr['x'] = x
                attr['y'] = y
                attr['z'] = z

    t = [3, 0, 0]
    M = matrix_from_translation(t)

    mesh = Mesh.from_polyhedron(6)
    mesh.apply_xform(M)

    viewer = MeshViewer()
    viewer.mesh = mesh
    # viewer.view.camera.target = t

    viewer.show()