hello,
i try to convert spatials from a scene file that only contains the rigid parts of a vehicle (boxes)
i want to fetch each part and create a rigid box collision shape to add to a compound one
so i use
s beeing a spatial from a list (i use the descendantMatches() function)
Code:
BoxCollisionShape sShape=(BoxCollisionShape) CollisionShapeFactory.createBoxShape(s);
ht300Shape.addChildShape(sShape,new Vector3f());
but the shapes are never added
sShape.getHalfextents() returns a 0,0,0 vector
is it possible to do so, i cant find any example of this
thx
normen
March 15, 2012, 7:46pm
2
Yes it works fine, the CollisionShapeFactory does it all the time. Must be something in your code.
@normen said:
Yes it works fine, the CollisionShapeFactory does it all the time. Must be something in your code.
no matter what i do it does not add the shapes, so
now i did this
Code:
CompoundCollisionShape compoundShape = new CompoundCollisionShape();
BoxCollisionShape box = new BoxCollisionShape(new Vector3f(1.2f, 0.5f, 2.4f));
compoundShape.addChildShape(box, new Vector3f(0, 1, 0));
spatial = (Node) assetManager.loadModel("Scenes/Rigid.j3o");
ArrayList<Spatial> list = findByName(spatial,"-geom-1");
for(Spatial s:list)
{
CollisionShape sShape = CollisionShapeFactory.createMeshShape(s);
compoundShape.addChildShape(sShape,new Vector3f(0,0,0));
}
…
private ArrayList<Spatial> findByName(Node root,String name)
{
List<Spatial> list = root.descendantMatches(Spatial.class);
ArrayList<Spatial> list2 = new ArrayList<Spatial>();
for(Spatial s:list)
{
if(s.getName().endsWith(name))
list2.add(s);
}
return list2;
}
it seems the two mesh are processed
_Rigid-geom-1 (Geometry)
_Rigid2-geom-1 (Geometry)
the box is added but not the other meshes
or at least not visible
normen
March 16, 2012, 1:26am
4
What do you mean by “visible”?
are you adding it to both a spatial and the physics space?
well the 1st box is visible with a blue outline, not the other objects
i would expect they all appear
@wezrule said:
are you adding it to both a spatial and the physics space?
no need for spacial to be added
addChildShape works for the 1st box (the actual code from the tutorial)
if i could only get the verticex of a spacial, i could have the dimensions to create the boxes i want
i see there is a getVerticesCount() method for the spacial object
but how can i get the vertex coords ?
why is there a setModelBound but no getModelBound method?
normen
March 16, 2012, 11:33am
9
Why do you do that manually :? CollisionShapeFactory does exactly the same. Also, are you sure they are not added? I guess the debug view just doesn’t get updated.
@normen said:
Why do you do that manually :? CollisionShapeFactory does exactly the same. Also, are you sure they are not added? I guess the debug view just doesn't get updated.
I added a second box and it gets displayed correcly
Code:
CompoundCollisionShape compoundShape = new CompoundCollisionShape();
BoxCollisionShape box = new BoxCollisionShape(new Vector3f(1.2f, 0.5f, 2.4f));
compoundShape.addChildShape(box, new Vector3f(0, 1, 0));
box = new BoxCollisionShape(new Vector3f(1.2f, 0.5f, 2.4f));
compoundShape.addChildShape(box, new Vector3f(0, 2, 0));
i found that
BoundingVolume wb = s.getWorldBound(); so objects are loaded correctly
would return data with Extents set to coerents value
as I trace/debug (into jme code), it does this
Code:
1)
BoxCollisionShape sShape=(BoxCollisionShape) CollisionShapeFactory.createBoxShape(s);
public static CollisionShape createBoxShape(Spatial spatial) {
…
return createSingleBoxShape((Geometry) spatial, spatial);
…
private static BoxCollisionShape createSingleBoxShape(Spatial spatial, Spatial parent) {
spatial.setModelBound(new BoundingBox());
BoxCollisionShape shape = new BoxCollisionShape(
((BoundingBox) spatial.getWorldBound()).getExtent(new Vector3f()));
return shape;
}
((BoundingBox) spatial.getWorldBound()).getExtent(new Vector3f()) returns correct extents data
but the extents of the shape objects has extents as (0,0,0)
[edit] the extents were empty in the spatial too
normen
March 16, 2012, 11:49am
11
Sorry, I don’t understand you. Everything works as it should.
in CollisionShapeFactory
Code:
private static BoxCollisionShape createSingleBoxShape(Spatial spatial, Spatial parent) {
spatial.setModelBound(new BoundingBox());
//TODO: using world bound here instead of "local world" bound...
BoxCollisionShape shape = new BoxCollisionShape(
((BoundingBox) spatial.getWorldBound()).getExtent(new Vector3f()));
return shape;
}
spatial.setModelBound(new BoundingBox()); will erase(obiously) all extents
spatial.getWorldBound()).getExtent ... returns a 0,0,0 vector
so i changed my code (instead of using the factory function)
Code:
for(Spatial s:list)
{
BoxCollisionShape sShape = new BoxCollisionShape(((BoundingBox) s.getWorldBound()).getExtent(new Vector3f()));
rootNode.attachChild(s);
compoundShape.addChildShape(sShape,s.getWorldBound().getCenter());
System.out.println(sShape.getHalfExtents());
}
so far it works as i avoid to call setModelBounds on the spacial
the other shapes appeared
i don't get this, maybe a bug, or i used it in the wrong way
anyway thx for your help