Example #1
0
    def to_meshes(self, u=16, v=16):
        """Convert the faces of the BRep shape to meshes.

        Parameters
        ----------
        u : int, optional
            The number of mesh faces in the U direction of the underlying surface geometry of every face of the BRep.
        v : int, optional
            The number of mesh faces in the V direction of the underlying surface geometry of every face of the BRep.

        Returns
        -------
        list[:class:`~compas.datastructures.Mesh`]

        """
        converter = BRepBuilderAPI_NurbsConvert(self.shape, False)
        brep = BRep()
        brep.shape = converter.Shape()
        meshes = []
        for face in brep.faces:
            srf = OCCNurbsSurface.from_face(face.face)
            mesh = srf.to_vizmesh(u, v)
            meshes.append(mesh)
        return meshes
Example #2
0
        Point(0, 2, 0),
        Point(1, 2, 2),
        Point(2, 2, 2),
        Point(3, 2, 0),
        Point(4, 2, 0)
    ],
    [
        Point(0, 3, 0),
        Point(1, 3, 0),
        Point(2, 3, 0),
        Point(3, 3, 0),
        Point(4, 3, 0)
    ],
]

surface = OCCNurbsSurface.from_points(points=points)

T = Translation.from_vector([0, -1.5, 0])
R = Rotation.from_axis_and_angle([0, 0, 1], radians(45))

surface.transform(R * T)

# ==============================================================================
# AABB
# ==============================================================================

box = surface.aabb()

# ==============================================================================
# Visualisation
# ==============================================================================
Example #3
0
# ==============================================================================

edges = list(TopologyExplorer(poly.Wire()).edges())

nsided = BRepFill_Filling()
for edge in edges:
    nsided.Add(edge, GeomAbs_C0)
nsided.Add(gp_Pnt(*(polygon.centroid + normal_polygon(polygon))))
nsided.Build()

# ==============================================================================
# Surface from BRep Filling Face
# ==============================================================================

face = nsided.Face()
surface = OCCNurbsSurface.from_face(face)

# ==============================================================================
# BRep
# ==============================================================================

brep = BRep()
brep.shape = face

# mesh = brep.to_tesselation()

BRepMesh_IncrementalMesh(brep.shape, 0.1, False, 0.1, False)

bt = BRep_Tool()
ex = TopExp_Explorer(brep.shape, TopAbs_FACE)
while ex.More():
     Point(3, 0, 0)],
    [Point(0, 1, 0),
     Point(1, 1, 2),
     Point(2, 1, 2),
     Point(3, 1, 0)],
    [Point(0, 2, 0),
     Point(1, 2, 2),
     Point(2, 2, 2),
     Point(3, 2, 0)],
    [Point(0, 3, 0),
     Point(1, 3, 0),
     Point(2, 3, 0),
     Point(3, 3, 0)],
]

surface = OCCNurbsSurface.from_points(points=points)

# ==============================================================================
# JSON Data
# ==============================================================================

string = surface.to_jsonstring(pretty=True)

print(string)

other = OCCNurbsSurface.from_jsonstring(string)

print(surface == other)

# ==============================================================================
# Visualisation
weights = [
    [1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
    [1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
    [1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
    [1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
    [1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
    [1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
]

surface = OCCNurbsSurface.from_parameters(
    points=points,
    weights=weights,
    u_knots=[
        1.0, 1 + 1 / 9, 1 + 2 / 9, 1 + 3 / 9, 1 + 4 / 9, 1 + 5 / 9, 1 + 6 / 9,
        1 + 7 / 9, 1 + 8 / 9, 2.0
    ],
    v_knots=[0.0, 1 / 9, 2 / 9, 3 / 9, 4 / 9, 5 / 9, 6 / 9, 7 / 9, 8 / 9, 1.0],
    u_mults=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    v_mults=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    u_degree=3,
    v_degree=3,
)

# ==============================================================================
# Visualisation
# ==============================================================================

view = App()

for row in surface.points:
    view.add(Polyline(row),
Example #6
0
import random
from compas.geometry import Polyline
from compas_occ.geometry import OCCNurbsSurface
from compas_view2.app import App


U = 10
V = 20

surface = OCCNurbsSurface.from_meshgrid(nu=U, nv=V)

# ==============================================================================
# Update
# ==============================================================================

for u in range(1, U):
    for v in range(1, V):
        point = surface.points[u, v]
        point.z = random.choice([+1, -1]) * random.random()
        surface.points[u, v] = point

# ==============================================================================
# Visualisation
# ==============================================================================

view = App()

for row in surface.points:
    view.add(Polyline(row), show_points=True, pointsize=20, pointcolor=(1, 0, 0), linewidth=2, linecolor=(0.3, 0.3, 0.3))

for col in zip(* surface.points):