Particle tips ImportAnimations

From PopcornFX
Jump to: navigation, search

For PK-Fx Editor version : v1.4.1 and above
Latest update : v1.9.0
Main page: Particle tutorials


You can import animation tracks into the popcorn editor and use them for various things, amongst which:

  • sample the path to make particles move on it.
  • sample a shape swept along the path.
  • move spawners around in the editor viewport for debugging.


Exporting from the 3D authoring software

First, create an animation, either with a path or with keyframes in your 3d authoring software.
Here, we created a dummy object (the sphere), a spline path, and we constrained the sphere on the spline using 'Motion path' in maya, or 'Path constraint' in 3dsmax:


Maya

Select the object and the path, then go to the "Constrain" menu and select "Motion Paths" > "Attach to Motion Path"


Animation path setup in Maya: Motion path
Larger version available here: AnimPath_Maya_MotionPath.gif


When you scrub the timeline, the object should move along the path:


Animation path in Maya
Larger version available here: AnimPath_Maya.gif


You then need to export your animation as an FBX file.
Under the "Animation" category, check the "Animation" checkbox
Under the "Bake Animation category", check the "Bake Animation" checkbox to convert the pathtrack to keyframes, and make sure "Step" is set to 1.
IMPORTANT: currently, the exporter will create one animation keyframe per frame (!), so make sure you have enough frames in your scene to have a smooth enough animation.


Animation path export options in Maya


3dsmax

Select the object, then go to the "Animation" menu and select "Constraints" > "Path constraint"


Animation path setup in 3ds: Path constraint
Larger version available here: AnimPath_3ds_PathConstraint.gif


When you scrub the timeline, the object should move along the path:


Animation path in 3ds
Larger version available here: AnimPath_3ds_small.gif


You then need to export your animation as an FBX file.
Under the "Animation" category, check the "Animation" checkbox
Under the "Bake Animation category", check the "Bake Animation" checkbox to convert the pathtrack to keyframes, and make sure "Step" is set to 1.
IMPORTANT: currently, the exporter will create one animation keyframe per frame (!), so make sure you have enough frames in your scene to have a smooth enough animation.


Animation path export options in 3ds



Importing into PopcornFX

First, you'll need to copy the FBX inside your PopcornFX project. To do this you can either navigate to your project directory in the windows explorer, and copy the FBX by hand in whatever project subdirectory you want.

Or, open your project in the PopcornFX editor, and navigate to the directory where you want your FBX animation to be stored.
Then drag&drop the FBX file in the content browser window. This will automatically copy the FBX in your project.
You can drag&drop a selection of multiple FBX files if you have more than one to import.


The editor will ask you if you want to import the new assets, click yes.

Importing new FBX assets in the content browser

Importing new FBX assets in the content browser


Once the FBX is in your project, make sure the content browser displays FBX assets by enabling the "Mesh" resource type in the Filter panel Then (on the right-hand-side of the content browser in the default layout).


Enabling the 'Mesh' resource filter


Double-click on your FBX to open the mesh importer.


In the Mesh Importer Settings treeview, click on the "Animation" node, then check the 'Animation' checkbox in node properties panel.
You can also optionally uncheck the 'Geometry' checkbox in the 'Geometry' node if you don't care about the geometry.


Then, click on the big 'Build Assets from FBX' button.


Importing new FBX assets in the content browser


Once the import is complete, if animation paths were found in the FBX and successfully imported, the viewport will display the number of animation paths:


Animation successfully imported


Using the animation

Now, in an effect file, create a new Animtrack sampler, and click on its AnimResource property. It will open a new 'Select Resource' window.
Pick the FBX file containing the animation path.


Choose the animation file


You can visualize the animtrack in the viewport by activating shapes debug view (Ctrl+D or click the debug shapes button on the top viewport toolbar), or by selecting the animtrack node in the treeview:


Debug view of the pathtrack Debug view of the pathtrack


The animtrack sampler can be used like any other sampler. For example, just write in the spawn script:

Position = MyTrackSampler.samplePosition(rand(0,1));

and particles will spawn randomly on the path.


spawning particles on the path


The parameter to the 'samplePosition' function is the cursor of the animation path, normalized in the [0, 1] range.
You can therefore also use the 'samplePosition' to make particles move along the path. For example, by creating an evolve script that samples the pathtrack with the particle's 'LifeRatio' field:

Position = MyTrackSampler.samplePosition(LifeRatio);


Advanced usage

Sweep custom shape along the path

From v1.5.3 you can sweep a custom shape on the animation path, and sample it with parametric coordinates.
To sweep a custom shape along the path, simply select which shape to sweep in the animtrack sampler's dropdown in the treeview:

sampling multiple tracks : sampler setup


Like for regular shape samplers, by default the swept shape will be sampler randomly. You can manually provide parametric coordinates grabbed from the swept shape directly, to sample at those specific locations.

For example, if to sample a single track, we write:

Position = Path.samplePosition(LifeRatio);

Then, we can also additionnaly provide a parametric coord to sweep the shape along the track:

int3 pCoords = SweptShape.sampleParametricCoords();
...
Position = Path.samplePosition(LifeRatio, pCoords);


Dynamic track index selection

From v1.5.3, In animation files that contain multiple paths, you can specify dynamically which path to sample.


sampling multiple tracks


There is an additional version of the 'sample' function that expects the track index.
For example, if to sample a single track, we write:

Position = Path.samplePosition(spawner.LifeRatio);

Then, if we want to sample the third track, we could simply pass the index '2' to the function (track IDs are zero-based, therefore the third track has ID 2, the second track ID 1, and the first track ID 0):

Position = Path.samplePosition(2, spawner.LifeRatio);

We could also randomly pick one of the three tracks:

Position = Path.samplePosition(rand(0,3), spawner.LifeRatio);

We can also additionnaly provide a parametric coord if we sweep a shape along the track:

int3 pCoords = SweptShape.sampleParametricCoords();
...
Position = Path.samplePosition(rand(0,3), spawner.LifeRatio, pCoords);


sampling multiple tracks : script