예제 #1
0
        private float getMultiplier(MDagPath objPath)
        {
            // Retrieve value of the size attribute from the node
            MObject footprintNode = objPath.node;

            if (!footprintNode.isNull)
            {
                MPlug plug = new MPlug(footprintNode, footPrint.size);
                if (!plug.isNull)
                {
                    MDistance sizeVal = new MDistance();
                    try
                    {
                        plug.getValue(sizeVal);
                        return((float)sizeVal.asCentimeters);
                    }
                    catch (Exception)
                    {
                        MGlobal.displayInfo("Error doing getValue on plugin");
                    }
                }
            }

            return(1.0f);
        }
예제 #2
0
        double twistFromHandle(MDagPath handlePath)
        // This method returns the twist of the IK handle.
        //
        {
            MFnIkHandle handleFn   = new MFnIkHandle(handlePath);
            MPlug       twistPlug  = handleFn.findPlug("twist");
            double      twistValue = 0.0;

            twistPlug.getValue(twistValue);
            return(twistValue);
        }
예제 #3
0
        public quadricGeom geometry()
        {
            MObject this_object = thisMObject();
            MPlug   plug        = new MPlug(this_object, radius1);

            plug.getValue(ref fGeometry.radius1);
            plug.attribute = radius2;     plug.getValue(ref fGeometry.radius2);
            plug.attribute = height; plug.getValue(ref fGeometry.height);
            plug.attribute = startAngle; plug.getValue(ref fGeometry.startAngle);
            plug.attribute = sweepAngle; plug.getValue(ref fGeometry.sweepAngle);
            plug.attribute = slices; plug.getValue(ref fGeometry.slices);
            plug.attribute = loops; plug.getValue(ref fGeometry.loops);
            plug.attribute = stacks; plug.getValue(ref fGeometry.stacks);
            plug.attribute = shapeType; plug.getValue(ref fGeometry.shapeType);

            return(fGeometry);
        }
예제 #4
0
        AwVector poleVectorFromHandle(MDagPath handlePath)
        {
            MFnIkHandle handleFn = new MFnIkHandle(handlePath);
            MPlug       pvxPlug = handleFn.findPlug("pvx");
            MPlug       pvyPlug = handleFn.findPlug("pvy");
            MPlug       pvzPlug = handleFn.findPlug("pvz");
            double      pvxValue, pvyValue, pvzValue;

            pvxValue = pvyValue = pvzValue = 0;
            pvxPlug.getValue(pvxValue);
            pvyPlug.getValue(pvyValue);
            pvzPlug.getValue(pvzValue);
            AwVector poleVector = new AwVector(pvxValue, pvyValue, pvzValue);

            return(poleVector);
        }
예제 #5
0
        public Point3DCollection receiveVertexPositionsFromMaya(string node_name)
        {
            MPlug   plLocal  = getPlug(node_name, "outMesh");
            MObject oOutMesh = new MObject();

            plLocal.getValue(oOutMesh);
            MFnMesh     m           = new MFnMesh(oOutMesh);
            MPointArray p_aVertices = new MPointArray();

            m.getPoints(p_aVertices, MSpace.Space.kWorld);
            Point3DCollection vertices = new Point3DCollection();

            foreach (MPoint p in p_aVertices)
            {
                vertices.Add(new Point3D(p.x, p.y, p.z));
            }
            return(vertices);
        }
예제 #6
0
        public override MBoundingBox boundingBox()
        {
            // Get the size
            //
            MObject thisNode = thisMObject();
            MPlug plug = new MPlug( thisNode, size );
            MDistance sizeVal = new MDistance();
            plug.getValue( sizeVal );

            double multiplier = sizeVal.asCentimeters;

            MPoint corner1 = new MPoint( -0.17, 0.0, -0.7 );
            MPoint corner2 = new MPoint( 0.17, 0.0, 0.3 );

            corner1 = corner1 * multiplier;
            corner2 = corner2 * multiplier;

            return new MBoundingBox( corner1, corner2 );
        }
예제 #7
0
        public override MBoundingBox boundingBox()
        {
            // Get the size
            //
            MObject   thisNode = thisMObject();
            MPlug     plug     = new MPlug(thisNode, size);
            MDistance sizeVal  = new MDistance();

            plug.getValue(sizeVal);

            double multiplier = sizeVal.asCentimeters;

            MPoint corner1 = new MPoint(-0.17, 0.0, -0.7);
            MPoint corner2 = new MPoint(0.17, 0.0, 0.3);

            corner1 = corner1 * multiplier;
            corner2 = corner2 * multiplier;

            return(new MBoundingBox(corner1, corner2));
        }
