Search in sources :

Example 81 with Spatial

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);
}
Also used : Quaternion(com.jme3.math.Quaternion) InputCapsule(com.jme3.export.InputCapsule) Vector3f(com.jme3.math.Vector3f)

Example 82 with Spatial

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);
    }
}
Also used : Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) SphereCollisionShape(com.jme3.bullet.collision.shapes.SphereCollisionShape) Vector3f(com.jme3.math.Vector3f) Mesh(com.jme3.scene.Mesh) Box(com.jme3.scene.shape.Box) BoxCollisionShape(com.jme3.bullet.collision.shapes.BoxCollisionShape)

Example 83 with 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);
}
Also used : OutputCapsule(com.jme3.export.OutputCapsule)

Example 84 with Spatial

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);
    }
}
Also used : Spatial(com.jme3.scene.Spatial) VehicleWheel(com.jme3.bullet.objects.VehicleWheel)

Example 85 with 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;
}
Also used : VehicleWheel(com.jme3.bullet.objects.VehicleWheel)

Aggregations

Spatial (com.jme3.scene.Spatial)123 Vector3f (com.jme3.math.Vector3f)74 Node (com.jme3.scene.Node)56 Geometry (com.jme3.scene.Geometry)50 DirectionalLight (com.jme3.light.DirectionalLight)46 Material (com.jme3.material.Material)39 Quaternion (com.jme3.math.Quaternion)34 FilterPostProcessor (com.jme3.post.FilterPostProcessor)17 Box (com.jme3.scene.shape.Box)17 KeyTrigger (com.jme3.input.controls.KeyTrigger)15 AmbientLight (com.jme3.light.AmbientLight)14 ColorRGBA (com.jme3.math.ColorRGBA)14 Camera (com.jme3.renderer.Camera)13 Sphere (com.jme3.scene.shape.Sphere)13 Texture (com.jme3.texture.Texture)12 TempVars (com.jme3.util.TempVars)12 InputCapsule (com.jme3.export.InputCapsule)11 ActionListener (com.jme3.input.controls.ActionListener)11 AnimControl (com.jme3.animation.AnimControl)10 OutputCapsule (com.jme3.export.OutputCapsule)9