public MayaSceneConfigure() { var _Linear = string.Empty; var _Angle = string.Empty; var _SceneStart = 0.0; var _SceneEnd = 0.0; // Fetch MGlobal.executeCommand("currentUnit -q -fullName -linear", out _Linear); MGlobal.executeCommand("currentUnit -q -fullName -angle", out _Angle); MGlobal.executeCommand("playbackOptions -q -ast", out _SceneStart); MGlobal.executeCommand("playbackOptions -q -aet", out _SceneEnd); // Parse start and end this.SceneStart = (int)(_SceneStart); this.SceneEnd = (int)(_SceneEnd); // Set this.LinearUnit = _Linear; this.AngleUnit = _Angle; // Change to CODTools formats MGlobal.executeCommand("currentUnit -linear cm"); MGlobal.executeCommand("currentUnit -angle deg"); // Progress this.CanProgress = true; }
public override void doIt(MArgList args) { // Draw a circle and get its dagPath // using an iterator MGlobal.executeCommand("circle"); MFnNurbsCurve circle = new MFnNurbsCurve(); MDagPath dagPath = new MDagPath(); MItDependencyNodes iter = new MItDependencyNodes(MFn.Type.kNurbsCurve); for (iter.reset(); !iter.isDone; iter.next()) { MObject item = iter.item; if (item.hasFn(MFn.Type.kNurbsCurve)) { circle.setObject(item); circle.getPath(dagPath); MGlobal.displayInfo("DAG_PATH is " + dagPath.fullPathName); if (dagPath.isValid) { // register callback for instance add AND remove // dagPath.InstanceAddedDagPath += userDAGChildAddedCB; dagPath.InstanceRemovedDagPath += userDAGChildRemovedCB; // C# SDK will cleanup events, when this plugin is unloaded // callbacks.append(node); MGlobal.displayInfo("CALLBACK ADDED FOR INSTANCE ADD/REMOVE"); } } } }
public static void Init(MFnDependencyNode babylonAttributesDependencyNode, BabylonPBRMetallicRoughnessMaterial babylonMaterial = null) { // Ensure all attributes are setup if (babylonAttributesDependencyNode.hasAttribute("babylonTransparencyMode") == false) { MGlobal.executeCommand($"addAttr -ln \"babylonTransparencyMode\" -nn \"Opacity Mode\" - at \"enum\" -en \"Opaque:Cutoff:Blend:\" {babylonAttributesDependencyNode.name};"); // Init alpha mode value based on material opacity if (babylonMaterial != null) { MGlobal.executeCommand($"setAttr \"{babylonAttributesDependencyNode.name}.babylonTransparencyMode\" {babylonMaterial.transparencyMode};"); } } if (babylonAttributesDependencyNode.hasAttribute("babylonBackfaceCulling") == false) { MGlobal.executeCommand($"addAttr -ln \"babylonBackfaceCulling\" -nn \"Backface Culling\" - at bool {babylonAttributesDependencyNode.name};"); MGlobal.executeCommand($"setAttr \"{babylonAttributesDependencyNode.name}.babylonBackfaceCulling\" 1;"); } if (babylonAttributesDependencyNode.hasAttribute("babylonUnlit") == false) { MGlobal.executeCommand($"addAttr -ln \"babylonUnlit\" -nn \"Unlit\" - at bool {babylonAttributesDependencyNode.name};"); } if (babylonAttributesDependencyNode.hasAttribute("babylonMaxSimultaneousLights") == false) { MGlobal.executeCommand($"addAttr -ln \"babylonMaxSimultaneousLights\" -nn \"Max Simultaneous Lights\" - at long -min 1 -dv 4 {babylonAttributesDependencyNode.name};"); } }
private static void CreateWorkspaceControl(string content, string hostName, int width, int height, bool retain = true, bool floating = true) { string closeCommand = $"workspaceControl -cl {hostName};"; string command = $@" workspaceControl -requiredPlugin DynaMaya -cp true -retain {retain.ToString().ToLower()} -floating {floating.ToString().ToLower()} -uiScript ""if (!`control -q -ex \""{content}\""`) {commandName} -{flagName}; control -e -parent \""{hostName}\"" \""{content}\"";"" -requiredPlugin {pluginName} -initialWidth {width} -initialHeight {height} ""{hostName}""; "; try { MGlobal.executeCommand(command); } catch (Exception) { Console.WriteLine("Error while creating workspace-control."); } }
public static Dictionary <string, List <object> > getParticles(string name, bool unitizeVelocity = false) { MDoubleArray pPos = new MDoubleArray(); MGlobal.executeCommand("getParticleAttr -at position -at velocity -array true " + name, pPos); List <object> particlePos = new List <object>(); List <object> particleVec = new List <object>(); int numPart = 0; var posAttr = DMInterop.getPlug(name, "position"); if (posAttr.isArray) { numPart = (int)posAttr.numElements; particlePos = new List <object>(numPart); particleVec = new List <object>(numPart); for (uint i = 0; i < numPart; i += 3) { particlePos.Add(Point.ByCoordinates(posAttr[i].asDouble(), posAttr[i + 1].asDouble(), posAttr[i + 2].asDouble())); } } return(new Dictionary <string, List <object> > { { "Particles", particlePos }, { "Velocity", particleVec } }); }
public static MDagPath AddDynamicChainControl(ref MDagPath hairSystem, MSelectionList jointChains = null, ConstantValue.HairPointLockType pointLock = ConstantValue.HairPointLockType.Base) { //get bones if (jointChains == null) { jointChains = BasicFunc.GetSelectedList(); } if (jointChains.length == 0) { return(null); } MDagPath dagPath_startJoint = new MDagPath(), dagPath_endJoint = new MDagPath(); if (jointChains.length == 1) { BasicFunc.Select(jointChains); jointChains.getDagPath((uint)0, dagPath_startJoint); MGlobal.executeCommand("select -hierarchy " + dagPath_startJoint.fullPathName); jointChains = BasicFunc.GetSelectedList(MFn.Type.kJoint); } jointChains.getDagPath(0, dagPath_startJoint); jointChains.getDagPath(jointChains.length - 1, dagPath_endJoint); MDagPath startCurveDagPath = JointProcess.CreateJointsCurve(jointChains); MDagPath outCurveDagPath = CurveToHair(ref hairSystem, startCurveDagPath, pointLock); JointProcess.AddIKHandle(dagPath_startJoint, dagPath_endJoint, JointProcess.IKSolverType.Spline, outCurveDagPath.fullPathName); BasicFunc.SetTransformParent(BasicFunc.GetParent(startCurveDagPath), BasicFunc.GetParent(dagPath_startJoint)); return(outCurveDagPath); }
public override void doIt(MArgList argl) { SubscribeAssemblyResolvingEvent(); if (!String.IsNullOrEmpty(wpfTitle)) { // Check the existence of the window int wndExist = int.Parse(MGlobal.executeCommandStringResult($@"format -stringArg `control -q -ex ""{wpfTitle}""` ""^1s""")); if (wndExist > 0) { MGlobal.executeCommand($@"catch (`workspaceControl -e -visible true ""{hostTitle}""`);"); return; } } if (dynStartUp != null) { if (dynStartUp.DynView != null) { if (dynStartUp.DynView.IsVisible) { MGlobal.displayWarning("Dynamo is already open"); return; } else { dynWnd.Show(); } } } else { newDmStartup(); dynWnd = dynStartUp.DynView; // Create the window to dock dynWnd.Show(); // Extract the window handle of the window we want to dock IntPtr mWindowHandle = new System.Windows.Interop.WindowInteropHelper(dynWnd).Handle; int width = (int)dynWnd.Width; int height = (int)dynWnd.Height; var title = dynWnd.Title; wpfTitle = title + " Internal"; hostTitle = title; dynWnd.Title = wpfTitle; mayaWnd = new MForeignWindowWrapper(mWindowHandle, true); uint flagIdx = argl.flagIndex(flagName); if (flagIdx == MArgList.kInvalidArgIndex) { // Create a workspace-control to wrap the native window wrapper, and use it as the parent of this WPF window CreateWorkspaceControl(wpfTitle, hostTitle, width, height, false); } } }
public static MSelectionList DuplicateDags(MSelectionList list) { if (list == null) { return(null); } MSelectionList originSelect = GetSelectedList(); CmdStrConstructor cc = new CmdStrConstructor("duplicate"); cc.UpdateToggle("rr", true); List <string> targets = new List <string>(); foreach (MDagPath dag in list.DagPaths()) { targets.Add(dag.fullPathName); } cc.UpdateTargets(targets); MGlobal.executeCommand(cc.ToString()); //string resultName = MGlobal.executeCommandStringResult("duplicate -rr"); MSelectionList newList = GetSelectedList(); Select(originSelect); return(newList); }
public static void ConvertHairSelection(HairSelectionType hairSelectionType, MDagPath dagPath = null) { //MGlobal.executeCommand("convertHairSelection \"current\""); if (dagPath != null) { BasicFunc.Select(dagPath); } switch (hairSelectionType) { case HairSelectionType.Follicles: { MGlobal.executeCommand("convertHairSelection \"follicles\""); break; } case HairSelectionType.HairSystem: { MGlobal.executeCommand("convertHairSelection \"hairSystems\""); break; } case HairSelectionType.OutputCurves: { MGlobal.executeCommand("convertHairSelection \"current\""); break; } case HairSelectionType.StartCurves: { MGlobal.executeCommand("convertHairSelection \"startCurves\""); break; } } }
// --- Utilities --- /// <summary> /// Retreive meshes having specified material id /// Meshes are split into 2 categories: Opaque or Transparent /// </summary> /// <param name="babylonScene"></param> /// <param name="materialId"></param> /// <param name="meshesOpaque"></param> /// <param name="meshesTransparent"></param> private void getMeshesByMaterialId(BabylonScene babylonScene, string materialId, List <BabylonMesh> meshesOpaque, List <BabylonMesh> meshesTransparent) { babylonScene.MeshesList.ForEach(mesh => { if (mesh.materialId == materialId) { // Get mesh full path name (unique) MStringArray meshFullPathName = new MStringArray(); // Surround uuid with quotes like so: ls "18D0785F-4E8E-1621-01E1-84AD39F92289"; // ls command output must be an array MGlobal.executeCommand($@"ls ""{mesh.id}"";", meshFullPathName); int meshOpaqueInt; MGlobal.executeCommand($@"getAttr {meshFullPathName[0]}.aiOpaque;", out meshOpaqueInt); if (meshOpaqueInt == 1) { meshesOpaque.Add(mesh); } else { meshesTransparent.Add(mesh); } } }); }
protected static void Init(MFnDependencyNode babylonAttributesDependencyNode, BabylonMaterial babylonMaterial = null) { // Ensure all attributes are setup if (babylonAttributesDependencyNode.hasAttribute("babylonBackfaceCulling") == false) { MGlobal.executeCommand($"addAttr -ln \"babylonBackfaceCulling\" -nn \"Backface Culling\" -at bool {babylonAttributesDependencyNode.name};"); } if (babylonAttributesDependencyNode.hasAttribute("babylonUnlit") == false) { MGlobal.executeCommand($"addAttr -ln \"babylonUnlit\" -nn \"Unlit\" -at bool {babylonAttributesDependencyNode.name};"); } if (babylonAttributesDependencyNode.hasAttribute("babylonMaxSimultaneousLights") == false) { MGlobal.executeCommand($"addAttr -ln \"babylonMaxSimultaneousLights\" -nn \"Max Simultaneous Lights\" -at long -min 1 -dv 4 {babylonAttributesDependencyNode.name};"); } // Initialise attributes according to babylon material if (babylonMaterial != null) { setAttributeValue(babylonAttributesDependencyNode.name + ".babylonBackfaceCulling", Convert.ToInt32(babylonMaterial.backFaceCulling)); setAttributeValue(babylonAttributesDependencyNode.name + ".babylonUnlit", Convert.ToInt32(babylonMaterial.isUnlit)); setAttributeValue(babylonAttributesDependencyNode.name + ".babylonMaxSimultaneousLights", babylonMaterial.maxSimultaneousLights); } }
/// <summary> /// Returns true if the attribute is locked. /// </summary> /// <param name="name">The name of the attribute in the format: {nodeName}.{attributeName}</param> public static bool isAttributeLocked(string name) { int isUnlocked; MGlobal.executeCommand($"getAttr -settable \"{name}\";", out isUnlocked); return(isUnlocked == 1 ? false : true); }
public static void ScaleNode(List <string> GeomName, List <double> Xval, List <double> Yval, List <double> Zval) { if (GeomName.Count < 1) { return; } double x, y, z; bool xs = false, ys = false, zs = false; if (Xval.Count == 1) { xs = true; } if (Yval.Count == 1) { ys = true; } if (Zval.Count == 1) { zs = true; } for (int i = 0; i < GeomName.Count; i++) { x = xs ? Xval[0] : Xval[i]; y = xs ? Yval[0] : Yval[i]; z = xs ? Zval[0] : Zval[i]; MGlobal.executeCommand(string.Format("scale {0} {1} {2} {3}", x, y, z, GeomName[i])); } }
private void GetTransform(MFnTransform mFnTransform, ref float[] position, ref float[] rotationQuaternion, ref float[] rotation, ref BabylonVector3.EulerRotationOrder rotationOrder, ref float[] scaling) { var transformationMatrix = new MTransformationMatrix(mFnTransform.transformationMatrix); var mayaRotationOrder = 0; MGlobal.executeCommand($"getAttr {mFnTransform.fullPathName}.rotateOrder", out mayaRotationOrder); rotationOrder = Tools.ConvertMayaRotationOrder((MEulerRotation.RotationOrder)mayaRotationOrder); position = transformationMatrix.getTranslation(); rotationQuaternion = transformationMatrix.getRotationQuaternion(); rotation = transformationMatrix.getRotation(); scaling = transformationMatrix.getScale(); // Switch coordinate system at object level position[2] *= -1; rotationQuaternion[0] *= -1; rotationQuaternion[1] *= -1; rotation[0] *= -1; rotation[1] *= -1; rotationOrder = Tools.InvertRotationOrder(rotationOrder); // Apply unit conversion factor to meter position[0] *= scaleFactorToMeters; position[1] *= scaleFactorToMeters; position[2] *= scaleFactorToMeters; }
private MIntArray GetMaxTime() { MIntArray maxTime = new MIntArray(); MGlobal.executeCommand("playbackOptions -q -animationEndTime", maxTime); return(maxTime); }
private MIntArray GetMinTime() { MIntArray minTime = new MIntArray(); MGlobal.executeCommand("playbackOptions -q -animationStartTime", minTime); return(minTime); }
public static List <Curve> getSmothMeshEdges(MFnMesh mayaMesh, bool createInMaya = false) { //MCommandResult result = new MCommandResult(); int ne = mayaMesh.numEdges; MFnTransform group = new MFnTransform(); List <Curve> curveObjects = new List <Curve>(ne); MStringArray resultStr = new MStringArray(); var fullName = mayaMesh.fullPathName.Split('|'); string transformName = fullName[fullName.Length - 2]; if (createInMaya) { for (int i = 0; i < ne; i++) { using (MCommandResult result = new MCommandResult()) { MGlobal.executeCommand( $"polyToCurve -name {transformName}Curves -form 2 -degree 3 -conformToSmoothMeshPreview 1 {transformName}.e[{i}]", result); result.getResult(resultStr); curveObjects.Add( DMCurve.CurveFromMfnNurbsCurveFromName(resultStr[0], MSpace.Space.kPostTransform.ToString())); } } } else { //Parallel.For(0, ne, i => { for (int i = 0; i < ne; i++) { using (MCommandResult result = new MCommandResult()) { MGlobal.executeCommand( $"polyToCurve -name deleteMe11232204332AA -form 2 -degree 3 -conformToSmoothMeshPreview 1 {transformName}.e[{i}]", result); result.getResult(resultStr); curveObjects.Add( DMCurve.CurveFromMfnNurbsCurveFromName(resultStr[0], MSpace.Space.kPostTransform.ToString())); try { MGlobal.deleteNode(DMInterop.getDependNode(resultStr[0])); } catch { MGlobal.displayWarning("getSmothMeshEdges: unable to delete temp object"); } } } // }); } return(curveObjects); }
bool IExtensionPlugin.UninitializePlugin() { // Remove menu from main menu bar MGlobal.executeCommand($@"deleteUI -menu ""{MenuPath}"";"); MGlobal.displayInfo("Babylon plug-in uninitialized"); return(true); }
public static void MoveSkinJointsTool(MDagPath dag = null) { if (dag != null) { BasicFunc.Select(dag); } MGlobal.executeCommand("MoveSkinJointsTool"); }
void AddMenuItemDivider(string labelStr, string parentMenuName) { string cmdStr = "menuItem -d 1 -dl \"" + labelStr + "\" -p \"" + parentMenuName + "\""; //Debug.Log(cmdStr); MGlobal.executeCommand(cmdStr); //MGlobal.executeCommand(cmdStr); }
public static void Create(MFnDependencyNode materialDependencyNode) { // Create Babylon Material dependency node string babylonMaterialNodeName; MGlobal.executeCommand($"shadingNode -asShader babylonAiStandardSurfaceMaterialNode;", out babylonMaterialNodeName); MGlobal.executeCommand($"connectAttr -f {materialDependencyNode.name}.outColor {babylonMaterialNodeName}.outTransparency;"); }
void AddMenuItem(string label, string parentMenuName, string command, string paramStr) { string cmdStr = "menuItem -l \"" + label + "\" -p \"" + parentMenuName + "\" -c \"" + command + " " + paramStr + "\""; //Debug.Log(cmdStr); MGlobal.executeCommand(cmdStr); //MGlobal.executeCommand(cmdStr); }
public void StartProgress(string Title, int Max) { if (this.CanProgress) { MGlobal.executeCommand("progressBar -e -bp -ii 1 $gMainProgressBar"); MGlobal.executeCommand("progressBar -e -ep $gMainProgressBar"); MGlobal.executeCommand(string.Format("progressBar -e -bp -ii 1 -st \"{0}\" -max {1} $gMainProgressBar", Title, Max)); } }
public static List <List <Curve> > getSmothMeshEdgesPerFace(MFnMesh mayaMesh, bool createInMaya = false) { MCommandResult ptcResult = new MCommandResult(); MCommandResult teResult = new MCommandResult(); int numPoly = mayaMesh.numPolygons; List <List <Curve> > curveObjects = new List <List <Curve> >(numPoly); MStringArray ptcResultStr = new MStringArray(); MStringArray teResultStr = new MStringArray(); MStringArray teResultStrFlat = new MStringArray(); List <Curve> tempCurveArray = null; if (createInMaya) { } else { for (int i = 0; i < numPoly; i++) { MGlobal.executeCommand($"polyListComponentConversion -te {mayaMesh.name}.f[{i}]", teResult); teResult.getResult(teResultStr); MGlobal.clearSelectionList(); foreach (var ters in teResultStr) { MGlobal.selectByName(ters, MGlobal.ListAdjustment.kAddToList); } MGlobal.executeCommand($"ls -sl -fl", teResult); teResult.getResult(teResultStrFlat); tempCurveArray = new List <Curve>((int)teResultStrFlat.length); foreach (var e in teResultStrFlat) { MGlobal.executeCommand($"polyToCurve -name deleteMe11232204332AA -form 2 -degree 3 -conformToSmoothMeshPreview 1 {e}", ptcResult); ptcResult.getResult(ptcResultStr); tempCurveArray.Add(DMCurve.CurveFromMfnNurbsCurveFromName(ptcResultStr[0], MSpace.Space.kPostTransform.ToString())); try { MGlobal.deleteNode(DMInterop.getDependNode(ptcResultStr[0])); } catch { MGlobal.displayWarning("getSmothMeshEdges: unable to delete temp object"); } } curveObjects.Add(tempCurveArray); } } return(curveObjects); }
static private void createIK2BsolverAfterNew(object sender, MBasicFunctionArgs arg) // This method creates the ik2Bsolver after a File->New. // { MSelectionList selList = new MSelectionList(); MGlobal.getActiveSelectionList(selList); MGlobal.executeCommand("createNode -n ik2BsolverCSharp ik2BsolverCSharp"); MGlobal.setActiveSelectionList(selList); }
private MMatrix GetMMatrix(MFnTransform mFnTransform, double currentFrame = 0) { // get transformation matrix at this frame MDoubleArray mDoubleMatrix = new MDoubleArray(); MGlobal.executeCommand($"getAttr -t {currentFrame} {mFnTransform.fullPathName}.matrix", mDoubleMatrix); mDoubleMatrix.get(out float[] localMatrix); return(new MMatrix(localMatrix)); }
internal static bool createLocator(double x, double y, double z, double rx, double ry, double rz, string name) { MStringArray moveResult = new MStringArray(); MStringArray rotateResult = new MStringArray(); MGlobal.executeCommand(string.Format("spaceLocator -a -p {0} {1} {2} -n {3}", x, y, z, name), moveResult); MGlobal.executeCommand(string.Format("rotate {0} {1} {2} {3}", rx, ry, rz, name), rotateResult); return(true); }
public static void ConnectAttr(string from, string to, bool force = true, bool showInIdle = false) { string cmdStr = string.Format("connectAttr {0} {1}", from, to); if (force) { cmdStr += " -f"; } MGlobal.executeCommand(cmdStr, showInIdle); }
bool IExtensionPlugin.InitializePlugin() { // Add menu to main menu bar MenuPath = MGlobal.executeCommandStringResult($@"menu - parent MayaWindow - label ""Babylon"";"); // Add item to this menu MGlobal.executeCommand($@"menuItem - label ""Babylon File Exporter..."" - command ""toBabylon"";"); MGlobal.displayInfo("Babylon plug-in initialized"); return(true); }
public bool UninitializePlugin() { try { // Clear UI if available MGlobal.executeCommand("catchQuiet(deleteUI(\"CODTools\"));"); } catch { } return(true); }