[SOLVED] Minie 4.2. PhysicsSpace.addAll doesn't add joints

Hi, I’m using version 4.2 of the Minie library and I noticed that PhysicsSpace.addAll doesn’t seem to add joints.I tried the TestRagDoll code with both standard bullet libraries (works fine) and Minie 4.2 (doesn’t connect the limbs).

I looked thought the list of known issues, and couldn’t find this, so apologies if it’s a duplicate.

Also, calling PhysicsSpace.add on the individual joints works fine, so there is an easy workaround.

Looking at the code for Minie 4.2, only spatials are added:

    this.add(spatial);
    if (spatial instanceof Node) {
        List<Spatial> children = ((Node)spatial).getChildren();
        Iterator var3 = children.iterator();
        while(var3.hasNext()) {
            Spatial child = (Spatial)var3.next();
            this.addAll(child);
        }
    }
}

Whereas in the bullet library joints get added too.

    this.add(spatial);
    if (spatial.getControl(RigidBodyControl.class) != null) {
        RigidBodyControl physicsNode = (RigidBodyControl)spatial.getControl(RigidBodyControl.class);
        List<PhysicsJoint> joints = physicsNode.getJoints();
        Iterator it1 = joints.iterator();

        while(it1.hasNext()) {
            PhysicsJoint physicsJoint = (PhysicsJoint)it1.next();
            if (physicsNode.equals(physicsJoint.getBodyA())) {
                this.add(physicsJoint);
            }
        }
    }

    if (spatial instanceof Node) {
        List<Spatial> children = ((Node)spatial).getChildren();
        Iterator it = children.iterator();

        while(it.hasNext()) {
            Spatial spat = (Spatial)it.next();
            this.addAll(spat);
        }
    }

}

Hope this is useful, and apologies if I’m doing something daft, or I’m using the wrong version or this is a deliberate change.

2 Likes

This is a known incompatibility between jme3-jbullet and Minie. It dates back to April 2019.

In jme3-jbullet, the semantics of addAll(Spatial) and removeAll(Spatial) are problematic because there might be double-ended joints that have one end included in the Spatial tree while the other end isn’t. In that situation, it’s not clear what addAll() and removeAll() should do.

If you need to add joints, you can write your own code to do that.

1 Like

Thanks, sorry for wasting your time with something you already knew about.
I know you probably have a million and one things to do (i.e making all this awesome software freely available), but if anyone has the time it might be worth updating the examples since it wasn’t immediately obvious (as a newbie) why things literally went to pieces on me! :wink:
So, if I understand correctly, the new behaviour is by design because if two spatials are connected by a joint it’s problematic to infer which of them the joint actually belongs to?

2 Likes

sorry for wasting your time

Not a waste. This forum is read by many people who can benefit from your inquiry.

it might be worth updating the examples

Which example needs to be updated?

it’s problematic to infer which of them the joint actually belongs to?

Exactly right!

Not an example, strictly speaking, but TestRagDoll is what I used for reference.

It’s difficult with the semantics, since this is the kind of thing I always agonise over (and usually change back and forth several times). But if physicsspace.add accept both joints and spatials, it seems a bit counter-intuitive that addall doesn’t. Would it make sense to separate them out into addSpatial and addJoint (and addAllSpatials and addAllJoints)? Obviously this is proposed without any understanding of the wider issues, and with all the naivety of someone who’s been using JME for just over a week, but I thought I’d share anyway! :wink:

1 Like

There are distinct versions of TestRagDoll for jme3-jbullet

https://github.com/jMonkeyEngine/jmonkeyengine/blob/v3.4/jme3-examples/src/main/java/jme3test/bullet/TestRagDoll.java

and for Minie

https://github.com/stephengold/Minie/blob/4.2.0/Jme3Examples/src/main/java/jme3test/bullet/TestRagDoll.java

But if physicsspace.add accept both joints and spatials, it seems a bit counter-intuitive that addall doesn’t. Would it make sense to separate them out into addSpatial and addJoint (and addAllSpatials and addAllJoints)?

I see how the PhysicsSpace.add() method accepting spatials is a source of confusion. Physics spaces don’t actually contain spatials, only collision objects and joints.

As indicated in MInie’s javadoc, add() and addAll() are provided for compatibility with jme3-bullet, which has had those methods since before 2014. In my own projects, I try to avoid “for compatibility” methods in favor of more specific ones like addCollisionObject() and addJoint().

Perhaps it’s time to start deprecating the “for compatibility” methods in Minie.

2 Likes

Ah, thanks: my mistake. :slightly_smiling_face:

Thanks for the clarification regarding PhysicsSpace.add(). Makes much better sense to me now! :slight_smile:

1 Like