2011-12-03 01:22:42 +00:00
|
|
|
/*
|
2012-10-05 17:22:45 +00:00
|
|
|
* Copyright (c) 2009-2012 jMonkeyEngine
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2011-12-03 01:22:42 +00:00
|
|
|
*/
|
|
|
|
package com.jme3.bullet.control;
|
|
|
|
|
|
|
|
import com.jme3.bullet.PhysicsSpace;
|
|
|
|
import com.jme3.bullet.collision.shapes.BoxCollisionShape;
|
|
|
|
import com.jme3.bullet.collision.shapes.CollisionShape;
|
|
|
|
import com.jme3.bullet.collision.shapes.SphereCollisionShape;
|
|
|
|
import com.jme3.bullet.objects.PhysicsRigidBody;
|
|
|
|
import com.jme3.bullet.util.CollisionShapeFactory;
|
|
|
|
import com.jme3.export.InputCapsule;
|
|
|
|
import com.jme3.export.JmeExporter;
|
|
|
|
import com.jme3.export.JmeImporter;
|
|
|
|
import com.jme3.export.OutputCapsule;
|
|
|
|
import com.jme3.math.Quaternion;
|
|
|
|
import com.jme3.math.Vector3f;
|
|
|
|
import com.jme3.renderer.RenderManager;
|
|
|
|
import com.jme3.renderer.ViewPort;
|
|
|
|
import com.jme3.scene.Geometry;
|
|
|
|
import com.jme3.scene.Mesh;
|
|
|
|
import com.jme3.scene.Spatial;
|
|
|
|
import com.jme3.scene.control.Control;
|
|
|
|
import com.jme3.scene.shape.Box;
|
|
|
|
import com.jme3.scene.shape.Sphere;
|
2016-03-20 02:47:16 -04:00
|
|
|
import com.jme3.util.clone.Cloner;
|
|
|
|
import com.jme3.util.clone.JmeCloneable;
|
2017-01-29 23:30:28 +03:00
|
|
|
|
2011-12-03 01:22:42 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
/**
|
2018-09-16 19:59:45 -07:00
|
|
|
* A physics control to link a PhysicsRigidBody to a spatial.
|
|
|
|
* <p>
|
|
|
|
* This class is shared between JBullet and Native Bullet.
|
2011-12-03 01:22:42 +00:00
|
|
|
*
|
|
|
|
* @author normenhansen
|
|
|
|
*/
|
2016-03-20 02:47:16 -04:00
|
|
|
public class RigidBodyControl extends PhysicsRigidBody implements PhysicsControl, JmeCloneable {
|
2011-12-03 01:22:42 +00:00
|
|
|
|
2018-09-16 19:59:45 -07:00
|
|
|
/**
|
|
|
|
* spatial to which this control is added, or null if none
|
|
|
|
*/
|
2011-12-03 01:22:42 +00:00
|
|
|
protected Spatial spatial;
|
2018-09-16 19:59:45 -07:00
|
|
|
/**
|
|
|
|
* true→control is enabled, false→control is disabled
|
|
|
|
*/
|
2011-12-03 01:22:42 +00:00
|
|
|
protected boolean enabled = true;
|
2018-09-16 19:59:45 -07:00
|
|
|
/**
|
|
|
|
* true→body is added to the physics space, false→not added
|
|
|
|
*/
|
2011-12-03 01:22:42 +00:00
|
|
|
protected boolean added = false;
|
2018-09-16 19:59:45 -07:00
|
|
|
/**
|
|
|
|
* space to which the body is (or would be) added
|
|
|
|
*/
|
2011-12-03 01:22:42 +00:00
|
|
|
protected PhysicsSpace space = null;
|
2018-09-16 19:59:45 -07:00
|
|
|
/**
|
|
|
|
* true→body is kinematic, false→body is static or dynamic
|
|
|
|
*/
|
2011-12-03 01:22:42 +00:00
|
|
|
protected boolean kinematicSpatial = true;
|
|
|
|
|
2018-09-16 19:59:45 -07:00
|
|
|
/**
|
|
|
|
* No-argument constructor needed by SavableClassUtil. Do not invoke
|
|
|
|
* directly!
|
|
|
|
*/
|
2011-12-03 01:22:42 +00:00
|
|
|
public RigidBodyControl() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-09-16 19:59:45 -07:00
|
|
|
* When using this constructor, the CollisionShape for the RigidBody is
|
|
|
|
* generated automatically when the control is added to a spatial.
|
|
|
|
*
|
|
|
|
* @param mass When not 0, a HullCollisionShape is generated, otherwise a
|
|
|
|
* MeshCollisionShape is used. For geometries with box or sphere meshes the
|
|
|
|
* proper box or sphere collision shape is used.
|
2011-12-03 01:22:42 +00:00
|
|
|
*/
|
|
|
|
public RigidBodyControl(float mass) {
|
|
|
|
this.mass = mass;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-09-16 19:59:45 -07:00
|
|
|
* Instantiate an enabled control with mass=1 and the specified collision
|
|
|
|
* shape.
|
|
|
|
*
|
|
|
|
* @param shape the desired shape (not null, alias created)
|
2011-12-03 01:22:42 +00:00
|
|
|
*/
|
|
|
|
public RigidBodyControl(CollisionShape shape) {
|
|
|
|
super(shape);
|
|
|
|
}
|
|
|
|
|
2018-09-16 19:59:45 -07:00
|
|
|
/**
|
|
|
|
* Instantiate an enabled control with the specified collision shape and
|
|
|
|
* mass.
|
|
|
|
*
|
|
|
|
* @param shape the desired shape (not null, alias created)
|
|
|
|
* @param mass the desired mass (≥0)
|
|
|
|
*/
|
2011-12-03 01:22:42 +00:00
|
|
|
public RigidBodyControl(CollisionShape shape, float mass) {
|
|
|
|
super(shape, mass);
|
|
|
|
}
|
|
|
|
|
2018-09-16 19:59:45 -07:00
|
|
|
/**
|
|
|
|
* Clone this control for a different spatial. No longer used as of JME 3.1.
|
|
|
|
*
|
|
|
|
* @param spatial the spatial for the clone to control (or null)
|
|
|
|
* @return a new control (not null)
|
|
|
|
*/
|
2016-03-11 05:37:07 -05:00
|
|
|
@Override
|
2011-12-03 01:22:42 +00:00
|
|
|
public Control cloneForSpatial(Spatial spatial) {
|
|
|
|
RigidBodyControl control = new RigidBodyControl(collisionShape, mass);
|
|
|
|
control.setAngularFactor(getAngularFactor());
|
|
|
|
control.setAngularSleepingThreshold(getAngularSleepingThreshold());
|
|
|
|
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.setKinematicSpatial(isKinematicSpatial());
|
|
|
|
control.setLinearSleepingThreshold(getLinearSleepingThreshold());
|
|
|
|
control.setPhysicsLocation(getPhysicsLocation(null));
|
|
|
|
control.setPhysicsRotation(getPhysicsRotationMatrix(null));
|
|
|
|
control.setRestitution(getRestitution());
|
|
|
|
|
|
|
|
if (mass > 0) {
|
|
|
|
control.setAngularVelocity(getAngularVelocity());
|
|
|
|
control.setLinearVelocity(getLinearVelocity());
|
|
|
|
}
|
|
|
|
control.setApplyPhysicsLocal(isApplyPhysicsLocal());
|
|
|
|
return control;
|
|
|
|
}
|
|
|
|
|
2018-09-16 19:59:45 -07:00
|
|
|
/**
|
|
|
|
* Create a shallow clone for the JME cloner.
|
|
|
|
*
|
|
|
|
* @return a new control (not null)
|
|
|
|
*/
|
2016-03-20 02:47:16 -04:00
|
|
|
@Override
|
|
|
|
public Object jmeClone() {
|
|
|
|
RigidBodyControl control = new RigidBodyControl(collisionShape, mass);
|
|
|
|
control.setAngularFactor(getAngularFactor());
|
|
|
|
control.setAngularSleepingThreshold(getAngularSleepingThreshold());
|
|
|
|
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.setKinematicSpatial(isKinematicSpatial());
|
|
|
|
control.setLinearSleepingThreshold(getLinearSleepingThreshold());
|
|
|
|
control.setPhysicsLocation(getPhysicsLocation(null));
|
|
|
|
control.setPhysicsRotation(getPhysicsRotationMatrix(null));
|
|
|
|
control.setRestitution(getRestitution());
|
|
|
|
|
|
|
|
if (mass > 0) {
|
|
|
|
control.setAngularVelocity(getAngularVelocity());
|
|
|
|
control.setLinearVelocity(getLinearVelocity());
|
|
|
|
}
|
|
|
|
control.setApplyPhysicsLocal(isApplyPhysicsLocal());
|
|
|
|
control.spatial = this.spatial;
|
2017-01-29 23:30:28 +03:00
|
|
|
control.setEnabled(isEnabled());
|
|
|
|
|
2016-03-20 02:47:16 -04:00
|
|
|
return control;
|
|
|
|
}
|
|
|
|
|
2018-09-16 19:59:45 -07:00
|
|
|
/**
|
|
|
|
* Callback from {@link com.jme3.util.clone.Cloner} to convert this
|
|
|
|
* shallow-cloned control into a deep-cloned one, using the specified cloner
|
|
|
|
* and original to resolve copied fields.
|
|
|
|
*
|
|
|
|
* @param cloner the cloner currently cloning this control (not null)
|
|
|
|
* @param original the control from which this control was shallow-cloned
|
|
|
|
* (unused)
|
|
|
|
*/
|
2016-03-20 02:47:16 -04:00
|
|
|
@Override
|
|
|
|
public void cloneFields( Cloner cloner, Object original ) {
|
|
|
|
this.spatial = cloner.clone(spatial);
|
|
|
|
}
|
|
|
|
|
2018-09-16 19:59:45 -07:00
|
|
|
/**
|
|
|
|
* Alter which spatial is controlled. Invoked when the control is added to
|
|
|
|
* or removed from a spatial. Should be invoked only by a subclass or from
|
|
|
|
* Spatial. Do not invoke directly from user code.
|
|
|
|
*
|
|
|
|
* @param spatial the spatial to control (or null)
|
|
|
|
*/
|
2011-12-03 01:22:42 +00:00
|
|
|
public void setSpatial(Spatial spatial) {
|
|
|
|
this.spatial = spatial;
|
2012-08-16 21:49:06 +00:00
|
|
|
setUserObject(spatial);
|
2011-12-03 01:22:42 +00:00
|
|
|
if (spatial == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (collisionShape == null) {
|
|
|
|
createCollisionShape();
|
|
|
|
rebuildRigidBody();
|
|
|
|
}
|
|
|
|
setPhysicsLocation(getSpatialTranslation());
|
|
|
|
setPhysicsRotation(getSpatialRotation());
|
|
|
|
}
|
|
|
|
|
2018-09-16 19:59:45 -07:00
|
|
|
/**
|
|
|
|
* Set the collision shape based on the controlled spatial and its
|
|
|
|
* descendents.
|
|
|
|
*/
|
2011-12-03 01:22:42 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-16 19:59:45 -07:00
|
|
|
/**
|
|
|
|
* Enable or disable this control.
|
|
|
|
* <p>
|
|
|
|
* When the control is disabled, the body is removed from physics space.
|
|
|
|
* When the control is enabled again, the body is moved to the current
|
|
|
|
* location of the spatial and then added to the physics space.
|
|
|
|
*
|
|
|
|
* @param enabled true→enable the control, false→disable it
|
|
|
|
*/
|
2011-12-03 01:22:42 +00:00
|
|
|
public void setEnabled(boolean enabled) {
|
|
|
|
this.enabled = enabled;
|
|
|
|
if (space != null) {
|
|
|
|
if (enabled && !added) {
|
|
|
|
if (spatial != null) {
|
|
|
|
setPhysicsLocation(getSpatialTranslation());
|
|
|
|
setPhysicsRotation(getSpatialRotation());
|
|
|
|
}
|
|
|
|
space.addCollisionObject(this);
|
|
|
|
added = true;
|
|
|
|
} else if (!enabled && added) {
|
|
|
|
space.removeCollisionObject(this);
|
|
|
|
added = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-16 19:59:45 -07:00
|
|
|
/**
|
|
|
|
* Test whether this control is enabled.
|
|
|
|
*
|
|
|
|
* @return true if enabled, otherwise false
|
|
|
|
*/
|
2011-12-03 01:22:42 +00:00
|
|
|
public boolean isEnabled() {
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-09-16 19:59:45 -07:00
|
|
|
* Test whether this control is in kinematic mode.
|
|
|
|
*
|
|
|
|
* @return true if the spatial location and rotation are applied to the
|
|
|
|
* rigid body, otherwise false
|
2011-12-03 01:22:42 +00:00
|
|
|
*/
|
|
|
|
public boolean isKinematicSpatial() {
|
|
|
|
return kinematicSpatial;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-09-16 19:59:45 -07:00
|
|
|
* Enable or disable kinematic mode. In kinematic mode, the spatial's
|
|
|
|
* location and rotation will be applied to the rigid body.
|
|
|
|
*
|
|
|
|
* @param kinematicSpatial true→kinematic, false→dynamic or static
|
2011-12-03 01:22:42 +00:00
|
|
|
*/
|
|
|
|
public void setKinematicSpatial(boolean kinematicSpatial) {
|
|
|
|
this.kinematicSpatial = kinematicSpatial;
|
|
|
|
}
|
|
|
|
|
2018-09-16 19:59:45 -07:00
|
|
|
/**
|
|
|
|
* Test whether physics-space coordinates should match the spatial's local
|
|
|
|
* coordinates.
|
|
|
|
*
|
|
|
|
* @return true if matching local coordinates, false if matching world
|
|
|
|
* coordinates
|
|
|
|
*/
|
2011-12-03 01:22:42 +00:00
|
|
|
public boolean isApplyPhysicsLocal() {
|
|
|
|
return motionState.isApplyPhysicsLocal();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-09-16 19:59:45 -07:00
|
|
|
* Alter whether physics-space coordinates should match the spatial's local
|
|
|
|
* coordinates.
|
|
|
|
*
|
|
|
|
* @param applyPhysicsLocal true→match local coordinates,
|
|
|
|
* false→match world coordinates (default=false)
|
2011-12-03 01:22:42 +00:00
|
|
|
*/
|
|
|
|
public void setApplyPhysicsLocal(boolean applyPhysicsLocal) {
|
|
|
|
motionState.setApplyPhysicsLocal(applyPhysicsLocal);
|
|
|
|
}
|
|
|
|
|
2018-09-16 19:59:45 -07:00
|
|
|
/**
|
|
|
|
* Access whichever spatial translation corresponds to the physics location.
|
|
|
|
*
|
|
|
|
* @return the pre-existing vector (not null)
|
|
|
|
*/
|
2011-12-03 01:22:42 +00:00
|
|
|
private Vector3f getSpatialTranslation(){
|
|
|
|
if(motionState.isApplyPhysicsLocal()){
|
|
|
|
return spatial.getLocalTranslation();
|
|
|
|
}
|
|
|
|
return spatial.getWorldTranslation();
|
|
|
|
}
|
|
|
|
|
2018-09-16 19:59:45 -07:00
|
|
|
/**
|
|
|
|
* Access whichever spatial rotation corresponds to the physics rotation.
|
|
|
|
*
|
|
|
|
* @return the pre-existing quaternion (not null)
|
|
|
|
*/
|
2011-12-03 01:22:42 +00:00
|
|
|
private Quaternion getSpatialRotation(){
|
|
|
|
if(motionState.isApplyPhysicsLocal()){
|
|
|
|
return spatial.getLocalRotation();
|
|
|
|
}
|
|
|
|
return spatial.getWorldRotation();
|
|
|
|
}
|
|
|
|
|
2018-09-16 19:59:45 -07:00
|
|
|
/**
|
|
|
|
* Update this control. Invoked once per frame, during the logical-state
|
|
|
|
* update, provided the control is added to a scene.
|
|
|
|
*
|
|
|
|
* @param tpf the time interval between frames (in seconds, ≥0)
|
|
|
|
*/
|
2011-12-03 01:22:42 +00:00
|
|
|
public void update(float tpf) {
|
|
|
|
if (enabled && spatial != null) {
|
|
|
|
if (isKinematic() && kinematicSpatial) {
|
|
|
|
super.setPhysicsLocation(getSpatialTranslation());
|
|
|
|
super.setPhysicsRotation(getSpatialRotation());
|
|
|
|
} else {
|
|
|
|
getMotionState().applyTransform(spatial);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-16 19:59:45 -07:00
|
|
|
/**
|
|
|
|
* Render this control. Invoked once per view port per frame, provided the
|
|
|
|
* control is added to a scene. Should be invoked only by a subclass or by
|
|
|
|
* the RenderManager.
|
|
|
|
*
|
|
|
|
* @param rm the render manager (not null)
|
|
|
|
* @param vp the view port to render (not null)
|
|
|
|
*/
|
2011-12-03 01:22:42 +00:00
|
|
|
public void render(RenderManager rm, ViewPort vp) {
|
|
|
|
}
|
|
|
|
|
2018-09-06 10:30:51 -07:00
|
|
|
/**
|
|
|
|
* If enabled, add this control's body to the specified physics space. In
|
|
|
|
* not enabled, alter where the body would be added. The body is removed
|
|
|
|
* from any other space it's currently in.
|
|
|
|
*
|
|
|
|
* @param newSpace where to add, or null to simply remove
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void setPhysicsSpace(PhysicsSpace newSpace) {
|
|
|
|
if (space == newSpace) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (added) {
|
|
|
|
space.removeCollisionObject(this);
|
|
|
|
added = false;
|
|
|
|
}
|
|
|
|
if (newSpace != null && isEnabled()) {
|
|
|
|
newSpace.addCollisionObject(this);
|
|
|
|
added = true;
|
2011-12-03 01:22:42 +00:00
|
|
|
}
|
2018-09-06 10:30:51 -07:00
|
|
|
/*
|
|
|
|
* If this control isn't enabled, its body will be
|
|
|
|
* added to the new space when the control becomes enabled.
|
|
|
|
*/
|
|
|
|
space = newSpace;
|
2011-12-03 01:22:42 +00:00
|
|
|
}
|
|
|
|
|
2018-09-16 19:59:45 -07:00
|
|
|
/**
|
|
|
|
* Access the physics space to which the body is (or would be) added.
|
|
|
|
*
|
|
|
|
* @return the pre-existing space, or null for none
|
|
|
|
*/
|
2011-12-03 01:22:42 +00:00
|
|
|
public PhysicsSpace getPhysicsSpace() {
|
|
|
|
return space;
|
|
|
|
}
|
|
|
|
|
2018-09-16 19:59:45 -07:00
|
|
|
/**
|
|
|
|
* Serialize this control, for example when saving to a J3O file.
|
|
|
|
*
|
|
|
|
* @param ex exporter (not null)
|
|
|
|
* @throws IOException from exporter
|
|
|
|
*/
|
2011-12-03 01:22:42 +00:00
|
|
|
@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);
|
|
|
|
}
|
|
|
|
|
2018-09-16 19:59:45 -07:00
|
|
|
/**
|
|
|
|
* De-serialize this control, for example when loading from a J3O file.
|
|
|
|
*
|
|
|
|
* @param im importer (not null)
|
|
|
|
* @throws IOException from importer
|
|
|
|
*/
|
2011-12-03 01:22:42 +00:00
|
|
|
@Override
|
|
|
|
public void read(JmeImporter im) throws IOException {
|
|
|
|
super.read(im);
|
|
|
|
InputCapsule ic = im.getCapsule(this);
|
|
|
|
enabled = ic.readBoolean("enabled", true);
|
|
|
|
kinematicSpatial = ic.readBoolean("kinematicSpatial", true);
|
|
|
|
spatial = (Spatial) ic.readSavable("spatial", null);
|
|
|
|
motionState.setApplyPhysicsLocal(ic.readBoolean("applyLocalPhysics", false));
|
|
|
|
setUserObject(spatial);
|
|
|
|
}
|
2018-09-16 19:59:45 -07:00
|
|
|
}
|