Animating shapekeys is a way to animate a mesh without an armature modifier ( is there a way to export this animation in javafx?
CodePudding user response:
Changing 3d points by listening an integer property
in this aproach .getPoints()
observable list values are replaced when an integerproperty value changes over time because that property is in a keyvalue and that key is played in a timeline from value 0 to 22 in one second each . so it's 22 fps . the blender object was exported in obj format and transformed to javafx meshview class with 3dViewer
This is a functional single class javafx app you can try
App.java
public class App extends Application {
@Override
public void start(Stage stage) {
PerspectiveCamera camera = new PerspectiveCamera(true);
camera.setRotationAxis(Rotate.Y_AXIS);
camera.setRotate(90);
camera.setTranslateX(-14.3);
camera.setTranslateY(1);
AnimatedMesh animatedMesh = new AnimatedMesh();
Group local = new Group(animatedMesh);
Group global = new Group(camera, local);
var scene = new Scene(global, 640, 480, true, SceneAntialiasing.BALANCED);
scene.setCamera(camera);
stage.setTitle("Animating vertices");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
class AnimatedMesh extends MeshView {
private final IntegerProperty keyCycle = new SimpleIntegerProperty();
private final float[] base = {-1.0f, 1.012933f, 0.986673f, 1.0f, 1.012933f, 0.986673f, 1.0f, 1.643719f, 0.972653f, -1.0f, 1.643719f, 0.972653f, -1.0f, -1.0f, -1.0f, -1.0f, 0.997948f, -1.014201f, 1.0f, 0.997948f, -1.014201f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.619252f, -1.019894f, 1.0f, 2.840016f, -1.037768f, 1.0f, 2.868222f, 0.950322f, -1.0f, 1.619252f, -1.019894f, -1.0f, 2.868222f, 0.950322f, -1.0f, 2.840016f, -1.037768f};
private final float[][] keyPoints = getKeyPoints();
private TriangleMesh mesh = new TriangleMesh();
public AnimatedMesh() {
super();
setMaterial(new PhongMaterial(Color.CORAL));
initMesh();
setMesh(mesh);
makeCycle();
keyCycle.addListener((o) -> {
mesh.getPoints().set(0, keyPoints[keyCycle.get()], 0, base.length);
});
this.setDrawMode(DrawMode.LINE);
setCullFace(CullFace.NONE);
}
private void makeCycle() {
KeyValue start = new KeyValue(keyCycle, 0);
KeyValue end = new KeyValue(keyCycle, 21);
KeyFrame kf = new KeyFrame(Duration.seconds(1), start, end);
Timeline tm = new Timeline(kf);
tm.setCycleCount(100);
tm.play();
}
private void initMesh() {
mesh.getPoints().addAll(base);
mesh.getTexCoords().addAll(0.625f, 0.5f, 0.625f, 0.75f, 0.375f, 0.25f, 0.625f, 0.25f, 0.625f, 0.0f, 0.375f, 0.0f, 0.375f, 1.0f, 0.625f, 1.0f, 0.375f, 0.75f, 0.125f, 0.5f, 0.375f, 0.5f, 0.125f, 0.25f, 0.875f, 0.5f, 0.875f, 0.25f);
mesh.getFaces().addAll(0, 0, 1, 1, 2, 1, 0, 0, 2, 1, 3, 0, 4, 2, 5, 3, 6, 4, 4, 2, 6, 4, 7, 5, 7, 6, 6, 7, 1, 1, 7, 6, 1, 1, 8, 8, 8, 9, 9, 10, 4, 2, 8, 9, 4, 2, 7, 11, 9, 10, 0, 0, 5, 3, 9, 10, 5, 3, 4, 2, 8, 8, 1, 1, 0, 0, 8, 8, 0, 0, 9, 10, 2, 1, 10, 7, 11, 7, 2, 1, 11, 7, 12, 1, 6, 4, 5, 3, 13, 3, 6, 4, 13, 3, 10, 4, 1, 1, 6, 7, 10, 7, 1, 1, 10, 7, 2, 1, 5, 3, 0, 0, 3, 0, 5, 3, 3, 0, 13, 3, 14, 0, 12, 12, 11, 13, 14, 0, 11, 13, 15, 3, 10, 4, 13, 3, 15, 3, 10, 4, 15, 3, 11, 4, 3, 0, 2, 1, 12, 1, 3, 0, 12, 1, 14, 0, 13, 3, 3, 0, 14, 0, 13, 3, 14, 0, 15, 3);
}
private float[][] getKeyPoints() {
float[][] kP = {new float[]{-1.0f, 1.048689f, 0.949828f, 1.0f, 1.048689f, 0.949828f, 1.0f, 1.698938f, 0.897047f, -1.0f, 1.698938f, 0.897047f, -1.0f, -1.0f, -1.0f, -1.0f, 0.992276f, -1.053461f, 1.0f, 0.992276f, -1.053461f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.606829f, -1.074894f, 1.0f, 2.805955f, -1.142184f, 1.0f, 2.91214f, 0.812976f, -1.0f, 1.606829f, -1.074894f, -1.0f, 2.91214f, 0.812976f, -1.0f, 2.805955f, -1.142184f},
new float[]{-1.0f, 1.102703f, 0.894169f, 1.0f, 1.102703f, 0.894169f, 1.0f, 1.782355f, 0.782834f, -1.0f, 1.782355f, 0.782834f, -1.0f, -1.0f, -1.0f, -1.0f, 0.983708f, -1.112769f, 1.0f, 0.983708f, -1.112769f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.588062f, -1.15798f, 1.0f, 2.754501f, -1.299919f, 1.0f, 2.978486f, 0.605496f, -1.0f, 1.588062f, -1.15798f, -1.0f, 2.978486f, 0.605496f, -1.0f, 2.754501f, -1.299919f},
new float[]{-1.0f, 1.170411f, 0.824399f, 1.0f, 1.170411f, 0.824399f, 1.0f, 1.886919f, 0.639665f, -1.0f, 1.886919f, 0.639665f, -1.0f, -1.0f, -1.0f, -1.0f, 0.972968f, -1.187114f, 1.0f, 0.972968f, -1.187114f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.564537f, -1.26213f, 1.0f, 2.690002f, -1.497643f, 1.0f, 3.061651f, 0.345416f, -1.0f, 1.564537f, -1.26213f, -1.0f, 3.061651f, 0.345416f, -1.0f, 2.690002f, -1.497643f},
new float[]{-1.0f, 1.247249f, 0.745223f, 1.0f, 1.247249f, 0.745223f, 1.0f, 2.005582f, 0.477193f, -1.0f, 2.005582f, 0.477193f, -1.0f, -1.0f, -1.0f, -1.0f, 0.960779f, -1.271482f, 1.0f, 0.960779f, -1.271482f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.53784f, -1.380322f, 1.0f, 2.616807f, -1.722027f, 1.0f, 3.156029f, 0.050269f, -1.0f, 1.53784f, -1.380322f, -1.0f, 3.156029f, 0.050269f, -1.0f, 2.616807f, -1.722027f},
new float[]{-1.0f, 1.328651f, 0.661342f, 1.0f, 1.328651f, 0.661342f, 1.0f, 2.131295f, 0.305068f, -1.0f, 2.131295f, 0.305068f, -1.0f, -1.0f, -1.0f, -1.0f, 0.947866f, -1.360862f, 1.0f, 0.947866f, -1.360862f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.509557f, -1.505536f, 1.0f, 2.539264f, -1.959741f, 1.0f, 3.256015f, -0.262412f, -1.0f, 1.509557f, -1.505536f, -1.0f, 3.256015f, -0.262412f, -1.0f, 2.539264f, -1.959741f},
new float[]{-1.0f, 1.410053f, 0.577461f, 1.0f, 1.410053f, 0.577461f, 1.0f, 2.257007f, 0.132944f, -1.0f, 2.257007f, 0.132944f, -1.0f, -1.0f, -1.0f, -1.0f, 0.934953f, -1.450243f, 1.0f, 0.934953f, -1.450243f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.481274f, -1.630749f, 1.0f, 2.46172f, -2.197454f, 1.0f, 3.356f, -0.575092f, -1.0f, 1.481274f, -1.630749f, -1.0f, 3.356f, -0.575092f, -1.0f, 2.46172f, -2.197454f},
new float[]{-1.0f, 1.48689f, 0.498284f, 1.0f, 1.48689f, 0.498284f, 1.0f, 2.37567f, -0.029529f, -1.0f, 2.37567f, -0.029529f, -1.0f, -1.0f, -1.0f, -1.0f, 0.922764f, -1.534611f, 1.0f, 0.922764f, -1.534611f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.454577f, -1.748942f, 1.0f, 2.388525f, -2.421838f, 1.0f, 3.450379f, -0.87024f, -1.0f, 1.454577f, -1.748942f, -1.0f, 3.450379f, -0.87024f, -1.0f, 2.388525f, -2.421838f},
new float[]{-1.0f, 1.554598f, 0.428514f, 1.0f, 1.554598f, 0.428514f, 1.0f, 2.480235f, -0.172697f, -1.0f, 2.480235f, -0.172697f, -1.0f, -1.0f, -1.0f, -1.0f, 0.912024f, -1.608955f, 1.0f, 0.912024f, -1.608955f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.431052f, -1.853092f, 1.0f, 2.324027f, -2.619563f, 1.0f, 3.533544f, -1.13032f, -1.0f, 1.431052f, -1.853092f, -1.0f, 3.533544f, -1.13032f, -1.0f, 2.324027f, -2.619563f},
new float[]{-1.0f, 1.608612f, 0.372855f, 1.0f, 1.608612f, 0.372855f, 1.0f, 2.563651f, -0.286911f, -1.0f, 2.563651f, -0.286911f, -1.0f, -1.0f, -1.0f, -1.0f, 0.903455f, -1.668263f, 1.0f, 0.903455f, -1.668263f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.412285f, -1.936177f, 1.0f, 2.272573f, -2.777298f, 1.0f, 3.59989f, -1.3378f, -1.0f, 1.412285f, -1.936177f, -1.0f, 3.59989f, -1.3378f, -1.0f, 2.272573f, -2.777298f},
new float[]{-1.0f, 1.644368f, 0.336011f, 1.0f, 1.644368f, 0.336011f, 1.0f, 2.618871f, -0.362517f, -1.0f, 2.618871f, -0.362517f, -1.0f, -1.0f, -1.0f, -1.0f, 0.897783f, -1.707524f, 1.0f, 0.897783f, -1.707524f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.399862f, -1.991178f, 1.0f, 2.238512f, -2.881714f, 1.0f, 3.643808f, -1.475145f, -1.0f, 1.399862f, -1.991178f, -1.0f, 3.643808f, -1.475145f, -1.0f, 2.238512f, -2.881714f},
new float[]{-1.0f, 1.657301f, 0.322684f, 1.0f, 1.657301f, 0.322684f, 1.0f, 2.638844f, -0.389864f, -1.0f, 2.638844f, -0.389864f, -1.0f, -1.0f, -1.0f, -1.0f, 0.895732f, -1.721725f, 1.0f, 0.895732f, -1.721725f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.395368f, -2.011072f, 1.0f, 2.226192f, -2.919482f, 1.0f, 3.659694f, -1.524823f, -1.0f, 1.395368f, -2.011072f, -1.0f, 3.659694f, -1.524823f, -1.0f, 2.226192f, -2.919482f},
new float[]{-1.0f, 1.644368f, 0.336011f, 1.0f, 1.644368f, 0.336011f, 1.0f, 2.61887f, -0.362517f, -1.0f, 2.61887f, -0.362517f, -1.0f, -1.0f, -1.0f, -1.0f, 0.897783f, -1.707524f, 1.0f, 0.897783f, -1.707524f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.399862f, -1.991178f, 1.0f, 2.238512f, -2.881714f, 1.0f, 3.643808f, -1.475145f, -1.0f, 1.399862f, -1.991178f, -1.0f, 3.643808f, -1.475145f, -1.0f, 2.238512f, -2.881714f},
new float[]{-1.0f, 1.608612f, 0.372855f, 1.0f, 1.608612f, 0.372855f, 1.0f, 2.563651f, -0.286911f, -1.0f, 2.563651f, -0.286911f, -1.0f, -1.0f, -1.0f, -1.0f, 0.903455f, -1.668263f, 1.0f, 0.903455f, -1.668263f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.412285f, -1.936177f, 1.0f, 2.272573f, -2.777297f, 1.0f, 3.599889f, -1.3378f, -1.0f, 1.412285f, -1.936177f, -1.0f, 3.599889f, -1.3378f, -1.0f, 2.272573f, -2.777297f},
new float[]{-1.0f, 1.554598f, 0.428514f, 1.0f, 1.554598f, 0.428514f, 1.0f, 2.480235f, -0.172697f, -1.0f, 2.480235f, -0.172697f, -1.0f, -1.0f, -1.0f, -1.0f, 0.912024f, -1.608955f, 1.0f, 0.912024f, -1.608955f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.431052f, -1.853092f, 1.0f, 2.324027f, -2.619563f, 1.0f, 3.533544f, -1.13032f, -1.0f, 1.431052f, -1.853092f, -1.0f, 3.533544f, -1.13032f, -1.0f, 2.324027f, -2.619563f},
new float[]{-1.0f, 1.48689f, 0.498284f, 1.0f, 1.48689f, 0.498284f, 1.0f, 2.37567f, -0.029529f, -1.0f, 2.37567f, -0.029529f, -1.0f, -1.0f, -1.0f, -1.0f, 0.922764f, -1.534611f, 1.0f, 0.922764f, -1.534611f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.454577f, -1.748942f, 1.0f, 2.388525f, -2.421838f, 1.0f, 3.450379f, -0.870239f, -1.0f, 1.454577f, -1.748942f, -1.0f, 3.450379f, -0.870239f, -1.0f, 2.388525f, -2.421838f},
new float[]{-1.0f, 1.410053f, 0.577461f, 1.0f, 1.410053f, 0.577461f, 1.0f, 2.257007f, 0.132944f, -1.0f, 2.257007f, 0.132944f, -1.0f, -1.0f, -1.0f, -1.0f, 0.934953f, -1.450243f, 1.0f, 0.934953f, -1.450243f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.481274f, -1.63075f, 1.0f, 2.46172f, -2.197454f, 1.0f, 3.356f, -0.575092f, -1.0f, 1.481274f, -1.63075f, -1.0f, 3.356f, -0.575092f, -1.0f, 2.46172f, -2.197454f},
new float[]{-1.0f, 1.328651f, 0.661342f, 1.0f, 1.328651f, 0.661342f, 1.0f, 2.131295f, 0.305068f, -1.0f, 2.131295f, 0.305068f, -1.0f, -1.0f, -1.0f, -1.0f, 0.947866f, -1.360862f, 1.0f, 0.947866f, -1.360862f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.509557f, -1.505536f, 1.0f, 2.539264f, -1.959741f, 1.0f, 3.256015f, -0.262412f, -1.0f, 1.509557f, -1.505536f, -1.0f, 3.256015f, -0.262412f, -1.0f, 2.539264f, -1.959741f},
new float[]{-1.0f, 1.247249f, 0.745222f, 1.0f, 1.247249f, 0.745222f, 1.0f, 2.005582f, 0.477192f, -1.0f, 2.005582f, 0.477192f, -1.0f, -1.0f, -1.0f, -1.0f, 0.960779f, -1.271482f, 1.0f, 0.960779f, -1.271482f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.53784f, -1.380322f, 1.0f, 2.616807f, -1.722027f, 1.0f, 3.15603f, 0.050269f, -1.0f, 1.53784f, -1.380322f, -1.0f, 3.15603f, 0.050269f, -1.0f, 2.616807f, -1.722027f},
new float[]{-1.0f, 1.170411f, 0.8244f, 1.0f, 1.170411f, 0.8244f, 1.0f, 1.886919f, 0.639665f, -1.0f, 1.886919f, 0.639665f, -1.0f, -1.0f, -1.0f, -1.0f, 0.972968f, -1.187114f, 1.0f, 0.972968f, -1.187114f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.564537f, -1.26213f, 1.0f, 2.690002f, -1.497643f, 1.0f, 3.061651f, 0.345416f, -1.0f, 1.564537f, -1.26213f, -1.0f, 3.061651f, 0.345416f, -1.0f, 2.690002f, -1.497643f},
new float[]{-1.0f, 1.048689f, 0.949828f, 1.0f, 1.048689f, 0.949828f, 1.0f, 1.698938f, 0.897047f, -1.0f, 1.698938f, 0.897047f, -1.0f, -1.0f, -1.0f, -1.0f, 0.992276f, -1.053461f, 1.0f, 0.992276f, -1.053461f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.606829f, -1.074894f, 1.0f, 2.805955f, -1.142184f, 1.0f, 2.91214f, 0.812976f, -1.0f, 1.606829f, -1.074894f, -1.0f, 2.91214f, 0.812976f, -1.0f, 2.805955f, -1.142184f},
new float[]{-1.0f, 1.012933f, 0.986673f, 1.0f, 1.012933f, 0.986673f, 1.0f, 1.643719f, 0.972653f, -1.0f, 1.643719f, 0.972653f, -1.0f, -1.0f, -1.0f, -1.0f, 0.997948f, -1.014201f, 1.0f, 0.997948f, -1.014201f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.619252f, -1.019894f, 1.0f, 2.840016f, -1.037767f, 1.0f, 2.868221f, 0.950322f, -1.0f, 1.619252f, -1.019894f, -1.0f, 2.868221f, 0.950322f, -1.0f, 2.840016f, -1.037767f},
new float[]{-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.623746f, 1.0f, -1.0f, 1.623746f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.623746f, -1.0f, 1.0f, 2.852336f, -1.0f, 1.0f, 2.852336f, 1.0f, -1.0f, 1.623746f, -1.0f, -1.0f, 2.852336f, 1.0f, -1.0f, 2.852336f, -1.0f}
};
return kP;
}
}
}