Problem with AddAll in physicsSpatial

Hi,



in PhysicsSpace AddAll

we can see that

[java]



if (spatial instanceof Node) {

List<Spatial> children = ((Node) spatial).getChildren();

for (Iterator<Spatial> it = children.iterator(); it.hasNext():wink: {

Spatial spat = it.next();

if (spat instanceof Node) {

addAll((Node) spat);

}

}

}[/java]



but AddAll take a Spatial as arg. so not sure to understand the reason of filtering out Non Node in the iteration. (if (spat instanceof Node) {)

in my case I have a Node where I attach several Geometry

each geometry have their own rigidcontrol



but since we have that check , all my geometry are not added to the physic space, i have to embeded them all in a node.

I do not see any issue if the code would simply be

[java]



for (Iterator<Spatial> it = children.iterator(); it.hasNext():wink: {

Spatial spat = it.next();

addAll(spat);

}



[/java]



but maybe I am overlooking something here.



Thx,

fred

1 Like

The check for a Node is only for the recursion, the RigidBodyControl of any Spatial should be found by the first if in that method. You sure your geometry has the RigidBodyControl added? I can load and add a map with multiple RigidBodyControls attached to geometries fine.

Yes I have a rigidbody but it is not checked since it is attached to a spatial.



here is my scenario, I a main Node which can contains either node or Geometry like RootNode in app can do.



Node mainNode = new Node(“Main”);

Geometry geoNode = new Geometry();



geoNode .addControl(new rigidBodyControl(0));

mainNode.attachChild(geoNode );



Node someotherNode = new Node();

… some cgeo attach to it

someotherNode.addControl(new rigidBodyControl(0));

mainNode.attachChild(someotherNode);



then

getPhysicspace().AddAll(mainNode );



what happens with AddAll is

someotherNode is added to physicsspace

while geoNode is not added.



because Geometry is Spatial not Node

Oh, now I see what you mean, theres another check before the recursion, yeah that shouldn’t be there, fixed in svn. Thanks!

great thx :slight_smile:

normen,



I updated and I am seeing a classcast exception with the updated code.

you should should remove the cast to Node as it is a Spatial that we want.





addAll((Node) spat);



should be just

addAll(spat);



Since AddAdd(Spatial spatial) no need to cast in Node.

Right. Thanks again ^^