use of com.jme3.scene.Spatial in project jmonkeyengine by jMonkeyEngine.
the class KinematicRagdollControl method read.
/**
* de-serialize this control
*
* @param im
* @throws IOException
*/
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule ic = im.getCapsule(this);
String[] loadedBoneList = ic.readStringArray("boneList", new String[0]);
boneList.addAll(Arrays.asList(loadedBoneList));
PhysicsBoneLink[] loadedBoneLinks = (PhysicsBoneLink[]) ic.readSavableArray("boneList", new PhysicsBoneLink[0]);
for (PhysicsBoneLink physicsBoneLink : loadedBoneLinks) {
boneLinks.put(physicsBoneLink.bone.getName(), physicsBoneLink);
}
modelPosition.set((Vector3f) ic.readSavable("modelPosition", new Vector3f()));
modelRotation.set((Quaternion) ic.readSavable("modelRotation", new Quaternion()));
targetModel = (Spatial) ic.readSavable("targetModel", null);
skeleton = (Skeleton) ic.readSavable("skeleton", null);
// preset //TODO
initScale = (Vector3f) ic.readSavable("initScale", null);
mode = ic.readEnum("mode", Mode.class, Mode.Kinematic);
blendedControl = ic.readBoolean("blendedControl", false);
weightThreshold = ic.readFloat("weightThreshold", -1.0f);
blendStart = ic.readFloat("blendStart", 0.0f);
blendTime = ic.readFloat("blendTime", 1.0f);
eventDispatchImpulseThreshold = ic.readFloat("eventDispatchImpulseThreshold", 10);
rootMass = ic.readFloat("rootMass", 15);
totalMass = ic.readFloat("totalMass", 0);
}
use of com.jme3.scene.Spatial in project jmonkeyengine by jMonkeyEngine.
the class RigidBodyControl method createCollisionShape.
protected void createCollisionShape() {
if (spatial == null) {
return;
}
if (spatial instanceof Geometry) {
Geometry geom = (Geometry) spatial;
Mesh mesh = geom.getMesh();
if (mesh instanceof Sphere) {
collisionShape = new SphereCollisionShape(((Sphere) mesh).getRadius());
return;
} else if (mesh instanceof Box) {
collisionShape = new BoxCollisionShape(new Vector3f(((Box) mesh).getXExtent(), ((Box) mesh).getYExtent(), ((Box) mesh).getZExtent()));
return;
}
}
if (mass > 0) {
collisionShape = CollisionShapeFactory.createDynamicMeshShape(spatial);
} else {
collisionShape = CollisionShapeFactory.createMeshShape(spatial);
}
}
use of com.jme3.scene.Spatial in project jmonkeyengine by jMonkeyEngine.
the class RigidBodyControl method write.
@Override
public void write(JmeExporter ex) throws IOException {
super.write(ex);
OutputCapsule oc = ex.getCapsule(this);
oc.write(enabled, "enabled", true);
oc.write(motionState.isApplyPhysicsLocal(), "applyLocalPhysics", false);
oc.write(kinematicSpatial, "kinematicSpatial", true);
oc.write(spatial, "spatial", null);
}
use of com.jme3.scene.Spatial in project jmonkeyengine by jMonkeyEngine.
the class VehicleControl method cloneFields.
@Override
public void cloneFields(Cloner cloner, Object original) {
this.spatial = cloner.clone(spatial);
for (VehicleWheel wheel : wheels) {
Spatial spatial = cloner.clone(wheel.getWheelSpatial());
wheel.setWheelSpatial(spatial);
}
}
use of com.jme3.scene.Spatial in project jmonkeyengine by jMonkeyEngine.
the class VehicleControl method jmeClone.
@Override
public Object jmeClone() {
VehicleControl control = new VehicleControl(collisionShape, mass);
control.setAngularFactor(getAngularFactor());
control.setAngularSleepingThreshold(getAngularSleepingThreshold());
control.setAngularVelocity(getAngularVelocity());
control.setCcdMotionThreshold(getCcdMotionThreshold());
control.setCcdSweptSphereRadius(getCcdSweptSphereRadius());
control.setCollideWithGroups(getCollideWithGroups());
control.setCollisionGroup(getCollisionGroup());
control.setDamping(getLinearDamping(), getAngularDamping());
control.setFriction(getFriction());
control.setGravity(getGravity());
control.setKinematic(isKinematic());
control.setLinearSleepingThreshold(getLinearSleepingThreshold());
control.setLinearVelocity(getLinearVelocity());
control.setPhysicsLocation(getPhysicsLocation());
control.setPhysicsRotation(getPhysicsRotationMatrix());
control.setRestitution(getRestitution());
control.setFrictionSlip(getFrictionSlip());
control.setMaxSuspensionTravelCm(getMaxSuspensionTravelCm());
control.setSuspensionStiffness(getSuspensionStiffness());
control.setSuspensionCompression(tuning.suspensionCompression);
control.setSuspensionDamping(tuning.suspensionDamping);
control.setMaxSuspensionForce(getMaxSuspensionForce());
for (Iterator<VehicleWheel> it = wheels.iterator(); it.hasNext(); ) {
VehicleWheel wheel = it.next();
VehicleWheel newWheel = control.addWheel(wheel.getLocation(), wheel.getDirection(), wheel.getAxle(), wheel.getRestLength(), wheel.getRadius(), wheel.isFrontWheel());
newWheel.setFrictionSlip(wheel.getFrictionSlip());
newWheel.setMaxSuspensionTravelCm(wheel.getMaxSuspensionTravelCm());
newWheel.setSuspensionStiffness(wheel.getSuspensionStiffness());
newWheel.setWheelsDampingCompression(wheel.getWheelsDampingCompression());
newWheel.setWheelsDampingRelaxation(wheel.getWheelsDampingRelaxation());
newWheel.setMaxSuspensionForce(wheel.getMaxSuspensionForce());
// Copy the wheel spatial reference directly for now. They'll
// get fixed up in the cloneFields() method
newWheel.setWheelSpatial(wheel.getWheelSpatial());
}
control.setApplyPhysicsLocal(isApplyPhysicsLocal());
control.setEnabled(isEnabled());
control.spatial = spatial;
return control;
}
Aggregations