Hi,
I wanted to give the new AnimComposer a try, and I noticed that after running the AnimMigrationUtils.migrate(model)
method and saving it, the model ‘breaks’.
The weird thing is, that when you actually play an animation on the broken model, it assembles itself again correct.
This is probably a weird explanation, so I added some screenshots and a test case:
public class AnimComposerErrorTest extends SimpleApplication {
public static void main(String[] args) {
new AnimComposerErrorTest().start();
}
@Override
@SneakyThrows
public void simpleInitApp() {
Spatial model = assetManager.loadModel("/Models/characters/human/human-all-rigged.j3o");
AnimMigrationUtils.migrate(model);
BinaryExporter exporter = BinaryExporter.getInstance();
exporter.save(model, new File(JmeSystem.getStorageFolder(), "migrated-model.j3o"));
assetManager.registerLocator(JmeSystem.getStorageFolder().getAbsolutePath(), FileLocator.class);
Spatial migratedModel = assetManager.loadModel("migrated-model.j3o");
model.move(-2, 0, 0);
//SpatialUtils.getFirstControl(model, AnimComposer.class).ifPresent(animComposer -> animComposer.setCurrentAction("idle"));
migratedModel.move(2, 0, 0);
//SpatialUtils.getFirstControl(migratedModel, AnimComposer.class).ifPresent(animComposer -> animComposer.setCurrentAction("idle"));
rootNode.attachChild(model);
rootNode.attachChild(migratedModel);
rootNode.addLight(new AmbientLight(ColorRGBA.White.mult(0.3f)));
rootNode.addLight(new DirectionalLight(Vector3f.UNIT_Y.negate(), ColorRGBA.White));
}
}
But when I uncomment the lines that start playing an animation it becomes:
The SpatialUtils.getFirstControl()
method only does a depth first traversal of the spatial and returns the first control that matches the given type, so no ‘magic’ happens in that method.