I am using scene editor on the jMonkeyEngine SDK to load in 3dmodels. However, I am running into a couple of issues.
-
It takes super long to render in the 3d models, which didn’t happen before. Here is the scene editor formatting:
-
I don’t know how to set collision detection to the model in the scene (the scene is a .j3o file). The objects just fall into the terrain like this:
This is what the model looks like (for reference)
I am trying to drive a plane as a vehicle, the plane somehow rotates and falls, which I didn’t set. I am new to the physics library. Can somebody help me with my issues?
Here is the code for rendering in the model:
bulletAppState = new BulletAppState();
bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
stateManager.attach(bulletAppState);
terrain.setSupportMultipleCollisions(true);
terrain.addControl(new RigidBodyControl(0));
bulletAppState.getPhysicsSpace().addAll(terrain);
spaceShipShape = new CompoundCollisionShape();
spaceship.addControl(new RigidBodyControl(0));
bulletAppState.getPhysicsSpace().add(spaceship);
playerCapsule = new CapsuleCollisionShape(1.5f, 15f, 1);
character = new CharacterControl(playerCapsule, 0.2f);
character.setJumpSpeed(20);
character.setFallSpeed(50);
character.setGravity(new Vector3f(0,-40f,0));
character.setLinearVelocity(new Vector3f(400, 0, 400));
character.setPhysicsLocation(new Vector3f(-30f, 100f, -101f));
bulletAppState.getPhysicsSpace().add(character);
float stiffness = 120.0f;//200=f1 car
float compValue = 0.2f; //(lower than damp!)
float dampValue = 0.3f;
final float mass = 400;
Node planeNode = (Node)assetManager.loadModel("Scenes/Plane2.j3o");
planeNode.addControl(new RigidBodyControl(0));
Geometry chasis = findGeom(planeNode, "Jet_Body") ;
BoundingBox box = (BoundingBox) chasis.getModelBound();
//Create a hull collision shape for the chassis
CollisionShape carHull = CollisionShapeFactory.createDynamicMeshShape(chasis);
//Create a vehicle control
plane = new VehicleControl(carHull, mass);
planeNode.addControl(plane);
//Setting default values for wheels
plane.setSuspensionCompression(compValue * 2.0f * FastMath.sqrt(stiffness));
plane.setSuspensionDamping(dampValue * 2.0f * FastMath.sqrt(stiffness));
plane.setSuspensionStiffness(stiffness);
plane.setMaxSuspensionForce(10000);
//Create four wheels and add them at their locations
//note that our fancy car actually goes backwards..
Vector3f wheelDirection = new Vector3f(0, -1, 0);
Vector3f wheelAxle = new Vector3f(-1, 0, 0);
Geometry wheel_fr = findGeom(planeNode, "WheelFrontRight");
wheel_fr.center();
box = (BoundingBox) wheel_fr.getModelBound();
float wheelRadius = box.getYExtent();
float back_wheel_h = (wheelRadius * 1.7f) - 1f;
float front_wheel_h = (wheelRadius * 1.9f) - 1f;
plane.addWheel(wheel_fr.getParent(), box.getCenter().add(0, -front_wheel_h, 0),
wheelDirection, wheelAxle, 0.2f, wheelRadius, true);
Geometry wheel_fl = findGeom(planeNode, "WheelFrontLeft");
wheel_fl.center();
box = (BoundingBox) wheel_fl.getModelBound();
plane.addWheel(wheel_fl.getParent(), box.getCenter().add(0, -front_wheel_h, 0),
wheelDirection, wheelAxle, 0.2f, wheelRadius, false);
Geometry wheel_br = findGeom(planeNode, "WheelBackRight");
wheel_br.center();
box = (BoundingBox) wheel_br.getModelBound();
plane.addWheel(wheel_br.getParent(), box.getCenter().add(0, -back_wheel_h, 0),
wheelDirection, wheelAxle, 0.2f, wheelRadius, false);
Geometry wheel_bl = findGeom(planeNode, "WheelBackLeft");
wheel_bl.center();
box = (BoundingBox) wheel_bl.getModelBound();
plane.addWheel(wheel_bl.getParent(), box.getCenter().add(0, -back_wheel_h, 0),
wheelDirection, wheelAxle, 0.2f, wheelRadius, false);
plane.getWheel(2).setFrictionSlip(4);
plane.getWheel(3).setFrictionSlip(4);
Thank you.