/// <summary> /// convert the actual node to editable mesh /// </summary> public void ConvertToMesh() { if (!this.IsValid) { return; } // get the current node world state IObjectState state = this.m_node.EvalWorldState(AssemblyFunctions.Core.Time, false); // get the object out of the state and check if it's possible to convert to editable mesh IObject obj = state.Obj; if (obj.CanConvertToType(AssemblyFunctions.GlobalInterface.TriObjectClassID) == 0) { return; } // convert the obj to triobject // if the node type was editable mesh, tit will return just the current node mesh // elsewhere it will return a new triobj instance which is not bound to anything ITriObject tri = obj.ConvertToType(AssemblyFunctions.Core.Time, AssemblyFunctions.GlobalInterface.TriObjectClassID) as ITriObject; // check if we got something if (tri == null) { return; } // remeber the obj and mesh for later use this.m_triMesh = tri.Mesh; this.m_baseObject = obj; // check if the tri is identical with the current object from the node state // if the node was already editable mesh we don't need to do anything if (this.m_triMesh == null || tri.Equals((INoncopyable)obj)) { return; } // notfiy all dependents // this notfiy was from a max sample. not sure why call first before change and call change afterwards this.m_node.NotifyDependents(Globals.FOREVER, Globals.PART_ALL, RefMessage.Change); // the the object reference of the node to the new triobj // important: if you exchange the object ref ith the same objref // like this.m_node.ObjectRef = this.m_node.ObjectRef you will produce a nice crash sometimes // the property setter inside max.net will delete the old reference and since the old is the new // the reference will be set to null which is illegal this.m_node.ObjectRef = tri; // notfiy all dependents this.m_node.NotifyDependents(Globals.FOREVER, 0, RefMessage.SubanimStructureChanged); this.m_node.NotifyDependents(Globals.FOREVER, Globals.PART_ALL, RefMessage.Change); }
/// <summary> /// collect and fill the property base on the trimesh /// </summary> public void CollectTriMeshData() { if (!this.IsValid) { return; } // get the current node world state IObjectState state = this.m_node.EvalWorldState(AssemblyFunctions.Core.Time, false); // get the object out of the state and check if it's possible to convert to editable mesh IObject obj = state.Obj; if (obj.CanConvertToType(AssemblyFunctions.GlobalInterface.TriObjectClassID) == 0) { return; } // convert the obj to triobject // if the node type was editable mesh, tit will return just the current node mesh // elsewhere it will return a new triobj instance which is not bound to anything ITriObject tri = obj.ConvertToType(AssemblyFunctions.Core.Time, AssemblyFunctions.GlobalInterface.TriObjectClassID) as ITriObject; if (tri == null) { return; } this.m_iNumVerts = tri.Mesh.NumVerts; this.m_iNumTris = tri.Mesh.NumFaces; // check if triobj is identical with the object from the node // if its not the same we got a new mesh so delete it if (!tri.Equals((INoncopyable)obj)) { tri.DeleteMe(); } }