本文整理匯總了Python中maya.OpenMaya.MPointArray方法的典型用法代碼示例。如果您正苦於以下問題:Python OpenMaya.MPointArray方法的具體用法?Python OpenMaya.MPointArray怎麽用?Python OpenMaya.MPointArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類maya.OpenMaya
的用法示例。
在下文中一共展示了OpenMaya.MPointArray方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: cache
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPointArray [as 別名]
def cache(self, triangle):
""" cache setter
append one triangle to the end of the current cache
:param triangle: argument must be of type tuple or list
it must consist of the following items in the exact same order:
id content data type
0 - p0 - MPointArray
1 - p2 - MPointArray
2 - p1 - MPointArray
3 - face normal - MVectorArray
4 - polygon id - MIntArray
5 - vector AB - MVectorArray
6 - vector AC - MvectorArray
note: no error or type checking is done!
"""
self.p0.append(triangle[0])
self.p1.append(triangle[1])
self.p2.append(triangle[2])
self.normals.append(triangle[3])
self.poly_id.append(int(triangle[4]))
self.AB.append(triangle[5])
self.AC.append(triangle[6])
示例2: __init__
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPointArray [as 別名]
def __init__(self):
log_lvl = sys._global_spore_dispatcher.spore_globals['LOG_LEVEL']
self.logger = logging_util.SporeLogger(__name__, log_lvl)
self.p0 = om.MPointArray()
self.p1 = om.MPointArray()
self.p2 = om.MPointArray()
self.normals = om.MVectorArray()
self.poly_id = om.MIntArray()
self.AB = om.MVectorArray()
self.AC = om.MVectorArray()
self.poly_verts = om.MPointArray()
self.uv_kd_tree = None
self.neighbor_lookup = {}
self.mesh = None
self.cached = True
self.weighted_ids = []
# @progress_bar.ProgressBar('Caching Geometry...')
示例3: hit_test
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPointArray [as 別名]
def hit_test(target, x, y, invert_y=True):
origin = om.MPoint()
direction = om.MVector()
view = window_utils.active_view()
if invert_y:
y = view.portHeight() - y
view.viewToWorld(x, y, origin, direction)
mesh_fn = get_mesh_fn(target)
if mesh_fn:
points = om.MPointArray()
intersect = mesh_fn.intersect(origin, direction, points, 1.0e-3, om.MSpace.kWorld)
if intersect:
point = points[0]
normal = om.MVector()
mesh_fn.getClosestNormal(point, normal, om.MSpace.kWorld)
tangent = get_tangent(normal)
position = (point.x, point.y, point.z)
tangent = (tangent.x, tangent.y, tangent.z)
normal = (normal.x, normal.y, normal.z)
return (position, normal, tangent)
示例4: __init__
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPointArray [as 別名]
def __init__(self):
self.position = om.MPointArray()
self.normal = om.MVectorArray()
self.poly_id = om.MIntArray()
self.u_coord = [] # om.MDoubleArray()
self.v_coord = [] # om.MDoubleArray()
示例5: __init__
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPointArray [as 別名]
def __init__(self):
self._locked = False
# sampled data from the ptc
self.points = om.MPointArray()
self.normals = om.MVectorArray()
self.poly_ids = om.MIntArray()
self.u_coords = om.MDoubleArray()
self.v_coords = om.MDoubleArray()
self.user = []
self.bb = None
示例6: get_points
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPointArray [as 別名]
def get_points(self):
"""
return all points from the cache
:return: MPointArray - list of all point positions
MVectorArray - list of all normals
MIntArray - list of all polygon ids
MDoubleArray - list of all u_coordinates
MDoubleArray - list of all v coordinates
"""
return self.points, self.normals, self.poly_ids, self.u_coords, self.v_coords, self.user
示例7: flush_cache
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPointArray [as 別名]
def flush_cache(self):
self.logger.debug('Flush GeoCache')
self.p0 = om.MPointArray()
self.p1 = om.MPointArray()
self.p2 = om.MPointArray()
self.normals = om.MVectorArray()
self.poly_id = om.MIntArray()
self.AB = om.MVectorArray()
self.AC = om.MVectorArray()
self.cached = False
示例8: getPoints
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPointArray [as 別名]
def getPoints(dag):
"""
Get the position in world space of each vertex on the provided mesh.
:param OpenMaya.MDagPath dag:
:return: Points
:rtype: list
"""
points = OpenMaya.MPointArray()
mesh = OpenMaya.MFnMesh(dag)
mesh.getPoints(points, OpenMaya.MSpace.kWorld)
return [OpenMaya.MVector(points[i]) for i in range(points.length())]
示例9: editCurve
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPointArray [as 別名]
def editCurve(parent, points, degree=1, form=kOpen):
assert isinstance(parent, DagNode), (
"parent must be of type cmdx.DagNode"
)
degree = min(3, max(1, degree))
cvs = om1.MPointArray()
curveFn = om1.MFnNurbsCurve()
for point in points:
cvs.append(om1.MPoint(*point))
mobj = curveFn.createWithEditPoints(cvs,
degree,
form,
False,
False,
True,
_encode1(parent.path()))
mod = om1.MDagModifier()
mod.renameNode(mobj, parent.name(namespace=True) + "Shape")
mod.doIt()
def undo():
mod.deleteNode(mobj)
mod.doIt()
def redo():
mod.undoIt()
commit(undo, redo)
shapeFn = om1.MFnDagNode(mobj)
return encode(shapeFn.fullPathName())
示例10: fn_createObject_openMaya
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPointArray [as 別名]
def fn_createObject_openMaya():
global importedObj
cmds.select( all = True, hierarchy = True)
currentObjs = cmds.ls(selection = True )
newMesh = om.MFnMesh()
mergeVertices = True
pointTolerance = 0.0001
for p in range(0, len(importedObj.polys), 1):
polylist = []
vCount = len(importedObj.polys[p])
polylist = om.MPointArray()
polylist.setLength(vCount)
for i in range(vCount):
polylist.set(importedObj.omVertices[int(importedObj.polys[p][i])], i)
newMesh.addPolygon(polylist, mergeVertices, pointTolerance)
if len(importedObj.weightMap) > 0:
for v in range(0, importedObj.vertexCount , 1):
c = importedObj.weightMap[v]
vColor = om.MColor(c,c,c,c )
newMesh.setVertexColor(vColor,v)
newMesh.updateSurface()
cmds.select( all = True, hierarchy = True)
cmds.select(currentObjs, deselect = True)
newObjs = cmds.ls(selection = True, transforms = True )
cmds.select(newObjs, replace = True)
cmds.sets( newObjs, e=True,forceElement='initialShadingGroup')
cmds.rename (newObjs, importObjectName)
示例11: validate_cache
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPointArray [as 別名]
def validate_cache(self):
""" check if the current cache is valid """
points = om.MPointArray()
mesh_fn = om.MFnMesh(self.mesh)
mesh_fn.getPoints(points)
if points.length() != self.poly_verts.length():
self.logger.debug('Validate GeoCache succeded')
return False
for i in xrange(points.length()):
if points[i] != self.poly_verts[i]:
self.logger.debug('Validate GeoCache failed')
return False
return True
"""
index = 0
tri_points = om.MPointArray()
tri_ids = om.MIntArray()
poly_iter = om.MItMeshPolygon(self.mesh)
while not poly_iter.isDone():
# get face triangles
poly_index = poly_iter.index()
poly_iter.getTriangles(tri_points, tri_ids, om.MSpace.kWorld)
# get triangle data
for i in xrange(tri_points.length() / 3):
# assert self.p0[i * 3] == tri_points[i * 3]
# assert self.p1[i * 3 + 1] == tri_points[i * 3 + 1]
# assert self.p2[i * 3 + 2] == tri_points[i * 3 + 2]
print self.p0[i*3].x, tri_points[i*3].x
print self.p0[i*3].y, tri_points[i*3].y
print self.p0[i*3].z, tri_points[i*3].z
print '-'
print self.p0[i*3+1].x, tri_points[i*3+1].x
print self.p0[i*3+1].y, tri_points[i*3+1].y
print self.p0[i*3+1].z, tri_points[i*3+1].z
print '-'
print self.p0[i*3+2].x, tri_points[i*3+2].x
print self.p0[i*3+2].y, tri_points[i*3+2].y
print self.p0[i*3+2].z, tri_points[i*3+2].z
# except AssertionError:
# return False
index += 1
poly_iter.next()
return True
"""
################################################################################################
# cache property
################################################################################################
示例12: NurbsCurveData
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPointArray [as 別名]
def NurbsCurveData(points, degree=1, form=om1.MFnNurbsCurve.kOpen):
"""Tuple of points to MObject suitable for nurbsCurve-typed data
Arguments:
points (tuple): (x, y, z) tuples per point
degree (int, optional): Defaults to 1 for linear
form (int, optional): Defaults to MFnNurbsCurve.kOpen,
also available kClosed
Example:
Create a new nurbs curve like this.
>>> data = NurbsCurveData(
... points=(
... (0, 0, 0),
... (0, 1, 0),
... (0, 2, 0),
... ))
...
>>> parent = createNode("transform")
>>> shape = createNode("nurbsCurve", parent=parent)
>>> shape["cached"] = data
"""
degree = min(3, max(1, degree))
cvs = om1.MPointArray()
curveFn = om1.MFnNurbsCurve()
data = om1.MFnNurbsCurveData()
mobj = data.create()
for point in points:
cvs.append(om1.MPoint(*point))
curveFn.createWithEditPoints(cvs,
degree,
form,
False,
False,
True,
mobj)
return mobj
示例13: compute
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPointArray [as 別名]
def compute(self, plug, dataBlock):
if plug == oyCenterOfMass.aCOMPos:
# get the mesh vertices for time from start to end
# get the meshes
arrayDataHandle = dataBlock.inputArrayValue( oyCenterOfMass.aObjectList )
numOfConnections = arrayDataHandle.elementCount()
inputDataHandle = OpenMaya.MDataHandle()
inputGeometryDataHandle = OpenMaya.MDataHandle()
mesh = OpenMaya.MObject()
meshList = OpenMaya.MObjectArray()
for i in range(numOfConnections):
arrayDataHandle.jumpToElement(i)
inputDataHandle = arrayDataHandle.inputValue()
inputGeometryDataHandle = inputDataHandle.child( oyCenterOfMass.aObjectList )
mesh = inputGeometryDataHandle.asMesh()
if mesh.hasFn( OpenMaya.MFn.kMesh ):
meshList.append( mesh )
numOfMesh = meshList.length()
# return if no mesh
if numOfMesh == 0:
return OpenMaya.MStatus.kSuccess
# read the mesh vertices in to one big array
verticesOfOneMesh = OpenMaya.MPointArray()
allVertices = OpenMaya.MPointArray()
meshFn = OpenMaya.MFnMesh()
for i in range(numOfMesh):
meshFn.getPoints ( verticesOfOneMesh, OpenMaya.MSpace.kWorld )
for j in range(verticesOfOneMesh.length()):
allVertices.append( verticesOfOneMesh[j] )
# set the time
return OpenMaya.MStatus.kSuccess
else:
return OpenMaya.kUnknownParameter
示例14: flatten
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPointArray [as 別名]
def flatten(mesh=None, uvset=None):
"""Creates a mesh from the UV layout of another mesh.
I use this to generate flattened versions of meshes from Marvelous Designer to easily use Quad
Draw to create clean meshes and then Transfer Attributes vertex positions through UVs.
:param mesh: Mesh to sample.
:param uvset: UV set name
"""
if mesh is None:
mesh = cmds.ls(sl=True)
if not mesh:
raise RuntimeError("No mesh selected.")
mesh = mesh[0]
o_mesh = shortcuts.get_mobject(shortcuts.get_shape(mesh))
fn_mesh = OpenMaya.MFnMesh(o_mesh)
if uvset is None:
uvset = fn_mesh.currentUVSetName()
vertex_count = fn_mesh.numUVs(uvset)
polygon_count = fn_mesh.numPolygons()
u_array = OpenMaya.MFloatArray()
v_array = OpenMaya.MFloatArray()
fn_mesh.getUVs(u_array, v_array, uvset)
vertex_array = OpenMaya.MPointArray(u_array.length())
for i in range(u_array.length()):
vertex_array.set(i, u_array[i], 0, -v_array[i])
polygon_counts = OpenMaya.MIntArray(polygon_count)
it_poly = OpenMaya.MItMeshPolygon(o_mesh)
polygon_connects = OpenMaya.MIntArray(fn_mesh.numFaceVertices())
face_vertex_index = 0
while not it_poly.isDone():
face_index = it_poly.index()
polygon_counts[face_index] = it_poly.polygonVertexCount()
for i in range(polygon_counts[face_index]):
int_ptr = shortcuts.get_int_ptr()
it_poly.getUVIndex(i, int_ptr)
uv_index = shortcuts.ptr_to_int(int_ptr)
polygon_connects[face_vertex_index] = uv_index
face_vertex_index += 1
it_poly.next()
new_mesh = OpenMaya.MFnMesh()
new_mesh.create(
vertex_count,
polygon_count,
vertex_array,
polygon_counts,
polygon_connects,
u_array,
v_array,
)
new_mesh.assignUVs(polygon_counts, polygon_connects)