Physics Debug shape doesn't update

I have two collision shapes based on the extents of a given spatial for a rigidBody. I store and switch these shapes at certain times and for some odd reason when in debugQuadView after the first collisionshape is switched out it no longer visibly updates the shape. For a quick reference I checked BetterCharacterControl.java which basically does a similar thing except it creates a new CollisionShape in a seperate function getShape() each time it is switched. Is their anyway around this, the actual physics object volume does change as proven by a quick collision test however i can’t get the physics debug shape to render correctly after the initial switch.

What version of jme?

Latest nightly build jME 3.0.0.10431, previous thread was a joke from the previous physics library in jme2

Its strange as I rebuild the display debug shape each time the actual collision shape object for some body changes… So you say you create a new collision shape and just add that right? Can you make a test case for this please?
The content of this post is meant to be read as a straight information or question without an implicit dismissive stance or interest in having the other party feel offended unless there’s emotes that hint otherwise or there’s an increased use of exclamation marks and all-capital words.

Lol used capsule instead of box and didn’t add certain parts to keep the box upright lol either way you can tell that it doesn’t change after the initial change. It does pop from the ground and moves around every time you change the shape showing that the shapes are changing just the visual representation is not updating.

[java]
/*

  • To change this template, choose Tools | Templates
  • and open the template in the editor.
    */
    package test;

import com.jme3.app.SimpleApplication;
import com.jme3.bounding.BoundingBox;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.collision.shapes.CompoundCollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;

/**
*

  • @author Kyle Williams
    */
    public class PhysicsCollisionShapeBug extends SimpleApplication {

    public static void main(String[] args) {
    PhysicsCollisionShapeBug app = new PhysicsCollisionShapeBug();
    app.start();
    }
    private BulletAppState bulletAppState;
    private CollisionShape[] shapes;
    private RigidBodyControl rigidBody;
    private boolean firstShape;

    @Override
    public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    //box with changing collisionShape
    Spatial spat = setUpModel(new Vector3f(0, 5, 0), 1, 1, 1, ColorRGBA.Green);
    recalculateShapes(spat);
    rigidBody = setUpPhysics(spat, shapes[0]);
    //floor
    Spatial floor = setUpModel(Vector3f.ZERO, 10, 1, 10, ColorRGBA.Gray);
    setUpPhysics(floor, null);

     setUpKeys();
    
     this.getFlyByCamera().setMoveSpeed(6f);
     this.getCamera().setLocation(new Vector3f(4, 5, 4));
    

    }

    public Spatial setUpModel(Vector3f location, float x, float y, float z, ColorRGBA color) {
    Geometry cube_leak = new Geometry(“Cube”, new Box(x, y, z));
    Material mat_tl = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
    mat_tl.setColor(“Color”, color); // purple
    cube_leak.setMaterial(mat_tl);
    cube_leak.setLocalTranslation(location);
    rootNode.attachChild(cube_leak);
    return cube_leak;
    }

    public RigidBodyControl setUpPhysics(Spatial spat, CollisionShape shape) {
    RigidBodyControl body;
    if (shape == null) {
    body = new RigidBodyControl(0);
    } else {
    body = new RigidBodyControl(shape, 8);
    }
    spat.addControl(body);
    bulletAppState.getPhysicsSpace().add(body);
    return body;
    }

    private void recalculateShapes(Spatial spatial) {
    shapes = new CollisionShape[2];
    firstShape = false;
    BoundingBox bb = (BoundingBox) spatial.getWorldBound();
    //use smaller side extent over larger side to create a more narrow hitbox
    //and because A-Pose and T-Pose difference greatly impacts value
    float diameter = bb.getXExtent() < bb.getZExtent() ? bb.getXExtent() : bb.getZExtent();
    float height = bb.getYExtent();

     //create collision shapes and wrap them in compound shape to help with offset
     CompoundCollisionShape ccs = new CompoundCollisionShape();
     shapes[0] = new CapsuleCollisionShape(diameter, height);      
     ccs.addChildShape(shapes[0], new Vector3f(0, -height * 0.1f, 0));
     shapes[0] = ccs;
    
     ccs = new CompoundCollisionShape();
     shapes[1] = new CapsuleCollisionShape(diameter, height * 0.6f);      
     ccs.addChildShape(shapes[1], new Vector3f(0, -(height * 0.6f), 0));
     shapes[1] = ccs;
    
      //TODO: Third shape required but to lazy to scroll all the way back to the top at this time I mean really why the hell is this class so long anyway, I mean its shorter than a lot of the classes for the editors but still really man -__-
     //TODO: Delete above line before commiting....
    

    }

    public void setUpKeys() {
    inputManager.addMapping("Switch Shape", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addListener(new ActionListener() {
    public void onAction(String name, boolean keyPressed, float tpf) {
    if (name.equals("Switch Shape") && keyPressed) {
    CollisionShape shape = firstShape ? shapes[0] : shapes[1];
    firstShape = !firstShape;
    rigidBody.setCollisionShape(shape);
    }
    }
    }, "Switch Shape");
    }

    @Override
    public void simpleUpdate(float tpf) {
    super.simpleUpdate(tpf);
    getCamera().lookAt(rigidBody.getPhysicsLocation(), Vector3f.UNIT_Y);
    }
    }
    [/java]

1 Like

Recreating the shapes each time seems to work but just switching shapes that where previously rendered doesn’t update

1 Like