ScriptSpot

Forum topic · Scripts Wanted

Generating splines between particle positions

By W DIGITAL · 2010-02-14

Description

Hi, there are scripts which generate splines of particle paths,
but how do i generate a spline between particle positions?

making a spline out of one frame of particle positions?

here is some starting information we could use, i just dont know how to assemble it:

--------------------------------Creating shapes-----------------------------
for i in 1 to numParts do
(
newShp = splineShape()
addNewSpline newShp
newShp.name = (shNm + i as string)
allShps += #(newShp)
)--end For
-------------------Adding Knots to Splines at specified intervals-------------
for t in fStrt to (fEnd/incr) do-- the "to" number here defines the multiplier or total number of knots
(
sliderTime = (t * incr)--sets the sliderTime multiplied by above number
for i in 1 to numParts do
(
pf.particleIndex = i
pId = pf.particleID
if pId != 0 then
(
pfShp = execute ("$'" + shNm + pId as string + "'")
addKnot pfShp 1 #smooth #curve pf.particlePosition
)--End If
)
)--End For

guess we need to create a spline by adding a knot for each pf.particleID at its pf.particlePosition (in one frame)
-pf.particleIndex = i
-pId = pf.particleID
-addKnot pfShp 1 #smooth #curve pf.particlePosition

*********************
i want to convert each particle into a spline knot so i can connect them anyway i want

Comments (14)

Not so clear...

Anubis · 2010-02-15

Hi Ian, I received your mail, but still not clear to me what you ask. I see so this scripts is too limited, it required all particles to start from [0,0,0] position. N/M, the script has increment option, so if set it to 1 it will create knot (on particle pos) on every frame. If something else you try to achieve, then pleace describe it with more details (and/or pictures).

W DIGITAL · 2010-02-15

hi anubis,
i want to make a spline knot for each particle position, so i can connect them and make my own individual spline shape,

(but not one spline per particle, a knot per frame, not like that)

One Spline - 33 Knots for 33 Particles

doesnt have to be animated, just create one knot for each particle, that way i have many knots which i can combine,,

maybe the script can even connect the closest knots somehow

There you go...

Anubis · 2010-02-15

-- int. step: select PF_Source
pf = $ -- assign to var.
posArray = #() -- where to collect Point3 val's
range = #(5, 8) -- define range
-- step 1: collect particles position
for t = range[1] to range[2] do
(
	sliderTime = t
	count = pf.NumParticles()
	temp = for i = 1 to count collect
	(
		pf.particleIndex = i
		pf.particlePosition
	)
	append posArray temp
)
-- step 2: create shapes from posArray
for data in posArray do
(
	sp = splineShape()
	addnewSpline sp
	for k in data do
	(
		addKnot sp 1 #smooth #curve k
	)
	updateShape sp
)
-- step 3: treat me with beer :D 

W DIGITAL · 2010-02-16

where do u live i will gladly buy u beer :)

a few questions:

1) unfortunately i cannot edit this spline, even when i put an EditSpline on it?
is it because it does not have a name?

2) do you know how i can connect the spline knots in a different way, it is connecting them by particleID, is there a way to randomize the IDs before making the spline? (or after?)

i found a script which has some random parameters, maybe we could randomize the particle IDs after they have been collected?
--------------------------------------------------------
m = instance s_objs[random 1 s_objs.count]

m.scale *= (random 1 1)

Rotate m (angleaxis (random 0 4) [0,0,1])
----------------------------------------------------------------

THanks alREADY ALOT!
i will try to make it up to you :)

i have tried to put your code in the other script, of course that doesnt work :) / no "get" function for undefined

