Beispiel #1
0
        override public void deform(MDataBlock block, MItGeometry iter, MMatrix m, uint multiIndex)
        {
            MDataHandle angleData = block.inputValue(angle);
            MDataHandle envData   = block.inputValue(envelope);
            double      magnitude = angleData.asDouble;

            float env = envData.asFloat;

            for (; !iter.isDone; iter.next())
            {
                MPoint pt = iter.position();

                // do the twist
                //

                double ff = magnitude * pt.y * env;
                if (ff != 0.0)
                {
                    double cct = Math.Cos(ff);
                    double cst = Math.Sin(ff);
                    double tt  = pt.x * cct - pt.z * cst;
                    pt.z = pt.x * cst + pt.z * cct;
                    pt.x = tt;;
                }

                iter.setPosition(pt);
            }
        }
Beispiel #2
0
        // The compute() method does the actual work of the node using the inputs
        // of the node to generate its output.
        //
        // Compute takes two parameters: plug and data.
        // - Plug is the the data value that needs to be recomputed
        // - Data provides handles to all of the nodes attributes, only these
        //   handles should be used when performing computations.
        //
        public override bool compute(MPlug plug, MDataBlock dataBlock)
        {
            MObject           thisNode   = thisMObject();
            MFnDependencyNode fnThisNode = new MFnDependencyNode(thisNode);

            MGlobal.displayInfo("affects::compute(), plug being computed is \"" + plug.name + "\"");

            if (plug.partialName() == "B")
            {
                // Plug "B" is being computed. Assign it the value on plug "A"
                // if "A" exists.
                //
                MPlug pA = fnThisNode.findPlug("A");

                MGlobal.displayInfo("\t\t... found dynamic attribute \"A\", copying its value to \"B\"");
                MDataHandle inputData = dataBlock.inputValue(pA);

                int value = inputData.asInt;

                MDataHandle outputHandle = dataBlock.outputValue(plug);

                outputHandle.set(value);
                dataBlock.setClean(plug);
            }
            else
            {
                return(false);
            }
            return(true);
        }
