Esempio n. 1
0
        public void sendCurveToMaya(string node_name, Point3DCollection controlVertices, List <double> knots, int degree,
                                    MFnNurbsCurveForm form)
        {
            var dn             = new MFnDagNode(getDagNode(node_name));
            var plCreate       = dn.findPlug("create");
            var plDynamoCreate = new MPlug();

            try
            {
                plDynamoCreate = dn.findPlug("dynamoCreate");
            }
            catch
            {
                var tAttr           = new MFnTypedAttribute();
                var ldaDynamoCreate = tAttr.create("dynamoCreate", "dc", MFnData.Type.kNurbsCurve, MObject.kNullObj);
                try
                {
                    dn.addAttribute(ldaDynamoCreate, MFnDependencyNode.MAttrClass.kLocalDynamicAttr);
                    plDynamoCreate = dn.findPlug(ldaDynamoCreate);
                    var dagm = new MDagModifier();
                    dagm.connect(plDynamoCreate, plCreate);
                    dagm.doIt();
                }
                catch
                {
                    return;
                }
            }

            var ncd    = new MFnNurbsCurveData();
            var oOwner = ncd.create();
            var nc     = new MFnNurbsCurve();

            var p_aControlVertices = new MPointArray();

            foreach (var p in controlVertices)
            {
                p_aControlVertices.Add(new MPoint(p.X, p.Y, p.Z));
            }

            var d_aKnots = new MDoubleArray();

            for (var i = 1; i < knots.Count - 1; ++i)
            {
                d_aKnots.Add(knots[i]);
            }

            nc.create(p_aControlVertices, d_aKnots, (uint)degree, (MFnNurbsCurve.Form)form, false, true, oOwner);

            plDynamoCreate.setMObject(oOwner);

            MGlobal.executeCommandOnIdle(string.Format("dgdirty {0}.create;", node_name));
        }
Esempio n. 2
0
        public void sendCurveToMaya(string node_name, Point3DCollection controlVertices, List<double> knots, int degree, MFnNurbsCurveForm form)
        {
            MFnDagNode dn = new MFnDagNode(getDagNode(node_name));
            MPlug plCreate = dn.findPlug("create");
            MPlug plDynamoCreate = new MPlug();

            try
            {
                plDynamoCreate = dn.findPlug("dynamoCreate");
            }
            catch
            {
                MFnTypedAttribute tAttr = new MFnTypedAttribute();
                MObject ldaDynamoCreate = tAttr.create("dynamoCreate", "dc", MFnData.Type.kNurbsCurve, MObject.kNullObj);
                try
                {
                    dn.addAttribute(ldaDynamoCreate, MFnDependencyNode.MAttrClass.kLocalDynamicAttr);
                    plDynamoCreate = dn.findPlug(ldaDynamoCreate);
                    MDagModifier dagm = new MDagModifier();
                    dagm.connect(plDynamoCreate, plCreate);
                    dagm.doIt();
                }
                catch
                {
                    return;
                }
            }

            MFnNurbsCurveData ncd = new MFnNurbsCurveData();
            MObject oOwner = ncd.create();
            MFnNurbsCurve nc = new MFnNurbsCurve();

            MPointArray p_aControlVertices = new MPointArray();
            foreach (Point3D p in controlVertices)
            {
                p_aControlVertices.Add(new MPoint(p.X, p.Y, p.Z));
            }

            MDoubleArray d_aKnots = new MDoubleArray();
            for (int i = 1; i < knots.Count - 1; ++i )
            {
                d_aKnots.Add(knots[i]);
            }

            nc.create(p_aControlVertices, d_aKnots, (uint)degree, (MFnNurbsCurve.Form)form, false, true, oOwner);

            plDynamoCreate.setMObject(oOwner);

            MGlobal.executeCommandOnIdle(String.Format("dgdirty {0}.create;", node_name));
        }
Esempio n. 3
0
        public static void ToMaya(Curve CurveToSend, string name)
        {
            NurbsCurve ctsAsNurb = null;

            if (CurveToSend is Rectangle)
            {
                Rectangle rec = (Rectangle)CurveToSend;
                ctsAsNurb = NurbsCurve.ByControlPoints(rec.Points, 1, true);
            }
            else if (CurveToSend is Polygon)
            {
                Polygon rec = (Polygon)CurveToSend;
                ctsAsNurb = NurbsCurve.ByControlPoints(rec.Points, 1, true);
            }
            else
            {
                ctsAsNurb = CurveToSend.ToNurbsCurve();
            }

            var ncd = new MFnNurbsCurveData();


            MFnNurbsCurveForm mfnform;

            if (ctsAsNurb.IsClosed)
            {
                mfnform = MFnNurbsCurveForm.kClosed;
            }
            else
            {
                mfnform = MFnNurbsCurveForm.kOpen;
            }

            var mayaCurve = new MFnNurbsCurve();

            var vtxs = new MPointArray();

            var cvs = ctsAsNurb.ControlPoints();
            var yUp = MGlobal.isYAxisUp;

            if (yUp)
            {
                foreach (var cv in cvs)
                {
                    var pt = new MPoint(cv.X, cv.Z, -cv.Y);
                    vtxs.Add(pt);
                    //pt.Dispose();
                }
            }
            else
            {
                foreach (var cv in cvs)
                {
                    var pt = new MPoint(cv.X, cv.Y, cv.Z);
                    vtxs.Add(pt);
                    //pt.Dispose();
                }
            }

            var knots    = ctsAsNurb.Knots();
            var crvKnots = new MDoubleArray(knots);

            crvKnots.RemoveAt(0);
            crvKnots.RemoveAt(crvKnots.Count - 1);

            MDagPath node       = null;
            var      nodeExists = false;

            Task checkNode  = null;
            Task deleteNode = null;

            try
            {
                node       = DMInterop.getDagNode(name);
                nodeExists = true;
            }
            catch (Exception)
            {
                nodeExists = false;
            }

            MObject obj;

            if (nodeExists)
            {
                MDagPath nodeShape = node;
                nodeShape.extendToShape();
                var modifyCrv = new MDGModifier();
                mayaCurve = new MFnNurbsCurve(nodeShape);

                try
                {
                    MFnNurbsCurveData dataCreator  = new MFnNurbsCurveData();
                    MObject           outCurveData = dataCreator.create();
                    var    span   = (vtxs.Count - ctsAsNurb.Degree);
                    string rblCmd = $"rebuildCurve -rt 0 -s {span} -d {ctsAsNurb.Degree} {name}";

                    if (mayaCurve.numCVs != vtxs.Count || mayaCurve.degree != ctsAsNurb.Degree)
                    {
                        MGlobal.executeCommand(rblCmd);
                    }

                    mayaCurve.setCVs(vtxs);
                    mayaCurve.setKnots(crvKnots, 0, crvKnots.length - 1);
                    mayaCurve.updateCurve();
                    modifyCrv.doIt();

                    if (CurveToSend.GetType() == typeof(Circle))
                    {
                        span   = 8;
                        rblCmd = $"rebuildCurve -rt 0 -s {span} {name}";
                        MGlobal.executeCommand(rblCmd);
                    }
                }
                catch (Exception e)
                {
                    MGlobal.displayWarning(e.Message);
                }
            }

            else
            {
                obj = mayaCurve.create(vtxs, crvKnots, (uint)ctsAsNurb.Degree, (MFnNurbsCurve.Form)mfnform,
                                       false, ctsAsNurb.IsRational);
                MFnDependencyNode nodeFn = new MFnDagNode(obj);
                nodeFn.setName(name);
            }
        }