Collsion shape generation problem

I have the following hierarchy





Now I want to generate a mesh collision shape from the static_world spatial/node(!). and box collision shapes with the the rotating_plane spatial, cause they will be moving platforms.



I am try generate mesh collision shape for the static_world spatial, and I get the following error,



java.lang.IllegalStateException: Spatial should not be attached to parent while creating compound collision shape!



Im using the follwing code:

[java]

Node level1 = (Node)assetManager.loadModel(“Scenes/level1.j3o”);

level1.setName(“level1”);

Node geo_basicPlatform = (Node) level1.getChild(0);

geo_basicPlatform.getChild(0).setName(“static_world”);

geo_basicPlatform.getChild(1).setName(“rotating_panel”);

geo_basicPlatform.setLocalScale(0.25f);

geo_basicPlatform.setShadowMode(ShadowMode.CastAndReceive);

CompoundCollisionShape cs_basicPlatform = CollisionShapeFactory.createMeshCompoundShape(geo_basicPlatform);

pn_basicPlatform = new PhysicsNode(geo_basicPlatform, cs_basicPlatform, 0f);

bulletAppState.getPhysicsSpace().add(pn_basicPlatform);

pn_basicPlatform.attachDebugShape(assetManager);

mainNode.attachChild(pn_basicPlatform);[/java]



is there anything wrong with the code, or do i need to take different approach to do this. I need to keep all of my assets in a single scene node , to add it to the water processor.

Uhm, is the error message not clear? “Spatial should not be attached to parent while creating compound collision shape!” Just attach the model after creating the collision shape…

Just attach the model after creating the collision shape..


nah, it didnt work out.

Anyway, i made an workaround and that is, when i took the child node from the scene_node to another temp_node, before using that temp_node any further, i had to remove it from the scene_node.

Isn't this odd?

[java] Node level1 = (Node)assetManager.loadModel("Scenes/level1.j3o");
level1.setName("level1");
Node geo_basicPlatform = (Node) level1.getChild(0);
level1.detachChildAt(0); // This line
geo_basicPlatform.setLocalScale(0.25f);
geo_basicPlatform.setShadowMode(ShadowMode.CastAndReceive);
CompoundCollisionShape cs_basicPlatform = CollisionShapeFactory.createMeshCompoundShape(geo_basicPlatform);
pn_basicPlatform = new PhysicsNode(geo_basicPlatform, cs_basicPlatform, 0f);
pn_basicPlatform.attachDebugShape(assetManager);
bulletAppState.getPhysicsSpace().add(pn_basicPlatform);
mainNode.attachChild(pn_basicPlatform);[/java]

Well, thats what’s meant by “attached to parent”… Just do

[java]geo_basicPlatform.detachFromParent();

CollisionShape cs_basicPlatform = CollisionShapeFactory.createMeshCompoundShape(geo_basicPlatform);

level1.attachChild(geo_basicPlatform);[/java]

or even easier:

[java]

CollisionShape cs_basicPlatform = CollisionShapeFactory.createMeshCompoundShape(level1);

rootNode.attachChild(level1);

[/java]

1 Like
geo_basicPlatform.detachFromParent();


there is no method in of this name.

CollisionShape cs_basicPlatform = CollisionShapeFactory.createMeshCompoundShape(level1);
rootNode.attachChild(level1);


I want to separate out different parts of "level1" to make different collision of different objects.Some are static, i wanna create MeshCompound for them, some are going to move, for those, I am gonna create BoxCompound.But, this code, is creating meshCompound for the whole level, which i dont want.

removeFromParent it is…

actually, that what i was saying, if you have a large level with a good number of moving objects, where you want to use custom collision shapes, then using this process will be too cumbersome.



and if you don’t want to handle then separately, then isn’t it render the whole “add/link to SceneComposer” useless?



or is the answer is to create several scene layer with moving and without moving objects and then marge then altogether?

Why is it “too cumbersome”? You have to load or create the mesh at some point, just generate the collision shape then too, store it and you’re done. I completely don’t get your point, for any type of collision check you have to generate data before, thats also true for the geometry collision checks via the bounding volumes etc.

so, when I convert a mesh to j3o, then, i should create a collision shape at that time, before importing or adding them to the scene?



Everything is a drap and drop upto this point, so how do i create collision shape/custom collision shape.

Yeah, for example. jMP will allow you to add HullCollisionShapes to models just as it allows adding MeshCollisionShapes to terrain right now. So you can simply save it in the j3o and then when you load it its got its collision shape already there. If you have generated meshes (which you indicated) you’d have to generate it directly after you have generated the mesh.