0 like 0 dislike
How do I access the position of the base spawner, or the position of any sampler for that matter, in an evolver script? I need the effect to move around when the position of the spawner is moved.

Any help on accessing this data in the evolve script would be helpful, thanks!
by phong (320 points)

1 Answer

1 like 0 dislike
Best answer

you can't use "spawner.something" in evolvers, but there's a trick to recompute it, using the localspace evolver :

1- Create a float3 particle field "SpawnerPosition" with full transform flags.
2- add a localspace evolver, set it to ModeEnter=Current -> ModeLeave=Current, make sure TransformTranslate and TransformRotate are both enabled.
3- create a script evolver _inside_ the localspace evolver, and write:
function void Eval()
    SpawnerPosition = float3(0); // 0,0,0 in the instance local space

now, when the evolve enters the localspace evolver, it will transform all transformable fields (including 'SpawnerPosition') from worldspace to each instance's local space.
the script inside the localspace evolver forces the SpawnerPosition field to the origin (therefore to the origin of the instance)
when the evolve exits the localspace evolver, it will transform all fields back to worldspace, and 'SpawnerPosition' will now contain the instance location in world coordinates.
you can then use that in another script to do whatever it is you need to do.

For samplers, you have access to "SamplerName.position()", "SamplerName.axisUp()", "SamplerName.axisForward()", "SamplerName.axisSide()" that you can use inside the localspace evolver and that allow you to reconstruct the sampler's basis.

by Julien (35.2k points)
Julien, thank you, I couldn't explain back to you how this works, although it does work. The explanation is much appreciated. I'll have to refer back to this explanation a few more times before I get a grip on it. Very helpful!