*********************************************************************
macroScript PFSplnr category:"phizikl" toolTip:"PF Position Spliner"
(
fltr_PFSplnr = newRolloutFloater "PF Position Spliner" 170 300
rollout rollout_PFSplnr "PF Position Spliner" width:160 height:280
(
button btn_CrtSpln "Create Splines" pos:[30,200] width:100 height:32
button btn_PkSrc "Pick PF Source" pos:[30,16] width:96 height:32
label lbl1 "Frame Range" pos:[40,56] width:68 height:16
spinner spn_FStrt "" pos:[80,72] width:60 height:16 range:[-9999,9999,0] type:#integer
spinner spn_FEnd "" pos:[80,96] width:60 height:16 range:[-9999,9999,30] type:#integer
spinner spn_Incr "" pos:[80,128] width:60 height:16 range:[1,9999,5] type:#integer
label lbl5 "Increment" pos:[24,128] width:48 height:16
editText edt_Name "" pos:[24,168] width:112 height:16 text:"PF-Shape_"
label lbl7 "Spline Name Base" pos:[40,152] width:96 height:16
label lbl8 "From:" pos:[24,72] width:32 height:16
label lbl9 "To:" pos:[24,96] width:32 height:16

global shNm = "PF-Shape_"
global fStrt = 0
global fEnd = 30
global incr = 5
on btn_PkSrc pressed do
(
fn pfFilt flt = (classOf flt == PF_Source)
global pf = pickObject message:"Pick PF Source...." filter:pfFilt
btn_PkSrc.caption = pf.name
)--End btn_PkSrc
on spn_FStrt changed stValue do (global fStrt = stValue)
on spn_FEnd changed eValue do (global fEnd = eValue)
on spn_Incr changed sIState do (global incr = sIState)
on edt_Name changed eNmState do (global shNm = eNmState)
on btn_CrtSpln pressed do

posArray = #() -- where to collect Point3 val's
range = #(30, 30) -- define range

(
allShps = #()
i2 = 1
pTest = false

--Collect ParticlePosition

for t = range[1] to range[2] do
(
sliderTime = t
count = pf.NumParticles()
temp = for i = 1 to count collect
(
pf.particleIndex = i
pf.particlePosition
)
append posArray temp
)
--Creating shapes
(
newShp = splineShape()
addNewSpline newShp
newShp.name = (shNm + i as string)
allShps += #(newShp)

) --Adding Knots to Splines at specified intervals
for k in data do
(
addKnot newShp 1 #smooth #curve k

)--End For

select allShps
updateShape $
)--End Btn
on rollout_PFSplnr open do
(
)

)
addRollout rollout_PFSplnr fltr_PFSplnr
)

I'm from Bulgaria

Anubis · 2010-02-16

"where do u live i will gladly buy u beer :)"

- Hehe, am live in Sofia, Bulgaria. The beer is a joke
(but I can invoice paypal mail, of course, :) ), N/M.

About your questions:

1) No problem to edit generated splines. When they created w/o assign name Max auto-name them as $Shape01, Shape02, ... and so on.

2) addKnot method is auto-connect the knots like you draw the spline on screen. And what about particleID? They are random :) in my code I collect particle position, so you can directly play/experiment with randomles tricks using this data, i.e. posArray. It's a multiarray, i.e. each item is also array and the item itself keep Point3 (part. pos.). For example if your start range is to say 10 and you have 30 particles in this frame (10f) then your first item (posArray[1]) will content all 30 position data of this particles.

3) You need to learn more about rollouts and MaxScript itself (as I see) to can join one peace of code into other ;) In this case I see no sense to mess 2 completed and different scripts in one. Even more advanced coders (I saw) write bugest and slow running tools when they try to build something too complex in one script.

So, learn step by step, write working snippets, do your duty job quikly, and then come free time - write a rollouts ui, tools, macros...

Cheers
Anubis

W DIGITAL · 2010-02-16

ok forget about the rollout

the created splines dont have names and i cannot put any modifier on it
like edit spline
it doesnt work

???

Are you sure?

Anubis · 2010-02-16

You really amaze me :) Max can't create object without name.

-- example line:
sp = splineShape()
addnewSpline sp
addKnot sp 1 #smooth #curve [0,0,0]
addKnot sp 1 #smooth #curve [20,0,0]
updateShape sp
-- the last line/command is very important !

W DIGITAL · 2010-02-17

You really amaze me too. I tell you things but you dont believe me :)

The spline shape had no name, and i could not modify it.

No joke.

I can gladly send you a screenshot.

The reason I mentioned it, is because It wasnt working! I am no programmer, I dont know maxscript, forgive me for asking how to include name--

but jes, your right, i am just making this all up, to take away your time :)

W DIGITAL · 2010-02-17

i have just tried at home, here the script works and it gives me name

i will try again to reproduce in office, and if so, i send you a screenshot!!

also, you say the IDs are random?

that is totally depends on the particle system, i have particles whicih have a clear hierarchy from 0 to 1000 etc.

so thats why my question was, how can i connect the knots randomly in your script?
how can i randomize the values AFTER it got the IDs from particleflow?

forgive my stupidity anubis, i am just not a programmer, so all your help is appreciated! even if you dont believe me :)

Anubis · 2010-02-17

