Skip to content

Commit

Permalink
remove morph target for frame 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Trass3r authored Jan 26, 2024
1 parent 47ea2cd commit d154775
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/toniarts/openkeeper/tools/convert/KmfModelLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,14 @@ private void handleAnim(Anim anim, Map<Integer, List<Material>> materials, Node
}

// now get the vertices for each frame, make sure we pick the last frame too
final int numMorphTracks = numFrames - 1; // first frame doesn't need one
// set up weights as identity matrix
// frames are columns, morph targets are rows
// first column is 0
var weights = new float[numFrames * numMorphTracks];
for (i = 0; i < numMorphTracks; ++i)
weights[i * numFrames + i+1] = 1;

for (int frame = 0; frame < anim.getFrames(); frame += Math.max(1, Math.min(frameSubdiv, anim.getFrames() - frame - 1)))
{
i = 0;
Expand Down Expand Up @@ -342,7 +350,6 @@ private void handleAnim(Anim anim, Map<Integer, List<Material>> materials, Node
++i;
}

// TODO: we don't need a morph target for frame 0
if (frame == 0) {
// unfortunately we need a valid position buffer for BVH generation etc.
var posBuffer = new VertexBuffer(Type.Position);
Expand All @@ -351,6 +358,7 @@ private void handleAnim(Anim anim, Map<Integer, List<Material>> materials, Node
baseVertices = vertices.clone();
for (i = 0; i < vertices.length; ++i)
baseVertices[i] = new Vector3f(vertices[i]);
continue;
}
// create a relative morph target
var morphTarget = new MorphTarget("submesh " + subMeshIndex + " frame " + frame);
Expand Down Expand Up @@ -416,20 +424,15 @@ private void handleAnim(Anim anim, Map<Integer, List<Material>> materials, Node
Geometry geom = createGeometry(subMeshIndex, anim.getName(), mesh, materials, animSprite.getMaterialIndex());

// Create a pose track for this mesh
var weights = new float[numFrames * numFrames];
// set up weights as identity matrix
for (i = 1; i < numFrames; ++i) {
weights[i * numFrames + i] = 1;
}
var morphTrack = new MorphTrack(geom, times, weights, numFrames);
var morphTrack = new MorphTrack(geom, times, weights, numMorphTracks);
animTracks.add(morphTrack);

//Attach the geometry to the node
node.attachChild(geom);
++subMeshIndex;
}
// base pose weights are 0
meshModel.setWeights(new float[numFrames]);
meshModel.setWeights(new float[numMorphTracks]);

Check failure on line 435 in src/toniarts/openkeeper/tools/convert/KmfModelLoader.java

View workflow job for this annotation

GitHub Actions / build

cannot find symbol

var nodeModel = new DefaultNodeModel();
nodeModel.addMeshModel(meshModel);
Expand Down

0 comments on commit d154775

Please sign in to comment.