This gets slightly more complicated. Now that you've imported
the geometry, you want it to change form. But it's just this crazy
mess of data, so what to do?
Here's what: attach particles to each of the vertices in a specified
layer, and then control those particles. So first, you need to define
a particle type that you want to apply to these vertices. That could
look something like this:
class RectParticle extends Particle {
public RectParticle() {
}
void draw() {
if (fixed()) {
fill(255, 0, 0);
}
else {
fill(100, 100, 100, 100);
}
super.draw();
}
}
This defines a particle type that draws itself as a box (red if the
particle is fixed, and gray if it isn't). It has no other behavior, so
it will just be acted upon by forces.
Once you've defined your particle type, you use the "applyParticles"
command to spread them onto a layer of your object:
yourNameHere.applyParticles("Layer_01",
new RectParticle());
The layer name in the first argument must match one of the layers
from your obj file exactly including capitalization. Remember that
spaces are converted into underscores "_". Having done
that, you'll end up with something like this:
[example]
Notice that the layer we have chosen is now sinking out of sight.
That's because the particles are affected by gravity. So let's turn
gravity off, which is more likely what we were after:
ps.setGravity(0);
[example]
Now these particles are useful for debugging because you can see
them, but they may not be what you want in the long term. Here is
a particle type that does absolutely nothing. No drawing, no moving.
Nothing. The only thing this particle type does is to be affected
by forces.
class NoShowParticle extends Particle {
public NoShowParticle() {
}
void draw() {
}
}
[example]
This is a useful template for the kinds of particles you may want
to spead on a layer.
If you wanted to have a layer move slowly to the right, you could
spread this kind of particle on it:
class RightParticle extends Particle {
public RightParticle() {
fix();
}
void draw() {
pos[0] = pos[0] + 1;
}
}
[example]
The particles are fixed, so they won't be affected by forces,
and they are moved one unit to the right in their loop each frame,
so the layer they are spread on moves to the right, retaining its
original shape. You can use variations on this to have layers move
or deform in any arbitrary way you choose.
|