예제 #8
0
		public override void loadImageMap(string fileName, int frame, MImage image)
		{
			image.readFromFile(fileName);

			uint width;
			uint height;
			image.getSize(out width, out height);
			uint size = width * height;

			blendPixel(image, size);

			MPlug depthMap = new MPlug(thisMObject(), useDepthMap);
			bool value = false;
			depthMap.getValue(ref value);

			if (value)
			{
				setDepthMap(image, width, height);
			}
			return;
		}
예제 #9
0
        public void receiveCurveFromMaya(string node_name, out Point3DCollection controlVertices, out List <double> weights, out List <double> knots, out int degree, out bool closed, out bool rational)
        {
            MPlug   plLocal = getPlug(node_name, "local");
            MObject oLocal  = new MObject();

            plLocal.getValue(oLocal);

            MFnNurbsCurve nc = new MFnNurbsCurve(oLocal);

            MPointArray p_aCVs = new MPointArray();

            nc.getCVs(p_aCVs, MSpace.Space.kWorld);
            controlVertices = new Point3DCollection();
            weights         = new List <double>();
            foreach (MPoint p in p_aCVs)
            {
                controlVertices.Add(new Point3D(p.x, p.y, p.z));
                weights.Add(1.0);
            }

            double min = 0, max = 0;

            nc.getKnotDomain(ref min, ref max);
            MDoubleArray d_aKnots = new MDoubleArray();

            nc.getKnots(d_aKnots);

            knots = new List <double>();
            knots.Add(min);
            foreach (double d in d_aKnots)
            {
                knots.Add(d);
            }
            knots.Add(max);

            degree   = nc.degree;
            closed   = nc.form == MFnNurbsCurve.Form.kClosed ? true : false;
            rational = true;
        }
예제 #10
0
        private void dumpInfo(MObject fileNode, MFnDependencyNode nodeFn, MObjectArray nodePath)
        {
            MObject           fileAttr   = nodeFn.attribute("fileTextureName");
            MPlug             plugToFile = new MPlug(fileNode, fileAttr);
            MFnDependencyNode dgFn       = new MFnDependencyNode();

            MGlobal.displayInfo("Name:    " + nodeFn.name);

            MObject fnameValue = new MObject();

            try
            {
                plugToFile.getValue(fnameValue);
            }
            catch (Exception)
            {
                MGlobal.displayInfo("error getting value from plug");
                return;
            }

            MFnStringData stringFn = new MFnStringData(fnameValue);

            MGlobal.displayInfo("Texture: " + stringFn.stringProperty);

            string path = "Path:    ";

            for (int i = (int)nodePath.length - 1; i >= 0; i--)
            {
                MObject currentNode = nodePath[i];
                dgFn.setObject(currentNode);

                path += dgFn.name + "(" + dgFn.typeName + ")";
                if (i > 0)
                {
                    path += " -> ";
                }
            }
            MGlobal.displayInfo(path);
        }
예제 #11
0
        public override void loadImageMap(string fileName, int frame, MImage image)
        {
            image.readFromFile(fileName);

            uint width;
            uint height;

            image.getSize(out width, out height);
            uint size = width * height;

            blendPixel(image, size);

            MPlug depthMap = new MPlug(thisMObject(), useDepthMap);
            bool  value    = false;

            depthMap.getValue(ref value);

            if (value)
            {
                setDepthMap(image, width, height);
            }
            return;
        }
예제 #12
0
        public quadricGeom geometry()
        {
            MObject this_object = thisMObject();
            MPlug plug = new MPlug(this_object, radius1);
            plug.getValue(ref fGeometry.radius1);
            plug.attribute=radius2;     plug.getValue(ref fGeometry.radius2);
            plug.attribute = height; plug.getValue(ref fGeometry.height);
            plug.attribute = startAngle; plug.getValue(ref fGeometry.startAngle);
            plug.attribute = sweepAngle; plug.getValue(ref fGeometry.sweepAngle);
            plug.attribute = slices; plug.getValue(ref fGeometry.slices);
            plug.attribute = loops; plug.getValue(ref fGeometry.loops);
            plug.attribute = stacks; plug.getValue(ref fGeometry.stacks);
            plug.attribute = shapeType; plug.getValue(ref fGeometry.shapeType);

            return fGeometry;
        }
