Merge pull request #6 from adam-urbanczyk/CapableRobot-cq1_pythonocc
Initial support for cqparts in cadquery-occ
This commit is contained in:
@ -134,7 +134,7 @@ class Vector(object):
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.wrapped == other.wrapped
|
||||
'''
|
||||
'''
|
||||
is not implemented in OCC
|
||||
def __ne__(self, other):
|
||||
return self.wrapped.__ne__(other)
|
||||
@ -164,24 +164,24 @@ class Matrix:
|
||||
"""
|
||||
|
||||
def __init__(self, matrix=None):
|
||||
|
||||
|
||||
if matrix is None:
|
||||
self.wrapped = gp_Trsf()
|
||||
else:
|
||||
self.wrapped = matrix
|
||||
|
||||
def rotateX(self, angle):
|
||||
|
||||
|
||||
self._rotate(gp.OX(),
|
||||
angle)
|
||||
|
||||
def rotateY(self, angle):
|
||||
|
||||
|
||||
self._rotate(gp.OY(),
|
||||
angle)
|
||||
|
||||
def rotateZ(self, angle):
|
||||
|
||||
|
||||
self._rotate(gp.OZ(),
|
||||
angle)
|
||||
|
||||
@ -194,12 +194,25 @@ class Matrix:
|
||||
self.wrapped = self.wrapped * new
|
||||
|
||||
def inverse(self):
|
||||
|
||||
|
||||
return Matrix(self.wrapped.Inverted())
|
||||
|
||||
def multiply(self,other):
|
||||
|
||||
def multiply(self, other):
|
||||
|
||||
if isinstance(other, Vector):
|
||||
return other.transform(self)
|
||||
|
||||
return Matrix(self.wrapped.Multiplied(other.wrapped))
|
||||
|
||||
def transposed_list(self):
|
||||
"""Needed by the cqparts gltf exporter
|
||||
"""
|
||||
|
||||
return Matrix(self.wrapped*other.wrapped)
|
||||
trsf = self.wrapped
|
||||
data = [[trsf.Value(i,j) for j in range(1,5)] for i in range(1,4)] + \
|
||||
[[0.,0.,0.,1.]]
|
||||
|
||||
return [data[j][i] for i in range(4) for j in range(4)]
|
||||
|
||||
class Plane(object):
|
||||
"""A 2D coordinate system in space
|
||||
|
||||
@ -100,6 +100,8 @@ from OCC.ShapeUpgrade import ShapeUpgrade_UnifySameDomain
|
||||
|
||||
from OCC.BRepTools import breptools_Write
|
||||
|
||||
from OCC.Visualization import Tesselator
|
||||
|
||||
from math import pi, sqrt
|
||||
|
||||
TOLERANCE = 1e-6
|
||||
@ -189,7 +191,7 @@ class Shape(object):
|
||||
@classmethod
|
||||
def cast(cls, obj, forConstruction=False):
|
||||
"Returns the right type of wrapper, given a FreeCAD object"
|
||||
'''
|
||||
'''
|
||||
if type(obj) == FreeCAD.Base.Vector:
|
||||
return Vector(obj)
|
||||
''' # FIXME to be removed?
|
||||
@ -583,7 +585,7 @@ class Shape(object):
|
||||
Jupyter 3D representation support
|
||||
"""
|
||||
|
||||
from .jupyter_tools import x3d_display
|
||||
from .jupyter_tools import x3d_display
|
||||
return x3d_display(self.wrapped, export_edges=True)
|
||||
|
||||
|
||||
@ -993,7 +995,22 @@ class Shell(Shape):
|
||||
class Mixin3D(object):
|
||||
|
||||
def tessellate(self, tolerance):
|
||||
return self.wrapped.tessellate(tolerance)
|
||||
tess = Tesselator(self.wrapped)
|
||||
tess.Compute(compute_edges=True, mesh_quality=tolerance)
|
||||
|
||||
vertices = []
|
||||
indexes = []
|
||||
|
||||
# add vertices
|
||||
for i_vert in range(tess.ObjGetVertexCount()):
|
||||
xyz = tess.GetVertex(i_vert)
|
||||
vertices.append(Vector(*xyz))
|
||||
|
||||
# add triangles
|
||||
for i_tr in range(tess.ObjGetTriangleCount()):
|
||||
indexes.append(tess.GetTriangleIndex(i_tr))
|
||||
|
||||
return vertices, indexes
|
||||
|
||||
def fillet(self, radius, edgeList):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user