Beispiel #1
0
 def to_collision_meshes(self):
     """Creates a list of collision meshes from a :class:`compas_fab.backends.CollisionObject`
     """
     collision_meshes = []
     for mesh, pose in zip(self.meshes, self.mesh_poses):
         pose = pose if isinstance(pose, Pose) else Pose(**pose)
         pose.position = pose.position if isinstance(pose.position, Point) else Point(**pose.position)
         pose.position.x = float(pose.position.x)
         pose.position.y = float(pose.position.y)
         pose.position.z = float(pose.position.z)
         pose.orientation = pose.orientation if isinstance(pose.orientation, Quaternion) else Quaternion(**pose.orientation)
         pose.orientation.x = float(pose.orientation.x)
         pose.orientation.y = float(pose.orientation.y)
         pose.orientation.z = float(pose.orientation.z)
         pose.orientation.w = float(pose.orientation.w)
         mesh = mesh if isinstance(mesh, Mesh) else Mesh(**mesh)
         mesh.triangles = [t if isinstance(t, MeshTriangle) else MeshTriangle(**t) for t in mesh.triangles]
         for triangle in mesh.triangles:
             triangle.vertex_indices = [int(x) for x in triangle.vertex_indices]
         mesh.vertices = [v if isinstance(v, Point) else Point(**v) for v in mesh.vertices]
         for vertex in mesh.vertices:
             vertex.x = float(vertex.x)
             vertex.y = float(vertex.y)
             vertex.z = float(vertex.z)
         root_name = getattr(self.header, 'frame_id', None) or self.header['frame_id']
         cm = CollisionMesh(mesh.mesh, self.id, pose.frame, root_name)
         collision_meshes.append(cm)
     return collision_meshes
Beispiel #2
0
 def from_mesh(cls, compas_mesh):
     """Construct a `Mesh` message from a :class:`compas.datastructures.Mesh`.
     """
     mesh_quads_to_triangles(compas_mesh)
     vertices, faces = compas_mesh.to_vertices_and_faces()
     triangles = [MeshTriangle(face) for face in faces]
     vertices = [Point(*v) for v in vertices]
     return cls(triangles, vertices)
Beispiel #3
0
    def from_sphere(cls, sphere):
        """Creates a `BoundingVolume` from a :class:`compas.geometry.Sphere`.

        Parameters
        ----------
        sphere: `compas.geometry.Sphere`
        """
        primitive = SolidPrimitive.from_sphere(sphere)
        pose = Pose(Point(*sphere.point), Quaternion(0, 0, 0, 1))
        return cls(primitives=[primitive], primitive_poses=[pose])
Beispiel #4
0
 def from_msg(cls, msg):
     triangles = [MeshTriangle.from_msg(t) for t in msg['triangles']]
     vertices = [Point.from_msg(v) for v in msg['vertices']]
     return cls(triangles, vertices)