예제 #13
0
		private void dumpInfo(MObject fileNode, MFnDependencyNode nodeFn, MObjectArray nodePath)
		{
			MObject fileAttr = nodeFn.attribute("fileTextureName");
			MPlug plugToFile = new MPlug(fileNode, fileAttr);
			MFnDependencyNode dgFn = new MFnDependencyNode();

			MGlobal.displayInfo("Name:    " + nodeFn.name);

			MObject fnameValue = new MObject();
			try
			{
				plugToFile.getValue(fnameValue);
			}
			catch (Exception)
			{
				MGlobal.displayInfo("error getting value from plug");
				return;
			}

			MFnStringData stringFn = new MFnStringData(fnameValue);
			MGlobal.displayInfo("Texture: " + stringFn.stringProperty);

			string path = "Path:    ";
			for (int i = (int)nodePath.length - 1; i >= 0; i--)
			{
				MObject currentNode = nodePath[i];
				dgFn.setObject(currentNode);

				path += dgFn.name + "(" + dgFn.typeName + ")";
				if (i > 0) path += " -> ";
			}
			MGlobal.displayInfo(path);
		}
예제 #14
0
		public override bool shouldSave(MPlug plug, ref bool result)
		//
		// Description
		//
		//    During file save this method is called to determine which
		//    attributes of this node should get written. The default behavior
		//    is to only save attributes whose values differ from the default.
		//
		//
		//
		{
			if( plug.attribute.equalEqual(mControlPoints) ||
				plug.attribute.equalEqual(mControlValueX) ||
				plug.attribute.equalEqual(mControlValueY) ||
				plug.attribute.equalEqual(mControlValueZ) )
			{
				if( hasHistory() ) {
					// Calling this will only write tweaks if they are
					// different than the default value.
					//
					return base.shouldSave( plug, ref result );
				}
				else {
					result = false;
				}
			}
			else if ( plug.attribute.equalEqual(cachedSurface) ) {
				if ( hasHistory() ) {
					result = false;
				}
				else {
					MObject data = new MObject();
					plug.getValue( data );
					result = ( ! data.isNull );
				}
			}
			else {
				return base.shouldSave( plug, ref result );
			}

			return true;
		}
예제 #15
0
		public override MBoundingBox boundingBox()
		//
		// Description
		//
		//    Returns the bounding box for this object.
		//    It is a good idea not to recompute here as this funcion is called often.
		//
		{
			MObject thisNode = thisMObject();
			MPlug c1Plug = new MPlug( thisNode, bboxCorner1 );
			MPlug c2Plug = new MPlug( thisNode, bboxCorner2 );
			MObject corner1Object = new MObject();
			MObject corner2Object = new MObject();
			c1Plug.getValue( corner1Object );
			c2Plug.getValue( corner2Object );

			double[] corner1 = new double[3];
			double[] corner2 = new double[3];

			MFnNumericData fnData = new MFnNumericData();
			fnData.setObject( corner1Object );
			fnData.getData(out corner1[0], out corner1[1], out corner1[2]);
			fnData.setObject( corner2Object );
			fnData.getData(out corner2[0], out corner2[1], out corner2[2]);

			MPoint corner1Point = new MPoint( corner1[0], corner1[1], corner1[2] );
			MPoint corner2Point = new MPoint( corner2[0], corner2[1], corner2[2] );

			return new MBoundingBox( corner1Point, corner2Point );
		}
