I have a model that’s similar to the first picture in this album: http://imgur.com/a/RdOv0#0.

Say I want to find all of the model’s smaller parts that intersect a sphere, like the dark red faces in the second picture. How would I go about doing this? Could I cast the Spatial to a Node and get all of the children as an iterator, and just call continue; if it’s not in the range? That’s the only thing that’s coming to mind and it seems too inefficient. Any help is appreciated.

You could try to use the collideWith Method of the Node with the small parts. But then you need to create another collidable representing your sphere. As i see it this would result in intersecting the bounding boxes of the small parts and the bounding box of your sphere collidable.

If you want to have it more accurate and speed is not important my only idea is to manually check the distance of every single vertex of your small parts to the sphere position. But then you would also have to take the rotation and scale of the small parts into account.

Yes you can get all children. There are 2 ways:

Way1 is recursive loop:

[java]

for(Spatial spat: nd){

if(spat instanceof Geometry){

((Geometry)spat).doWhatEver();

}

if(spat instanceof Node){

((Node)spat).doWhatEver();

}

}[/java]

Way2 is SceneGraphVisitor:

[java]

//Search for geometries

SceneGraphVisitor sgv = new SceneGraphVisitor() {

public void visit(Spatial spatial) {

System.out.println(spatial);

if (spatial instanceof Geometry) {

Geometry geom = (Geometry) spatial;

System.out.println(geom.getMaterial()); // I get a material of every geometry

}

}

};

yourNode.depthFirstTraversal(sgv);

[/java]

Was taken from here:

http://hub.jmonkeyengine.org/groups/general-2/forum/topic/how-to-get-only-geometries-from-a-node/

So if I output my model as an OBJ that saves all seperate models as their own geometries attached to a main node, I can load the model and cast it to a node, and just use it like that?

@naas I was thinking that, and I’ll probably work from there. This model has 100 different geometries, each with about 6-8 polygons. It’s for a collapsible physics idea I’m messing with. I’m having a problem with the SceneComposer as well though, it doesn’t seem to want to save at all. When I add a Node to the scene and attach all of the Geometries to it, and choose save, it just reverts back to how it was when I opened it.

@mifth I’ll give both of them a go.

Thanks to both! I’ll post back here if it works!

I got it working, thanks to both of you!