Ok, man, I believe you it can happen what you describe, but am sure this is not normal. The code i'm wrote is fine :) when Max start to do strange things, just restart it. And you said want help, but never try to learn something. You always ask for "How to" tips (what mean you know something) but actually you ask for "write complete tool for me". This is not the same thinks, right? I have and other job to do. Finally, I reply already on your "how to" questions. Read my post about "posArray" and this time think about. And what do you need to know about randomize ? Even you know this function, its only one: "random var1 var2", where both arguments can be float, integer, color, point3, ... the important is just to be comparable, for example:

random 0 9999
random black white
random [0,0,0] [100,100,100]
-- and so on...

P.S. - "how can i connect the knots randomly in your script?"
- My script done exactly this (the knots are connected randomly) :)

W DIGITAL · 2010-02-17

anubis, what you say i cannot agree with,
i try as much as possible to do it myself, but like i said im not a programmer, its hard for you to imagine there are people that just are not code compatible,
i even looked in the maxscript help for random parameters,
then i tried putting random infront and behind the posArray parameters, of course it didnt work

first of all

1) i dont expect you to write a complete tool for me, i posted my question here for anyone else to help me as well, i wrote you the email because i was thinking maybe its easy for you, im sorry i wrote that email

2)im sorry to say but they are not connected randomly, do you want a screenshot, i can prove it to you, at least that way you dont think i am full of nonsense all the time!!!!!!!!!

Anubis · 2010-02-17

OK, lets fix the terminology first to not become disappointed each other ;) I was use "particleIndex" in the code to collect their position, not "particleID". But lets to say in your case they match (ie particleIndex[1] is the same as particleID[1]). Well, if this is the case, Ok, they are not random.

So, what's next? You'll need additional randomization of collected data (posArray) before create a spline. So just do it using Max random() function. It's only one as I said. The difference is only how you will used it. Even here (in the forum) "random" is discussed in many threads. And yes, they may not concrete binded to the particle position, but this is not important, the "logic behind" is the same.

Also you say - nothing in the help. Nope, everything is there :) Yes, no examples for everything (and never will be), but think yuorself, if is everything already done and writen inside then the sites and forums like this will never exist :)

There is why I say you not make effort to find the way, and "to find the way" for me not means "copy/paste existng code". Also cannot agree with you so you must to be a programmer to work with MaxScript. Em I programmer? LOL

Well, let tell you more about me. I think too so I'm not code compatible person! Yes, I was playing with many languages, most of them scripting, and with most of them just for fun. But... am not go too far (LOL). The words like "script languages are user friendly and they are designed for NOT programmers" alway was sound for me like a joke. But now I can say for sure so this words are TRUE. And the MaxScript use really "humane" code. Think about it as one of the Max features, because it is exactly that. So, without understanding how the Max and it features works no progress coming.

And finally to not say what I'm talk more but help less, I'll ponter you to this topic:
http://www.scriptspot.com/forums/3ds-max/general-scripting/random-object…

But am sure you will ask again how to use the example code posted there, oh, I'll write you an example. So, in above script (posArray) you have 2 steps and you need to insert a new randomize step in between them.

tmpArray = #() -- temp empty array

for data in posArray do
(
    miniArray = #() -- another temp array
    while data.count > 0 do (
        rndIndex = random 1 data.count
        append miniArray data[rndIndex] -- add to miniArray
        deleteItem data rndIndex -- remove it from data
    )
    append tmpArray miniArray -- build multiarray
)

posArray = tmpArray -- last step here
-- now all pos.data is randomized and ready for the next step (spline creation)

Finally, inserting this code after step 1 in above code and tadaaa... what's happen (?) - am done your job. But if you now continue with "ok, but my specific issue is... and I with to make this... like this...", well, you can guess what I'll say, right? I give you enough help support :)

Cheers
Anubis

W DIGITAL · 2010-02-17

yes you have,
and trust me i am very thankful!!!
you are the most helpful person on this site!!! :)

but, since i DO wnat to understand, and not just copy and paste,

how would i have figured out to write all this

tmpArray = #() -- temp empty array

for data in posArray do
(
miniArray = #() -- another temp array
while data.count > 0 do (
rndIndex = random 1 data.count
append miniArray data[rndIndex] -- add to miniArray
deleteItem data rndIndex -- remove it from data
)
append tmpArray miniArray -- build multiarray
)

posArray = tmpArray

where do i find information in the helpfile which helps me write codes like that BY MYSELF????

i really want to learn some essential stuff, so i dont have to ask all the time (i hate to ask :( and i always feel bad for taking up others time, )

Anubis · 2010-02-18

I glad to hear you wish to learn, and don't worry, nothing comes for a day or week of practice. You'll build your own style, step by step, you know :)

Best wishes

Anubis