Beispiel #3
0
        public override bool compute(MPlug plug, MDataBlock dataBlock)
        {
            if (plug.equalEqual(animCube.outputMesh))
            {
                /* Get time */
                MDataHandle timeData = dataBlock.inputValue(animCube.time);
                MTime       time     = timeData.asTime;

                /* Get output object */

                MDataHandle outputHandle = dataBlock.outputValue(outputMesh);

                MFnMeshData dataCreator   = new MFnMeshData();
                MObject     newOutputData = dataCreator.create();

                createMesh(time, ref newOutputData);

                outputHandle.set(newOutputData);
                dataBlock.setClean(plug);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Beispiel #4
0
        double springFactor(MDataBlock block)
        {
            MDataHandle handle = block.inputValue(aSpringFactor);
            double      value  = 0.0;

            value = handle.asDouble;
            return(value);
        }
 public override bool getInternalValueInContext(MPlug plug, MDataHandle dataHandle, MDGContext ctx)
 {
     if (plug.equalEqual(aTransparency))
     {
         dataHandle.set(fTransparency);
         return true;
     }
     return base.getInternalValueInContext(plug, dataHandle, ctx);
 }
Beispiel #6
0
 public override bool getInternalValueInContext(MPlug plug, MDataHandle dataHandle, MDGContext ctx)
 {
     if (plug.equalEqual(aTransparency))
     {
         dataHandle.set(fTransparency);
         return(true);
     }
     return(base.getInternalValueInContext(plug, dataHandle, ctx));
 }
Beispiel #7
0
        double end2WeightValue(MDataBlock block)
        {
            MDataHandle hValue = block.inputValue(mEnd2Weight);

            double value = 0.0;

            value = hValue.asDouble;
            return(value);
        }
Beispiel #8
0
        public override bool compute(MPlug plug, MDataBlock dataBlock)
        //
        //	Description:
        //		Computes a color value
        //	from a surface noraml angle.
        //
        {
            if ((plug.notEqual(aOutColor)) && (plug.parent.notEqual(aOutColor)))
            {
                return(false);
            }

            MFloatVector resultColor;

            MFloatVector walkable      = dataBlock.inputValue(aColor1).asFloatVector;
            MFloatVector nonWalkable   = dataBlock.inputValue(aColor2).asFloatVector;
            MFloatVector surfaceNormal = dataBlock.inputValue(aTriangleNormalCamera).asFloatVector;
            MFloatMatrix viewMatrix    = dataBlock.inputValue(aMatrixEyeToWorld).asFloatMatrix;
            float        angle         = dataBlock.inputValue(aAngle).asFloat;

            // Normalize the view vector
            //
            surfaceNormal.normalize();
            MFloatVector WSVector = surfaceNormal.multiply(viewMatrix);

            // find dot product
            //
            float scalarNormal = WSVector.multiply(new MFloatVector(0, 1, 0));

            // take the absolute value
            //
            if (scalarNormal < 0.0)
            {
                scalarNormal *= -1.0f;
            }

            if (Math.Cos(angle * AWdegreesToRadians) < scalarNormal)
            {
                resultColor = walkable;
            }
            else
            {
                resultColor = nonWalkable;
            }

            // set ouput color attribute
            //
            MDataHandle  outColorHandle = dataBlock.outputValue(aOutColor);
            MFloatVector outColor       = outColorHandle.asFloatVector;

            outColor = resultColor;
            outColorHandle.setClean();

            return(true);
        }
Beispiel #9
0
        public override bool setInternalValueInContext(MPlug plug, MDataHandle dataHandle, MDGContext ctx)
        {
            if (plug.equalEqual(aTransparency))
            {
                fTransparency = dataHandle.asDouble;
                setImageDirty();
                return(true);
            }

            return(base.setInternalValueInContext(plug, dataHandle, ctx));
        }
Beispiel #10
0
		public override bool setInternalValueInContext(MPlug plug, MDataHandle dataHandle, MDGContext ctx)
		{
			if (plug.equalEqual(aTransparency))
			{
				fTransparency = dataHandle.asDouble;
				setImageDirty();
				return true;
			}

			return base.setInternalValueInContext(plug, dataHandle, ctx);
		}
Beispiel #11
0
        public override bool getInternalValue(MPlug plug, MDataHandle datahandle)
        {
            bool isOk = true;

            if (plug.attribute.equalEqual(radius1))
            {
                datahandle.set(fGeometry.radius1);
                isOk = true;
            }
            else if (plug.attribute.equalEqual(radius2))
            {
                datahandle.set(fGeometry.radius2);
                isOk = true;
            }
            else if (plug.attribute.equalEqual(height))
            {
                datahandle.set(fGeometry.height);
                isOk = true;
            }
            else if (plug.attribute.equalEqual(startAngle))
            {
                datahandle.set(fGeometry.startAngle);
                isOk = true;
            }
            else if (plug.attribute.equalEqual(sweepAngle))
            {
                datahandle.set(fGeometry.sweepAngle);
                isOk = true;
            }
            else if (plug.attribute.equalEqual(slices))
            {
                datahandle.set(fGeometry.slices);
                isOk = true;
            }
            else if (plug.attribute.equalEqual(loops))
            {
                datahandle.set(fGeometry.loops);
                isOk = true;
            }
            else if (plug.attribute.equalEqual(stacks))
            {
                datahandle.set(fGeometry.stacks);
                isOk = true;
            }
            else
            {
                isOk = base.getInternalValue(plug, datahandle);
            }

            return(isOk);
        }
Beispiel #12
0
        override public bool compute(MPlug plug, MDataBlock dataBlock)
        {
            bool res = plug.attribute.equalEqual(output);

            if (res)
            {
                MDataHandle inputData;
                inputData = dataBlock.inputValue(input);

                MDataHandle outputHandle = dataBlock.outputValue(output);
                outputHandle.asFloat = 10 * (float)Math.Sin((double)inputData.asFloat);
                dataBlock.setClean(plug);
                return(true);
            }

            return(false);
        }
        override public void deform(MDataBlock block, MItGeometry iter, MMatrix m, uint multiIndex)
        {
            MDataHandle angleData = block.inputValue(angle);
            MDataHandle envData   = block.inputValue(envelope);
            double      magnitude = angleData.asDouble;

            float env = envData.asFloat;

            var startTime = DateTime.Now;

            var poses = new MPointArray();

            iter.allPositions(poses);

            //var newPos = VulankCompute.ComputeData(poses, (float)magnitude, env);
            VulankCompute.ComputeData(poses, (float)magnitude, env);

            iter.setAllPositions(poses);

            var timeSpand = DateTime.Now - startTime;

            MGlobal.displayInfo(string.Format("---------- total time : {0}", timeSpand.TotalSeconds));
            //for (; !iter.isDone; iter.next())
            //{
            //MPoint pt = iter.position();

            //// do the twist
            ////

            //double ff = magnitude * pt.y * env;
            //if (ff != 0.0)
            //{
            //    double cct = Math.Cos(ff);
            //    double cst = Math.Sin(ff);
            //    double tt = pt.x * cct - pt.z * cst;
            //    pt.z = pt.x * cst + pt.z * cct;
            //    pt.x = tt; ;
            //}

            //iter.setPosition(pt);
            //}
        }
        public override void validateAndSetValue(MPlug plug, MDataHandle handle, MDGContext context)
        {
            //	Make sure that there is something interesting to process.
            //
            if (plug.isNull)
            {
                throw new ArgumentNullException("plug");
            }

            if (plug.equalEqual(aRockInX))
            {
                MDataBlock  block       = _forceCache(context);
                MDataHandle blockHandle = block.outputValue(plug);

                // Update our new rock in x value
                double rockInX = handle.asDouble;
                blockHandle.set(rockInX);
                rockXValue = rockInX;

                // Update the custom transformation matrix to the
                // right rock value.
                rockingTransformCheckMatrix ltm = getRockingTransformMatrix();
                if (ltm != null)
                {
                    ltm.setRockInX(rockXValue);
                }
                else
                {
                    MGlobal.displayError("Failed to get rock transform matrix");
                }

                blockHandle.setClean();

                // Mark the matrix as dirty so that DG information
                // will update.
                dirtyMatrix();

                return;
            }
            base.validateAndSetValue(plug, handle, context);
        }
Beispiel #15
0
 public override bool setInternalValue(MPlug plug, MDataHandle dataHandle)
 {
     return(base.setInternalValue(plug, dataHandle));
 }
Beispiel #16
0
        public override bool compute(MPlug plug, MDataBlock datablock)
        //
        // Description
        //
        //    When input attributes are dirty this method will be called to
        //    recompute the output attributes.
        //
        {
            if (plug.attribute.equalEqual(outputSurface))
            {
                // Create some user-defined geometry data and access the
                // geometry so that we can set it
                //
                MFnPluginData fnDataCreator = new MFnPluginData();
                fnDataCreator.create(new MTypeId(apiMeshData.id));
                apiMeshData meshData = (apiMeshData)fnDataCreator.data();
                apiMeshGeom meshGeom = meshData.fGeometry;

                // If there is an input mesh then copy it's values
                // and construct some apiMeshGeom for it.
                //
                bool hasHistory = computeInputMesh(plug,
                                                   datablock,
                                                   meshGeom.vertices,
                                                   meshGeom.face_counts,
                                                   meshGeom.face_connects,
                                                   meshGeom.normals,
                                                   meshGeom.uvcoords);

                // There is no input mesh so check the shapeType attribute
                // and create either a cube or a sphere.
                //
                if (!hasHistory)
                {
                    MDataHandle sizeHandle = datablock.inputValue(size);
                    double      shape_size = sizeHandle.asDouble;
                    MDataHandle typeHandle = datablock.inputValue(shapeType);
                    short       shape_type = typeHandle.asShort;

                    switch (shape_type)
                    {
                    case 0:                              // build a cube
                        buildCube(shape_size,
                                  meshGeom.vertices,
                                  meshGeom.face_counts,
                                  meshGeom.face_connects,
                                  meshGeom.normals,
                                  meshGeom.uvcoords
                                  );
                        break;

                    case 1:                              // build a sphere
                        buildSphere(shape_size,
                                    32,
                                    meshGeom.vertices,
                                    meshGeom.face_counts,
                                    meshGeom.face_connects,
                                    meshGeom.normals,
                                    meshGeom.uvcoords
                                    );
                        break;
                    }                     // end switch
                }

                meshGeom.faceCount = meshGeom.face_counts.length;

                // Assign the new data to the outputSurface handle
                //
                MDataHandle outHandle = datablock.outputValue(outputSurface);
                outHandle.set(meshData);

                datablock.setClean(plug);
                return(true);
            }

            return(false);
        }
Beispiel #17
0
        public override bool setInternalValue(MPlug plug, MDataHandle datahandle)
        {
            bool isOk = true;

            // In the case of a disk or partial disk the inner radius must
            // never exceed the outer radius and the minimum radius is 0
            //
            if (plug.attribute.equalEqual(radius1))
            {
                double innerRadius = datahandle.asDouble;
                double outerRadius = fGeometry.radius2;

                if (innerRadius > outerRadius)
                {
                    outerRadius = innerRadius;
                }

                if (innerRadius < 0)
                {
                    innerRadius = 0;
                }

                fGeometry.radius1 = innerRadius;
                fGeometry.radius2 = outerRadius;
                isOk = true;
            }
            else if (plug.attribute.equalEqual(radius2))
            {
                double outerRadius = datahandle.asDouble;
                double innerRadius = fGeometry.radius1;

                if (outerRadius <= 0)
                {
                    outerRadius = 0.1;
                }

                if (innerRadius > outerRadius)
                {
                    innerRadius = outerRadius;
                }

                if (innerRadius < 0)
                {
                    innerRadius = 0;
                }

                fGeometry.radius1 = innerRadius;
                fGeometry.radius2 = outerRadius;
                isOk = true;
            }
            else if (plug.attribute.equalEqual(height))
            {
                double val = datahandle.asDouble;
                if (val <= 0)
                {
                    val = 0.1;
                }
                fGeometry.height = val;
            }
            else if (plug.attribute.equalEqual(startAngle))
            {
                double val = datahandle.asDouble;
                fGeometry.startAngle = val;
            }
            else if (plug.attribute.equalEqual(sweepAngle))
            {
                double val = datahandle.asDouble;
                fGeometry.sweepAngle = val;
            }
            else if (plug.attribute.equalEqual(slices))
            {
                short val = datahandle.asShort;
                if (val < 3)
                {
                    val = 3;
                }
                fGeometry.slices = val;
            }
            else if (plug.attribute.equalEqual(loops))
            {
                short val = datahandle.asShort;
                if (val < 3)
                {
                    val = 3;
                }
                fGeometry.loops = val;
            }
            else if (plug.attribute.equalEqual(stacks))
            {
                short val = datahandle.asShort;
                if (val < 2)
                {
                    val = 2;
                }
                fGeometry.stacks = val;
            }
            else
            {
                isOk = base.setInternalValue(plug, datahandle);
            }

            return(isOk);
        }
Beispiel #18
0
        public override bool setInternalValue(MPlug plug, MDataHandle datahandle)
        {
            bool isOk = true;

            // In the case of a disk or partial disk the inner radius must
            // never exceed the outer radius and the minimum radius is 0
            //
            if (plug.attribute.equalEqual(radius1))
            {
                double innerRadius = datahandle.asDouble;
                double outerRadius = fGeometry.radius2;

                if (innerRadius > outerRadius)
                {
                    outerRadius = innerRadius;
                }

                if (innerRadius < 0)
                {
                    innerRadius = 0;
                }

                fGeometry.radius1 = innerRadius;
                fGeometry.radius2 = outerRadius;
                isOk = true;
            }
            else if (plug.attribute.equalEqual(radius2))
            {
                double outerRadius = datahandle.asDouble;
                double innerRadius = fGeometry.radius1;

                if (outerRadius <= 0)
                {
                    outerRadius = 0.1;
                }

                if (innerRadius > outerRadius)
                {
                    innerRadius = outerRadius;
                }

                if (innerRadius < 0)
                {
                    innerRadius = 0;
                }

                fGeometry.radius1 = innerRadius;
                fGeometry.radius2 = outerRadius;
                isOk = true;
            }
            else if (plug.attribute.equalEqual(height))
            {
                double val = datahandle.asDouble;
                if (val <= 0)
                {
                    val = 0.1;
                }
                fGeometry.height = val;
            }
            else if (plug.attribute.equalEqual(startAngle))
            {
                double val = datahandle.asDouble;
                fGeometry.startAngle = val;
            }
            else if (plug.attribute.equalEqual(sweepAngle))
            {
                double val = datahandle.asDouble;
                fGeometry.sweepAngle = val;
            }
            else if (plug.attribute.equalEqual(slices))
            {
                short val = datahandle.asShort;
                if (val < 3)
                {
                    val = 3;
                }
                fGeometry.slices = val;
            }
            else if (plug.attribute.equalEqual(loops))
            {
                short val = datahandle.asShort;
                if (val < 3)
                {
                    val = 3;
                }
                fGeometry.loops = val;
            }
            else if (plug.attribute.equalEqual(stacks))
            {
                short val = datahandle.asShort;
                if (val < 2)
                {
                    val = 2;
                }
                fGeometry.stacks = val;
            }
            else
            {
                isOk = base.setInternalValue(plug, datahandle);
            }

            return isOk;
        }
        public override void validateAndSetValue(MPlug plug, MDataHandle handle, MDGContext context)
        {
            //	Make sure that there is something interesting to process.
            //
            if (plug.isNull)
                throw new ArgumentNullException("plug");

            if (plug.equalEqual(aRockInX))
            {
                MDataBlock block = _forceCache(context);
                MDataHandle blockHandle = block.outputValue(plug);

                // Update our new rock in x value
                double rockInX = handle.asDouble;
                blockHandle.set(rockInX);
                rockXValue = rockInX;

                // Update the custom transformation matrix to the
                // right rock value.
                rockingTransformCheckMatrix ltm = getRockingTransformMatrix();
                if (ltm != null)
                {
                    ltm.setRockInX(rockXValue);
                }
                else
                {
                    MGlobal.displayError("Failed to get rock transform matrix");
                }

                blockHandle.setClean();

                // Mark the matrix as dirty so that DG information
                // will update.
                dirtyMatrix();

                return;
            }
            base.validateAndSetValue(plug, handle, context);
        }
        public override bool compute(MPlug plug, MDataBlock dataBlock)
        {
            if (plug.equalEqual(gOutputFloat_2Float_3Float))
            {
                // attribute affecting generic attribute case.  Based on the
                // input attribute, we modify the output generic attribute
                MDataHandle inputDataInt = dataBlock.inputValue(gInputInt);
                int         inputInt     = inputDataInt.asInt;

                // Get the output handle
                MDataHandle outputData       = dataBlock.outputValue(plug);
                bool        isGenericNumeric = false;
                bool        isGenericNull    = false;

                // Is the output handle generic data
                if (outputData.isGeneric(ref isGenericNumeric, ref isGenericNull))
                {
                    // Based on the inputHandle, update the generic
                    // output handle
                    if (inputInt == 1)
                    {
                        outputData.setGenericBool(false, true);
                    }
                    else if (inputInt == 2)
                    {
                        outputData.setGenericBool(true, true);
                    }
                    else if (inputInt == 3)
                    {
                        outputData.setGenericChar(127, true);
                    }
                    else if (inputInt == 4)
                    {
                        outputData.setGenericDouble(3.145, true);
                    }
                    else if (inputInt == 5)
                    {
                        outputData.setGenericFloat((float)9.98, true);
                    }
                    else if (inputInt == 6)
                    {
                        outputData.setGenericShort(3245, true);
                    }
                    else if (inputInt == 7)
                    {
                        outputData.setGenericInt(32768, true);
                    }
                    else if (inputInt == 8)
                    {
                        MFnNumericData numericData = new MFnNumericData();
                        MObject        obj         = numericData.create(MFnNumericData.Type.k2Float);
                        numericData.setData((float)1.5, (float)6.7);
                        outputData.set(obj);
                    }
                    else if (inputInt == 9)
                    {
                        MFnNumericData numericData = new MFnNumericData();
                        MObject        obj         = numericData.create(MFnNumericData.Type.k3Float);
                        numericData.setData((float)2.5, (float)8.7, (float)2.3345);
                        outputData.set(obj);
                    }
                    else if (inputInt == 10)
                    {
                        outputData.setGenericInt(909, true);
                    }

                    // Mark the data clean
                    outputData.setClean();
                    dataBlock.setClean(gOutputFloat_2Float_3Float);
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
Beispiel #21
0
        public override bool getInternalValue(MPlug plug, MDataHandle datahandle)
        {
            bool isOk = true;

            if (plug.attribute.equalEqual(radius1))
            {
                datahandle.set(fGeometry.radius1);
                isOk = true;
            }
            else if (plug.attribute.equalEqual(radius2))
            {
                datahandle.set(fGeometry.radius2);
                isOk = true;
            }
            else if (plug.attribute.equalEqual(height))
            {
                datahandle.set(fGeometry.height);
                isOk = true;
            }
            else if (plug.attribute.equalEqual(startAngle))
            {
                datahandle.set(fGeometry.startAngle);
                isOk = true;
            }
            else if (plug.attribute.equalEqual(sweepAngle))
            {
                datahandle.set(fGeometry.sweepAngle);
                isOk = true;
            }
            else if (plug.attribute.equalEqual(slices))
            {
                datahandle.set(fGeometry.slices);
                isOk = true;
            }
            else if (plug.attribute.equalEqual(loops))
            {
                datahandle.set(fGeometry.loops);
                isOk = true;
            }
            else if (plug.attribute.equalEqual(stacks))
            {
                datahandle.set(fGeometry.stacks);
                isOk = true;
            }
            else
            {
                isOk = base.getInternalValue(plug, datahandle);
            }

            return isOk;
        }
Beispiel #22
0
		public override bool getInternalValue(MPlug plug, MDataHandle result)
		//
		// Description
		//
		//    Handle internal attributes.
		//
		//    Attributes that require special storage, bounds checking,
		//    or other non-standard behavior can be marked as "Internal" by
		//    using the "MFnAttribute.setInternal" method.
		//
		//    The get/setInternalValue methods will get called for internal
		//    attributes whenever the attribute values are stored or retrieved
		//    using getAttr/setAttr or MPlug getValue/setValue.
		//
		//    The inherited attribute mControlPoints is internal and we want
		//    its values to get stored only if there is input history. Otherwise
		//    any changes to the vertices are stored in the cachedMesh and outputMesh
		//    directly.
		//
		//    If values are retrieved then we want the controlPoints value
		//    returned if there is history, this will be the offset or tweak.
		//    In the case of no history, the vertex position of the cached mesh
		//    is returned.
		//
		{
			bool isOk = true;

			if( plug.attribute.equalEqual(mControlPoints) ||
				plug.attribute.equalEqual(mControlValueX) ||
				plug.attribute.equalEqual(mControlValueY) ||
				plug.attribute.equalEqual(mControlValueZ) )
			{
				// If there is input history then the control point value is
				// directly returned. This is the tweak or offset that
				// was applied to the vertex.
				//
				// If there is no input history then return the actual vertex
				// position and ignore the controlPoints attribute.
				//
				if ( hasHistory() ) {
					return base.getInternalValue( plug, result );
				}
				else {
					double val = 0.0;
					if ( plug.attribute.equalEqual(mControlPoints) && !plug.isArray ) {
						MPoint pnt = new MPoint();
						int index = (int)plug.logicalIndex;
						value( index, ref pnt );
						result.set( pnt[0], pnt[1], pnt[2] );
					}
					else if ( plug.attribute.equalEqual(mControlValueX) ) {
						MPlug parentPlug = plug.parent;
						int index = (int)parentPlug.logicalIndex;
						value( index, 0, ref val );
						result.set( val );
					}
					else if ( plug.attribute.equalEqual(mControlValueY) ) {
						MPlug parentPlug = plug.parent;
						int index = (int)parentPlug.logicalIndex;
						value( index, 1, ref val );
						result.set( val );
					}
					else if ( plug.attribute.equalEqual(mControlValueZ) ) {
						MPlug parentPlug = plug.parent;
						int index = (int)parentPlug.logicalIndex;
						value( index, 2, ref val );
						result.set( val );
					}
				}
			}
			// This inherited attribute is used to specify whether or
			// not this shape has history. During a file read, the shape
			// is created before any input history can get connected.
			// This attribute, also called "tweaks", provides a way to
			// for the shape to determine if there is input history
			// during file reads.
			//
			else if ( plug.attribute.equalEqual(mHasHistoryOnCreate) ) {
				result.set( fHasHistoryOnCreate );
			}
			else {
				isOk = base.getInternalValue( plug, result );
			}

			return isOk;
		}
Beispiel #23
0
        public override bool compute(MPlug plug, MDataBlock block)
        {
            if (plug.equalEqual(constraintGeometry))
            {
                //
                block.inputValue(constraintParentInverseMatrix);
                //
                MArrayDataHandle targetArray = block.inputArrayValue(compoundTarget);
                uint             targetArrayCount = targetArray.elementCount();
                double           weight, selectedWeight = 0;
                if (weightType == GeometrySurfaceConstraintCommand.ConstraintType.kSmallestWeight)
                {
                    selectedWeight = float.MaxValue;
                }
                MObject selectedMesh = null;
                uint    i;
                for (i = 0; i < targetArrayCount; i++)
                {
                    MDataHandle targetElement = targetArray.inputValue();
                    weight = targetElement.child(targetWeight).asDouble;
                    if (!equivalent(weight, 0.0))
                    {
                        if (weightType == GeometrySurfaceConstraintCommand.ConstraintType.kLargestWeight)
                        {
                            if (weight > selectedWeight)
                            {
                                MObject mesh = targetElement.child(targetGeometry).asMesh;
                                if (!mesh.isNull)
                                {
                                    selectedMesh   = mesh;
                                    selectedWeight = weight;
                                }
                            }
                        }
                        else
                        {
                            if (weight < selectedWeight)
                            {
                                MObject mesh = targetElement.child(targetGeometry).asMesh;
                                if (!mesh.isNull)
                                {
                                    selectedMesh   = mesh;
                                    selectedWeight = weight;
                                }
                            }
                        }
                    }
                    targetArray.next();
                }
                //
                if (selectedMesh == null)
                {
                    block.setClean(plug);
                }
                else
                {
                    // The transform node via the geometry attribute will take care of
                    // updating the location of the constrained geometry.
                    MDataHandle outputConstraintGeometryHandle = block.outputValue(constraintGeometry);
                    outputConstraintGeometryHandle.setMObject(selectedMesh);
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
Beispiel #24
0
        public override bool compute(MPlug plug, MDataBlock dataBlock)
        //
        //	Descriptions:
        //		compute output force.
        //
        {
            if (plug.notEqual(mOutputForce))
            {
                return(false);
            }

            // get the logical index of the element this plug refers to.
            //
            uint multiIndex = plug.logicalIndex;

            // Get input data handle, use outputArrayValue since we do not
            // want to evaluate both inputs, only the one related to the
            // requested multiIndex. Evaluating both inputs at once would cause
            // a dependency graph loop.

            MArrayDataHandle hInputArray = dataBlock.outputArrayValue(mInputData);

            hInputArray.jumpToElement(multiIndex);

            // get children of aInputData.

            MDataHandle hCompond = hInputArray.inputValue();

            MDataHandle        hPosition  = hCompond.child(mInputPositions);
            MObject            dPosition  = hPosition.data();
            MFnVectorArrayData fnPosition = new MFnVectorArrayData(dPosition);
            MVectorArray       points     = fnPosition.array();

            // The attribute mInputPPData contains the attribute in an array form
            // prepared by the particleShape if the particleShape has per particle
            // attribute fieldName_attrName.
            //
            // Suppose a field with the name dynExprField1 is connecting to
            // particleShape1, and the particleShape1 has per particle float attribute
            // dynExprField1_magnitude and vector attribute dynExprField1_direction,
            // then hInputPPArray will contains a MdoubleArray with the corresponding
            // name "magnitude" and a MvectorArray with the name "direction".  This
            // is a mechanism to allow the field attributes being driven by dynamic
            // expression.
            MArrayDataHandle mhInputPPData = dataBlock.inputArrayValue(mInputPPData);

            mhInputPPData.jumpToElement(multiIndex);

            MDataHandle       hInputPPData = mhInputPPData.inputValue();
            MObject           dInputPPData = hInputPPData.data();
            MFnArrayAttrsData inputPPArray = new MFnArrayAttrsData(dInputPPData);

            MDataHandle       hOwnerPPData = dataBlock.inputValue(mOwnerPPData);
            MObject           dOwnerPPData = hOwnerPPData.data();
            MFnArrayAttrsData ownerPPArray = new MFnArrayAttrsData(dOwnerPPData);

            string magString = "magnitude";

            MFnArrayAttrsData.Type doubleType = MFnArrayAttrsData.Type.kDoubleArray;

            bool         arrayExist;
            MDoubleArray magnitudeArray;

            arrayExist = inputPPArray.checkArrayExist(magString, out doubleType);
            if (arrayExist)
            {
                magnitudeArray = inputPPArray.getDoubleData(magString);
            }
            else
            {
                magnitudeArray = new MDoubleArray();
            }

            MDoubleArray magnitudeOwnerArray;

            arrayExist = ownerPPArray.checkArrayExist(magString, out doubleType);
            if (arrayExist)
            {
                magnitudeOwnerArray = ownerPPArray.getDoubleData(magString);
            }
            else
            {
                magnitudeOwnerArray = new MDoubleArray();
            }

            string dirString = "direction";

            MFnArrayAttrsData.Type vectorType = MFnArrayAttrsData.Type.kVectorArray;
            MVectorArray           directionArray;

            arrayExist = inputPPArray.checkArrayExist(dirString, out vectorType);
            if (arrayExist)
            {
                directionArray = inputPPArray.getVectorData(dirString);
            }
            else
            {
                directionArray = new MVectorArray();
            }

            MVectorArray directionOwnerArray;

            arrayExist = ownerPPArray.checkArrayExist(dirString, out vectorType);
            if (arrayExist)
            {
                directionOwnerArray = ownerPPArray.getVectorData(dirString);
            }
            else
            {
                directionOwnerArray = new MVectorArray();
            }

            // Compute the output force.
            //
            MVectorArray forceArray = new MVectorArray();

            apply(dataBlock, points.length, magnitudeArray, magnitudeOwnerArray,
                  directionArray, directionOwnerArray, forceArray);

            // get output data handle
            //
            MArrayDataHandle  hOutArray = dataBlock.outputArrayValue(mOutputForce);
            MArrayDataBuilder bOutArray = hOutArray.builder();

            // get output force array from block.
            //
            MDataHandle        hOut          = bOutArray.addElement(multiIndex);
            MFnVectorArrayData fnOutputForce = new MFnVectorArrayData();
            MObject            dOutputForce  = fnOutputForce.create(forceArray);

            // update data block with new output force data.
            //
            hOut.set(dOutputForce);
            dataBlock.setClean(plug);

            return(true);
        }
 public override bool setInternalValueInContext(MPlug plug, MDataHandle dataHandle, MDGContext ctx)
 {
     MGlobal.displayInfo("testHLSLShader::setInternalValueInContext");
     return base.setInternalValueInContext(plug, dataHandle, ctx);
 }
Beispiel #26
0
        public override void doIt(MArgList args /*, MPxCommandClass cmd*/)
        {
            // This method is called from script when this command is called.
            // It should set up any class data necessary for redo/undo,
            // parse any given arguments, and then call redoIt.
            MArgDatabase argData = new MArgDatabase(/*cmd.*/ syntax, args);

            __isIndex = argData.isFlagSet(kIndexFlag);

            // Get the plug specified on the command line.
            MSelectionList slist = argData.SelectionObjects;

            if (slist.length == 0)
            {
                throw new ArgumentException("Must specify an array plug in the form <nodeName>.<multiPlugName>.", "args");
            }
            __fPlug = slist.getPlug(0);
            if (__fPlug == null)
            {
                throw new ArgumentException("Must specify an array plug in the form <nodeName>.<multiPlugName>.", "args");
            }

            // Construct a data handle containing the data stored in the plug.
            MDataHandle dh = new MDataHandle();

            try {
                __fPlug.getValue(dh);
            } catch (Exception) {
                throw new ApplicationException("Could not get the plug value.");
            }

            MArrayDataHandle adh;
            uint             indx = 0;

            try {
                adh = new MArrayDataHandle(dh);
            } catch (Exception) {
                __fPlug.destructHandle(dh);
                throw new ApplicationException("Could not create the array data handle.");
            }

            // Iterate over the values in the multiPlug.  If the index flag has been used, just return
            // the logical indices of the child plugs.  Otherwise, return the plug values.
            string errorMsg = null;

            for (uint i = 0; i < adh.elementCount(); i++, adh.next())
            {
                try {
                    indx = adh.elementIndex();
                } catch (Exception) {
                    continue;
                }
                if (__isIndex)
                {
                    appendToResult((int)indx);
                }
                else
                {
                    MDataHandle h = adh.outputValue();
                    if (h.isNumeric)
                    {
                        switch (h.numericType)
                        {
                        case MFnNumericData.Type.kBoolean: appendToResult(h.asBool); break;

                        case MFnNumericData.Type.kShort: appendToResult(h.asShort); break;

                        case MFnNumericData.Type.kInt: appendToResult(h.asInt); break;

                        case MFnNumericData.Type.kFloat: appendToResult(h.asFloat); break;

                        case MFnNumericData.Type.kDouble: appendToResult(h.asDouble); break;

                        default:
                            errorMsg = string.Format("{0}This sample command only supports boolean, integer, and floating point values. Not {1}.\n",
                                                     errorMsg != null ? errorMsg : "", h.numericType.ToString());

                            break;
                        }
                    }
                }
            }
            __fPlug.destructHandle(dh);

            if (errorMsg != null)
            {
                throw new ApplicationException(errorMsg);
            }
            ;

            return;
        }
 public override bool setInternalValueInContext(MPlug plug, MDataHandle dataHandle, MDGContext ctx)
 {
     MGlobal.displayInfo("testHLSLShader::setInternalValueInContext");
     return(base.setInternalValueInContext(plug, dataHandle, ctx));
 }
Beispiel #28
0
        //
        // Description
        //
        //     This function takes an input surface of type kMeshData and converts
        //     the geometry into this nodes attributes.
        //     Returns false if nothing is connected.
        //
        public bool computeInputMesh(MPlug plug,
                                     MDataBlock datablock,
                                     MPointArray vertices,
                                     MIntArray counts,
                                     MIntArray connects,
                                     MVectorArray normals,
                                     apiMeshGeomUV uvs)
        {
            // Get the input subdiv
            //
            MDataHandle inputData = datablock.inputValue(inputMesh);
            MObject     surf      = inputData.asMesh;

            // Check if anything is connected
            //
            MObject thisObj  = thisMObject();
            MPlug   surfPlug = new MPlug(thisObj, inputMesh);

            if (!surfPlug.isConnected)
            {
                datablock.setClean(plug);
                return(false);
            }

            // Extract the mesh data
            //
            MFnMesh surfFn = new MFnMesh(surf);

            surfFn.getPoints(vertices, MSpace.Space.kObject);

            // Check to see if we have UVs to copy.
            //
            bool hasUVs = surfFn.numUVsProperty > 0;

            surfFn.getUVs(uvs.ucoord, uvs.vcoord);

            for (int i = 0; i < surfFn.numPolygons; i++)
            {
                MIntArray polyVerts = new MIntArray();
                surfFn.getPolygonVertices(i, polyVerts);
                int pvc = (int)polyVerts.length;
                counts.append(pvc);
                int uvId;
                for (int v = 0; v < pvc; v++)
                {
                    if (hasUVs)
                    {
                        surfFn.getPolygonUVid(i, v, out uvId);
                        uvs.faceVertexIndex.append(uvId);
                    }
                    connects.append(polyVerts[v]);
                }
            }

            for (int n = 0; n < (int)vertices.length; n++)
            {
                MVector normal = new MVector();
                surfFn.getVertexNormal(n, normal);
                normals.append(normal);
            }

            return(true);
        }
Beispiel #29
0
        public override bool setInternalValue(MPlug plug, MDataHandle handle)
        {
            bool isOk = true;

            if( plug.attribute.equalEqual(mControlPoints) ||
                plug.attribute.equalEqual(mControlValueX) ||
                plug.attribute.equalEqual(mControlValueY) ||
                plug.attribute.equalEqual(mControlValueZ) )
            {
                // If there is input history then set the control points value
                // using the normal mechanism. In this case we are setting
                // the tweak or offset that will get applied to the input
                // history.
                //
                // If there is no input history then ignore the controlPoints
                // attribute and set the vertex position directly in the
                // cachedMesh.
                //
                if ( hasHistory() ) {
                    verticesUpdated();
                    return base.setInternalValue( plug, handle );
                }
                else {
                    if( plug.attribute.equalEqual(mControlPoints) && !plug.isArray) {
                        int index = (int)plug.logicalIndex;
                        MPoint point = new MPoint();
                        double[] ptData = handle.Double3;
                        point.x = ptData[0];
                        point.y = ptData[1];
                        point.z = ptData[2];
                        setValue( index, point );
                    }
                    else if( plug.attribute.equalEqual(mControlValueX) ) {
                        MPlug parentPlug = plug.parent;
                        int index = (int)parentPlug.logicalIndex;
                        setValue( index, 0, handle.asDouble );
                    }
                    else if( plug.attribute.equalEqual(mControlValueY) ) {
                        MPlug parentPlug = plug.parent;
                        int index = (int)parentPlug.logicalIndex;
                        setValue( index, 1, handle.asDouble );
                    }
                    else if( plug.attribute.equalEqual(mControlValueZ) ) {
                        MPlug parentPlug = plug.parent;
                        int index = (int)parentPlug.logicalIndex;
                        setValue( index, 2, handle.asDouble );
                    }
                }
            }
            // This inherited attribute is used to specify whether or
            // not this shape has history. During a file read, the shape
            // is created before any input history can get connected.
            // This attribute, also called "tweaks", provides a way to
            // for the shape to determine if there is input history
            // during file reads.
            //
            else if ( plug.attribute.equalEqual(mHasHistoryOnCreate) ) {
                fHasHistoryOnCreate = handle.asBool;
            }
            else {
                isOk = base.setInternalValue( plug, handle );
            }

            return isOk;
        }
Beispiel #30
0
		public override void doIt(MArgList args/*, MPxCommandClass cmd*/)
		{
			// This method is called from script when this command is called.
			// It should set up any class data necessary for redo/undo,
			// parse any given arguments, and then call redoIt.
			MArgDatabase argData = new MArgDatabase(/*cmd.*/syntax, args);

            __isIndex = argData.isFlagSet(kIndexFlag);

			// Get the plug specified on the command line.
			MSelectionList slist = argData.SelectionObjects;
			if ( slist.length == 0 ) {
				throw new ArgumentException("Must specify an array plug in the form <nodeName>.<multiPlugName>.", "args");
			}
			__fPlug = slist.getPlug (0) ;
			if ( __fPlug == null ) {
				throw new ArgumentException("Must specify an array plug in the form <nodeName>.<multiPlugName>.", "args");
			}

			// Construct a data handle containing the data stored in the plug.
			MDataHandle dh = new MDataHandle() ;

            try {
                __fPlug.getValue(dh);
            } catch (Exception) {
                throw new ApplicationException("Could not get the plug value.");
            }

			MArrayDataHandle adh ;
			uint indx =0 ;
			try {
				adh = new MArrayDataHandle(dh);
			} catch (Exception) {
				__fPlug.destructHandle(dh) ;
				throw new ApplicationException("Could not create the array data handle.");
			}

			// Iterate over the values in the multiPlug.  If the index flag has been used, just return
			// the logical indices of the child plugs.  Otherwise, return the plug values.
            string errorMsg = null;
            for (uint i = 0; i < adh.elementCount(); i++, adh.next())
            {
				try {
					indx = adh.elementIndex() ;
				} catch (Exception) {
					continue ;
				}
				if ( __isIndex ) {
					appendToResult ((int)indx) ;
				} else {
					MDataHandle h = adh.outputValue () ;
					if (h.isNumeric)
					{
						switch (h.numericType)
						{
							case MFnNumericData.Type.kBoolean: appendToResult (h.asBool) ; break;
							case MFnNumericData.Type.kShort: appendToResult (h.asShort) ; break;
							case MFnNumericData.Type.kInt: appendToResult (h.asInt) ; break;
							case MFnNumericData.Type.kFloat: appendToResult (h.asFloat) ; break;
							case MFnNumericData.Type.kDouble: appendToResult (h.asDouble) ; break;
							default:
                                errorMsg = string.Format("{0}This sample command only supports boolean, integer, and floating point values. Not {1}.\n",
                                    errorMsg != null ? errorMsg : "", h.numericType.ToString());

								break;
						}
					}
				}
			}
			__fPlug.destructHandle (dh) ;

            if (errorMsg != null)
                throw new ApplicationException(errorMsg); ;

			return;
		}
Beispiel #31
0
        //
        // Description
        //
        //    Handle internal attributes.
        //
        //    Attributes that require special storage, bounds checking,
        //    or other non-standard behavior can be marked as "Internal" by
        //    using the "MFnAttribute.setInternal" method.
        //
        //    The get/setInternalValue methods will get called for internal
        //    attributes whenever the attribute values are stored or retrieved
        //    using getAttr/setAttr or MPlug getValue/setValue.
        //
        //    The inherited attribute mControlPoints is internal and we want
        //    its values to get stored only if there is input history. Otherwise
        //    any changes to the vertices are stored in the cachedMesh and outputMesh
        //    directly.
        //
        //    If values are retrieved then we want the controlPoints value
        //    returned if there is history, this will be the offset or tweak.
        //    In the case of no history, the vertex position of the cached mesh
        //    is returned.
        //
        public override bool getInternalValue(MPlug plug, MDataHandle result)
        {
            bool isOk = true;

            if( plug.attribute.equalEqual(mControlPoints) ||
                plug.attribute.equalEqual(mControlValueX) ||
                plug.attribute.equalEqual(mControlValueY) ||
                plug.attribute.equalEqual(mControlValueZ) )
            {
                // If there is input history then the control point value is
                // directly returned. This is the tweak or offset that
                // was applied to the vertex.
                //
                // If there is no input history then return the actual vertex
                // position and ignore the controlPoints attribute.
                //
                if ( hasHistory() ) {
                    return base.getInternalValue( plug, result );
                }
                else {
                    double val = 0.0;
                    if ( plug.attribute.equalEqual(mControlPoints) && !plug.isArray ) {
                        MPoint pnt = new MPoint();
                        int index = (int)plug.logicalIndex;
                        value( index, ref pnt );
                        result.set( pnt[0], pnt[1], pnt[2] );
                    }
                    else if ( plug.attribute.equalEqual(mControlValueX) ) {
                        MPlug parentPlug = plug.parent;
                        int index = (int)parentPlug.logicalIndex;
                        value( index, 0, ref val );
                        result.set( val );
                    }
                    else if ( plug.attribute.equalEqual(mControlValueY) ) {
                        MPlug parentPlug = plug.parent;
                        int index = (int)parentPlug.logicalIndex;
                        value( index, 1, ref val );
                        result.set( val );
                    }
                    else if ( plug.attribute.equalEqual(mControlValueZ) ) {
                        MPlug parentPlug = plug.parent;
                        int index = (int)parentPlug.logicalIndex;
                        value( index, 2, ref val );
                        result.set( val );
                    }
                }
            }
            // This inherited attribute is used to specify whether or
            // not this shape has history. During a file read, the shape
            // is created before any input history can get connected.
            // This attribute, also called "tweaks", provides a way to
            // for the shape to determine if there is input history
            // during file reads.
            //
            else if ( plug.attribute.equalEqual(mHasHistoryOnCreate) ) {
                result.set( fHasHistoryOnCreate );
            }
            else {
                isOk = base.getInternalValue( plug, result );
            }

            return isOk;
        }
        //
        //	Calls applyRotationLocks && applyRotationLimits
        //	This method verifies that the passed value can be set on the
        //	rotate plugs. In the base class, limits as well as locking are
        //	checked by this method.
        //
        //	The compute, validateAndSetValue, and rotateTo functions
        //	all use this method.
        //
        protected override void checkAndSetRotation(MDataBlock block, MPlug plug, MEulerRotation newRotation, MSpace.Space space)
        {
            MDGContext context = block.context;

            updateMatrixAttrs(context);

            MEulerRotation outRotation = newRotation;

            if (context.isNormal)
            {
                //	For easy reading.
                //
                MPxTransformationMatrix xformMat = baseTransformationMatrix;

                //	Get the current translation in transform space for
                //	clamping and locking.
                //
                MEulerRotation savedRotation =
                    xformMat.eulerRotation(MSpace.Space.kTransform);

                //	Translate to transform space, since the limit test needs the
                //	values in transform space. The locking test needs the values
                //	in the same space as the savedR value - which is transform
                //	space as well.
                //
                baseTransformationMatrix.rotateTo(newRotation, space);

                outRotation = xformMat.eulerRotation(MSpace.Space.kTransform);

                //	Now that everything is in the same space, apply limits
                //	and change the value to adhere to plug locking.
                //
                outRotation = applyRotationLimits(outRotation, block);
                outRotation = applyRotationLocks(outRotation, savedRotation);

                //	The value that remain is in transform space.
                //
                xformMat.rotateTo(outRotation, MSpace.Space.kTransform);

                //	Get the value that was just set. It needs to be in transform
                //	space since it is used to set the datablock values at the
                //	end of this method. Getting the vaolue right before setting
                //	ensures that the transformation matrix and data block will
                //	be synchronized.
                //
                outRotation = xformMat.eulerRotation(MSpace.Space.kTransform);
            }
            else
            {
                //	Get the rotation for clamping and locking. This will get the
                //	rotate value in transform space.
                //
                double[]       s3            = block.inputValue(rotate).Double3;
                MEulerRotation savedRotation = new MEulerRotation(s3[0], s3[1], s3[2]);

                //	Create a local transformation matrix for non-normal context
                //	calculations.
                //
                MPxTransformationMatrix local = createTransformationMatrix();
                if (null == local)
                {
                    throw new InvalidOperationException("rockingTransformCheck::checkAndSetRotation internal error");
                }

                //	Fill the newly created transformation matrix.
                //
                computeLocalTransformation(local, block);

                //	Translate the values to transform space. This will allow the
                //	limit and locking tests to work properly.
                //
                local.rotateTo(newRotation, space);

                outRotation = local.eulerRotation(MSpace.Space.kTransform);

                //	Apply limits
                //
                outRotation = applyRotationLimits(outRotation, block);

                outRotation = applyRotationLocks(outRotation, savedRotation);

                local.rotateTo(outRotation, MSpace.Space.kTransform);

                //	Get the rotate value in transform space for placement in the
                //	data block.
                //
                outRotation = local.eulerRotation(MSpace.Space.kTransform);

                local.Dispose();
            }

            MDataHandle handle = block.outputValue(plug);

            if (plug.equalEqual(rotate))
            {
                handle.set(outRotation.x, outRotation.y, outRotation.z);
            }
            else if (plug.equalEqual(rotateX))
            {
                handle.set(outRotation.x);
            }
            else if (plug.equalEqual(rotateY))
            {
                handle.set(outRotation.y);
            }
            else
            {
                handle.set(outRotation.z);
            }

            return;
        }