Python maya.OpenMaya.MFloatArray() Examples

The following are 4 code examples of maya.OpenMaya.MFloatArray(). 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: paintRemoveInfluenceCtxCommands.py    From maya-skinning-tools with GNU General Public License v3.0 5 votes vote down vote up
def select(self):
        # variables
        selection = OpenMaya.MSelectionList()
        weights = OpenMaya.MFloatArray()

        # get infliences vertices
        self.skinCluster.getPointsAffectedByInfluence(
            self.influence, 
            selection, 
            weights
        )

        # if no vertices select joint
        if not selection.isEmpty():
            selection.add(self.influence)
        
        # set selection
        componentMode = OpenMaya.MGlobal.kSelectComponentMode
        componentMaskMode = OpenMaya.MSelectionMask.kSelectMeshVerts
        componentMask = OpenMaya.MSelectionMask(componentMaskMode)
        OpenMaya.MGlobal.setSelectionMode(componentMode)
        OpenMaya.MGlobal.setComponentSelectionMask(componentMask)
        OpenMaya.MGlobal.setHiliteList(selection)  
        OpenMaya.MGlobal.setActiveSelectionList(selection)  
        
    # ------------------------------------------------------------------------ 
Example #2
Source File: randomizeUVDeformer.py    From anima with MIT License 4 votes vote down vote up
def deform(self, data_block, geometry_iterator, local_to_world_matrix, geometry_index):
        """do deformation
        """
        envelope_attribute = OpenMayaMPx.cvar.MPxDeformerNode_envelope
        envelope_value = data_block.inputValue(envelope_attribute).asFloat()

        input_geometry_object = \
            self.get_deformer_input_geometry(data_block, geometry_index)

        # Obtain the list of normals for each vertex in the mesh.
        mesh_fn = OpenMaya.MFnMesh(input_geometry_object)

        uv_shell_array = OpenMaya.MIntArray()
        u_array = OpenMaya.MFloatArray()
        v_array = OpenMaya.MFloatArray()
        script_util = OpenMaya.MScriptUtil(0)
        shells_ptr = script_util.asUintPtr()

        mesh_fn.getUvShellsIds(uv_shell_array, shells_ptr)
        mesh_fn.getUVs(u_array, v_array)

        max_offset_attr_handle = \
            data_block.inputValue(RandomizeDeformer.aMaxOffset)
        max_offset = max_offset_attr_handle.asInt()

        # compute and write the new uvs
        for uv_id in xrange(len(u_array)):
            shell_id = uv_shell_array[uv_id]
            offset_u = shell_id % max_offset
            u_array[uv_id] += offset_u

        mesh_fn.setUVs(u_array, v_array)

        uv_shell_array.clear()
        u_array.clear()
        v_array.clear()

        # # Iterate over the vertices to move them.
        # while not geometry_iterator.isDone():
        #     # Obtain the vertex normal of the geometry.
        #     # This normal is the vertex's averaged normal value if that
        #     # vertex is shared among several polygons.
        #     vertex_index = geometry_iterator.index()
        #     normal = OpenMaya.MVector(normals[vertex_index])
        #  Cast the MFloatVector into a simple vector.
        #
        #     # Increment the point along the vertex normal.
        #     point = geometry_iterator.position()
        #     newPoint = \
        #         point + (normal * vertexIncrement * meshInflation * envelopeValue)
        #
        #     # Clamp the new point within the bounding box.
        #     self.clampPointInBoundingBox(newPoint, boundingBox)
        #
        #     # Set the position of the current vertex to the new point.
        #     geometry_iterator.setPosition(newPoint)
        #
        #     # Jump to the next vertex.
        #     geometry_iterator.next() 
Example #3
Source File: instanceAlongCurve.py    From instanceAlongCurve with MIT License 4 votes vote down vote up
def __init__(self, mObject, dataBlock, rampAttr, normalize, instanceCount):            
            self.ramp = OpenMaya.MRampAttribute(OpenMaya.MPlug(mObject, rampAttr.ramp))
            self.rampOffset = dataBlock.inputValue(rampAttr.rampOffset).asFloat()
            self.rampRandomAmplitude = dataBlock.inputValue(rampAttr.rampRandomAmplitude).asFloat()
            self.rampAmplitude = dataBlock.inputValue(rampAttr.rampAmplitude).asFloat()
            self.rampRepeat = dataBlock.inputValue(rampAttr.rampRepeat).asFloat()

            if normalize:
                self.rampAxis = dataBlock.inputValue(rampAttr.rampAxis.compound).asVector().normal()
            else:
                self.rampAxis = dataBlock.inputValue(rampAttr.rampAxis.compound).asVector()

            self.useDynamicAmplitudeValues = False

            amplitudePlug = OpenMaya.MPlug(mObject, rampAttr.rampAmplitude)

            if amplitudePlug.isConnected():

                # Get connected input plugs
                connections = OpenMaya.MPlugArray()
                amplitudePlug.connectedTo(connections, True, False)

                # Find input transform
                if connections.length() == 1:
                    node = connections[0].node()
                    nodeFn = OpenMaya.MFnDependencyNode(node)

                    resultColors = OpenMaya.MFloatVectorArray()
                    resultTransparencies = OpenMaya.MFloatVectorArray()

                    uValues = OpenMaya.MFloatArray(instanceCount, 0.0)
                    vValues = OpenMaya.MFloatArray(instanceCount, 0.0)

                    # Sample a line, for more user flexibility
                    for i in xrange(instanceCount):
                        uValues.set(i / float(instanceCount), i)
                        vValues.set(i / float(instanceCount), i)

                    # For now... then we can just use the plug (TODO)
                    if(node.hasFn(OpenMaya.MFn.kTexture2d)):                        
                        
                        OpenMayaRender.MRenderUtil.sampleShadingNetwork(nodeFn.name() + ".outColor", instanceCount, False, False, OpenMaya.MFloatMatrix(), None, uValues, vValues, None, None, None, None, None, resultColors, resultTransparencies)

                        self.rampAmplitudeValues = []
                        self.useDynamicAmplitudeValues = True

                        for i in xrange(resultColors.length()):
                            self.rampAmplitudeValues.append(resultColors[i].length() / math.sqrt(3))

    # Ramps base offset 
Example #4
Source File: flatten.py    From cmt with MIT License 4 votes vote down vote up
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)