PDA

View Full Version : Maxscript Mesh Duplication?


Okt
03-13-2009, 04:22 AM
It might just be that I'm not totally thinking straight it's 4am, however I'm working on some scripts for a project and was wondering if anyone knows how I could lets say duplicate a mesh in my max file to a new location in the same scene. I have a mesh in my file called "box01" and an array of x,y,z coords. I'd like to be able to duplicate this mesh and move it to a location based on one of the elements in the array.

Coords are returned as [x,y,z]

Mesh names aren't important because I'm attaching them all to a single mesh before exporting it all.

Thanks

jerry
03-13-2009, 05:26 AM
<bool>maxOps.CloneNodes <&node array>nodes offset:<point3> expandHierarchy:<boolean> cloneType:<enum> actualNodeList:<node array> newNodes:<node array>

I think this function should do the trick, for more info look in the help as always :) Found this by using the listener, it actually is helpfull sometimes :P

I hope this was what you were looking for.

renderhjs
03-13-2009, 07:40 AM
more complete info can be found here:
http://www.kxcad.net/autodesk/Autodesk_MAXScript_Reference_9/interface_maxops.htm

search on that page for 'CloneNodes'

example code:
--Clone the source.
result = #()
--Instanced copy.
maxOps.cloneNodes object_to_clone_here offset:[0,0,0] expandedHierarchy:true cloneType:#instance actualNodeList:#() newNodes:&result
the_result = result[1]
http://www.3dbuzz.com/vbforum/showthread.php?t=86499

Mark Dygert
03-13-2009, 08:16 AM
http://www.neilblevins.com/soulburnscripts/soulburnscripts.htm

Have you checked out Neil Blevins Object Replacer script? Probably does what you need it to, if not could have some handy insight.

SyncViewS
03-13-2009, 08:48 AM
Hi Okt,
here is a function doing the job. Works with Editable Poly and Mesh. Gets an object and an array of Point3 and clones the source to specified positions, then attaches them to the source.

You may want to look to this thread (http://forums.cgsociety.org/showthread.php?f=98&t=635477) discussing how to speed up attachment of a large number of objects.

function cloneNodesToPos oSample ap3Pos =
(
if ( ( ((classOf oSample) == Editable_Poly)
or ((classOf oSample) == Editable_Mesh) )
and ((classOf ap3Pos) == Array) ) then
(
local iNumClones = ap3Pos.count
local aoTempClone = #()

local aoClones = #()

with redraw off
(
for i = 1 to iNumClones do
(
maxOps.CloneNodes oSample offset:(ap3Pos[i] - oSample.pos) expandHierarchy:false cloneType:#copy newNodes:&aoTempClone
aoClones[i] = aoTempClone[1]
)

if ((classOf oSample) == Editable_Poly) then
for item in aoClones do
polyop.attach oSample item
else if ((classOf oSample) == Editable_Mesh) then
for item in aoClones do
meshop.attach oSample item
)
)
else
(
throw "Wrong input in function cloneNodesToPos()"
)
)

(
aPos = #()

for i = 1 to 10 do
aPos[i] = (random [-100, -100, -100] [100, 100, 100])

EPolySample = convertToPoly(Torus())
cloneNodesToPos EPolySample aPos

for i = 1 to 10 do
aPos[i] = (random [-100, -100, -100] [100, 100, 100])

EMeshSample = convertToMesh(Sphere())
cloneNodesToPos EMeshSample aPos
)

Mark Dygert
03-13-2009, 09:01 AM
Wow, or just have the man that knows how to get things done, step in out of left field and save the day! NICE work SyncViewS! Fast too!

/saved =P

SyncViewS
03-13-2009, 09:21 AM
Hey Vig thanks, it's just a little function. I like coding snippets here and there when got the chance. Some of them may eventually grow into more complex scripts.

Okt
03-14-2009, 10:35 PM
Wow guys thanks, the maxOps.CloneNodes function was what I was looking for.

@SyncViewS, thanks for the function, unfortunately for what I'm applying the functionality to it isn't really what I need. But seeing how to structure the resulting array and all that was a big help.

I'm writing a script which takes in all the gameplay telemetry from our student game project and turning it into a visual representation our level designers can toss into their maps in UnrealEd to get a better idea of the player path and player's use of our mechanics. I'll be posting in a few days to get some help turning it into a lean mean script.

Basically I get a log file from the game which after being parsed and reformatted by a simple perl script looks something like this:

LEVELSTART&
PLAYERSPAWN&
102092.01,3741.62,-64822.92,HEAVY&
102092.02,3741.63,-64964.61,HEAVY&
102092.05,3741.67,-65389.59,HEAVY&
CAMERARESET&
102092.06,3741.70,-66097.70,LIGHT&
102092.10,3741.71,-66524.59,LIGHT&
102092.09,3741.72,-66666.93,LIGHT&
PLAYERDEATH&
...


102092.01,3741.62,-64822.92,HEAVY&, this is basically the player's x,y,z, and state. Our game has three states, HEAVY, LIGHT, and NORMAL. it just allows us to see where the player is switching between the states.

LEVELSTART&, PLAYERSPAWN&, CAMERARESET&, PLAYERDEATH&, and a few others are simply events which occur.

So what I do is create a new spline and add knots at the player location every line. Every time the state changes I start a new spline with a new materialID. (This allows for different colouring in the game version) Also there is a set of simple geometry which relates to the different states and all the different events. These get placed when the event happens at the last known player location.

Being a student and all I'd be curious to know how much of this kind of thing actually gets done during the production stage of a game being developed by industry professionals.

Cheers all!
-Evan