Notifications
Clear all

[Closed] Max geometry esporter in C#

if you insist…

void MeshObj::CreateVertexList(S3DVertex* outverts, material_info& m)
 {
 	int index = 0;
 	int matid_counter = 0;
 	FaceEx* f;
 	TVFace mapface;
 
 	for(int i=0; i < number_of_faces;i++)
 	{
 // for all faces of material matid
 
 		f = mesh->GetFace(i);
 		if(f->matID == m.id)
 		{
 			index = 3 * matid_counter;
 			mesh->GetMapFaceIndex(MAPCHANNEL_2,i,mapface.t);
 
 			for(int j = 0; j < 3; j++)
 			{
 				int tbIndex = mesh->GetFaceVertexTangentBinormal(i, j); 
 				m.bbox += mesh->GetVertex(f->vert[j],true); // expand the bounding box
 				outverts[index].pos = vector3d(mesh->GetVertex(f->vert[j],true));
 				outverts[index].normal = vector3d(mesh->GetNormal(f->norm[j],true));
 				outverts[index].tangent = vector3d(tm.VectorTransform(mesh->GetTangent(tbIndex)));
 				outverts[index].binormal = vector3d(tm.VectorTransform(mesh->GetBinormal(tbIndex)));
 				Point3 vcolour;
 				if(mesh->GetColorVertex(f->color[j],vcolour))
 					outverts[index].color = SColor(vcolour);
 				else // set the vertex colour to white
 					outverts[index].color = SColor(255,255,255,255);
 				float alpha;
 				if(mesh->GetAlphaVertex(f->alpha[j],alpha))
 					outverts[index].color.setAlpha(alpha);
 				outverts[index].tcoord1 = vector2d(mesh->GetTexVertex(f->texCoord[j]));
 				outverts[index].tcoord2 = vector2d(mesh->GetMapVertex(MAPCHANNEL_2,mapface.t[j]));
 				outverts[index].vertindex = f->vert[j];
 				index++;
 			}
 			matid_counter++;
 		}
 	}
 }

this is the function i use to collect all the geometry info of a particular material id from a max mesh, mesh is an IGameMesh* and tm is the inverse tranform of the object so the tangent and binormal are in local space. The Initial outverts array is the “worse case” array which is then optimized later.

ok, this is very nice but you are running too, i ask a little example of c# or a step by step example to avoid a lot of incomprehension

So, i read the Lesson7 example found in internet, i compiled this dll and in max work:
http://dl.dropbox.com/u/47659776/ClassLibrary2.rar
and maxscript loading:


   pathdll = @"C:\Documents and Settings\Admin\Desktop\ClassLibrary2.dll"
   clearListener()
   dll = dotnet.loadAssembly pathdll
   esp = dll.createInstance("AutodeskMaxDllDemo.NodeReport")
   showMethods esp
   showProperties esp
   esp.GetReport()
   
and return:
"Node Scene Root
   	Node Box001
   "
   OK

Now:

  1. the Autodesk.Max.dll must be installed in the max root installation folder ?
  2. these dll work for max2011 32 bit, but for all other version of max ?
  3. how can i get the geometry data like yout C++ code ? i want a maxscript new function example :
nodegroups = selection as array
   fout =  fopen "esportmesh.bin" "wb"
   meshdata =  dll.createInstance("GameMesh.meshdata")
   meshdata.getdata nodegroups
   meshdata.writetofile fout
   fclose fout.

we must resolve this question before continuing, for my purpose i need only some basic informations with c# code:
A) Pass a node , editmesh, editpoly as function parameter
B) Use the corresponding maxscript function like getVerts , getFace , ecc…
C) Use the corresponding maxscript modifier to get the Edit_Normal data, Skin data ecc…

:buttrock:

and an off-topic question: why maxscipt lock the dll file ? i’m try to delete the ClassLibrary2.dll but is running in max, i write in maxscript “gc light:on” (i use it to kill some file not correctly closed) but nothing , so i unkock it with Unlocker.exe but nothing…
I must close max every time i compiling a new dll ?

2 Replies
 lo1
(@lo1)
Joined: 1 year ago

Posts: 0

instead of dotnet.loadassembly path use

(dotnetclass "System.Reflection.Assembly").Load ((dotnetclass "System.IO.File").ReadAllBytes path)
(@kickflipkid687)
Joined: 1 year ago

Posts: 0

Somewhat off topic, I tried this again, and I can load the reflection just fine from what I can tell, but when I go to create and Instance, it returns undefined.

Im calling my namespace and form1 like I do with my normal loadassembly?

 
wee = dll.CreateInstance( "turboTools.ObjectPlacer.form1")

Thanks, i will try…
After 1h of test i found finally a interessant function to work with max nodes:


 		public static String GetNodeName(uint handle)
 		{
 			IGlobal Global = Autodesk.Max.GlobalInterface.Instance;
 			IInterface13 Interface = Global.COREInterface13;
 			IINode theNode = Interface.GetINodeByHandle(handle);
 			return theNode.Name;
 		}

