Fix a bug with bad bones placing.
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8951 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
e4c4380ab5
commit
2ac215f477
@ -8,7 +8,6 @@ import com.jme3.animation.SpatialTrack;
|
|||||||
import com.jme3.animation.Track;
|
import com.jme3.animation.Track;
|
||||||
import com.jme3.scene.Spatial;
|
import com.jme3.scene.Spatial;
|
||||||
import com.jme3.scene.plugins.blender.BlenderContext;
|
import com.jme3.scene.plugins.blender.BlenderContext;
|
||||||
import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType;
|
|
||||||
import com.jme3.scene.plugins.blender.animations.Ipo;
|
import com.jme3.scene.plugins.blender.animations.Ipo;
|
||||||
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
|
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
|
||||||
import com.jme3.scene.plugins.blender.file.Pointer;
|
import com.jme3.scene.plugins.blender.file.Pointer;
|
||||||
@ -21,6 +20,8 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper;
|
|||||||
* @author Marcin Roguski (Kaelthas)
|
* @author Marcin Roguski (Kaelthas)
|
||||||
*/
|
*/
|
||||||
public abstract class Constraint {
|
public abstract class Constraint {
|
||||||
|
public static final int BAKE_DYNAMIC = 0x01;
|
||||||
|
public static final int BAKE_STATIC = 0x02;
|
||||||
|
|
||||||
/** The name of this constraint. */
|
/** The name of this constraint. */
|
||||||
protected final String name;
|
protected final String name;
|
||||||
@ -72,24 +73,38 @@ public abstract class Constraint {
|
|||||||
throw new BlenderFileException("The constraint has no data specified!");
|
throw new BlenderFileException("The constraint has no data specified!");
|
||||||
}
|
}
|
||||||
Space ownerSpace = Space.valueOf(((Number) constraintStructure.getFieldValue("ownspace")).byteValue());
|
Space ownerSpace = Space.valueOf(((Number) constraintStructure.getFieldValue("ownspace")).byteValue());
|
||||||
Object owner = blenderContext.getLoadedFeature(ownerOMA, LoadedFeatureDataType.LOADED_FEATURE);
|
this.owner = new Feature(ownerSpace, ownerOMA, blenderContext);
|
||||||
if(owner instanceof Spatial) {
|
|
||||||
this.owner = new Feature((Spatial)owner, ownerSpace, ownerOMA, blenderContext);
|
|
||||||
} else {
|
|
||||||
this.owner = new Feature((Bone)owner, ownerSpace, ownerOMA, blenderContext);
|
|
||||||
}
|
|
||||||
this.ipo = influenceIpo;
|
this.ipo = influenceIpo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method bakes the required sontraints into its owner.
|
||||||
|
* @param bakeFlag the bake type flag support the following values:
|
||||||
|
* <li> BAKE_DYNAMIC - bake animation's constraints
|
||||||
|
* <li> BAKE_STATIC - bake static constraints
|
||||||
|
*/
|
||||||
|
public void bake(int bakeFlag) {
|
||||||
|
this.owner.update();
|
||||||
|
if(this.target != null) {
|
||||||
|
this.target.update();
|
||||||
|
}
|
||||||
|
if((bakeFlag & BAKE_DYNAMIC) != 0) {
|
||||||
|
this.bakeDynamic();
|
||||||
|
}
|
||||||
|
if((bakeFlag & BAKE_STATIC) != 0) {
|
||||||
|
this.bakeStatic();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bake the animation's constraints into its owner.
|
* Bake the animation's constraints into its owner.
|
||||||
*/
|
*/
|
||||||
public abstract void bakeDynamic();
|
protected abstract void bakeDynamic();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bake the static constraints into its owner.
|
* Bake the static constraints into its owner.
|
||||||
*/
|
*/
|
||||||
public abstract void bakeStatic();
|
protected abstract void bakeStatic();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns the bone traces for the bone that is affected by the given constraint.
|
* This method returns the bone traces for the bone that is affected by the given constraint.
|
||||||
|
@ -35,13 +35,13 @@ import java.util.logging.Logger;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeDynamic() {
|
protected void bakeDynamic() {
|
||||||
// TODO: implement 'Action' constraint
|
// TODO: implement 'Action' constraint
|
||||||
LOGGER.log(Level.WARNING, "'Action' constraint NOT implemented!");
|
LOGGER.log(Level.WARNING, "'Action' constraint NOT implemented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeStatic() {
|
protected void bakeStatic() {
|
||||||
// TODO: implement 'Action' constraint
|
// TODO: implement 'Action' constraint
|
||||||
LOGGER.log(Level.WARNING, "'Action' constraint NOT implemented!");
|
LOGGER.log(Level.WARNING, "'Action' constraint NOT implemented!");
|
||||||
}
|
}
|
||||||
|
@ -35,13 +35,13 @@ import java.util.logging.Logger;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeDynamic() {
|
protected void bakeDynamic() {
|
||||||
// TODO: implement ChildOf constraint
|
// TODO: implement ChildOf constraint
|
||||||
LOGGER.log(Level.WARNING, "ChildOf constraint NOT implemented!");
|
LOGGER.log(Level.WARNING, "ChildOf constraint NOT implemented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeStatic() {
|
protected void bakeStatic() {
|
||||||
// TODO: implement ChildOf constraint
|
// TODO: implement ChildOf constraint
|
||||||
LOGGER.log(Level.WARNING, "ChildOf constraint NOT implemented!");
|
LOGGER.log(Level.WARNING, "ChildOf constraint NOT implemented!");
|
||||||
}
|
}
|
||||||
|
@ -36,13 +36,13 @@ import java.util.logging.Logger;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeDynamic() {
|
protected void bakeDynamic() {
|
||||||
//TODO: implement when curves are implemented
|
//TODO: implement when curves are implemented
|
||||||
LOGGER.log(Level.INFO, "'Clamp to' not yet implemented! Curves not yet implemented!", name);
|
LOGGER.log(Level.INFO, "'Clamp to' not yet implemented! Curves not yet implemented!", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeStatic() {
|
protected void bakeStatic() {
|
||||||
//TODO: implement when curves are implemented
|
//TODO: implement when curves are implemented
|
||||||
LOGGER.log(Level.INFO, "'Clamp to' not yet implemented! Curves not yet implemented!", name);
|
LOGGER.log(Level.INFO, "'Clamp to' not yet implemented! Curves not yet implemented!", name);
|
||||||
}
|
}
|
||||||
|
@ -36,13 +36,13 @@ import com.jme3.scene.plugins.blender.file.Structure;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeDynamic() {
|
protected void bakeDynamic() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
LOGGER.log(Level.WARNING, "'Damp Track' constraint NOT implemented!");
|
LOGGER.log(Level.WARNING, "'Damp Track' constraint NOT implemented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeStatic() {
|
protected void bakeStatic() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
LOGGER.log(Level.WARNING, "'Damp Track' constraint NOT implemented!");
|
LOGGER.log(Level.WARNING, "'Damp Track' constraint NOT implemented!");
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ import com.jme3.scene.plugins.ogre.AnimData;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeDynamic() {
|
protected void bakeDynamic() {
|
||||||
AnimData animData = blenderContext.getAnimData(this.owner.getOma());
|
AnimData animData = blenderContext.getAnimData(this.owner.getOma());
|
||||||
if(animData != null) {
|
if(animData != null) {
|
||||||
Object owner = this.owner.getObject();
|
Object owner = this.owner.getObject();
|
||||||
@ -69,7 +69,7 @@ import com.jme3.scene.plugins.ogre.AnimData;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeStatic() {
|
protected void bakeStatic() {
|
||||||
Matrix4f targetWorldMatrix = target.getWorldTransformMatrix();
|
Matrix4f targetWorldMatrix = target.getWorldTransformMatrix();
|
||||||
Vector3f targetLocation = targetWorldMatrix.toTranslationVector();
|
Vector3f targetLocation = targetWorldMatrix.toTranslationVector();
|
||||||
Matrix4f m = owner.getParentWorldTransformMatrix();
|
Matrix4f m = owner.getParentWorldTransformMatrix();
|
||||||
|
@ -35,13 +35,13 @@ import java.util.logging.Logger;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeDynamic() {
|
protected void bakeDynamic() {
|
||||||
//TODO: implement when curves are implemented
|
//TODO: implement when curves are implemented
|
||||||
LOGGER.log(Level.INFO, "'Follow path' not implemented! Curves not yet implemented!");
|
LOGGER.log(Level.INFO, "'Follow path' not implemented! Curves not yet implemented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeStatic() {
|
protected void bakeStatic() {
|
||||||
//TODO: implement when curves are implemented
|
//TODO: implement when curves are implemented
|
||||||
LOGGER.log(Level.INFO, "'Follow path' not implemented! Curves not yet implemented!");
|
LOGGER.log(Level.INFO, "'Follow path' not implemented! Curves not yet implemented!");
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ import java.util.logging.Logger;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeDynamic() {
|
protected void bakeDynamic() {
|
||||||
// try {
|
// try {
|
||||||
// IK solver is only attached to bones
|
// IK solver is only attached to bones
|
||||||
// Bone ownerBone = (Bone) blenderContext.getLoadedFeature(ownerOMA, LoadedFeatureDataType.LOADED_FEATURE);
|
// Bone ownerBone = (Bone) blenderContext.getLoadedFeature(ownerOMA, LoadedFeatureDataType.LOADED_FEATURE);
|
||||||
@ -128,7 +128,7 @@ import java.util.logging.Logger;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeStatic() {
|
protected void bakeStatic() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ import com.jme3.scene.plugins.ogre.AnimData;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeDynamic() {
|
protected void bakeDynamic() {
|
||||||
AnimData animData = blenderContext.getAnimData(owner.getOma());
|
AnimData animData = blenderContext.getAnimData(owner.getOma());
|
||||||
if(animData != null) {
|
if(animData != null) {
|
||||||
Object owner = this.owner.getObject();
|
Object owner = this.owner.getObject();
|
||||||
@ -79,7 +79,7 @@ import com.jme3.scene.plugins.ogre.AnimData;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeStatic() {
|
protected void bakeStatic() {
|
||||||
Transform targetTransform = this.target.getTransform();
|
Transform targetTransform = this.target.getTransform();
|
||||||
Transform ownerTransform = this.owner.getTransform();
|
Transform ownerTransform = this.owner.getTransform();
|
||||||
Vector3f ownerLocation = ownerTransform.getTranslation();
|
Vector3f ownerLocation = ownerTransform.getTranslation();
|
||||||
|
@ -73,7 +73,7 @@ import com.jme3.scene.plugins.ogre.AnimData;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeDynamic() {
|
protected void bakeDynamic() {
|
||||||
Object owner = this.owner.getObject();
|
Object owner = this.owner.getObject();
|
||||||
AnimData animData = blenderContext.getAnimData(this.owner.getOma());
|
AnimData animData = blenderContext.getAnimData(this.owner.getOma());
|
||||||
if(animData != null) {
|
if(animData != null) {
|
||||||
@ -90,7 +90,7 @@ import com.jme3.scene.plugins.ogre.AnimData;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeStatic() {
|
protected void bakeStatic() {
|
||||||
Transform ownerTransform = this.owner.getTransform();
|
Transform ownerTransform = this.owner.getTransform();
|
||||||
Vector3f ownerLocation = ownerTransform.getTranslation();
|
Vector3f ownerLocation = ownerTransform.getTranslation();
|
||||||
this.locLimit(ownerLocation, ipo.calculateValue(0));
|
this.locLimit(ownerLocation, ipo.calculateValue(0));
|
||||||
|
@ -36,13 +36,13 @@ import java.util.logging.Logger;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeDynamic() {
|
protected void bakeDynamic() {
|
||||||
// TODO: implement 'Lock track' constraint
|
// TODO: implement 'Lock track' constraint
|
||||||
LOGGER.log(Level.WARNING, "'Lock track' constraint NOT implemented!");
|
LOGGER.log(Level.WARNING, "'Lock track' constraint NOT implemented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeStatic() {
|
protected void bakeStatic() {
|
||||||
// TODO: implement 'Lock track' constraint
|
// TODO: implement 'Lock track' constraint
|
||||||
LOGGER.log(Level.WARNING, "'Lock track' constraint NOT implemented!");
|
LOGGER.log(Level.WARNING, "'Lock track' constraint NOT implemented!");
|
||||||
}
|
}
|
||||||
|
@ -35,13 +35,13 @@ import java.util.logging.Logger;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeDynamic() {
|
protected void bakeDynamic() {
|
||||||
// TODO: implement 'Min max' constraint
|
// TODO: implement 'Min max' constraint
|
||||||
LOGGER.log(Level.WARNING, "'Min max' constraint NOT implemented!");
|
LOGGER.log(Level.WARNING, "'Min max' constraint NOT implemented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeStatic() {
|
protected void bakeStatic() {
|
||||||
// TODO: implement 'Min max' constraint
|
// TODO: implement 'Min max' constraint
|
||||||
LOGGER.log(Level.WARNING, "'Min max' constraint NOT implemented!");
|
LOGGER.log(Level.WARNING, "'Min max' constraint NOT implemented!");
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,8 @@ import com.jme3.scene.plugins.blender.file.Structure;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeDynamic() {}
|
protected void bakeDynamic() {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeStatic() {}
|
protected void bakeStatic() {}
|
||||||
}
|
}
|
||||||
|
@ -37,13 +37,13 @@ import com.jme3.scene.plugins.blender.file.Structure;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeDynamic() {
|
protected void bakeDynamic() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
LOGGER.log(Level.WARNING, "'Pivot' constraint NOT implemented!");
|
LOGGER.log(Level.WARNING, "'Pivot' constraint NOT implemented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeStatic() {
|
protected void bakeStatic() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
LOGGER.log(Level.WARNING, "'Pivot' constraint NOT implemented!");
|
LOGGER.log(Level.WARNING, "'Pivot' constraint NOT implemented!");
|
||||||
}
|
}
|
||||||
|
@ -35,13 +35,13 @@ import java.util.logging.Logger;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeDynamic() {
|
protected void bakeDynamic() {
|
||||||
// TODO: implement 'Python' constraint
|
// TODO: implement 'Python' constraint
|
||||||
LOGGER.log(Level.WARNING, "'Python' constraint NOT implemented!");
|
LOGGER.log(Level.WARNING, "'Python' constraint NOT implemented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeStatic() {
|
protected void bakeStatic() {
|
||||||
// TODO: implement 'Python' constraint
|
// TODO: implement 'Python' constraint
|
||||||
LOGGER.log(Level.WARNING, "'Python' constraint NOT implemented!");
|
LOGGER.log(Level.WARNING, "'Python' constraint NOT implemented!");
|
||||||
}
|
}
|
||||||
|
@ -35,13 +35,13 @@ import java.util.logging.Logger;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeDynamic() {
|
protected void bakeDynamic() {
|
||||||
// TODO: implement 'Rigid body joint' constraint
|
// TODO: implement 'Rigid body joint' constraint
|
||||||
LOGGER.log(Level.WARNING, "'Rigid body joint' constraint NOT implemented!");
|
LOGGER.log(Level.WARNING, "'Rigid body joint' constraint NOT implemented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeStatic() {
|
protected void bakeStatic() {
|
||||||
// TODO: implement 'Rigid body joint' constraint
|
// TODO: implement 'Rigid body joint' constraint
|
||||||
LOGGER.log(Level.WARNING, "'Rigid body joint' constraint NOT implemented!");
|
LOGGER.log(Level.WARNING, "'Rigid body joint' constraint NOT implemented!");
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ import com.jme3.scene.plugins.ogre.AnimData;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeDynamic() {
|
protected void bakeDynamic() {
|
||||||
AnimData animData = blenderContext.getAnimData(this.owner.getOma());
|
AnimData animData = blenderContext.getAnimData(this.owner.getOma());
|
||||||
if(animData != null) {
|
if(animData != null) {
|
||||||
Object owner = this.owner.getObject();
|
Object owner = this.owner.getObject();
|
||||||
@ -69,7 +69,7 @@ import com.jme3.scene.plugins.ogre.AnimData;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeStatic() {
|
protected void bakeStatic() {
|
||||||
Transform targetTransform = this.target.getTransform();
|
Transform targetTransform = this.target.getTransform();
|
||||||
Transform ownerTransform = this.owner.getTransform();
|
Transform ownerTransform = this.owner.getTransform();
|
||||||
Quaternion ownerRotation = ownerTransform.getRotation();
|
Quaternion ownerRotation = ownerTransform.getRotation();
|
||||||
|
@ -68,7 +68,7 @@ import com.jme3.scene.plugins.ogre.AnimData;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeDynamic() {
|
protected void bakeDynamic() {
|
||||||
AnimData animData = blenderContext.getAnimData(owner.getOma());
|
AnimData animData = blenderContext.getAnimData(owner.getOma());
|
||||||
if(animData != null) {
|
if(animData != null) {
|
||||||
Object owner = this.owner.getObject();
|
Object owner = this.owner.getObject();
|
||||||
@ -88,7 +88,7 @@ import com.jme3.scene.plugins.ogre.AnimData;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeStatic() {
|
protected void bakeStatic() {
|
||||||
Transform ownerTransform = this.owner.getTransform();
|
Transform ownerTransform = this.owner.getTransform();
|
||||||
float[] angles = ownerTransform.getRotation().toAngles(null);
|
float[] angles = ownerTransform.getRotation().toAngles(null);
|
||||||
this.rotLimit(angles, ipo.calculateValue(0));
|
this.rotLimit(angles, ipo.calculateValue(0));
|
||||||
|
@ -45,7 +45,7 @@ import com.jme3.scene.plugins.ogre.AnimData;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeDynamic() {
|
protected void bakeDynamic() {
|
||||||
//loading mesh points (blender ensures that the target is a mesh-object)
|
//loading mesh points (blender ensures that the target is a mesh-object)
|
||||||
List<Vector3f> pts = new ArrayList<Vector3f>();
|
List<Vector3f> pts = new ArrayList<Vector3f>();
|
||||||
Node target = (Node) this.target.getObject();
|
Node target = (Node) this.target.getObject();
|
||||||
@ -89,7 +89,7 @@ import com.jme3.scene.plugins.ogre.AnimData;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeStatic() {
|
protected void bakeStatic() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ import com.jme3.scene.plugins.ogre.AnimData;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeDynamic() {
|
protected void bakeDynamic() {
|
||||||
AnimData animData = blenderContext.getAnimData(this.owner.getOma());
|
AnimData animData = blenderContext.getAnimData(this.owner.getOma());
|
||||||
if(animData != null) {
|
if(animData != null) {
|
||||||
Object owner = this.owner.getObject();
|
Object owner = this.owner.getObject();
|
||||||
@ -71,7 +71,7 @@ import com.jme3.scene.plugins.ogre.AnimData;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeStatic() {
|
protected void bakeStatic() {
|
||||||
Transform targetTransform = this.target.getTransform();
|
Transform targetTransform = this.target.getTransform();
|
||||||
Transform ownerTransform = this.owner.getTransform();
|
Transform ownerTransform = this.owner.getTransform();
|
||||||
this.sizeLike(ownerTransform.getScale(), targetTransform.getScale(), ipo.calculateValue(0));
|
this.sizeLike(ownerTransform.getScale(), targetTransform.getScale(), ipo.calculateValue(0));
|
||||||
|
@ -73,7 +73,7 @@ import com.jme3.scene.plugins.ogre.AnimData;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeDynamic() {
|
protected void bakeDynamic() {
|
||||||
AnimData animData = blenderContext.getAnimData(this.owner.getOma());
|
AnimData animData = blenderContext.getAnimData(this.owner.getOma());
|
||||||
if(animData != null) {
|
if(animData != null) {
|
||||||
Object owner = this.owner.getObject();
|
Object owner = this.owner.getObject();
|
||||||
@ -90,7 +90,7 @@ import com.jme3.scene.plugins.ogre.AnimData;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeStatic() {
|
protected void bakeStatic() {
|
||||||
Transform ownerTransform = this.owner.getTransform();
|
Transform ownerTransform = this.owner.getTransform();
|
||||||
this.sizeLimit(ownerTransform.getScale(), ipo.calculateValue(0));
|
this.sizeLimit(ownerTransform.getScale(), ipo.calculateValue(0));
|
||||||
this.owner.applyTransform(ownerTransform);
|
this.owner.applyTransform(ownerTransform);
|
||||||
|
@ -37,13 +37,13 @@ import com.jme3.scene.plugins.blender.file.Structure;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeDynamic() {
|
protected void bakeDynamic() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
LOGGER.log(Level.WARNING, "'Splie IK' constraint NOT implemented!");
|
LOGGER.log(Level.WARNING, "'Splie IK' constraint NOT implemented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeStatic() {
|
protected void bakeStatic() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
LOGGER.log(Level.WARNING, "'Spline IK' constraint NOT implemented!");
|
LOGGER.log(Level.WARNING, "'Spline IK' constraint NOT implemented!");
|
||||||
}
|
}
|
||||||
|
@ -35,13 +35,13 @@ import java.util.logging.Logger;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeDynamic() {
|
protected void bakeDynamic() {
|
||||||
// TODO: implement 'Stretch to' constraint
|
// TODO: implement 'Stretch to' constraint
|
||||||
LOGGER.log(Level.WARNING, "'Stretch to' constraint NOT implemented!");
|
LOGGER.log(Level.WARNING, "'Stretch to' constraint NOT implemented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeStatic() {
|
protected void bakeStatic() {
|
||||||
// TODO: implement 'Stretch to' constraint
|
// TODO: implement 'Stretch to' constraint
|
||||||
LOGGER.log(Level.WARNING, "'Stretch to' constraint NOT implemented!");
|
LOGGER.log(Level.WARNING, "'Stretch to' constraint NOT implemented!");
|
||||||
}
|
}
|
||||||
|
@ -35,13 +35,13 @@ import java.util.logging.Logger;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeDynamic() {
|
protected void bakeDynamic() {
|
||||||
// TODO: implement 'Transform' constraint
|
// TODO: implement 'Transform' constraint
|
||||||
LOGGER.log(Level.WARNING, "'Transform' constraint NOT implemented!");
|
LOGGER.log(Level.WARNING, "'Transform' constraint NOT implemented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bakeStatic() {
|
protected void bakeStatic() {
|
||||||
// TODO: implement 'Transform' constraint
|
// TODO: implement 'Transform' constraint
|
||||||
LOGGER.log(Level.WARNING, "'Transform' constraint NOT implemented!");
|
LOGGER.log(Level.WARNING, "'Transform' constraint NOT implemented!");
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,24 @@ import com.jme3.scene.plugins.blender.file.Structure;
|
|||||||
/** The blender context. */
|
/** The blender context. */
|
||||||
protected BlenderContext blenderContext;
|
protected BlenderContext blenderContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs the feature. This object should be loaded later
|
||||||
|
* when it is read from the blender file.
|
||||||
|
* The update method should be called before the feature is used.
|
||||||
|
*
|
||||||
|
* @param space
|
||||||
|
* the spatial's evaluation space
|
||||||
|
* @param oma
|
||||||
|
* the spatial's old memory address
|
||||||
|
* @param blenderContext
|
||||||
|
* the blender context
|
||||||
|
*/
|
||||||
|
public Feature(Space space, Long oma, BlenderContext blenderContext) {
|
||||||
|
this.space = space;
|
||||||
|
this.oma = oma;
|
||||||
|
this.blenderContext = blenderContext;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs the feature based on spatial.
|
* Constructs the feature based on spatial.
|
||||||
*
|
*
|
||||||
@ -43,9 +61,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
|
|||||||
* the blender context
|
* the blender context
|
||||||
*/
|
*/
|
||||||
public Feature(Spatial spatial, Space space, Long oma, BlenderContext blenderContext) {
|
public Feature(Spatial spatial, Space space, Long oma, BlenderContext blenderContext) {
|
||||||
this.space = space;
|
this(space, oma, blenderContext);
|
||||||
this.oma = oma;
|
|
||||||
this.spatial = spatial;
|
|
||||||
this.blenderContext = blenderContext;
|
this.blenderContext = blenderContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,12 +78,26 @@ import com.jme3.scene.plugins.blender.file.Structure;
|
|||||||
* the blender context
|
* the blender context
|
||||||
*/
|
*/
|
||||||
public Feature(Bone bone, Space space, Long oma, BlenderContext blenderContext) {
|
public Feature(Bone bone, Space space, Long oma, BlenderContext blenderContext) {
|
||||||
this.space = space;
|
this(space, oma, blenderContext);
|
||||||
this.oma = oma;
|
|
||||||
this.blenderContext = blenderContext;
|
|
||||||
this.bone = bone;
|
this.bone = bone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method should be called before the feature is used.
|
||||||
|
* It may happen that the object this feature refers to was not yet loaded from blend file
|
||||||
|
* when the instance of this class was created.
|
||||||
|
*/
|
||||||
|
public void update() {
|
||||||
|
Object owner = blenderContext.getLoadedFeature(oma, LoadedFeatureDataType.LOADED_FEATURE);
|
||||||
|
if(owner instanceof Spatial) {
|
||||||
|
this.spatial = (Spatial) owner;
|
||||||
|
} else if(owner instanceof Bone) {
|
||||||
|
this.bone = (Bone) owner;
|
||||||
|
} else {
|
||||||
|
throw new IllegalStateException("Unknown type of owner: " + owner.getClass());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the feature's old memory address
|
* @return the feature's old memory address
|
||||||
*/
|
*/
|
||||||
|
@ -11,9 +11,11 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import com.jme3.animation.AnimControl;
|
import com.jme3.animation.AnimControl;
|
||||||
import com.jme3.animation.Animation;
|
import com.jme3.animation.Animation;
|
||||||
|
import com.jme3.animation.Bone;
|
||||||
import com.jme3.animation.BoneTrack;
|
import com.jme3.animation.BoneTrack;
|
||||||
import com.jme3.animation.Skeleton;
|
import com.jme3.animation.Skeleton;
|
||||||
import com.jme3.animation.SkeletonControl;
|
import com.jme3.animation.SkeletonControl;
|
||||||
|
import com.jme3.math.Matrix4f;
|
||||||
import com.jme3.scene.Geometry;
|
import com.jme3.scene.Geometry;
|
||||||
import com.jme3.scene.Mesh;
|
import com.jme3.scene.Mesh;
|
||||||
import com.jme3.scene.Node;
|
import com.jme3.scene.Node;
|
||||||
@ -88,16 +90,33 @@ import com.jme3.util.BufferUtils;
|
|||||||
Pointer pArmatureObject = (Pointer) modifierStructure.getFieldValue("object");
|
Pointer pArmatureObject = (Pointer) modifierStructure.getFieldValue("object");
|
||||||
if (pArmatureObject.isNotNull()) {
|
if (pArmatureObject.isNotNull()) {
|
||||||
ArmatureHelper armatureHelper = blenderContext.getHelper(ArmatureHelper.class);
|
ArmatureHelper armatureHelper = blenderContext.getHelper(ArmatureHelper.class);
|
||||||
ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
|
|
||||||
|
|
||||||
Structure armatureObject = pArmatureObject.fetchData(blenderContext.getInputStream()).get(0);
|
Structure armatureObject = pArmatureObject.fetchData(blenderContext.getInputStream()).get(0);
|
||||||
|
|
||||||
// load skeleton
|
// load skeleton
|
||||||
Structure armatureStructure = ((Pointer) armatureObject.getFieldValue("data")).fetchData(blenderContext.getInputStream()).get(0);
|
Structure armatureStructure = ((Pointer) armatureObject.getFieldValue("data")).fetchData(blenderContext.getInputStream()).get(0);
|
||||||
|
|
||||||
|
Structure pose = ((Pointer) armatureObject.getFieldValue("pose")).fetchData(blenderContext.getInputStream()).get(0);
|
||||||
|
List<Structure> chanbase = ((Structure) pose.getFieldValue("chanbase")).evaluateListBase(blenderContext);
|
||||||
|
|
||||||
|
Map<Long, Structure> bonesPoseChannels = new HashMap<Long, Structure>(chanbase.size());
|
||||||
|
for (Structure poseChannel : chanbase) {
|
||||||
|
Pointer pBone = (Pointer) poseChannel.getFieldValue("bone");
|
||||||
|
bonesPoseChannels.put(pBone.getOldMemoryAddress(), poseChannel);
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
|
||||||
|
Matrix4f armatureObjectMatrix = objectHelper.getMatrix(armatureObject, "obmat", true);
|
||||||
|
Matrix4f inverseMeshObjectMatrix = objectHelper.getMatrix(objectStructure, "obmat", true).invertLocal();
|
||||||
|
Matrix4f objectToArmatureTransformation = armatureObjectMatrix.multLocal(inverseMeshObjectMatrix);
|
||||||
|
|
||||||
List<Structure> bonebase = ((Structure) armatureStructure.getFieldValue("bonebase")).evaluateListBase(blenderContext);
|
List<Structure> bonebase = ((Structure) armatureStructure.getFieldValue("bonebase")).evaluateListBase(blenderContext);
|
||||||
//load the skeleton and its bones first
|
List<Bone> bonesList = new ArrayList<Bone>();
|
||||||
objectHelper.toObject(armatureObject, blenderContext);
|
for (int i = 0; i < bonebase.size(); ++i) {
|
||||||
Skeleton skeleton = blenderContext.getSkeleton(armatureObject.getOldMemoryAddress());
|
armatureHelper.buildBones(bonebase.get(i), null, bonesList, objectToArmatureTransformation, bonesPoseChannels, blenderContext);
|
||||||
|
}
|
||||||
|
bonesList.add(0, new Bone(""));
|
||||||
|
Skeleton skeleton = new Skeleton(bonesList.toArray(new Bone[bonesList.size()]));
|
||||||
|
|
||||||
// read mesh indexes
|
// read mesh indexes
|
||||||
this.meshOMA = meshStructure.getOldMemoryAddress();
|
this.meshOMA = meshStructure.getOldMemoryAddress();
|
||||||
@ -179,8 +198,7 @@ import com.jme3.util.BufferUtils;
|
|||||||
List<Constraint> constraints = blenderContext.getConstraints(boneOMA);
|
List<Constraint> constraints = blenderContext.getConstraints(boneOMA);
|
||||||
if (constraints != null && constraints.size() > 0) {
|
if (constraints != null && constraints.size() > 0) {
|
||||||
for (Constraint constraint : constraints) {
|
for (Constraint constraint : constraints) {
|
||||||
constraint.bakeDynamic();
|
constraint.bake(Constraint.BAKE_DYNAMIC | Constraint.BAKE_STATIC);
|
||||||
constraint.bakeStatic();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,16 +31,11 @@
|
|||||||
*/
|
*/
|
||||||
package com.jme3.scene.plugins.blender.objects;
|
package com.jme3.scene.plugins.blender.objects;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import com.jme3.animation.Bone;
|
|
||||||
import com.jme3.animation.Skeleton;
|
|
||||||
import com.jme3.asset.BlenderKey.FeaturesToLoad;
|
import com.jme3.asset.BlenderKey.FeaturesToLoad;
|
||||||
import com.jme3.light.DirectionalLight;
|
import com.jme3.light.DirectionalLight;
|
||||||
import com.jme3.light.Light;
|
import com.jme3.light.Light;
|
||||||
@ -58,7 +53,6 @@ import com.jme3.scene.Spatial.CullHint;
|
|||||||
import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
|
import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
|
||||||
import com.jme3.scene.plugins.blender.BlenderContext;
|
import com.jme3.scene.plugins.blender.BlenderContext;
|
||||||
import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType;
|
import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType;
|
||||||
import com.jme3.scene.plugins.blender.animations.ArmatureHelper;
|
|
||||||
import com.jme3.scene.plugins.blender.cameras.CameraHelper;
|
import com.jme3.scene.plugins.blender.cameras.CameraHelper;
|
||||||
import com.jme3.scene.plugins.blender.constraints.Constraint;
|
import com.jme3.scene.plugins.blender.constraints.Constraint;
|
||||||
import com.jme3.scene.plugins.blender.constraints.ConstraintHelper;
|
import com.jme3.scene.plugins.blender.constraints.ConstraintHelper;
|
||||||
@ -239,31 +233,6 @@ public class ObjectHelper extends AbstractBlenderHelper {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case OBJECT_TYPE_ARMATURE:
|
case OBJECT_TYPE_ARMATURE:
|
||||||
//load the skeleton first and store it in the blender context
|
|
||||||
Structure armatureStructure = ((Pointer) objectStructure.getFieldValue("data")).fetchData(blenderContext.getInputStream()).get(0);
|
|
||||||
Structure pose = ((Pointer) objectStructure.getFieldValue("pose")).fetchData(blenderContext.getInputStream()).get(0);
|
|
||||||
List<Structure> chanbase = ((Structure) pose.getFieldValue("chanbase")).evaluateListBase(blenderContext);
|
|
||||||
|
|
||||||
Map<Long, Structure> bonesPoseChannels = new HashMap<Long, Structure>(chanbase.size());
|
|
||||||
for (Structure poseChannel : chanbase) {
|
|
||||||
Pointer pBone = (Pointer) poseChannel.getFieldValue("bone");
|
|
||||||
bonesPoseChannels.put(pBone.getOldMemoryAddress(), poseChannel);
|
|
||||||
}
|
|
||||||
|
|
||||||
Matrix4f armatureObjectMatrix = this.getMatrix(objectStructure, "obmat", true);
|
|
||||||
Matrix4f inverseMeshObjectMatrix = this.getMatrix(objectStructure, "obmat", true).invertLocal();
|
|
||||||
Matrix4f objectToArmatureTransformation = armatureObjectMatrix.multLocal(inverseMeshObjectMatrix);
|
|
||||||
|
|
||||||
List<Structure> bonebase = ((Structure) armatureStructure.getFieldValue("bonebase")).evaluateListBase(blenderContext);
|
|
||||||
ArmatureHelper armatureHelper = blenderContext.getHelper(ArmatureHelper.class);
|
|
||||||
List<Bone> bonesList = new ArrayList<Bone>();
|
|
||||||
for (int i = 0; i < bonebase.size(); ++i) {
|
|
||||||
armatureHelper.buildBones(bonebase.get(i), null, bonesList, objectToArmatureTransformation, bonesPoseChannels, blenderContext);
|
|
||||||
}
|
|
||||||
bonesList.add(0, new Bone(""));
|
|
||||||
Skeleton skeleton = new Skeleton(bonesList.toArray(new Bone[bonesList.size()]));
|
|
||||||
blenderContext.setSkeleton(objectStructure.getOldMemoryAddress(), skeleton);
|
|
||||||
|
|
||||||
//need to create an empty node to properly create parent-children relationships between nodes
|
//need to create an empty node to properly create parent-children relationships between nodes
|
||||||
Node armature = new Node(name);
|
Node armature = new Node(name);
|
||||||
armature.setLocalTransform(t);
|
armature.setLocalTransform(t);
|
||||||
@ -292,7 +261,7 @@ public class ObjectHelper extends AbstractBlenderHelper {
|
|||||||
List<Constraint> objectConstraints = blenderContext.getConstraints(objectStructure.getOldMemoryAddress());
|
List<Constraint> objectConstraints = blenderContext.getConstraints(objectStructure.getOldMemoryAddress());
|
||||||
if(objectConstraints!=null) {
|
if(objectConstraints!=null) {
|
||||||
for(Constraint objectConstraint : objectConstraints) {
|
for(Constraint objectConstraint : objectConstraints) {
|
||||||
objectConstraint.bakeStatic();
|
objectConstraint.bake(Constraint.BAKE_STATIC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user