Hi all.
I found this weekend this thread form @sinokgr and I decided to play with:
http://forums.cgsociety.org/showthread.php?t=1138801
I’ve managed to get from C# a “mesh object” (dotNetObject:Autodesk.Max.Wrappers.Mesh) to MaxScript. But I’m not able to asign it to a node with MaxScript. I suppose I have to convert it to a “true” mesh.
Here are the codes:
C# code (nearly the same as the mentioned thread):
using Autodesk.Max;
namespace exportMesh
{
static public class Class1
{
static IGlobal global = GlobalInterface.Instance;
static private ITriObject GetTriObjectFromNode(IINode node)
{
IObject obj = node.EvalWorldState(0, true).Obj;
IClass_ID myClass = global.Class_ID.Create(9, 0);
if (obj.CanConvertToType(myClass) == 1)
{
ITriObject tri = (ITriObject)obj.ConvertToType(0, myClass);
return tri;
}
else
{
return null;
}
}
// Function that returns a modified mesh
static public IMesh exportMesh(uint handle)
{
IINode node = global.COREInterface.GetINodeByHandle(handle);
IMesh myMesh = GetTriObjectFromNode(node).Mesh_;
//Do something with the mesh
return (myMesh);
}
}
}
And here’s the MaxScript code:
(
Global a
--Load assembly
dotNet.loadAssembly @"D:\Pruebas\3DMax\C#\ClassLibrary1_PruebaMax02.dll"
--Prepare scene
delete objects
myTeapot = teapot()
addModifier myTeapot (turboSmooth iterations:3)
--CS
t = timestamp()
a =(dotnetclass "exportMesh.Class1").exportMesh myTeapot.inode.handle
format "CS took %s
" ((timestamp() - t)*.001)
format "a = %
" a
format "ClassOf a: %
" (classOf a)
)
And I get this result:
CS took 0.005s
a = dotNetObject:Autodesk.Max.Wrappers.Mesh
ClassOf a: dotNetObject
So I can ask in the listener for lots of things (a.numverts, a.numfaces, …) but I don’t know how to use this mesh:
nd = Editable_Mesh()
nd.mesh = a >>> throws an error “-- Unable to convert: dotNetObject:Autodesk.Max.Wrappers.Mesh to type: Mesh”
Any suggestions? Is it possible to use this dotNetObject as a MaxScript mesh?
Thanks a lot for your help.