Notifications
Clear all

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

Hi,
Lets say i have a scripted application running in max all nicely. Certain parts of this application are quite intensive, involving running long loops and reading/manipulating lots of data.
After optimizing maxscript and making it run as fast as possible, I’m considering rewriting certain portions in c++ perhaps using the maxSDK to speed them up – rather than rewriting the whole application is c++.
I’m just wondering how i could say re-write 1 key function in c++ and then call that function in maxscript, for an equivalent result, just perhaps faster execution, since it will be machine code, not interpreted.
Do i make a dll or something? I’m quite new in this area. Any pointers are welcome.

25 Replies
1 Reply
(@f97ao)
Joined: 11 months ago

Posts: 0

What you need to do is a maxScript Extension.
It works very good to write the time critical functions in c++ and then you call them from MaxScript. So in maxScript you write for example:
“CreateBigObjects 1000” –this will call your own c++ function that generates lots of objects.

You have to install the 3dsMax SDK (it’s normally not installed, you have to select it at the installation). Make sure to look in the manual for MaxScript extensions. There are several examples. They are hard to understand, but I figured them out in a few days so it’s possible. Another tip is to check in the source code that will be available when you install the max SDK. Most plugins for max are extremely big, but especially the smaller ones are possible to understand.

You can also join the Sparks forum on Autodesk homepage, they have discussions about c++ and the SDK.

Hope this points you in the right direction.

/Andreas

Thanks, I do have the SDK installed, though when reading through the reference I didn’t find anything appropriate for me. Now I will look into these MaxScript extensions, seems like what I’m looking for. Thanks.

BTW, does Visual C++ 2005 Express version work with the SDK? I’m thinking the compiler is different and doesnt like some code that’s part of the standard includes in maxSDK. Or I could be doing something wrong…

For example, when compiling a sample, gscript, I get the following error:

include\polyobj.h(109) : error C2065: 'i' : undeclared identifier

And I checked the source of that file, and it’s probably incorrectly using the scope of the ‘i’ variable. Maybe its fine with Visual C++ 7.0, as stated in the software requirements section.

The help file that shipped with the 3ds Max 8 SDK is very good. It really helps new beginners who are newer to Maxscript and newer to C++ coding in the SDK. It is light years ahead of the old help files.

Chris J.

Which saving of time can I hope by using routines C ++ ?

Here is a routine which calculates rotations 3D with maxscript:

fn slowTask theVertex theRotMatrix = (
	for i=1 to 12345678 do (
		theVertex*=theRotMatrix
		)	
	)

(
local theRotMatrix=(quat 2.0 [0,0,1])as matrix3
local theVertex=[11.1,22.2,33.3]
local startTime=timestamp()

slowTask theVertex theRotMatrix

local endTime=timestamp()
format "Processing took % ms
" (endTime-startTime)
)

Can anybody test the speed difference between maxscript and C ++ please ?

EDIT: I don’t have an compiler installed on my pc. I wish at first to have an idea.

[QUOTE=arketip]Which saving of time can I hope by using routines C ++ ?

Can anybody test the speed difference between maxscript and C ++ please ?
[/QUOTE=arketip]

This really depends on what you are doing. Some things are not faster in c++ at all, while some things are enormously much faster.

In general the Autodesk people said that the code is 10-100x faster in C++, but it really depends on what you are doing.
What you want to be careful is if you have to do MANY things in MaxScript. This will always be far slower. Big loops checking for example the position about a vertex will not be fast.

Another thing you need to be careful with is modifying geometry in complex ways. If you mix modifying geometry with big loops you have a BIG problem if it needs to be fast.

Example

A loop that moves a vertex in an Editable_Poly 10000 times. This will in fact be almost 10000 slower in MaxScript than it would be in c++.

However if you move the 10000 vertex points with ONE command in MaxScript then there will be no speed difference. Basically you want to use as few commands as possible in MaxScript, then it can actually be very fast.

/Andreas

Just curious as to how difficult you think it is to use the sdk if you’ve only got a scripting background? I’m still only a beginner in maxscript compared to you guys but a few of the bits I’ve written in maxscript are really intensive (find and replace on geometry objects for example) so c++ may sort that out. A few people have said that c++ is very like maxscript – is this really the case that it’s similar in terms of its structure and language? I find maxscript really easy to work with (aside from trying to figure out how certain badly document commands may work) so is c++ a big jump again?

Cheers,

John

1 Reply
(@f97ao)
Joined: 11 months ago

Posts: 0

It depends on what you want to do and also if you have any previous experience with other programming languages.

But if you think that maxScript is “real easy” then it should be possible.

First I would recommend you to quickly readup on the basics on c++. Check here for example
www.cplusplus.com

If you read most of it you are in a far better position to begin working with the sdk.

If you want to work with interfaces you want to check out these (they show you how to do windows, buttons, getting keyboards presses etc)
http://www.winprog.net/

In the future I hope to write a few tutorials on writing plugins for max, right now I really need to dig deeper into them myself.

So in short. C++ is a big jump for most things, but not impossible.

/Andreas

To be honest I’ve only ever used scripting languages like actionscript (pre 2.0), php, lingo and maxscript so maxscript would be the nearest to a proper language I’d have used – I’ll take a look at those links though. Also a few people were asking in a cg academy thread about doing a bobo like dvd on the max sdk – might be worth a look?

1 Reply
(@f97ao)
Joined: 11 months ago

Posts: 0

Well, give it a shot if you really need the extra power. A dvd for the max SDK would be great. Even if you know c++ quite well it’s not so easy to use the max SDK. I expect to become drastically better in this area pretty soon, since I begin a new job as a MaxScript/Max SDK/C++ developer

/Andreas

I just started wading through the sdk getting started help files last night…having a dvd for max sdk would be pretty cool. I havent finished reading the manual but there doesnt seem to be much explaining how to get started by writing a simple plugin. All the plugins examples I expect to be simple like “sphere” or whatnot are thousands of lines of code…it would be nice to see some hello world type examples!

Hi thanks for the replies

andreas : lets say i have to calculate many 3D operations (vector, matrices) but in memory only.

And nobody can translate my little script in cpp ?

1 Reply
(@stuh505)
Joined: 11 months ago

Posts: 0

Well it’s not just a matter of translating it into cpp, it’s a matter of translating it into the specific classes of the SDK.

I’m just starting to look at the SDK so I can’t write and example using the SDK yet…but I did write a barebones program in C++ to do the equivalent operations as your maxscript program.

You’re not going to believe this…but the C++ time was 37 seconds compared to 23 seconds to run the maxscript…


#include <stdio.h>
#include <time.h>

void main()
{
 float m[] = {0.999391,-0.0348995,0, 0.0348995,0.999391,0, 0,0,1, 0,0,0};
 float v[] = {11.1,22.2,33.3};
 time_t startTime = time (NULL);
 time_t endTime;
 for (int i=0; i < 12345678; i++)
 {
  v[0] = m[0]*v[0] + m[1]*v[1] + m[2]*v[2];
  v[1] = m[3]*v[0] + m[4]*v[1] + m[5]*v[2];
  v[2] = m[6]*v[0] + m[7]*v[1] + m[8]*v[2];
 }
 endTime = time (NULL);
 printf ("seconds: %ld", (endTime-startTime));
 return;
}

Page 1 / 2