PDA

View Full Version : script materials


Jacobborsting
10-16-2008, 03:06 PM
Hi,

I'm trying to control 40 boxes using pflow. I've set up a birthscript to spawn a particle per box and set the particles shape to be the same as the box.

All of my boxes have different materials assigned to them. Is it possible to assign the same material to the particle as the referencebox? So that the 40 particles has the same material as the corresponding box, using script?

The only way I know how to do that is by making a multisub with the 40 different materials and match the particles ID so they match.

It would be great if I could do something like this
pCont.particleShape = boxesArray[i].mesh
pCont.particleMaterial = boxesArray[i].material
:p

msmith81
05-21-2009, 05:00 PM
It would be great if I could do something like this
pCont.particleShape = boxesArray[i].mesh
pCont.particleMaterial = boxesArray[i].material
:p

Hi, I was just trying to do this exact same thing and I would be very interested if anyone had a solution.

Piflik
05-21-2009, 05:33 PM
Since you already have the boxes, you can use a Script Operator to bake the motion of the Particles into the boxes. that way you don't need to apply the Materials to the Particles.

On channels used pCont do
(
pCont.useTM = true
pCont.useTime = true
)

On init pCont do
(
global BoxArr = $Box* as array
)

On proceed pCont do
(
count = pCont.NumParticles()
for i in 1 to count do
(
pCont.particleIndex = i
at time pCont.particleTime with animate on
(
BoxArr[pCont.particleID].Transform = pCont.particleTM
)
)

)
on release pCont do
(
)

(Be advised that this script bakes the animation into keyframes. When you load it into a Scrtipt Operator make sure that you're at frame 0 and turned of 'realtime' and 'loop' in the Time Configuration Dialog. Then let the animation run once and turn the Particle System off afterwards.)

msmith81
05-21-2009, 05:56 PM
thanks Piflik! That's a clever work around and should do the trick.:thumbsup: I wonder though why the material property of the particles would not be exposed directly through scripting, it seems like most other properties are.

Bobo
05-21-2009, 07:34 PM
thanks Piflik! That's a clever work around and should do the trick.:thumbsup: I wonder though why the material property of the particles would not be exposed directly through scripting, it seems like most other properties are.

There is no such property.
PFlow takes a bunch of different meshes, one per particle. A particle mesh can have multiple MatIDs. PFlow has to provide the Renderer with a SINGLE mesh containing ALL meshes combined, each still showing its own sub-materials. So it builds a MultiMaterial internally with the Materials from Shapes or Material operators and the shape Material IDs combined (similar to how you get new MatIDs when you attach multiple meshes in Editable Mesh).
So PFlow does MatID manipulations and creates a single Multi-Material out of all materials in the flow to pass to the renderer, and thus the only thing you can do in a Script Operator is manipulate the Material IDs.

msmith81
05-21-2009, 07:56 PM
wow, thanks Bobo that makes perfect sense to me now! You are always around to provide such valuable insight. Thank you!

CGTalk Moderation
05-21-2009, 07:56 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.