Unsharing the AnimControl between spatials of same model

I have multiple entities in my game that uses the same animated model, however, I need them to play animations separately.



Example:



[java]

Spatial spat1 = assetManager.loadModel(“Models/MyModel.j3o”);

AnimControl control1 = spat1.getControl(AnimControl.class);

AnimChannel chan1 = control1.createChannel();

chan1.setAnim(“Animation”);



Spatial spat2 = assetManager.loadModel(“Models/MyModel.j3o”);

AnimControl control2 = spat2.getControl(AnimControl.class);

AnimChannel chan2 = control2.createChannel();

chan2.setAnim(“OtherAnimation”);

[/java]



The problem is that both the models will be playing the “OtherAnimation”. How would I be able to get them to play their animations separately?

I tried assetManager.loadModel("").clone(), that didn’t work. I tried deepClone() that just left them in T-pose and anims didn’t work. I noticed there is a cloneForAnim() on the Mesh class, though I am unsure how to use it.

This should work fine. Can you post a test case that shows the issue? You can use the jME3 bundled models if need be

Okay, well that’s annoying. It works with both Oto and Sinbad from the testData. But with my own models it won’t work.

Do you know of any reason why it would be doing this? Possibly an export issue from blender?

Oto and sinbad are a bit special, i think they reference j3m materials directly. I already saw a similar issue so I guess if you can post a jMP project that has the issue with the latest 3.0 beta it would help me find the issue

Aren’t spat1 and spat2 the same object ? I though assetManager returned the same object if it was already loaded in memory ?

@ozonegrif That’s what I thought, it’ll be sharing the model/skeleton. The clone method info says it still shares a lot of data even though it’s being cloned.



@Momoko_Fan https://rapidshare.com/files/4128356131/jMP_Model_Anim_Problem.zip There is a link to the download. it’s under one mb big. I’ve included the model that I’m using and the blender file for it. I’m still unable to figure out why it’s doing it. I’ve re-exported the model several times, however, I may still be missing something if it’s an export issue.

Is it possible that its actually the animcontrol that is shared?

I think I found the issue, shared geometry models aren’t cloned properly for animation … I’ll take a closer look at this later

1 Like

@Momoko_Fan Have you looked at the problem yet? I’m in no rush but I’m curious about this issue. Also is there a way to unshare the geometry for that model?

1 Like

The Animation system misses some clone() methods, only cloneForSpatial is implemented.

This issue is more complex than it seems to be. Implementing it via cloning would probably be very difficult if not impossible. The framework of how shared meshes are handled must be changed entirely…

@nyfinscyf: This issue should be fixed in SVN now. Can you please check your model file to see if it works? For some reason I get a file not found error on that file you linked



EDIT: I was able to find a copy of the project and fixed a minor bug with animation. Everything is working now :slight_smile:

@Momoko_Fan I updated to the latest nightly build and now get this:



[java]

WARNING: Failed to find loader: com.jme3.scene.plugins.blender.BlenderModelLoader

java.lang.ClassNotFoundException: com.jme3.scene.plugins.blender.BlenderModelLoader

at java.net.URLClassLoader$1.run(URLClassLoader.java:366)

at java.net.URLClassLoader$1.run(URLClassLoader.java:355)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:354)

at java.lang.ClassLoader.loadClass(ClassLoader.java:423)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)

at java.lang.ClassLoader.loadClass(ClassLoader.java:356)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:186)

at com.jme3.asset.DesktopAssetManager.registerLoader(DesktopAssetManager.java:135)

at com.jme3.asset.AssetConfig.loadText(AssetConfig.java:74)

at com.jme3.asset.DesktopAssetManager.<init>(DesktopAssetManager.java:88)

at com.jme3.system.JmeDesktopSystem.newAssetManager(JmeDesktopSystem.java:56)

at com.jme3.system.JmeSystem.newAssetManager(JmeSystem.java:87)

at com.jme3.app.Application.initAssetManager(Application.java:162)

at com.jme3.app.Application.initialize(Application.java:490)

at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:204)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:129)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:205)

at java.lang.Thread.run(Thread.java:722)

[/java]

However, it still runs, and the animations work in that test project.

Now the weird thing is the models are stuck in T-Pose in my actual project and I still get that warning message.

I’ve checked my plugins and the Blender one is there and active. I am on a new laptop and this is a fresh install of JME.





EDIT: Found the issue for why my models are in T-Pose. I made some changes to them in blender which messed it up. So that’s fine, however, i’m still getting that warning.

The layout of the libraries changed, you’re gonna have to add the blender support library to your project