SDK MaxScript Function Publishing

SDK MaxScript Function Publishing

MehdiZangenehBar
Advocate Advocate
4,294 Views
12 Replies
Message 1 of 13

SDK MaxScript Function Publishing

MehdiZangenehBar
Advocate
Advocate

I just want to recreate InterpCurve3D in c++ and publish it to the MaxScript. this is the c# version:

using Autodesk.Max;

namespace MyProject
{
    public static class MyClass
    {
        static IGlobal g = GlobalInterface.Instance;
        static IInterface14 i = g.COREInterface14;
        public static IPoint3 InterpCurve3D(uint handle,float param)
        {
            IINode node = i.GetINodeByHandle(handle);
            IObject obj = node.EvalWorldState(g.COREInterface.Time, true).Obj;
            ISplineShape shape = obj as ISplineShape;
            return shape.InterpCurve3D(0, 0, param, 0);
        }
    }
}

and this is the c++ version that I'm trying to create:

#include <maxscript/maxscript.h>
#include <maxscript/macros/define_instantiation_functions.h>
#include <maxscript/foundation/numbers.h>

def_visible_primitive(SampleFunction, "SampleFunction");
Value*
SampleFunction_cf(Value** arg_list, int count)
{
	INode* node = arg_list[0]->to_node;
	float param = arg_list[0]->to_float;
	ReferenceTarget* ref = node->GetObjectRef();
	TimeValue t = GetCOREInterface()->GetTime();
	ObjectState os = node->EvalWorldState(t);
	ShapeObject* spline = (ShapeObject*)os.obj;
	Point3 result = spline->InterpCurve3D(t,1,param,0);
}

In "IntervalArray" example, I saw return_value_tls for returning value, but actually I don't know how I can use it. I'm using VS 2017, Max 2018

 

0 Likes
Accepted solutions (4)
4,295 Views
12 Replies
Replies (12)
Message 2 of 13

istan
Advisor
Advisor
Accepted solution
return new Point3Value(result );

pretty simple..

0 Likes
Message 3 of 13

MehdiZangenehBar
Advocate
Advocate

Not working...

Point3Value >> expected a type specifier

 

0 Likes
Message 4 of 13

istan
Advisor
Advisor

3dmath.h included?

0 Likes
Message 5 of 13

MehdiZangenehBar
Advocate
Advocate

Now works, Thank You. but I still got errors on build. this is my code:

#include <maxscript/maxscript.h>
#include <maxscript/macros/define_instantiation_functions.h>
#include <maxscript/foundation/3dmath.h>

def_visible_primitive(SampleFunction, "SampleFunction");
Value*
SampleFunction_cf(Value** arg_list, int count)
{
	INode* node = arg_list[0]->to_node;
	float param = arg_list[0]->to_float;
	ReferenceTarget* ref = node->GetObjectRef();
	TimeValue t = GetCOREInterface()->GetTime();
	ObjectState os = node->EvalWorldState(t);
	ShapeObject* spline = (ShapeObject*)os.obj;
	Point3 result = spline->InterpCurve3D(t,1,param,0);
	return new Point3Value(result);
}

Errors:

qualified name is not allowed in member declaration

0 Likes
Message 6 of 13

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

 

	INode* node = arg_list[0]->to_node();
	float param = arg_list[1]->to_float();

 

 

0 Likes
Message 7 of 13

MehdiZangenehBar
Advocate
Advocate

Finally I build the code :), Thank You!

0 Likes
Message 8 of 13

MehdiZangenehBar
Advocate
Advocate

I'm new to c++ and I have some beginner questions:

Why I should use Point3Value instead of Point3?

Why IntervalArray used return_value_tls instead of return?

0 Likes
Message 9 of 13

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

#1 every published function has to return MXS Value... Point3Value is a wrapper for c++ SDK Point3 

 

#2 return_value_tls is special macros to return mxs value and free allocated for local values memory. in your case you don't have to do it   

0 Likes
Message 10 of 13

istan
Advisor
Advisor

As you wrote you are a C++ beginner: Honestly, just a tip: I would not start learning C++ by writing plugins for 3dsmax.

0 Likes
Message 11 of 13

MehdiZangenehBar
Advocate
Advocate

You right, I should learn basic of C++ first, But actually at the moment I don't want to work on large projects, I just want to expose some necessary functions to MaxScript. So this challenges will encourage me to learn C++ and helps me to understand what I should learn first.

0 Likes
Message 12 of 13

MehdiZangenehBar
Advocate
Advocate

When I move the line

#include <maxscript/foundation/3dmath.h>

Before

#include <maxscript/macros/define_instantiation_functions.h>

My function in MaxScript will be undefined. So my question is include priority matters?

0 Likes
Message 13 of 13

MehdiZangenehBar
Advocate
Advocate
Accepted solution

I'm so exited! it works very well so far:

#include <maxscript/maxscript.h>
#include <maxscript/foundation/3dmath.h>
#include <maxscript/macros/define_instantiation_functions.h>

def_visible_primitive(ShapeInterp, "ShapeInterp");
Value* ShapeInterp_cf(Value **arg_list, int count)
{
	INode* node = arg_list[0]->to_node();
	int curveIndex = arg_list[1]->to_int();
	float percent = arg_list[2]->to_float();
	int type = arg_list[3]->to_int();
	TimeValue t = GetCOREInterface()->GetTime();
	ShapeObject* shape = (ShapeObject*)node->EvalWorldState(t).obj;
	Point3 result = shape->InterpCurve3D(t, curveIndex-1, percent/(float)100,type)*node->GetObjectTM(t);
	return new Point3Value(result);
}

Compare to the Max version, has great benefits:

  1. Works on any shape not only splines.
  2. Works at WorldState (Max version only works on base object not modifiers).
  3. It's not completed yet, but so far works faster(1.6 times) than default version.

Next I want to add argument cheking and default values.