Python maya.OpenMaya.MPointArray() Examples
The following are 14
code examples of maya.OpenMaya.MPointArray().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
maya.OpenMaya
, or try the search function
.
Example #1
Source File: geo_cache.py From spore with MIT License | 6 votes |
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...')
Example #2
Source File: geo_cache.py From spore with MIT License | 6 votes |
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])
Example #3
Source File: mesh_utils.py From spore with MIT License | 6 votes |
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)
Example #4
Source File: spore_sampler.py From spore with MIT License | 5 votes |
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()
Example #5
Source File: ptc_cache.py From spore with MIT License | 5 votes |
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
Example #6
Source File: ptc_cache.py From spore with MIT License | 5 votes |
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
Example #7
Source File: geo_cache.py From spore with MIT License | 5 votes |
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
Example #8
Source File: mesh.py From maya-skinning-tools with GNU General Public License v3.0 | 5 votes |
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())]
Example #9
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 5 votes |
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())
Example #10
Source File: maya_PasteFromExternal.py From OD_CopyPasteExternal with Apache License 2.0 | 5 votes |
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)
Example #11
Source File: geo_cache.py From spore with MIT License | 4 votes |
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 ################################################################################################
Example #12
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 4 votes |
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
Example #13
Source File: oyCenterOfMass.py From anima with MIT License | 4 votes |
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
Example #14
Source File: flatten.py From cmt with MIT License | 4 votes |
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)