View Full Version : object pos = particle pos problem
Gravey 09-11-2006, 08:18 AM Hi all
I have a situation where i need objects to move along 'pivot to pivot' with particles. Getting them to move along is fine. There is a simple script in the max help that show you how to do this, also one of allan mckay's tutorials shows this too. The problem is: the none of the objects are actually alligned exactly 'pivot to pivot' with their corresponding particle!
In this situation this is a big issue. If anyone could help me force the objects to behave as i have asked them to, it would be a great help.
Cheers in advance
|
|
davestewart
09-11-2006, 02:16 PM
Hey,
I wrote the following script a while back to lock objects' position / rotation to PFlow particles using scripted controllers. It works for what I want, but if I look very closely at the pivot, the rotation is very slightly off. Is this what you're talking about?
Cheers,
Dave
Gravey
09-12-2006, 12:00 AM
Hi thanks for the reply.
I'm having trouble getting ur script to work, does it support multiple objects ???
I basically have a simple pflow that doesn't give birth until frame 25 and contains a total of 12 particles. The objects I'm trying to constrain are instanced omni lights which i've already created. If instancing is a problem, it would be ok if i had to make them all unique. Also you mensioned the rotations were slightly off, this isnt a problem, i only need the positions to be 100% locked on.
EDIT: And i get this error when trying to select multiple objects at once,
MAXScript Rollout Handler Exception: -- Unknown property: "IScriptCtrl" in Controller:Position_Script <<
also i tried making them unique, didn't work. i guess i'm still missing something
A little more explination on how to use your script would be much appreciated
Thanks
davestewart
09-12-2006, 09:12 AM
Ah, sorry about that.
Yeah - the script was actually written to do just what you're doing... constrain lights to particles.
I'll take a look now with a similar setup to your's. First question though - are you running max 8?
Cheers,
Dave
Gravey
09-12-2006, 09:29 AM
This project requres max7 unfortunately. I have max8 but ultimately the final scene must be in max7. Are there elements of the script that are new to max8 and wont work in max7?
i'm interested in seeing what you come up with
davestewart
09-12-2006, 09:56 AM
Yeah, the new scripted controllers (IScriptCtrl) can use weak references to nodes in the scene, as oposed to the old "depndsOn". If you like I can edit the script so that it works in max 7. Gimme 5 mins...
Gravey
09-12-2006, 10:06 AM
that would be awesom thanks heaps can't wait
davestewart
09-12-2006, 10:40 AM
There you go... bit of an update. Thought I'd add teh scaling option too so now it's a bit more versatile. If you wanted to extend it, you could probbaly bugger about with it and match the light's colors to the particles.
Anyway, enjoy!
Dave
Gravey
09-12-2006, 10:59 AM
thanks for the update but i'm still having the same problem. ie. the position of the lights are still offset from the particle's position. I posted on the orbaz forum and Oleg gave this response:
" The discrepancy in particle/object-light position is due to particle position adjustment in the following integration step. You need to "foresee" the particle position by adding the offset defined by the current particle speed and length of the integration interval. "
Now unfortunatly i'm not too good with maxscript at this current time so i'm not sure how to go about solving this issue. - could you be of further assistance ?
davestewart
09-12-2006, 11:20 AM
Hmmm.... I probably could - but as with most busy people don't have the time! In my head I think I know the maths, but it would take a bit of testing to get it right, and then to integrate it into the tool.
Strange that it doesn't work for you. The position stuff is fine at my end...?
I'm really sorry I can't be of more help!
Cheers anyway,
Dave
Gravey
09-12-2006, 11:39 AM
i understand completely how busy you must be. thanks a bunch for all your help!
is any1 else on the forum able to help me out with this task?
HalfVector
09-12-2006, 02:16 PM
Hi.
I think this should work.
on Proceed pCont do
(
-- Array of objects
global points = $Point* as Array
-- Particle count
count = pCont.numParticles()
-- Integration step for our particle flow node
integrationStep = $PF_Source_01.getIntegrationStep()
-- Speed multiplier
speedMult = integrationStep.ticks
-- Reset objects position
if currentTime >= 0 then points.pos = [0,0,0]
-- Loop through each particle
for i = 1 to count do (
-- Set current particle
pCont.particleIndex = i
-- Calculate the current object location based on the particle position
points[i].pos = pCont.particlePosition + pCont.particleSpeed * speedMult
)
)
Hope it helps.
Gravey
09-13-2006, 12:01 AM
that works perfectly! Many many thanks to you HalfVector! Now if its not too much trouble, would you mind explaining the math and/or reasons behind this code so that i may further my understanding of maxscript ? Most of it is straight forward, its just the integration step part that i'm not sure of. If its too complex, i understand, but it would be the icing on the cake if its not too much trouble!
HalfVector
09-13-2006, 12:39 AM
Well, I'm not sure about this but anyway...
Ok, seems like the position (particlePosition) of the particle in the Proceed method is not the position for the current step but for the previous one, that is, the actual position is not calculated yet (that's the part I'm not sure of!).
So you have to calculate the actual position yourself.
If the physics would be calculated once per-frame, it would be as simple as:
objectPos = pCont.particlePos + pCont.particleSpeed
But keep in mind that PFlow can calculate the "physics" of the particle system more than once per-frame. The number of times it is calculated comes defined by the integration step property. So if the integration step is 1/8 frames, the "physics" will be calculated eight times per frame (once each 0.125 frames or 0.125 * 160 = 20 ticks).
That means that if you have to calculate the position for the next step, you can't just add the speed as we did before. We have to scale the speed depending on the integration step. That's why I get the integration step with the function getIntegrationStep() (returns the integration step in viewport mode if MAX it's no rendering or in render mode otherwise), convert that to ticks and finally, when calculating the actual position, I add the scaled speed.
objectPos = pCont.particlePosition + pCont.particleSpeed * scaledSpeed
Sorry if I've not been clear enough but my english is somewhat terrible!. :)
davestewart
09-13-2006, 07:27 AM
Good work fella
Gravey
09-13-2006, 07:50 AM
thanks again to both of you for the help on this one. I'm only just getting into maxscript now. I mainly want to use it for particle flow.
Does anyone know of any good pflow specific scripting tutorials or dvds even ? I know the cg-academy ones are good but they're not really centered around pflow.
CGTalk Moderation
09-13-2006, 07:50 AM
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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.