Notifications
Clear all

[Closed] Integrating maxSDK or C++ applications in maxscript?

Wow
Maxscript seems favored in the matrix calculation.
Let us see on an equal base (with arrays) what it happens.

fn slowTask theVertex theRotMatrix = (
	for i=1 to 12345678 do (
		theVertex[1] = theRotMatrix[1][1]*theVertex[1] + theRotMatrix[1][2]*theVertex[2] + theRotMatrix[1][3]*theVertex[3]
		theVertex[2] = theRotMatrix[2][1]*theVertex[1] + theRotMatrix[2][2]*theVertex[2] + theRotMatrix[2][3]*theVertex[3]
		theVertex[3] = theRotMatrix[3][1]*theVertex[1] + theRotMatrix[3][2]*theVertex[2] + theRotMatrix[3][3]*theVertex[3]
		)	
	)

It is difficult in that case to write a totally symmetric routine.

You have to remember that max SDK has it’s own functions for handling matrices, that probably are very optimized and fast. MaxScript uses the same functions.

I’m afraid that I’m not good enough yet with the max sdk to help you translate it. I have only done a few programs in the sdk and they didn’t work with geometry at all.

In a few months I will be far more prepared to handle these tasks.

However I can explain a few things about efficiency in maxScript and SDK, that is worth thinking about. I’ve done a bit of heavy programs in Matlab which is similar to maxscript with regards to efficiency.

As long as put all the time intense areas into very FEW calls, scripts will be very fast. Probably as fast as if it was written in Max SDK.

The reason is that the calls take time. For example lets say one call in a script takes 0.0001 seconds to do. In c++ this takes practically 0 time (perhaps something like 0.000000001).

Lets also say we are detaching a face on a big object which takes 1 seconds to perform.

In maxScript this would take 1.00001 seconds to run and in the sdk it would take 1 second. As you see there is practically no difference at all. What takes time is to do the Detach, and this is programed in C++.

However If we would do a very big loop gathering data and then do the detach. Say a loop that repeats 100000 times, then it’s very different.

for i=1 to 100000 do –this will take 10sec in maxScript and 0 time in c++
(
–get some data
)
Detach() –this takes 1sec.

In MaxScript this takes 11seconds and in c++ it takes only 1.

The way to avoid the slowness in maxScript here is if the big nasty loop can be done with fewer commands. Perhaps the data can be put in a matrix instead and called with one command. Or of course the big nasty loop can be done in c++ instead and exported into MaxScript like this:

GetAllData() –a c++ function that has been exported into MaxScript. Takes 0.000… time to perform
Detach()–takes 1 sec.

Now we are using maxScript and c++ together and it’s 11 times faster than it would be in maxScript.

The main important thing to realize here is that for many cases the Max SDK doesn’t have to be any faster. It’s also important to note that many things don’t even have to be that fast. If it takes 0.0001 or 0.00000000000001sec to update an object normally doesn’t matter.

Hope that gave some pointers.
/Andreas

Thank you, Andreas

My conclusion is that it is not necessary to use cpp for the whole program.
I prefer to continue to use maxscript for the interface for example and all the fast calculations. But that is advantageous to use cpp just in certain function calls, where maxscript is slow.

I have to have several parameters between cpp and mascript (input and output parameters). To send and receive arrays for example.

That is probably not very complex.

Hi, I havent looked at the new sdk helpfile yet, but I was hoping to see an example for probably a very simple function like:
fn add a b = a+b
and convert that to cpp…
I guess from that example, we might be able to get the basic idea and components in creating functions using the sdk…
(sorry if I’m not much of a help arketip…)

1 Reply
(@f97ao)
Joined: 11 months ago

Posts: 0

I may be able to put together an example like that in a while.

But just so you know, what you just wrote will probably need 5-10 pages of code just to start.

/Andreas

I have to have several parameters between cpp and mascript (input and output parameters). To send and receive arrays for example.

Sending and recieving arrays is very costly, so you would not want to put something like this in a loop. If you do all your arrays in c++ or all in maxscript, either way you can usually pass by reference which avoids making a copy.

f97 is right, the SDK will also have optimized functions. The main reason C++ will be faster is because it is designed for being fast and it provides compiled code, whereas maxscript is interpreted. This means that each maxscript command must first be translated into machine code while it’s running…but the program written in C++ is already provided in machine code.

galagast: I completely agree with you. The ideal would be to have a function like fn add a b written for cpp.

stuh: in fact to send and receive an array by reference (or other values) will be even more convenient for me… and about the structure of arrays ? It is the same in cpp and maxscript ?

EDIT:andreas: 5 to 10 pages of headers not really useful for us, isn’t ?
Is not there any wizzard which generates the code for that automatically?

galagast: I completely agree with you. The ideal would be to have a function like fn add a b written for cpp.

The maxscript addition function is written in c++, so you already have that.

if i want learn C++ , for sdk of max or other 3d software like softimage sdk . is here anybody show me a guide in learning process ? i think it is not necessary to learn whole c++ .

thanks .

1 Reply
(@f97ao)
Joined: 11 months ago

Posts: 0

Seriously, stay away from the max SDK if you are unfamilair with c++.
I would first learn maxScripting, then you quickly learn how to build useful programs.
To program in the sdk will need very serious dedication, there are many things you will have to learn such as windows programming, different libraries and just the main 3ds Max core code (which is extremely big). C++ in itself is the easy part I’m afraid.

/Andreas

Yes you will have to learn all of C++, and probably more. And you should learn as much as possible of C, and probably more. And you should learn the Windows Win32 API, and GDI, and some MFC wouldn’t hurt either.

Chris J.

to learn C++:
The C++ Programming Language by Bjarne Strostrup.(the creator of c++)
Bruce Eckel’s Thinking in C++ http://www.mindview.net

for API programming:
Programming Windows 98 by petzold! MSPress

To learn ASM:
The Art of Assembly Language(AoA) by Randall Hyde!

As far as i remember if you read the SDK help you will find these clues…

or if you have TIME check out AMAZON.com for BOOOOKSSSS…

But this is just a start…C++ and programming is far from scripting.

Page 2 / 2