Hi,
I tried running the jmeTests project, and many programs ran, but the one that was most important for me: The TestRagDoll program, rendered only the physics world’s “floor”, the cubes and the sphere. The ragdoll was nowhere to be seen. The other two ragdoll programs worked, but the TestRagDoll was the kind of program I needed JMonkey for.
So I copied that code and tried narrowing down the problem, but CapsuleColissionShape objects are still not visible on the screen. Am I doing something wrong or is there a problem with my computer hardware that makes it not render correctly?
The code:
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.PhysicsSpace;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.bullet.joints.ConeJoint;
import com.jme3.bullet.joints.PhysicsJoint;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;
import com.jme3.system.AppSettings;
/**
*
* @author normenhansen
*/
public class Main extends SimpleApplication implements ActionListener {
private BulletAppState bulletAppState = new BulletAppState();
private Node ragDoll = new Node();
private Node shoulders;
private Vector3f upforce = new Vector3f(0, 200, 0);
private boolean applyForce = false;
public static void main(String[] args) {
Main app = new Main();
app.setShowSettings(false);
AppSettings settings = new AppSettings(true);
settings.put("Width", 1280);
settings.put("Height", 720);
settings.put("Title", "My prog");
settings.put("VSync", true);
//Anti-Aliasing
settings.put("Samples", 4);
app.setSettings(settings);
app.start();
}
@Override
public void simpleInitApp() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
bulletAppState.setDebugEnabled(true);
inputManager.addMapping("Pull ragdoll up", new MouseButtonTrigger(0));
inputManager.addListener(this, "Pull ragdoll up");
PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
//createRagDoll();
Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
material.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
Box box = new Box(0.1f, 0.1f, 1);
Geometry boxGeometry = new Geometry("Box", box);
boxGeometry.setMaterial(material);
boxGeometry.setLocalTranslation(2, -5, 0);
//RigidBodyControl automatically uses box collision shapes when attached to single geometry with box mesh
boxGeometry.addControl(new RigidBodyControl(2));
rootNode.attachChild(boxGeometry);
bulletAppState.getPhysicsSpace().add(boxGeometry);
Box box2 = new Box(0.1f, 0.1f, 1);
Geometry boxGeometry2 = new Geometry("Box", box2);
boxGeometry2.setMaterial(material);
boxGeometry2.setLocalTranslation(2, -5, -2);
//RigidBodyControl automatically uses box collision shapes when attached to single geometry with box mesh
boxGeometry2.addControl(new RigidBodyControl(2));
rootNode.attachChild(boxGeometry2);
bulletAppState.getPhysicsSpace().add(boxGeometry2);
createLimb(0.1f, 0.1f, new Vector3f(3,-5,-2), false, material);
}
private Node createLimb(float width, float height, Vector3f location, boolean rotate, Material mat) {
int axis = rotate ? PhysicsSpace.AXIS_X : PhysicsSpace.AXIS_Y;
CapsuleCollisionShape shape = new CapsuleCollisionShape(width, height, axis);
Node node = new Node("Limb");
node.setMaterial(mat);
RigidBodyControl rigidBodyControl = new RigidBodyControl(shape, 1);
node.setLocalTranslation(location);
node.addControl(rigidBodyControl);
return node;
}
private void createRagDoll() {
// shoulders = createLimb(2, 5, new Vector3f(0, 5, -3), true);
// Node uArmL = createLimb(0.2f, 0.5f, new Vector3f(-5.75f, -4.8f, 2), false);
// Node uArmR = createLimb(0.2f, 0.5f, new Vector3f(5.75f, -4.8f, 2), false);
// Node lArmL = createLimb(0.2f, 0.5f, new Vector3f(-5.75f, -4.2f, 2), false);
// Node lArmR = createLimb(0.2f, 0.5f, new Vector3f(5.75f, -4.2f, 2), false);
// Node body = createLimb(4f, 1, new Vector3f(4, -4, 2), false);
// Node hips = createLimb(0.2f, 0.5f, new Vector3f(5.00f, -4.5f, 2), true);
// Node uLegL = createLimb(0.2f, 0.5f, new Vector3f(-5.25f, -4.2f, 2), false);
// Node uLegR = createLimb(0.2f, 0.5f, new Vector3f(5.25f, -4.2f, 2), false);
// Node lLegL = createLimb(0.2f, 0.5f, new Vector3f(-5.25f, -4.2f, 2), false);
// Node lLegR = createLimb(0.2f, 0.5f, new Vector3f(5.25f, -4.2f, 2), false);
// join(body, shoulders, new Vector3f(1, 2, -3));
// join(body, hips, new Vector3f(0f, -0.5f, 0));
//
// join(uArmL, shoulders, new Vector3f(-0.75f, 1.4f, 0));
// join(uArmR, shoulders, new Vector3f(0.75f, 1.4f, 0));
// join(uArmL, lArmL, new Vector3f(-0.75f, .4f, 0));
// join(uArmR, lArmR, new Vector3f(0.75f, .4f, 0));
//
// join(uLegL, hips, new Vector3f(-.25f, -0.5f, 0));
// join(uLegR, hips, new Vector3f(.25f, -0.5f, 0));
// join(uLegL, lLegL, new Vector3f(-.25f, -1.7f, 0));
// join(uLegR, lLegR, new Vector3f(.25f, -1.7f, 0));
// ragDoll.attachChild(shoulders);
// ragDoll.attachChild(body);
// ragDoll.attachChild(hips);
// ragDoll.attachChild(uArmL);
// ragDoll.attachChild(uArmR);
// ragDoll.attachChild(lArmL);
// ragDoll.attachChild(lArmR);
// ragDoll.attachChild(uLegL);
// ragDoll.attachChild(uLegR);
// ragDoll.attachChild(lLegL);
// ragDoll.attachChild(lLegR);
rootNode.attachChild(ragDoll);
bulletAppState.getPhysicsSpace().addAll(ragDoll);
}
private PhysicsJoint join(Node A, Node B, Vector3f connectionPoint) {
Vector3f pivotA = A.worldToLocal(connectionPoint, new Vector3f());
Vector3f pivotB = B.worldToLocal(connectionPoint, new Vector3f());
ConeJoint joint = new ConeJoint(A.getControl(RigidBodyControl.class), B.getControl(RigidBodyControl.class), pivotA, pivotB);
joint.setLimit(1f, 1f, 0);
return joint;
}
public void onAction(String string, boolean bln, float tpf) {
if ("Pull ragdoll up".equals(string)) {
if (bln) {
shoulders.getControl(RigidBodyControl.class).activate();
applyForce = true;
} else {
applyForce = false;
}
}
}
@Override
public void simpleUpdate(float tpf) {
//cam.lookAt(ragDoll.getLocalTranslation(), Vector3f.UNIT_Y);
if (applyForce) {
shoulders.getControl(RigidBodyControl.class).applyForce(upforce, Vector3f.ZERO);
}
}
}
This is the output from the program:
run:
Jul 04, 2019 9:13:03 AM com.jme3.system.JmeDesktopSystem initialize
INFO: Running on jMonkeyEngine 3.2-stable
* Branch: HEAD
* Git Hash: ea23b6a
* Build Date: 2019-01-02
Jul 04, 2019 9:13:05 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: LWJGL 2.9.3 context running on thread jME3 Main
* Graphics Adapter: null
* Driver Version: null
* Scaling Factor: 1
Jul 04, 2019 9:13:05 AM com.jme3.renderer.opengl.GLRenderer loadCapabilitiesCommon
INFO: OpenGL Renderer Information
* Vendor: Intel Open Source Technology Center
* Renderer: Mesa DRI Intel® Bay Trail
* OpenGL Version: 3.0 Mesa 18.0.5
* GLSL Version: 1.30
* Profile: Compatibility
Jul 04, 2019 9:13:05 AM com.jme3.asset.AssetConfig loadText
WARNING: Cannot find loader com.jme3.scene.plugins.blender.BlenderModelLoader
Jul 04, 2019 9:13:06 AM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFO: Audio Renderer Information
* Device: OpenAL Soft
* Vendor: OpenAL Community
* Renderer: OpenAL Soft
* Version: 1.1 ALSOFT 1.15.1
* Supported channels: 64
* ALC extensions: ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_DEDICATED ALC_EXT_disconnect ALC_EXT_EFX ALC_EXT_thread_local_context ALC_SOFT_loopback
* AL extensions: AL_EXT_ALAW AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_MULAW AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET AL_EXT_source_distance_model AL_LOKI_quadriphonic AL_SOFT_buffer_samples AL_SOFT_buffer_sub_data AL_SOFTX_deferred_updates AL_SOFT_direct_channels AL_SOFT_loop_points AL_SOFT_source_latency
Jul 04, 2019 9:13:06 AM com.jme3.audio.openal.ALAudioRenderer initOpenAL
WARNING: Pausing audio device not supported.
Jul 04, 2019 9:13:06 AM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFO: Audio effect extension version: 1.0
Jul 04, 2019 9:13:06 AM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFO: Audio max auxiliary sends: 4
Bullet-Native: Initializing java classes
BUILD SUCCESSFUL (total time: 7 seconds)