Skip to main content

height of box animated from external file

2 replies [Last post]
marty
Offline
Joined: 2004-05-15

Hi All,

I can't figure out how to do the following:
I am trying to make a box animate and get a height between 0.0 and 1.0 (with ten intervals). This height is read from an external data file and the number of frames can be quite big (+30).
To read from an external file is no problem, to create a box with a custom height is also done, but to animate it... pff

Anybody an idea?
Thx

update:
I am trying to create a 3d graph of a grid of seperate 'niches' (cells) containing a number of species. Using fortran I do a lot of calculations on the spread of these species over the map, with each phase a new map is written to a text file (maybe sometimes, written directly into the application). This textfile contains, for every phase, an array of the map. The number of species should be presented by the height of the box (0.1 -> 1.0), and shoud dynamically change over time. Anybody a better idea to do this ór an idea how to solve the above problem? Thx

Message was edited by: marty

Reply viewing options

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

Check RotPosScaleTCBSplinePathInterpolator
com.sun.j3d.utils.behaviors.interpolators.RotPosScaleTCBSplinePathInterpolator or

KBRotPosScaleSplinePathInterpolator
- com.sun.j3d.utils.behaviors.interpolators.KBRotPosScaleSplinePathInterpolator

There is Java3D demo with this last one. I guess one of then you meet your needs.

Alessandro

---------------------------------
Yahoo! Mail - Agora com 250MB de espaço gratuito. Abra uma conta agora!
[att1.html]

marty
Offline
Joined: 2004-05-15

well, not exactly...
At least, I didn't get it to work with that. The problem is that KBRotPosScaleSplinePathInterpolator and RotPosScaleTCBSplinePathInterpolator require a fixed number of keyframes and a predefined vector.

But i get my keyframes and the location of each box from an external file, and the number of frames varies...
I've come a little closer to the solution:

In the class 'thsbox' <> I've added a behavior to the TransformGroup of the box:

public class BoxBehavior extends Behavior{
public TransformGroup tg=new TransformGroup();
public Transform3D scale = new Transform3D();
public float [] data; //the array containing the subsequent heights of the box, and with as much elements as there are keyframes..
public int p; // current keyframe
public WakeupCondition trigger = new WakeupOnElapsedFrames(20); // switch every 20 frames

// create BoxBehavior
BoxBehavior(TransformGroup tg,float [] data,int p){
this.tg = tg;
this.data=data;
this.p=p;
}

// initialize the Behavior
// set initial wakeup condition
// called when behavior beacomes live
public void initialize(){
// set initial wakeup condition
this.wakeupOn(trigger);
}

// behave
// called by Java 3D when appropriate stimulus occures
public void processStimulus(Enumeration criteria){
// decode event
p++;
if (p==phases) p=0;
// do what is necessary
scale.setScale(new Vector3d(1.0, data[p], 1.0));
tg.setTransform(scale);
this.wakeupOn(trigger);
}

} // end of class BoxBehavior

This behavior works only for the first (x=0;y=0) box. After 20 frames (the second keyframe) all other boxes disappear :( How can I make it work for every box ???

Thx!!