本文整理汇总了Python中utility.coercemesh函数的典型用法代码示例。如果您正苦于以下问题:Python coercemesh函数的具体用法?Python coercemesh怎么用?Python coercemesh使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了coercemesh函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MeshBooleanSplit
def MeshBooleanSplit(input0, input1, delete_input=True):
"""Performs a boolean split operation on two sets of input meshes
Parameters:
input0, input1 = identifiers of meshes
delete_input[opt] = delete the input meshes
Returns:
list of identifiers of new meshes on success
None on error
"""
id = rhutil.coerceguid(input0)
if id: input0 = [id]
id = rhutil.coerceguid(input1)
if id: input1 = [id]
meshes0 = [rhutil.coercemesh(id, True) for id in input0]
meshes1 = [rhutil.coercemesh(id, True) for id in input1]
if not meshes0 or not meshes1: raise ValueError("no meshes to work with")
newmeshes = Rhino.Geometry.Mesh.CreateBooleanSplit(meshes0, meshes1)
rc = []
for mesh in newmeshes:
id = scriptcontext.doc.Objects.AddMesh(mesh)
if id!=System.Guid.Empty: rc.append(id)
if rc and delete_input:
input = input0 + input1
for id in input:
id = rhutil.coerceguid(id, True)
scriptcontext.doc.Objects.Delete(id, True)
scriptcontext.doc.Views.Redraw()
return rc
示例2: MeshOutline
def MeshOutline(object_ids, view=None):
"""Creates polyline curve outlines of mesh objects
Parameters:
objects_ids = identifiers of meshes to outline
view(opt) = view to use for outline direction
Returns:
list of polyline curve id on success
Example:
import rhinoscriptsyntax as rs
objs = rs.GetObjects("Select mesh objects to outline", rs.filter.mesh)
if objs: rs.MeshOutline(objs)
See Also:
IsMesh
"""
viewport = __viewhelper(view).MainViewport
meshes = []
mesh = rhutil.coercemesh(object_ids, False)
if mesh: meshes.append(mesh)
else: meshes = [rhutil.coercemesh(id,True) for id in object_ids]
rc = []
for mesh in meshes:
polylines = mesh.GetOutlines(viewport)
if not polylines: continue
for polyline in polylines:
id = scriptcontext.doc.Objects.AddPolyline(polyline)
rc.append(id)
scriptcontext.doc.Views.Redraw()
return rc
示例3: MeshMeshIntersection
def MeshMeshIntersection(mesh1, mesh2, tolerance=None):
"""Calculates the intersections of a mesh object with another mesh object
Parameters:
mesh1, mesh2 = identifiers of meshes
tolerance[opt] = the intersection tolerance
Returns:
List of 3d point arrays that define the vertices of the intersection curves
"""
mesh1 = rhutil.coercemesh(mesh1, True)
mesh2 = rhutil.coercemesh(mesh2, True)
if tolerance is None: tolerance = Rhino.RhinoMath.ZeroTolerance
polylines = Rhino.Geometry.Intersect.Intersection.MeshMeshAccurate(mesh1, mesh2, tolerance)
if polylines: return list(polylines)
示例4: MeshQuadCount
def MeshQuadCount(object_id):
"""Returns the number of quad faces of a mesh object
Parameters:
object_id = identifier of a mesh object
"""
mesh = rhutil.coercemesh(object_id, True)
return mesh.Faces.QuadCount
示例5: IsMeshClosed
def IsMeshClosed(object_id):
"""Verifies a mesh object is closed
Parameters:
object_id = identifier of a mesh object
"""
mesh = rhutil.coercemesh(object_id, True)
return mesh.IsClosed
示例6: MeshArea
def MeshArea(object_ids):
"""Returns the approximate area of one or more mesh objects
Parameters:
object_ids = identifiers of one or more mesh objects
Returns:
a list containing 3 numbers if successful where
element[0] = number of meshes used in calculation
element[1] = total area of all meshes
element[2] = the error estimate
None if not successful
"""
id = rhutil.coerceguid(object_ids)
if id: object_ids = [object_ids]
meshes_used = 0
total_area = 0.0
error_estimate = 0.0
for id in object_ids:
mesh = rhutil.coercemesh(id, True)
if mesh:
mp = Rhino.Geometry.AreaMassProperties.Compute(mesh)
if mp:
meshes_used += 1
total_area += mp.Area
error_estimate += mp.AreaError
if meshes_used==0: return scriptcontext.errorhandler()
return meshes_used, total_area, error_estimate
示例7: PullCurveToMesh
def PullCurveToMesh(mesh_id, curve_id):
"""Pulls a curve to a mesh. The function makes a polyline approximation of
the input curve and gets the closest point on the mesh for each point on
the polyline. Then it "connects the points" to create a polyline on the mesh
Parameters:
mesh_id = identifier of mesh that pulls
curve_id = identifier of curve to pull
Returns:
Guid of new curve on success
None on error
Example:
import rhinoscriptsyntax as rs
mesh = rs.GetObject("Select mesh that pulls", rs.filter.mesh)
curve = rs.GetObject("Select curve to pull", rs.filter.curve)
rs.PullCurveToMesh( mesh, curve )
See Also:
IsMesh
"""
mesh = rhutil.coercemesh(mesh_id, True)
curve = rhutil.coercecurve(curve_id, -1, True)
tol = scriptcontext.doc.ModelAbsoluteTolerance
polyline = curve.PullToMesh(mesh, tol)
if not polyline: return scriptcontext.errorhandler()
rc = scriptcontext.doc.Objects.AddCurve(polyline)
if rc==System.Guid.Empty: raise Exception("unable to add polyline to document")
scriptcontext.doc.Views.Redraw()
return rc
示例8: ProjectPointToMesh
def ProjectPointToMesh(points, mesh_ids, direction):
"""Projects one or more points onto one or more meshes
Parameters:
points = one or more 3D points
mesh_ids = identifiers of one or more meshes
direction = direction vector to project the points
Returns:
list of projected points on success
Example:
import rhinoscriptsyntax as rs
mesh = rs.GetObject("Select mesh to project onto", rs.filter.mesh)
objects = rs.GetObjects("Select points to project", rs.filter.point)
points = [rs.PointCoordinates(obj) for obj in objects]
# project down...
results = rs.ProjectPointToMesh(points, mesh, (0,0,-1))
rs.AddPoints( results )
See Also:
ProjectCurveToMesh
ProjectCurveToSurface
ProjectPointToSurface
"""
pts = rhutil.coerce3dpointlist(points, False)
if pts is None:
pts = [rhutil.coerce3dpoint(points, True)]
direction = rhutil.coerce3dvector(direction, True)
id = rhutil.coerceguid(mesh_ids, False)
if id: mesh_ids = [id]
meshes = [rhutil.coercemesh(id, True) for id in mesh_ids]
tolerance = scriptcontext.doc.ModelAbsoluteTolerance
rc = Rhino.Geometry.Intersect.Intersection.ProjectPointsToMeshes(meshes, pts, direction, tolerance)
return rc
示例9: MeshHasVertexColors
def MeshHasVertexColors(object_id):
"""Verifies a mesh object has vertex colors
Parameters:
object_id = identifier of a mesh object
"""
mesh = rhutil.coercemesh(object_id, True)
return mesh.VertexColors.Count>0
示例10: MeshFaceNormals
def MeshFaceNormals(mesh_id):
"""Returns the face unit normal for each face of a mesh object
Parameters:
mesh_id = identifier of a mesh object
Returns:
List of 3D vectors that define the face unit normals of the mesh
None on error
Example:
import rhinoscriptsyntax as rs
obj = rs.GetObject("Select mesh", rs.filter.mesh)
normals = rs.MeshFaceNormals(obj)
if normals:
for vector in normals: print vector
See Also:
MeshHasFaceNormals
MeshFaceCount
MeshFaces
"""
mesh = rhutil.coercemesh(mesh_id, True)
if mesh.FaceNormals.Count != mesh.Faces.Count:
mesh.FaceNormals.ComputeFaceNormals()
rc = []
for i in xrange(mesh.FaceNormals.Count):
normal = mesh.FaceNormals[i]
rc.append(Rhino.Geometry.Vector3d(normal))
return rc
示例11: MeshFaces
def MeshFaces(object_id, face_type=True):
"""Returns the face vertices of a mesh
Parameters:
object_id = identifier of a mesh object
face_type[opt] = The face type to be returned. True = both triangles
and quads. False = only triangles
Returns:
a list of 3D points that define the face vertices of the mesh. If
face_type is True, then faces are returned as both quads and triangles
(4 3D points). For triangles, the third and fourth vertex will be
identical. If face_type is False, then faces are returned as only
triangles(3 3D points). Quads will be converted to triangles.
"""
mesh = rhutil.coercemesh(object_id, True)
rc = []
for i in xrange(mesh.Faces.Count):
getrc, p0, p1, p2, p3 = mesh.Faces.GetFaceVertices(i)
p0 = Rhino.Geometry.Point3d(p0)
p1 = Rhino.Geometry.Point3d(p1)
p2 = Rhino.Geometry.Point3d(p2)
p3 = Rhino.Geometry.Point3d(p3)
rc.append( p0 )
rc.append( p1 )
rc.append( p2 )
if face_type:
rc.append(p3)
else:
if p2!=p3:
rc.append( p2 )
rc.append( p3 )
rc.append( p0 )
return rc
示例12: MeshBooleanUnion
def MeshBooleanUnion(mesh_ids, delete_input=True):
"""Performs boolean union operation on a set of input meshes
Parameters:
mesh_ids = identifiers of meshes
delete_input[opt] = delete the input meshes
Returns:
list of identifiers of new meshes
Example:
import rhinoscriptsyntax as rs
input = rs.GetObjects("Select meshes to union", rs.filter.mesh)
if input: rs.MeshBooleanUnion(input)
See Also:
MeshBooleanDifference
MeshBooleanIntersection
MeshBooleanSplit
"""
if len(mesh_ids)<2: raise ValueError("mesh_ids must contain at least 2 meshes")
meshes = [rhutil.coercemesh(id, True) for id in mesh_ids]
newmeshes = Rhino.Geometry.Mesh.CreateBooleanUnion(meshes)
rc = []
for mesh in newmeshes:
id = scriptcontext.doc.Objects.AddMesh(mesh)
if id!=System.Guid.Empty: rc.append(id)
if rc and delete_input:
for id in mesh_ids:
id = rhutil.coerceguid(id, True)
scriptcontext.doc.Objects.Delete(id, True)
scriptcontext.doc.Views.Redraw()
return rc
示例13: MeshClosestPoint
def MeshClosestPoint(object_id, point, maximum_distance=None):
"""Returns the point on a mesh that is closest to a test point
Parameters:
object_id = identifier of a mesh object
point = point to test
maximum_distance[opt] = upper bound used for closest point calculation.
If you are only interested in finding a point Q on the mesh when
point.DistanceTo(Q) < maximum_distance, then set maximum_distance to
that value
Returns:
Tuple containing the results of the calculation where
element[0] = the 3-D point on the mesh
element[1] = the index of the mesh face on which the 3-D point lies
None on error
Example:
import rhinocriptsyntax as rs
obj = rs.GetObject("Select mesh", rs.filter.mesh)
point = rs.GetPoint("Pick test point")
intersect = rs.MeshClosestPoint(obj, point)
if intersect: rs.AddPoint(intersect)
See Also:
MeshFaceCount
MeshFaces
"""
mesh = rhutil.coercemesh(object_id, True)
point = rhutil.coerce3dpoint(point, True)
tolerance=maximum_distance if maximum_distance else 0.0
face, closest_point = mesh.ClosestPoint(point, tolerance)
if face<0: return scriptcontext.errorhandler()
return closest_point, face
示例14: MeshArea
def MeshArea(object_ids):
"""Returns approximate area of one or more mesh objects
Parameters:
object_ids = identifiers of one or more mesh objects
Returns:
list containing 3 numbers if successful where
element[0] = number of meshes used in calculation
element[1] = total area of all meshes
element[2] = the error estimate
None if not successful
Example:
import rhinoscriptsyntax as rs
obj = rs.GetObject("Select mesh", rs.filter.mesh )
if obj:
area_rc = rs.MeshArea(obj)
if area_rc: print "Mesh area:", area_rc[1]
See Also:
MeshVolume
"""
id = rhutil.coerceguid(object_ids)
if id: object_ids = [object_ids]
meshes_used = 0
total_area = 0.0
error_estimate = 0.0
for id in object_ids:
mesh = rhutil.coercemesh(id, True)
if mesh:
mp = Rhino.Geometry.AreaMassProperties.Compute(mesh)
if mp:
meshes_used += 1
total_area += mp.Area
error_estimate += mp.AreaError
if meshes_used==0: return scriptcontext.errorhandler()
return meshes_used, total_area, error_estimate
示例15: JoinMeshes
def JoinMeshes(object_ids, delete_input=False):
"""Joins two or or more mesh objects together
Parameters:
object_ids = identifiers of two or more mesh objects
delete_input[opt] = delete input after joining
Returns:
identifier of newly created mesh on success
Example:
import rhinoscriptsyntax as rs
objs = rs.GetObjects("Select meshes to join", rs.filter.mesh)
if objs and len(objs)>1: rs.JoinMeshes(objs, True)
See Also:
JoinCurves
JoinSurfaces
"""
meshes = [rhutil.coercemesh(id,True) for id in object_ids]
joined_mesh = Rhino.Geometry.Mesh()
for mesh in meshes: joined_mesh.Append(mesh)
rc = scriptcontext.doc.Objects.AddMesh(joined_mesh)
if delete_input:
for id in object_ids:
guid = rhutil.coerceguid(id)
scriptcontext.doc.Objects.Delete(guid,True)
scriptcontext.doc.Views.Redraw()
return rc