Author Topic: How to import vertex animations  (Read 3608 times)

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
How to import vertex animations
« on: May 09, 2017, 02:12:21 pm »
As you know, Egon, I'm writing that JSON-serialized file format. Right now, I'm working on the vertex animations. I've stored the frames in a file. The current version of the method looks like the following. But the trouble now is that the only idea I have is to clone the only Mesh instance I have and distort it with a vertex controller. But that doesn't really seem right to me.

Code: [Select]
     public static Object3D loadVertexAnimated(String fileName) {
        NoBonesImporter jImporter = new NoBonesImporter();
        ArrayList<ArrayList> objects = jImporter.getList(fileName);
ArrayList<NoBoneAnimation> importedAnimations = jImporter.getAnimations(fileName);
Object3D[] list = Object3D[objects.size()];
for (int i = 0; i < objects.size(); i++) {
     ArrayList<ArrayList> theObject = objects.get(i);
     ArrayList<ArrayList> importedVertices = theObject.get(0);
             ArrayList<ArrayList> importedUVs = theObject.get(1);
             ArrayList<ArrayList> importedFaces = theObject.get(2);
             float[] coordinates = makeCoordinates(importedVertices);
             float[] uvs = makeUVs(importedUVs);
             int[] indices = makeIndices(importedFaces);
     Object3D anObject = new Object3D(coordinates, uvs, indices,0);
     list[i] = anObject;

        }

int numTriangles = importedVertices.size(), numFrames = importedAnimations.size();
for (i = 0; i < numFrames; i++) {
     tmp.clearObject();
     int frame = i;
     Object3D anObject = list[i];
     Mesh aMesh = anObject.getMesh();
     NoBoneAnimation anAnimation = animations.get(i);
     String name = anAnimation.name;
     int numFrames = anAnimation.frames.size();
     Animation animation = new Animation(numFrames);

     for (ArrayList<ArrayList> importedVertices: anAnimation.frames) {
// Create a new mesh with vertex controller?
SimpleVector[] vertices = SimpleVector[importedVertices.size()];
for (int j = 0; j < vertices.length; j++) {
      SimpleVector v = new SimpleVector(vert.get(0), vert.get(1), vert.get(2));
vertices[j] = v;
      }
animation.addKeyFrame(...);
     }
}
Object3D anObject = makeAnimated3D(pose, objectsBonesReferences.get(i), theObject);
     }

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12298
    • View Profile
    • http://www.jpct.net
Re: How to import vertex animations
« Reply #1 on: May 09, 2017, 08:40:50 pm »
I'm not quite sure what you mean. You have a mesh and you want to save it in different versions with different vertex positions?

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: How to import vertex animations
« Reply #2 on: May 09, 2017, 08:52:16 pm »
Yes, to be more precise, right now I'm getting the infamous "The sizes of the animations meshes don't match" message. And the difference is always 8. Build(), strip(), compress() and a host of other attemps haven't changed this.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12298
    • View Profile
    • http://www.jpct.net
Re: How to import vertex animations
« Reply #3 on: May 09, 2017, 09:21:49 pm »
8 sounds exactly like the bounding box vertices that are added automatically. Calling build() on every mesh should actually help. Where do you get the meshes from that you want save?

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: How to import vertex animations
« Reply #4 on: May 09, 2017, 09:40:01 pm »
From the JSON file. I actually fill an array of SimpleVectors. The only way I could think to apply them to a mesh is to call Object3D.cloneMesh(false), then to use a vertex controller to change the mesh's vertices. I must be doing something wrong because no animation runs (won't work with or without toControl.setVertexController(this, true)):

Code: [Select]
public VertexController(Mesh toControl, SimpleVector[] newVertices) {
        super.init(toControl, true);
        toControl.setVertexController(this, true);
        SimpleVector[] vertices = super.getDestinationMesh();
        for (int i = 0; i < vertices.length; i++) {
            vertices[i].x = newVertices[i].x;
            vertices[i].y = newVertices[i].y;
            vertices[i].z = newVertices[i].z;
        }
    }

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: How to import vertex animations
« Reply #5 on: May 09, 2017, 10:53:26 pm »
I solved it instead by creating Object3Ds for each Mesh and building them all (seems crazy redundant, doesn't it?). So, hey, vertex animations work and they come out of Max serialized. Performance tests to follow.