Notifications
Clear all

[Closed] SDK: Advice on what shoud I port

Hi!
I wrote maxscript, but it works too long for me, so I though about exporting it to C++.
The bad part about it all – Max SDK is not very noob-friendly, so I decided to port as minimum as possible out of it.

Someone familiar with SDK, can please tell, which parts of the script below I can port without nightmare?


obj = $Man 
getFaceC = meshop.getFaceCenter 
cam  = $Camera1
		
		          
				
				f_count = getnumfaces obj
				del_faces = #{}
				del_faces.count = f_count

for i = 1 to f_count do 
	(
		del_faces[i]  =true
	)
				
				for g = 1 to 2 do (
				execute("cam = $Camera"+(g as string))
				viewport.setCamera cam
				completeRedraw()
				v_pos = (Inverse(getViewTM())).row4
				
				for i = 1 to f_count do (
					f_pos = getFaceC obj i
					dir = normalize (f_pos - v_pos)
					exampleray = ray v_pos dir
					result = intersectRayScene exampleray
					if result.count <=1 then del_faces[i]  =false
					)    
				)

				
				meshop.deleteFaces obj del_faces delIsoVerts: true   

Like, I have no idea how to get object by name from within SDK (obj = $Man ),
but I guess I don’t need it at all, if I keep it on maxscript side.

And stuff like this function – ‘intersectRayScene ’ – SDK has intersectRay as well, will it work faster, even if maxscript has exactly the same function?

4 Replies

you need to decide what sort of plugin to use, modifier, compound object and utility spring to mind as possible candidates. Have a look at whats already available with max and decide which best suits how you would like it to work. have a look how other people attack similar tasks in maxplugins.de. Once you know what plugin type to use start with a plugin of the same type from the sdk samples as a base for the code.

A small aside, just something I noticed in your code:

del_faces = #{}
del_faces.count = f_count

for i = 1 to f_count do 
(
	del_faces[i]  =true
)

is equivalent to:

del_faces = #{1..f_count}

It won’t help performance very much, but it saves a few lines at least.

As for what to make into a plugin, at a glance it seems to me as though the raying is the bottleneck here, right? I assume that this maxscript function just wraps the SDK function, so you might not get a huge speed-up from moving to the SDK there. But you could certainly try it and benchmark, that’s the only way to find out

Thanks for the replies.

I was worried that it is only the wrapper around here too, hmmm, maybe I should rather look for some way to optimize actual logic itself.

Also… Seems like intersectRayScene did not make it into SDK. Oh well. Poor little me :bounce:

Isn’t it this, or some similar method?
virtual BOOL RenderGlobalContext::IntersectWorld ( Ray & ray, int skipID, ISect & hit, ISectList & xplist, int blurFrame = NO_MOTBLUR )
This method takes the specified ray and intersects it with the entire 3ds Max scene.