예제 #16
0
        public override void redoIt()
        {
            MObject  dependNode   = new MObject();
            MOStream stdoutstream = MStreamUtils.stdOutStream();

            for (; !iter.isDone; iter.next())
            {
                // Get the selected dependency node and create
                // a function set for it
                //
                try
                {
                    iter.getDependNode(dependNode);
                }
                catch (System.Exception)
                {
                    MStreamUtils.writeCharBuffer(MStreamUtils.stdErrorStream(), "Error getting the dependency node");
                    continue;
                }

                MFnDependencyNode fnDN;
                try
                {
                    fnDN = new MFnDependencyNode(dependNode);
                }
                catch (System.Exception)
                {
                    MStreamUtils.writeCharBuffer(MStreamUtils.stdErrorStream(), "Error creating MFnDependencyNode");
                    continue;
                }

                MFnTypedAttribute fnAttr  = new MFnTypedAttribute();
                MObject           newAttr = fnAttr.create("blindDoubleData", "BDD", blindDoubleData.tid);

                try
                {
                    fnDN.addAttribute(newAttr, MFnDependencyNode.MAttrClass.kLocalDynamicAttr);
                }
                catch (System.Exception)
                {
                    // do nothing
                    // addAttribute only need call once, the redundant calls will return false (throw exception)
                }

                // Create a plug to set and retrieve value off the node.
                //
                MPlug plug = new MPlug(dependNode, newAttr);


                // ----------------------------------- Attention ------------------------------------
                // --------------------------------- Downcast Begin -----------------------------------
                // the following codes are used to get the c# object
                //
                MFnPluginData pdFnCreator = new MFnPluginData();

                // 1. you cannot gain blindDoubleData by the following code
                //    {code}
                //          blindDoubleData newData = new blindDoubleData()
                //    {code}
                //    As we need to keep the relationship between c# impl and c++ instance pointer
                //    We cannot use the above ctor codes, otherwise, the mandatory information used for down casting is omitted

                // 2. you cannot use the tempData gained by the following code
                //    {code}
                //          MObject tempData = pdFnCreator.create(blindDoubleData.tid);
                //    {code}
                //    reason:
                //          tempData is useless, we cannot use tempData to do downcast
                //          the create function gains the tempData by the following code
                //
                //          {code}
                //              newHandle = new MObject(mayaHandle);
                //          {code}
                //
                //     the mayaHandle is the actual pointer, which we store. But we have no information about the newHandle

                // the return object is useless. the data we needed is stored in pdFnCreator
                pdFnCreator.create(blindDoubleData.tid);

                // 3. get "the data" we needed
                blindDoubleData newData = pdFnCreator.data() as blindDoubleData;
                // ---------------------------------- Downcast End -----------------------------------
                if (newData == null)
                {
                    continue;
                }

                newData.value = 3.2;

                plug.setValue(newData);

                // Now try to retrieve the value of the plug as an MObject.
                //
                MObject sData = new MObject();

                try
                {
                    plug.getValue(sData);
                }
                catch (System.Exception)
                {
                    continue;
                }

                // Convert the data back to MPxData.
                //
                MFnPluginData pdFn = new MFnPluginData(sData);

                blindDoubleData data = pdFn.data() as blindDoubleData;

                // Get the value.
                //
                if (null == data)
                {
                    // error
                    MStreamUtils.writeCharBuffer(MStreamUtils.stdErrorStream(), "error: failed to retrieve data.");
                }
                MStreamUtils.writeLine(stdoutstream);
                MStreamUtils.writeCharBuffer(stdoutstream, ">>>>>>>>>>>>>>>>>>>>>>>> blindDoubleData binary >>>>>>>>>>>>>>>>>>>>");
                MStreamUtils.writeLine(stdoutstream);
                data.writeBinary(stdoutstream);
                MStreamUtils.writeLine(stdoutstream);
                MStreamUtils.writeCharBuffer(stdoutstream, ">>>>>>>>>>>>>>>>>>>>>>>> blindDoubleData ascii >>>>>>>>>>>>>>>>>>>>");
                MStreamUtils.writeLine(stdoutstream);
                data.writeASCII(stdoutstream);
            }
            return;
        }
예제 #17
0
        private float getMultiplier(MDagPath objPath)
        {
            // Retrieve value of the size attribute from the node
            MObject footprintNode = objPath.node;
            if (!footprintNode.isNull)
            {
                MPlug plug = new MPlug(footprintNode, footPrint.size);
                if (!plug.isNull)
                {
                    MDistance sizeVal = new MDistance();
                    try
                    {
                        plug.getValue(sizeVal);
                        return (float)sizeVal.asCentimeters;
                    }
                    catch (Exception)
                    {
                        MGlobal.displayInfo("Error doing getValue on plugin");
                    }
                }
            }

            return 1.0f;
        }