thanks, now i can delete the dll witout close max

according with Max SDK i tried to get the IMesh from a IINode, but i can’t undestand the ConvertToType parameters… why don’t exist a SDK documents in C# ???:bounce:

		public static String GetTriMeshFromNode(uint handle)
		{
			int t = 0;
			IGlobal Global = Autodesk.Max.GlobalInterface.Instance;
			IINode node = Global.COREInterface13.GetINodeByHandle(handle);
			
			IObject obj = node.EvalWorldState(0,true).Obj;

			if (node.ObjectRef.SuperClassID != SClass_ID.Geomobject) return ("SuperClass : " + node.ObjectRef.SuperClassID.ToString() + " not valid");

			IMesh mesh = obj.ConvertToType(t, IClass_ID ?!?!?!?!?);

			return mesh.GetVert(0).ToString() ;

		}

you found it in fn get_method1 in geometry_class.ms but:

i’m trying to translate the Max SDK C++ example into C# code without success… in internet ( http://www.ephere.com/autodesk/max/ ) where are some little fragments of source code or, always, an plugin extension what i can do the same thing in maxscript… but nothing else.

The Topic question is this:
“Someone can write with C# an example to use a function similar to maxscript’s function with which get the maxscript’s parameters (example nodes, point3 ,mesh, materiale ecc…) witout plugin or similar class extension?

the C# source code what i did work only with some “System” value like “Int32”, “String”, “Short” ecc… or conversion do into maxscritp example:
BytesArray = dotnet.ValueToDotNetObject #(1,2,3,4,5,6,7,8,9,…) (dotNetClass “System.Byte[]”)

I see axample the “15. From C++ to Maxscript and vice versa” of “3DSMAX_SDK_DavidLanier.pdf”

So what exactly is the problem with using the C++ SDK documentation? The C# wrapper is not going to be different from that with only a few minor exceptions. I guess the bottom-line is that the SDK is very convoluted and difficult to get in to, regardless of whether you’re using C++ or C#. The core concepts will be quite easy and straightforward, but there are a lot of things around a plugin which you’ll have to get exactly right to make it work.

As for making a gup that exposes functions to maxscript: the David Lanier book is a little bit outdated in that respect. It will be easier to do this using function publishing. That is a reasonably well documented topic in the SDK documentation too.

exemple: can you made in C# the example found in “15. From C++ to Maxscript and vice versa” ?


#include "Maxscrpt\Maxscrpt.h"
#include "maxscrpt\Strings.h"
#include "maxscrpt\arrays.h"
#include "maxscrpt
umbers.h"
#include "maxscrpt\maxobj.h"
#include "maxscrpt\definsfn.h"
def_visible_primitive(MyFunction, "MyFunction" );
Value* MyFunction_cf(Value** arg_list, int count)
{
return &false_value ; //return the Maxscript false value
}

i have tried to compile a c++ dll with maxsdk but don’t work, there are a lot of error during compiling in Maxscrpt.h…, and 3dsPluginWizard in Visual Studio express give me a “Access denied” ??? with c# and Autodesk.max.dll i resolve a lot of issue but i can’t understand now traslate the sdk documentation… why is so difficult ???

this is the only thing what work:


using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.Max;

namespace ClassLibrary
{
	public class MyClass
	{
		//some test
		public String GetNodeName(uint handle)
		{
			IGlobal global = Autodesk.Max.GlobalInterface.Instance;
			IINode node = global.COREInterface13.GetINodeByHandle(handle);
			return node.Name;
		}
		public int GetTimeValue()
		{
			IGlobal global = Autodesk.Max.GlobalInterface.Instance;
			int t = global.COREInterface13.Time;
			global.TheListener.EditStream.Printf(t.ToString() + "
", null);
			return t;
		}
	}
}

Also with Max.NET tutorials don’t work nothing… compiled the test.dll, put into plugins folder, load with


 mytestfn = (dotNetObject "MyProject.MyPlugin").MyTestFunction
 mytestfn $ 1
 

and always – — runtime error , no method found which matched argument list

using System;
 using System.Windows.Forms;
 using System.ComponentModel;
 using System.Collections.Generic;
 using System.Data;
 using System.Text;
 using Autodesk.Max;
 
 namespace MyProject
 {
 	public class MyPlugin : IPlugin
 	{
 		/* into maxscript write this to instanciate the function
 		 * mytestfn = (dotNetObject "MyProject.MyPlugin").MyTestFunction
 		*/
 		public void Cleanup() {}
 		public void Initialize(IGlobal global, ISynchronizeInvoke sync) {}
 		public void MyTestFunction(IValue val, int count)
 		{
 			MessageBox.Show("Didn't work");
 		}
 	}
 }

Now can i pass a **** parameters ??? i test all possible parameters…

 lo1

Is the casing correct?

Page 2 / 3