def flip_normals(self): mesh_flip_cycles(self.mesh) # this is a bit of a hack # faces of the viewmesh only get calculated at the time when the mesh # is assigned to the viewmesh self.meshview.mesh = self.mesh self.view.update_index_buffer('faces:front', self.view.array_faces_front) self.view.update_index_buffer('faces:back', self.view.array_faces_back) self.view.updateGL()
def my_mesh_thicken(mesh, thickness=1.0, cls=None): """Thicken a mesh. Parameters ---------- mesh : Mesh A mesh to thicken. thickness : real The mesh thickness Returns ------- thickened_mesh : Mesh The thickened mesh. """ if cls is None: cls = type(mesh) # offset in both directions mesh_top, mesh_bottom = map(lambda eps: my_mesh_offset(mesh, eps * thickness / 2., cls), [+1, -1]) # flip bottom part mesh_flip_cycles(mesh_bottom) # join parts thickened_mesh = meshes_join([mesh_top, mesh_bottom], cls) # close boundaries n = thickened_mesh.number_of_vertices() / 2 edges_on_boundary = [] for boundary in list(my_edges_on_boundaries(thickened_mesh)): edges_on_boundary.extend(boundary) for u, v in edges_on_boundary: if u < n and v < n: thickened_mesh.add_face([u, v, v + n, u + n]) return thickened_mesh
import compas from compas.datastructures import Mesh from compas.datastructures import mesh_quads_to_triangles from compas.datastructures import mesh_flip_cycles from compas.plotters import MeshPlotter from compas.utilities import i_to_blue from compas.geometry import scale_points # mesh = Mesh.from_obj(compas.get('models/head-poses/head-reference.obj')) mesh = Mesh.from_obj(compas.get('models/camel-poses/camel-reference.obj')) mesh_flip_cycles(mesh) vertices = scale_points(mesh.get_vertices_attributes('xyz'), 10.0) for key, attr in mesh.vertices(True): x, y, z = vertices[key] attr['x'] = x attr['y'] = y attr['z'] = z # mesh = Mesh.from_obj(compas.get('faces.obj')) # mesh_quads_to_triangles(mesh) # mesh = Mesh.from_polyhedron(12) # mesh_quads_to_triangles(mesh)
# ============================================================================== # Initialise # ============================================================================== HERE = os.path.dirname(__file__) DATA = os.path.abspath(os.path.join(HERE, '..', 'data')) FILE_I1 = os.path.join(DATA, 'data.json') FILE_I2 = os.path.join(DATA, 'fabric.json') SHELL = Mesh.from_json(FILE_I1) FABRIC = Mesh.from_json(FILE_I2) SHELL.name = 'Shell' FABRIC.name = 'Fabric' mesh_flip_cycles(FABRIC) THICKNESS = 0.04 # ============================================================================== # Offsets # ============================================================================== EDOS = FABRIC.copy() IDOS = FABRIC.copy() EDOS.name = 'Extrados' IDOS.name = 'Intrados' for key in FABRIC.vertices(): normal = FABRIC.vertex_normal(key)
else: json.dump(mesh.data, fp) # ============================================================================== # Set the path to the input file. # ============================================================================== HERE = os.path.dirname(__file__) FILE_I = os.path.join(HERE, 'data', 'cablenet.json') # ============================================================================== # Main # ============================================================================== # cablenet: Cablenet = Cablenet.from_json(FILE_I) cablenet = Cablenet.from_json(FILE_I) mesh_flip_cycles(cablenet) THICKNESS = 0.200 OFFSET_0 = 0.02 OFFSET_1 = 0.03 # ============================================================================== # Build blocks # ============================================================================== blocks = [] for face_key in cablenet.faces(): vertices = cablenet.face_vertices(face_key) points = cablenet.get_vertices_attributes('xyz', keys=vertices) normals = [cablenet.vertex_normal(key) for key in vertices] face_normal = cablenet.face_normal(face_key)
unrolled.append(quadmesh) return unrolled # ============================================================================== # Initialise # ============================================================================== HERE = os.path.dirname(__file__) DATA = os.path.join(HERE, '..', 'data') FILE_I = os.path.join(DATA, 'fabric.json') BASE = Shell.from_json(FILE_I) mesh_flip_cycles(BASE) SIDE = 'edos' SEEM = -0.020 COLOR = (255, 0, 0) if SIDE == 'idos' else (0, 0, 255) THICKNESS = -0.020 if SIDE == 'idos' else +0.020 # ============================================================================== # Fabric layer from extended dual # ============================================================================== FABRIC = BASE.copy() mesh_flip_cycles(FABRIC) for key in BASE.vertices():
IDOS = SHELL.copy() EDOS.name = 'Extrados' IDOS.name = 'Intrados' for key in SHELL.vertices(): normal = SHELL.vertex_normal(key) xyz = SHELL.vertex_coordinates(key) up = scale_vector(normal, 0.5 * THICKNESS) down = scale_vector(normal, -0.5 * THICKNESS) EDOS.set_vertex_attributes(key, 'xyz', add_vectors(xyz, up)) IDOS.set_vertex_attributes(key, 'xyz', add_vectors(xyz, down)) mesh_flip_cycles(IDOS) # ============================================================================== # Construct VOLUME # ============================================================================== VOLUME = IDOS.copy() VOLUME.name = 'Volume' max_int_key = VOLUME._max_int_key + 1 max_int_fkey = VOLUME._max_int_fkey + 1 for key, attr in EDOS.vertices(True): VOLUME.add_vertex(key=key + max_int_key, **attr) for fkey in EDOS.faces():
up = scale_vector(normal, 0.5 * thickness) down = scale_vector(normal, -0.5 * thickness) edos.set_vertex_attributes(key, 'xyz', add_vectors(xyz, up)) idos.set_vertex_attributes(key, 'xyz', add_vectors(xyz, down)) # ============================================================================== # Construct volume # ============================================================================== volume = idos.copy() volume.name = 'Volume' # flip its cycles to make the bottom normals point downwards mesh_flip_cycles(volume) # set the key offset max_int_key = volume._max_int_key + 1 max_int_fkey = volume._max_int_fkey + 1 # add the vertices of the edos for key, attr in edos.vertices(True): volume.add_vertex(key=key + max_int_key, **attr) # add the faces of the edos for fkey in edos.faces(): vertices = edos.face_vertices(fkey)