예제 #18
0
        //
        // Description
        //
        //    During file save this method is called to determine which
        //    attributes of this node should get written. The default behavior
        //    is to only save attributes whose values differ from the default.
        //
        //
        //
        public override bool shouldSave(MPlug plug, ref bool result)
        {
            if( plug.attribute.equalEqual(mControlPoints) ||
                plug.attribute.equalEqual(mControlValueX) ||
                plug.attribute.equalEqual(mControlValueY) ||
                plug.attribute.equalEqual(mControlValueZ) )
            {
                if( hasHistory() ) {
                    // Calling this will only write tweaks if they are
                    // different than the default value.
                    //
                    return base.shouldSave( plug, ref result );
                }
                else {
                    result = false;
                }
            }
            else if ( plug.attribute.equalEqual(cachedSurface) ) {
                if ( hasHistory() ) {
                    result = false;
                }
                else {
                    MObject data = new MObject();
                    plug.getValue( data );
                    result = ( ! data.isNull );
                }
            }
            else {
                return base.shouldSave( plug, ref result );
            }

            return true;
        }
예제 #19
0
        public override void draw(Autodesk.Maya.OpenMayaUI.M3dView view, MDagPath path, Autodesk.Maya.OpenMayaUI.M3dView.DisplayStyle style, Autodesk.Maya.OpenMayaUI.M3dView.DisplayStatus status)
        {
            // Get the size
            //
            MObject thisNode = thisMObject();
            MPlug plug = new MPlug( thisNode, size );
            MDistance sizeVal = new MDistance();
            plug.getValue( sizeVal );

            float multiplier = (float) sizeVal.asCentimeters;

            view.beginGL();

            if ( ( style == M3dView.DisplayStyle.kFlatShaded ) ||
                 ( style == M3dView.DisplayStyle.kGouraudShaded ) )
            {
                // Push the color settings
                //
                OpenGL.glPushAttrib( (uint)OpenGL.GL_CURRENT_BIT );

                if ( status == M3dView.DisplayStatus.kActive ) {
                    view.setDrawColor( 13, (int)M3dView.ColorTable.kActiveColors );
                } else {
                    view.setDrawColor(13, (int)M3dView.ColorTable.kDormantColors);
                }

                OpenGL.glBegin((uint)OpenGL.GL_TRIANGLE_FAN);
                    int i;
                    int last = footPrintData.soleCount - 1;
                    for ( i = 0; i < last; ++i ) {
                        OpenGL.glVertex3f(footPrintData.sole[i,0] * multiplier,
                                        footPrintData.sole[i,1] * multiplier,
                                        footPrintData.sole[i,2] * multiplier);
                    }
                OpenGL.glEnd();
                OpenGL.glBegin((uint)OpenGL.GL_TRIANGLE_FAN);
                last = footPrintData.heelCount - 1;
                    for ( i = 0; i < last; ++i ) {
                        OpenGL.glVertex3f(footPrintData.heel[i,0] * multiplier,
                                        footPrintData.heel[i,1] * multiplier,
                                        footPrintData.heel[i,2] * multiplier);
                    }
                OpenGL.glEnd();

                OpenGL.glPopAttrib();
            }

            // Draw the outline of the foot
            //
            OpenGL.glBegin((uint)OpenGL.GL_LINES);
            {
                int last = footPrintData.soleCount - 1;
                for (int i = 0; i < last; ++i)
                {
                    OpenGL.glVertex3f(footPrintData.sole[i, 0] * multiplier,
                                    footPrintData.sole[i, 1] * multiplier,
                                    footPrintData.sole[i, 2] * multiplier);
                    OpenGL.glVertex3f(footPrintData.sole[i + 1, 0] * multiplier,
                                    footPrintData.sole[i + 1, 1] * multiplier,
                                    footPrintData.sole[i + 1, 2] * multiplier);
                }
                last = footPrintData.heelCount - 1;
                for (int i = 0; i < last; ++i)
                {
                    OpenGL.glVertex3f(footPrintData.heel[i, 0] * multiplier,
                                    footPrintData.heel[i, 1] * multiplier,
                                    footPrintData.heel[i, 2] * multiplier);
                    OpenGL.glVertex3f(footPrintData.heel[i + 1, 0] * multiplier,
                                    footPrintData.heel[i + 1, 1] * multiplier,
                                    footPrintData.heel[i + 1, 2] * multiplier);
                }
            }
            OpenGL.glEnd();

            view.endGL();
        }
예제 #20
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;
        }
