[SOLVED] Dynamic Anim Control With GLTF models

Hello,
I’m trying to use DynamicAnimControl and I’m getting this exception when using GLTF models:

java.lang.IllegalArgumentException: The controlled spatial must have a SkinningControl or a SkeletonControl. Make sure the Control is there and not on some other Spatial.
	at com.jme3.bullet.animation.DacLinks.createSpatialData(DacLinks.java:771)
	at com.jme3.bullet.control.AbstractPhysicsControl.setSpatial(AbstractPhysicsControl.java:405)
	at com.jme3.scene.Spatial.addControl(Spatial.java:775)
	at com.scenemaxeng.projector.SceneMaxApp$6.run(SceneMaxApp.java:1422)
	at com.jme3.app.LegacyApplication$RunnableWrapper.call(LegacyApplication.java:822)
	at com.jme3.app.AppTask.invoke(AppTask.java:147)
	at com.jme3.app.LegacyApplication.runQueuedTasks(LegacyApplication.java:733)
	at com.jme3.app.LegacyApplication.update(LegacyApplication.java:748)
	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:247)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
	at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:197)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:232)
	at java.lang.Thread.run(Thread.java:745)

It works fine with J3O model however…
What am I doing wrong? Or does DynamicAnimControl works only with J3O models?

Here is the code which causes the exception:

DynamicAnimControl modelCtl = new DynamicAnimControl();

model.addControl(modelCtl);
modelCtl.setPhysicsSpace(bulletAppState.getPhysicsSpace());

it crashes in the model.addControl command

1 Like

Pretty much self explaining…

Gltf loader wraps the loaded model inside a parent node I guess, so most probably the SkinningControl (if you are using JME 3.3) or SkeletonControl (if you are using JME 3.2) object should be in the child. So you should find that child and add DynamicAnimControl to that.

2 Likes

Yes!

And in Minie there’s even a utility method that makes it easy to find the control: RagUtils.findSControl(modelRoot);

4 Likes

Thanks guys. Everything is working!
How hard do you think it is to display all bones in a models with labels of their names for debugging \ educating purpose?
I don’t care much for the hierarchy but rather for selecting main bones for linking…
Do we have such demo in any of our tests?

1 Like

I think the difficulty would depend on how pretty you want to make it.

1 Like

I did this for my model viewer. It’s really only a couple lines of code.

2 Likes

Doesn’t need to be so much pretty. I teach kids and I need a way to show them the name of the joints so they can decide which ones to link

1 Like

would you mind share those lines? :slight_smile:

1 Like

I’m on my phone, hard to type code. But basically I query the joints and put them in a lemur’s listbox. Once you have the joint names, you can display them however you want.

List joints = control.getArmature().getJointList().stream()
.map(Joint::getName)
.collect(Collectors.toList());

1 Like

Thanks I already did that. I wanted something else - to show the bones on the model and attach a label with the bone (joint) name for each bone.

1 Like

Maybe you can use Heart for this? It’s a utility lib of @sgold. I use it to display armatures.

An easy solution would probably be to add a label with the joint name to the attachmentsnode of the joint. You can even add a BillboardControl to it if needed.

2 Likes

Thanks Stephen, I changed my code to using findSControl. I would like to suggest that for public methods such as this one maybe it will be better to use a little bit more verbose names for example: findSkinningControl

1 Like

Or perhaps findSkinningControlOrSkeletonControl()?

I think you could shorten it to findSkinningOrSkeletonControl() without losing any useful information. :smiley:

I think I would stick with findSkinningControl becuase SkeletonControl is deprecated and they serve the same functionality no?

I would suggest to use findAnimRoot() and return the spatial that contains either of those controls.

5 Likes

I’m convinced there are many uses for a utility method such as @Ali_RS described, to find the animation/skinning Spatial in an unfamiliar model.

I’ve tentatively decided:

  1. to add it to the Heart library, so it can be used with or without Minie
  2. to return a list of all such spatials, so apps can easily handle models containing more than one
  3. to name it listAnimSpatials()
2 Likes

The new method has been released in the Heart v5.4 library, which is available from JCenter and JmonkeyStore.

You’ll find it in the MySpatial utility class. Due to a last-minute change of heart (no pun intended), it’s actual name is listAnimationSpatials().

3 Likes