/** * Sets an object to animate. The object's index is <code>index</code> and it's parent index is * <code>parentIndex</code>. A parent index of -1 indicates it has no parent. * * @param objChange The spatial that will be updated by this SpatialTransformer. * @param index The index of that spatial in this transformer's array * @param parentIndex The parentIndex in this transformer's array for this Spatial */ public void setObject(Spatial objChange, int index, int parentIndex) { toChange[index] = objChange; pivots[index].setTranslation(objChange.getLocalTranslation()); pivots[index].setScale(objChange.getLocalScale()); pivots[index].setRotationQuaternion(objChange.getLocalRotation()); parentIndexes[index] = parentIndex; }
public void setSpatial(Spatial model) { if (model == null) { removeFromPhysicsSpace(); clearData(); return; } targetModel = model; Node parent = model.getParent(); Vector3f initPosition = model.getLocalTranslation().clone(); Quaternion initRotation = model.getLocalRotation().clone(); initScale = model.getLocalScale().clone(); model.removeFromParent(); model.setLocalTranslation(Vector3f.ZERO); model.setLocalRotation(Quaternion.IDENTITY); model.setLocalScale(1); // HACK ALERT change this // I remove the skeletonControl and readd it to the spatial to make sure it's after the // ragdollControl in the stack // Find a proper way to order the controls. SkeletonControl sc = model.getControl(SkeletonControl.class); model.removeControl(sc); model.addControl(sc); // ---- removeFromPhysicsSpace(); clearData(); // put into bind pose and compute bone transforms in model space // maybe dont reset to ragdoll out of animations? scanSpatial(model); if (parent != null) { parent.attachChild(model); } model.setLocalTranslation(initPosition); model.setLocalRotation(initRotation); model.setLocalScale(initScale); logger.log(Level.INFO, "Created physics ragdoll for skeleton {0}", skeleton); }