예제 #21
0
		public override void redoIt()
		{
			MObject dependNode = new MObject();
			MOStream stdoutstream = MStreamUtils.stdOutStream();
			for(; !iter.isDone; iter.next())
			{
				// Get the selected dependency node and create
				// a function set for it
				//
				try
				{
					iter.getDependNode(dependNode);
				}
				catch (System.Exception)
				{
					MStreamUtils.writeCharBuffer(MStreamUtils.stdErrorStream(), "Error getting the dependency node");
					continue;
				}

				MFnDependencyNode fnDN;
				try
				{
					fnDN = new MFnDependencyNode(dependNode);
				}
				catch(System.Exception)
				{
					MStreamUtils.writeCharBuffer(MStreamUtils.stdErrorStream(), "Error creating MFnDependencyNode");
					continue;
				}

				MFnTypedAttribute fnAttr = new MFnTypedAttribute();
				MObject newAttr = fnAttr.create("blindDoubleData", "BDD", blindDoubleData.tid);

				try
				{
					fnDN.addAttribute(newAttr, MFnDependencyNode.MAttrClass.kLocalDynamicAttr);
				}
				catch (System.Exception)
				{
					// do nothing
					// addAttribute only need call once, the redundant calls will return false (throw exception) 
				}
				
				// Create a plug to set and retrieve value off the node.
				//
				MPlug plug = new MPlug(dependNode, newAttr);


				// ----------------------------------- Attention ------------------------------------
				// --------------------------------- Downcast Begin -----------------------------------
				// the following codes are used to get the c# object 
				// 
				MFnPluginData pdFnCreator = new MFnPluginData();

				// 1. you cannot gain blindDoubleData by the following code
				//    {code}
				//          blindDoubleData newData = new blindDoubleData()
				//    {code}
				//    As we need to keep the relationship between c# impl and c++ instance pointer
				//    We cannot use the above ctor codes, otherwise, the mandatory information used for down casting is omitted

				// 2. you cannot use the tempData gained by the following code
				//    {code}
				//          MObject tempData = pdFnCreator.create(blindDoubleData.tid); 
				//    {code}
				//    reason:
				//          tempData is useless, we cannot use tempData to do downcast
				//          the create function gains the tempData by the following code
				//
				//          {code}
				//              newHandle = new MObject(mayaHandle);    
				//          {code}
				//
				//     the mayaHandle is the actual pointer, which we store. But we have no information about the newHandle

				// the return object is useless. the data we needed is stored in pdFnCreator
				pdFnCreator.create(blindDoubleData.tid);

				// 3. get "the data" we needed
				blindDoubleData newData = pdFnCreator.data() as blindDoubleData;
				// ---------------------------------- Downcast End -----------------------------------
				if (newData == null)
					continue;

				newData.value = 3.2;

				plug.setValue(newData);
				
				// Now try to retrieve the value of the plug as an MObject.
				//
				MObject sData = new MObject();

				try
				{
					plug.getValue( sData );
				}
				catch (System.Exception)
				{
					continue;
				}

				// Convert the data back to MPxData.
				//
				MFnPluginData pdFn = new MFnPluginData( sData );

				blindDoubleData data = pdFn.data() as blindDoubleData;
		
				// Get the value.
				//
				if ( null == data ) {
					// error
					MStreamUtils.writeCharBuffer(MStreamUtils.stdErrorStream(), "error: failed to retrieve data.");
				}
				MStreamUtils.writeLine(stdoutstream);
				MStreamUtils.writeCharBuffer(stdoutstream, ">>>>>>>>>>>>>>>>>>>>>>>> blindDoubleData binary >>>>>>>>>>>>>>>>>>>>");
				MStreamUtils.writeLine(stdoutstream);
				data.writeBinary(stdoutstream);
				MStreamUtils.writeLine(stdoutstream);
				MStreamUtils.writeCharBuffer(stdoutstream, ">>>>>>>>>>>>>>>>>>>>>>>> blindDoubleData ascii >>>>>>>>>>>>>>>>>>>>");
				MStreamUtils.writeLine(stdoutstream);
				data.writeASCII(stdoutstream);
			}
			return;
		}
예제 #22
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;
		}
