Attach two mesh in c# api

elpie89
Advocate
Advocate

Attach two mesh in c# api

elpie89
Advocate
Advocate

Hi all,

I have to attach two mesh and to do it I have to use the .Net API.

Every time I need to find something in the c# API I'm completely lost.

Can I have some help?

Thanks

 

0 Likes
Reply
Accepted solutions (1)
1,219 Views
14 Replies
Replies (14)

istan
Advisor
Advisor

I would write a MXS and call it from C# with ExecuteMAXScript()..

0 Likes

elpie89
Advocate
Advocate

I need to add this feature on the BabylonExporter unfortunately

https://github.com/BabylonJS/Exporters

I need to do it in a proper way or they will never accept the pull request

0 Likes

istan
Advisor
Advisor

So what's the problem to pass a string which is holding the MXS code to a C# function? You'll have to have 3dsmax running anyway..

0 Likes

elpie89
Advocate
Advocate

Sorry I already had this discussion with someone else, and make me completely upset.

It is not a big priority for me right now, if I want to do it fast I will do it as you said.

But calling max script is a really dirty solution, there is no way to maintain and verify that string in the long term.

 

0 Likes

istan
Advisor
Advisor

I leave it up to you. It was just a suggestion. IMHO maintaining a MXS file is more simple than with C#. E.g. no need to compile against a certain Max Version, no VS debugging necessary, simple interactive development, ..

0 Likes

Anonymous
Not applicable
Accepted solution

You have to use the epi, Editable Poly interface to do that.

 

To do that, get the node, the ref object, cast it to polyobject then get the interface EPoly. The EPoly interface has the attach method which you can use to attach multiple objects together.

Anonymous
Not applicable

elpie89
Advocate
Advocate

How do you do the conversion?

IEPoly epoly = (IEPoly)myObject.GetInterface( EPOLY13_INTERFACE );

 EPOLY13_INTERFACE does not exist.

0 Likes

Anonymous
Not applicable

 

class EPolyInterface
{
    private static readonly IGlobal Global = GlobalInterface.Instance;
    public static readonly IInterface_ID EditablePolyInterfaceID = Global.Interface_ID.Create(0x092779, 0x634020);
}

 

 

0 Likes

elpie89
Advocate
Advocate

I'm trying to do what you say and I get the EditablePoly Interface without problem, thanks to you.

bu this cast should work, instead epoly is always null

What am I missing?

 

IEPoly epoly = (IEPoly)mNode.GetInterface(EPolyInterface.EditablePolyInterfaceID);

0 Likes

elpie89
Advocate
Advocate

So this actually works

IEPoly epoly = (IEPoly)mNode.ActualINode.ObjectRef.GetInterface( Loader.EditablePoly);

Before to do this I need to convert the mesh in a Editable Poly

How can I do it?

Thanks

0 Likes

Anonymous
Not applicable

For the MNMesh class, there are two methods, which can convert your object to an MNMesh or bact to a Mesh object.

These are the two methods:

 

IMesh m = Global.Mesh;
IMNMesh mn = Global.MNMesh;
mn.OutToTri(m);
mn.SetFromTri(m);
0 Likes

Anonymous
Not applicable

But if you have a Mesh object (Editable Mesh), then you can add one mesh object to the other one since the IMesh has an Add method.

 

IMesh mesh1 = Global.IMesh.Create();
IMesh mesh2 = Global.IMesh.Create();

mesh1.Add(mesh2);

And in fact: Doing operations on a mesh object is almost always faster then doing the same on an Editable Poly object. So first do your job first on a Mesh object, then convert it to an EditablePoly object.

0 Likes

elpie89
Advocate
Advocate

So thanks again, I'm doing some progress understanding how does it work under the hood

But this has still no sense for me

How you see in the watch section seems like the add function doesn't work, or probably I' m missing something else

I'm doing this on a simple teapot

 

Thanks again for your patient

Capture.JPG

0 Likes