package vgp.tutor.key;
import jv.anim.PsAnimation;
import jv.anim.PsKeyframe;
import jv.loader.PgLoader;
import jv.number.PuString;
import jv.object.PsConfig;
import jv.object.PsDebug;
import jv.object.PsUtil;
import jv.project.PgGeometry;
import jv.project.PjProject;
import jv.project.PvViewerIf;
/**
* Demo project of keyframe animation of precomputed models.
*
* @author Konrad Polthier
* @version 15.02.02, 1.60 revised (kp) Bug removed which restricted numFiles<10.
* 25.01.02, 1.50 revised (kp) Animation of a set of geometries handled.
* 16.09.00, 1.20 revised (kp) Register this project as time listener instead of keyframe object.
* 04.07.00, 1.10 revised (kp) Made keyframe object the dynamic geometry.
* 00.00.99, 1.00 created (kp)
*/
public class PjKeyframe extends PjProject {
private static String m_defaultModel = "models/cmc/Lawson_3_90_60_Anim.*.byu";
private static int m_defaultNumKeys = 5;
protected PsKeyframe [] m_keyframe;
protected String m_fileName;
protected int m_numKeys;
protected PsAnimation m_anim;
public PjKeyframe() {
super("Keyframe Animation");
// Show animation panel
m_anim = new PsAnimation();
m_anim.enableKeys(true);
setAnimation(m_anim);
if (getClass() == PjKeyframe.class)
init();
}
public void init() {
super.init();
}
public void start() {
PvViewerIf viewer = getViewer();
if (m_fileName == null) {
m_fileName = viewer.getParameter("Model");
try {
String num = viewer.getParameter("Number");
if (num != null)
m_numKeys = Integer.parseInt(num);
} catch (NumberFormatException e) {
m_numKeys = 1;
}
}
if (m_fileName == null)
setFileName(PsConfig.getCodeBase()+m_defaultModel, m_defaultNumKeys);
if (load()) {
// If applet parameter does not forbid showing of animation panel
// then show it now:
String panelVis = viewer.getParameter("Animation");
if (panelVis==null || panelVis.equalsIgnoreCase("show"))
m_anim.getAnimationPanel().setVisible(true);
}
super.start();
}
public String getFileName() { return m_fileName; }
public void setFileName(String fileName, int numKeys) {
if (fileName != null) {
m_fileName = fileName;
m_numKeys = numKeys;
} else {
m_fileName = PsConfig.getCodeBase()+m_defaultModel;
m_numKeys = m_defaultNumKeys;
}
}
public boolean load() {
if (m_fileName == null) {
if (PsDebug.WARNING) PsDebug.warning("missing file name to load");
return false;
}
PgGeometry geom;
if (m_keyframe != null) {
for (int i=0; i