예제 #23
0
        //
        // Description
        //
        //    Returns the bounding box for this object.
        //    It is a good idea not to recompute here as this funcion is called often.
        //
        public override MBoundingBox boundingBox()
        {
            MObject thisNode = thisMObject();
            MPlug c1Plug = new MPlug( thisNode, bboxCorner1 );
            MPlug c2Plug = new MPlug( thisNode, bboxCorner2 );
            MObject corner1Object = new MObject();
            MObject corner2Object = new MObject();
            c1Plug.getValue( corner1Object );
            c2Plug.getValue( corner2Object );

            double[] corner1 = new double[3];
            double[] corner2 = new double[3];

            MFnNumericData fnData = new MFnNumericData();
            fnData.setObject( corner1Object );
            fnData.getData(out corner1[0], out corner1[1], out corner1[2]);
            fnData.setObject( corner2Object );
            fnData.getData(out corner2[0], out corner2[1], out corner2[2]);

            MPoint corner1Point = new MPoint( corner1[0], corner1[1], corner1[2] );
            MPoint corner2Point = new MPoint( corner2[0], corner2[1], corner2[2] );

            return new MBoundingBox( corner1Point, corner2Point );
        }
예제 #24
0
        public override void draw(Autodesk.Maya.OpenMayaUI.M3dView view, MDagPath path, Autodesk.Maya.OpenMayaUI.M3dView.DisplayStyle style, Autodesk.Maya.OpenMayaUI.M3dView.DisplayStatus status)
        {
            // Get the size
            //
            MObject   thisNode = thisMObject();
            MPlug     plug     = new MPlug(thisNode, size);
            MDistance sizeVal  = new MDistance();

            plug.getValue(sizeVal);

            float multiplier = (float)sizeVal.asCentimeters;

            view.beginGL();

            if ((style == M3dView.DisplayStyle.kFlatShaded) ||
                (style == M3dView.DisplayStyle.kGouraudShaded))
            {
                // Push the color settings
                //
                OpenGL.glPushAttrib((uint)OpenGL.GL_CURRENT_BIT);

                if (status == M3dView.DisplayStatus.kActive)
                {
                    view.setDrawColor(13, (int)M3dView.ColorTable.kActiveColors);
                }
                else
                {
                    view.setDrawColor(13, (int)M3dView.ColorTable.kDormantColors);
                }

                OpenGL.glBegin((uint)OpenGL.GL_TRIANGLE_FAN);
                int i;
                int last = footPrintData.soleCount - 1;
                for (i = 0; i < last; ++i)
                {
                    OpenGL.glVertex3f(footPrintData.sole[i, 0] * multiplier,
                                      footPrintData.sole[i, 1] * multiplier,
                                      footPrintData.sole[i, 2] * multiplier);
                }
                OpenGL.glEnd();
                OpenGL.glBegin((uint)OpenGL.GL_TRIANGLE_FAN);
                last = footPrintData.heelCount - 1;
                for (i = 0; i < last; ++i)
                {
                    OpenGL.glVertex3f(footPrintData.heel[i, 0] * multiplier,
                                      footPrintData.heel[i, 1] * multiplier,
                                      footPrintData.heel[i, 2] * multiplier);
                }
                OpenGL.glEnd();

                OpenGL.glPopAttrib();
            }

            // Draw the outline of the foot
            //
            OpenGL.glBegin((uint)OpenGL.GL_LINES);
            {
                int last = footPrintData.soleCount - 1;
                for (int i = 0; i < last; ++i)
                {
                    OpenGL.glVertex3f(footPrintData.sole[i, 0] * multiplier,
                                      footPrintData.sole[i, 1] * multiplier,
                                      footPrintData.sole[i, 2] * multiplier);
                    OpenGL.glVertex3f(footPrintData.sole[i + 1, 0] * multiplier,
                                      footPrintData.sole[i + 1, 1] * multiplier,
                                      footPrintData.sole[i + 1, 2] * multiplier);
                }
                last = footPrintData.heelCount - 1;
                for (int i = 0; i < last; ++i)
                {
                    OpenGL.glVertex3f(footPrintData.heel[i, 0] * multiplier,
                                      footPrintData.heel[i, 1] * multiplier,
                                      footPrintData.heel[i, 2] * multiplier);
                    OpenGL.glVertex3f(footPrintData.heel[i + 1, 0] * multiplier,
                                      footPrintData.heel[i + 1, 1] * multiplier,
                                      footPrintData.heel[i + 1, 2] * multiplier);
                }
            }
            OpenGL.glEnd();


            view.endGL();
        }