Generating splines between particle positions

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

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Anubis's picture

Not so clear...

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).

my recent MAXScripts RSS (archive here)

W DIGITAL's picture

hi anubis, i want to make a

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

Anubis's picture

There you go...

-- 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 

my recent MAXScripts RSS (archive here)

W DIGITAL's picture

where do u live i will gladly

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
)

Anubis's picture

I'm from Bulgaria

"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

my recent MAXScripts RSS (archive here)

W DIGITAL's picture

ok forget about the

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

???

Anubis's picture

Are you sure?

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 !

my recent MAXScripts RSS (archive here)

W DIGITAL's picture

You really amaze me too. I

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's picture

i have just tried at home,

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's picture

Ok, man, I believe you it can

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) :)

my recent MAXScripts RSS (archive here)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.