PDA

View Full Version : [HELP] Dynamic shape instancer (with script) ?


mattjakob
02-08-2010, 10:43 AM
Hello,
could someone help me fix this script? I think it's pretty handy... it's supposed to help you dynamically create any mesh shape and assign it to any particle.
In this way it's easy to render complex shapes in a particle system, even if the required shapes have different materials.

The idea is very basic: for each particle it creates a snapshot of a template mesh and then applies a TM to the created mesh to match the TM of the particle. To keep track of the particles that have already a mesh assigned Im using a global array.


PROBLEMS:
- (major) it simulated fine in the viewport and when rendered as a single frame but it doesnt render correctly when rendered as a sequence (in the render you only see one mesh, while in the viewport you see the simulation correctly)
- sometimes the reset/cleaning functions don't work properly and have to manually delete the instances created.

SCENE FILE (3DS Max 2010): DynamicMultiplier.zip (http://www.mattjakob.com/DynamicMultiplier.zip)


Thanks

HornBerger
02-08-2010, 06:57 PM
As far as i know (also if my opinion matters) i think in order to get the geometry to render you need to assign keys to the position rotation scale controllers for each geometry instanced as particle and they should contain keyframes storing the information of the transformation matrix (beacuse if you render the particles with shape operator the particles will appear in the render this shows that the particle are there but the geometry objects controllers have no keys containing the transformation data) then again this is just my guess*

however i came up with another solution to the problem, this solution does not involve the use of instance geometry rather i have used the pcont.particle shape property, A multi sub object material and a material static operator and to get the materials to work i have used the pCont.setParticleMtlIndex values so that every 3 particles have 1 material applied to them (which is the material associated with the geometry object which also gets changed after every 3 particles in my case from pyramid to teapot to a box)
[Attached .Max Scene file] hopefully it will help you understand what i mean more clearly and heres the code:

inital experimentation have shown no issues with uvw mapping also i can modify the mesh (checked with a bend modifier) Also Note:** in order to get the particles to render in active time segment i have used the option single mesh under the render option parameter found in the render operator of the pflow_source

on ChannelsUsed pCont do
(
pCont.useTime = true
pCont.useSpeed = true
pcont.usemtlindex = true
pcont.useshape = true
)

on Init pCont do
(

)

on Proceed pCont do
(
count = pCont.NumParticles()
j = 0
theindex = 1
theshape = $pyramid01.mesh
for i = 1 to count do
(
pcont.particleindex = i
if (mod i 3) == 0 do
(
j = j + 1
if j==1 then
(
theshape = $pyramid01.mesh
theindex = 1
)
else if j==2 then
(
theshape = $box01.mesh
theindex = 2
)
else if j==3 then
(
theshape = $teapot01.mesh
theindex = 3
j = 0
)
)
pcont.particleshape = theshape
pcont.setParticleMtlIndex i theindex
)
)

on Release pCont do
(

)

:) cheers!

mattjakob
02-09-2010, 10:20 AM
Thanks for your reply.
I agree with your solution, unfortunately the problem arises when you start attaching nodes.
Because of a hideous bug in pflow the Shape attribute of each particle is not retained throughout the events, hence the particles get all the same shape.
Moreover I couldnt get that approach work with multiple materials (as in shapes made of more that one mesh).

Try this to see what I mean:

http://forums.cgsociety.org/attachment.php?attachmentid=150474&stc=1


Thats why I think the only solution is to algorithmically create a mesh for each particle (snapshot of a selected template mesh) and update the TM attributes with the ones of the particles at each frame. It's fairly easy to implement and runs fast... BUT DOESNT APPEAR IN THE RENDER SEQUENCE (so far).

Does anyone know how to set keyframes via maxscript? Id like to try to bake the animation of the algorithmically generated meshes and see if in this way they get rendered.

Thanks,

JohnnyRandom
02-09-2010, 04:19 PM
I have been thinking about your problem too, and haven't come up with a solution yet.


As for baking flows there are two tools that I know of that work really well...

First is Galagasts (aka Jeff Lim) Tera Flow Event Baker (fourth post)
http://www.orbaz.com/forum/viewtopic.php?t=2068&postdays=0&postorder=asc&start=0
and

then Pflow Baker by Ofer Zelichover
http://www.scriptspot.com/3ds-max/scripts/pflow-baker

I haven't tested them with your scene but anyway to answer to question :)

mattjakob
02-09-2010, 04:33 PM
actually I just managed to solve it :bounce:
Im using the on animate method to bake the objects position. It's a bit rusty but I finally managed to get a sequence to render !!!

HornBerger
02-09-2010, 05:03 PM
Lol, good to know you finally found the solution to the problem :thumbsup:
on animate hey :hmm: (but does that keep the dynamism ? or you get your pflow animation then perform the "baking" (static) ? ) here's my attempt (thought would post it anyways)
for k = 1 to count do
(
unhide themesh[k]
transformArr[1] = (pf_node_current.getParticleTMByID k).position
transformArr[2] = (pf_node_current.getParticleTMByID k).rotation as eulerangles
transformArr[3] = (pf_node_current.getParticleTMByID k).scale*100
for i = 1 to 2 do
(
for j = 1 to 3 do
(

thekey = addnewkey themesh[k].controller[i][j].controller theframe
if i==2 then
(
case j of
(
1 : thekey.value = transformArr[2].x
2 : thekey.value = transformArr[2].y
3 : thekey.value = transformArr[2].z
)
)
else
thekey.value = transformArr[i][j]
)
)
)
the aim of the code is to "bake" but keep the dynamic feature of the pflow alive (for example if you change the rotation or speed or position operators the key frames get modified accordingly )
unfortunately the code is a bit flaw full may be i will fix it some day :shrug:

cheers! :)

mattjakob
02-09-2010, 05:06 PM
yes, it does mantain the dynamism: I inserted the function that copied the TM matrix from the particle to the mesh into an on anim method.

JohnnyRandom
02-09-2010, 05:11 PM
Heh, cool HornBerger, interesting approach :)

CGTalk Moderation
02-09-2010, 05:11 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.