Quick question about scattering several objects about...

disanti

27-06-2007 01:18:01

I want to scatter some decal mesh around my game's level with the 3ds max scatter tool, and was wondering if it's possible for oFusion to export the instances created by this to the OSM format.

Should I just write a maxscript to emulate the scatter tool, but place mesh instances instead of a compound object?

Thanks.

Lioric

27-06-2007 03:49:14

Depending on the type of object created it might be currently supported (if you could provide a sample scene we can take a look at it)

Or using maxscript to convert them to meshes should be an easy process

disanti

27-06-2007 06:06:47

OK, I made a maxscript to do this for me -- tested it and it works perfectly with oFusion.

I'm going to post the script for anyone else who might want to do this in the future.
utility oFusionScatter "oFusion Scatter"
(
pickButton btnSrc "None" pos:[8,24] width:144 height:24
label lbl1 "Object to scatter:" pos:[8,8] width:144 height:16
label lbl2 "Destination object:" pos:[8,56] width:144 height:16
pickButton btnDest "None" pos:[8,72] width:144 height:24
label lbl3 "Number to scatter:" pos:[8,104] width:96 height:16
spinner spnNum "" pos:[104,104] width:48 height:16 range:[0,1000,0] type:#integer scale:1
label lbl5 "Scale deviation (%):" pos:[8,120] width:96 height:16
spinner spn2 "" pos:[104,120] width:48 height:16 range:[0,1000,0]
button btnScatter "Scatter" pos:[8,144] width:144 height:24

on btnSrc picked obj do
(
if obj != undefined then
(
btnSrc.text = obj.name
)
)
on btnDest picked obj do
(
if obj != undefined then
(
btnDest.text = obj.name
)
)
on btnScatter pressed do
(
mesh = snapshotAsMesh (getNodeByName btnDest.text exact: true ignorecase: false all: false)
scatter = getNodeByName btnSrc.text exact: true ignorecase: false all: false

for i = 0 to (spnNum.value as integer) do
(
j = random 1 mesh.numverts
pos = getVert mesh j
norm = getNormal mesh j

obj = instance scatter dir: norm
obj.name = uniqueName obj.name

obj.pos.x = pos.x
obj.pos.y = pos.y
obj.pos.z = pos.z

scl = [0,0,0] + ( random 0.0 (spn2.value / 100.0) )
if (random 0 1) == 1 do scl = scl * -1
obj.scale = obj.scale + scl
)
)
)

Use it in 3ds max by:
1) Run the maxscript.
2) Under the utilities panel, select MAXScript. From the drop down, select "oFusion Scatter".
3) Pick the object you want to scatter, and the distributive object.
4) Set the number of objects you want scattered.
5) Scale deviation just varies the scale of the instanced geometry.
6) Click the Scatter button and export.

It places the instanced geometry on randomly selected vertices of the mesh, and rotates them to point in the direction of the vertex normal. I recommend resetting the xforms first too.

Lioric

28-06-2007 03:57:47

good job :) I will post this in the new wiki section