public static bool Export_To(string _filepath) { List <IINode> nodes = GetSelection(); foreach (IINode _node in nodes) { IIDerivedObject _gObject = (IIDerivedObject)_node.ObjectRef; IClass_ID classID = maxGlobal.Class_ID.Create((uint)BuiltInClassIDA.TRIOBJ_CLASS_ID, 0); ITriObject _mObject = (ITriObject)_gObject.ObjRef.ConvertToType(0, classID); IMesh _mMesh = _mObject.Mesh; _mMesh.BuildNormals(); IIDerivedObject theObj = (IIDerivedObject)_node.ObjectRef; for (int m = 0; m < theObj.Modifiers.Count; m++) { IModifier theModifier = theObj.GetModifier(m); if (theModifier.ClassName == "Skin") { IISkin _skin = (IISkin)theModifier.GetInterface((InterfaceID)(0x00010000)); IISkinContextData _skinContext = _skin.GetContextInterface(_node); ComputeVertexData(_mMesh, _skinContext, semantic, _filepath); } } } return(true); }
/// <summary> /// Adds an object space modifier to provided node (by handle). /// </summary> /// <param name="nodeHandle"> Input the node handle to add the modifier to. </param> /// <param name="cid"> Input the class id of the modifier add. </param> /// <returns> Returns 1 if successful or -1 if not. </returns> static public int AddOsmModifier(uint nodeHandle, IClass_ID cid) { try { IGlobal global = Autodesk.Max.GlobalInterface.Instance; IInterface14 ip = global.COREInterface14; IINode node = ip.GetINodeByHandle(nodeHandle); IObject obj = node.ObjectRef; IIDerivedObject dobj = global.CreateDerivedObject(obj); object objMod = ip.CreateInstance(SClass_ID.Osm, cid as IClass_ID); IModifier mod = (IModifier)objMod; dobj.AddModifier(mod, null, 0); // top of stack node.ObjectRef = dobj; } catch (Exception ex) { Debug.Print(ex.Message); return(-1); } return(1); }
public static bool ExportAnimation(int[] _frames, string _filename, int _samplingRate) { List <IINode> nodes = GetSelection(); foreach (IINode _node in nodes) { IIDerivedObject theObj = (IIDerivedObject)_node.ObjectRef; IInterval interval = maxGlobal.Interval.Create(); interval.SetInfinite(); maxGlobal.IGameInterface.InitialiseIGame(false); for (int m = 0; m < theObj.Modifiers.Count; m++) { IModifier theModifier = theObj.GetModifier(m); if (theModifier.ClassName == "Skin") { IISkin _skin = (IISkin)theModifier.GetInterface((InterfaceID)(0x00010000)); IINode _bone = _skin.GetBone(0); int nbBones = _skin.NumBones; List <string> boneName = new List <string>(); for (int b = 0; b < nbBones; b++) { boneName.Add(_skin.GetBone(b).Name); } #region create bindPose World Pose bindPose = new Pose("bindPose"); BuildBind(_bone, -1, bindPose); #endregion ROD_core.Graphics.Animation.Clip_Skinning clip = new ROD_core.Graphics.Animation.Clip_Skinning(); clip.sequencesData = new List <Pose>(); clip.sequencesTiming = new List <TimeSpan>(); for (int f = 0; f < _frames.Length; f++) { // create Pose at frame (_frame) Pose _pose = new Pose("frame" + _frames[f].ToString()); BuildLJoint(_bone, -1, _pose, _frames, f, _samplingRate, bindPose); clip.sequencesData.Add(_pose); clip.sequencesTiming.Add(TimeSpan.FromSeconds(_frames[f] / 30)); } clip.saveToFile(_filename); } } } return(true); }
public static bool IsSkinned(this IINode node) { IIDerivedObject derivedObject = node.ActualINode.ObjectRef as IIDerivedObject; if (derivedObject == null) { return(false); } for (int index = 0; index < derivedObject.NumModifiers; index++) { IModifier modifier = derivedObject.GetModifier(index); if (modifier.ClassID.PartA == 9815843 && modifier.ClassID.PartB == 87654) // Skin { return(true); } } return(false); }
public static bool ExportSkeleton(string _filenameSkeleton) { List <IINode> nodes = GetSelection(); foreach (IINode _node in nodes) { IIDerivedObject theObj = (IIDerivedObject)_node.ObjectRef; IInterval interval = maxGlobal.Interval.Create(); interval.SetInfinite(); maxGlobal.IGameInterface.InitialiseIGame(false); for (int m = 0; m < theObj.Modifiers.Count; m++) { IModifier theModifier = theObj.GetModifier(m); if (theModifier.ClassName == "Skin") { IISkin _skin = (IISkin)theModifier.GetInterface((InterfaceID)(0x00010000)); IINode _bone = _skin.GetBone(0); int nbBones = _skin.NumBones; List <string> boneName = new List <string>(); for (int b = 0; b < nbBones; b++) { boneName.Add(_skin.GetBone(b).Name); } #region create bindPose World Pose bindPose = new Pose("bindPose"); BuildBind(_bone, -1, bindPose); #endregion Skeleton skelete = new Skeleton("skelete", bindPose); skelete.saveToFile(_filenameSkeleton); } } } return(true); }
/// <summary> /// This will return a modifier from the stack /// </summary> /// <param name="nodeToSearch"> Input node to search. </param> /// <param name="cid"> Input the class id of the modifier to find. </param> /// <returns> The found modifier or null if not found. </returns> static public IModifier GetModifier(IINode nodeToSearch, IClass_ID cid) { IGlobal global = Autodesk.Max.GlobalInterface.Instance; IIDerivedObject dobj = nodeToSearch.ObjectRef as IIDerivedObject; while (dobj != null) { int nmods = dobj.NumModifiers; for (int i = 0; i < nmods; i++) { IModifier mod = dobj.GetModifier(i); // have to compare ClassID Parts A and B separately. The equals operator is not // implemented so it will return false even when they are equal. if ((mod.ClassID.PartA == cid.PartA) && (mod.ClassID.PartB == cid.PartB)) { return(mod); } } dobj = dobj.ObjRef as IIDerivedObject; } return(null); }