Feature: constraint applied to a spatial can now also target a bone

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9854 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Kae..pl 12 years ago
parent a5e9159149
commit 3563bbf179
  1. 2
      engine/src/blender/com/jme3/scene/plugins/blender/animations/ArmatureHelper.java
  2. 6
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/BoneConstraint.java
  3. 30
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/SpatialConstraint.java
  4. 2
      engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java

@ -57,6 +57,8 @@ import java.util.logging.Logger;
public class ArmatureHelper extends AbstractBlenderHelper { public class ArmatureHelper extends AbstractBlenderHelper {
private static final Logger LOGGER = Logger.getLogger(ArmatureHelper.class.getName()); private static final Logger LOGGER = Logger.getLogger(ArmatureHelper.class.getName());
public static final String ARMETURE_NODE_MARKER = "armeture-node";
/** A map of bones and their old memory addresses. */ /** A map of bones and their old memory addresses. */
private Map<Bone, Long> bonesOMAs = new HashMap<Bone, Long>(); private Map<Bone, Long> bonesOMAs = new HashMap<Bone, Long>();

@ -27,7 +27,7 @@ import com.jme3.scene.plugins.ogre.AnimData;
/*package*/ class BoneConstraint extends Constraint { /*package*/ class BoneConstraint extends Constraint {
private static final Logger LOGGER = Logger.getLogger(BoneConstraint.class.getName()); private static final Logger LOGGER = Logger.getLogger(BoneConstraint.class.getName());
/** The OMA of the target armature. */ /** The OMA of the target armature. */
private Long targetArmatureOMA; protected Long targetArmatureOMA;
public BoneConstraint(Structure constraintStructure, Long ownerOMA, Ipo influenceIpo, BlenderContext blenderContext) public BoneConstraint(Structure constraintStructure, Long ownerOMA, Ipo influenceIpo, BlenderContext blenderContext)
throws BlenderFileException { throws BlenderFileException {
@ -116,7 +116,7 @@ import com.jme3.scene.plugins.ogre.AnimData;
* OMA of the bone * OMA of the bone
* @return <b>true</b> if the bone has animations and <b>false</b> otherwise * @return <b>true</b> if the bone has animations and <b>false</b> otherwise
*/ */
private boolean hasAnimation(Long boneOMA) { protected boolean hasAnimation(Long boneOMA) {
AnimData animData = blenderContext.getAnimData(boneOMA); AnimData animData = blenderContext.getAnimData(boneOMA);
if(animData != null) { if(animData != null) {
Bone bone = blenderContext.getBoneContext(boneOMA).getBone(); Bone bone = blenderContext.getBoneContext(boneOMA).getBone();
@ -143,7 +143,7 @@ import com.jme3.scene.plugins.ogre.AnimData;
* @param referenceAnimData * @param referenceAnimData
* the object containing the animations * the object containing the animations
*/ */
private void applyAnimData(BoneContext boneContext, Space space, AnimData referenceAnimData) { protected void applyAnimData(BoneContext boneContext, Space space, AnimData referenceAnimData) {
ConstraintHelper constraintHelper = blenderContext.getHelper(ConstraintHelper.class); ConstraintHelper constraintHelper = blenderContext.getHelper(ConstraintHelper.class);
Transform transform = constraintHelper.getBoneTransform(space, boneContext.getBone()); Transform transform = constraintHelper.getBoneTransform(space, boneContext.getBone());

@ -3,9 +3,11 @@ package com.jme3.scene.plugins.blender.constraints;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
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.SpatialTrack; import com.jme3.animation.SpatialTrack;
import com.jme3.math.Quaternion; import com.jme3.math.Quaternion;
import com.jme3.math.Transform; import com.jme3.math.Transform;
@ -13,6 +15,8 @@ import com.jme3.math.Vector3f;
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.BlenderContext.LoadedFeatureDataType;
import com.jme3.scene.plugins.blender.animations.ArmatureHelper;
import com.jme3.scene.plugins.blender.animations.BoneContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.constraints.ConstraintHelper.Space; import com.jme3.scene.plugins.blender.constraints.ConstraintHelper.Space;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
@ -24,7 +28,9 @@ import com.jme3.scene.plugins.ogre.AnimData;
* This includes: nodes, cameras nodes and light nodes. * This includes: nodes, cameras nodes and light nodes.
* @author Marcin Roguski (Kaelthas) * @author Marcin Roguski (Kaelthas)
*/ */
/*package*/ class SpatialConstraint extends Constraint { /*package*/ class SpatialConstraint extends BoneConstraint {
private static final Logger LOGGER = Logger.getLogger(SpatialConstraint.class.getName());
/** The owner of the constraint. */ /** The owner of the constraint. */
private Spatial owner; private Spatial owner;
/** The target of the constraint. */ /** The target of the constraint. */
@ -33,6 +39,7 @@ import com.jme3.scene.plugins.ogre.AnimData;
public SpatialConstraint(Structure constraintStructure, Long ownerOMA, Ipo influenceIpo, BlenderContext blenderContext) public SpatialConstraint(Structure constraintStructure, Long ownerOMA, Ipo influenceIpo, BlenderContext blenderContext)
throws BlenderFileException { throws BlenderFileException {
super(constraintStructure, ownerOMA, influenceIpo, blenderContext); super(constraintStructure, ownerOMA, influenceIpo, blenderContext);
targetOMA = targetArmatureOMA;//spatial constraint uses only targetOMA and not armatureTargetOMA which is set by BoneConstraint
} }
@Override @Override
@ -76,6 +83,22 @@ import com.jme3.scene.plugins.ogre.AnimData;
AnimData animData = blenderContext.getAnimData(oma); AnimData animData = blenderContext.getAnimData(oma);
if(animData == null) { if(animData == null) {
Spatial currentSpatial = (Spatial)blenderContext.getLoadedFeature(oma, LoadedFeatureDataType.LOADED_FEATURE); Spatial currentSpatial = (Spatial)blenderContext.getLoadedFeature(oma, LoadedFeatureDataType.LOADED_FEATURE);
if(currentSpatial != null) {
if(currentSpatial.getUserData(ArmatureHelper.ARMETURE_NODE_MARKER) == Boolean.TRUE) {//look for it among bones
BoneContext currentBoneContext = blenderContext.getBoneByName(subtargetName);
Bone currentBone = currentBoneContext.getBone();
Bone parent = currentBone.getParent();
boolean foundAnimation = false;
while(parent != null && !foundAnimation) {
BoneContext boneContext = blenderContext.getBoneByName(parent.getName());
foundAnimation = this.hasAnimation(boneContext.getBoneOma());
animData = blenderContext.getAnimData(boneContext.getBoneOma());
parent = parent.getParent();
}
if(foundAnimation) {
this.applyAnimData(currentBoneContext, spaces[i], animData);
}
} else {
Spatial parent = currentSpatial.getParent(); Spatial parent = currentSpatial.getParent();
while(parent != null && animData == null) { while(parent != null && animData == null) {
Structure parentStructure = (Structure)blenderContext.getLoadedFeature(parent.getName(), LoadedFeatureDataType.LOADED_STRUCTURE); Structure parentStructure = (Structure)blenderContext.getLoadedFeature(parent.getName(), LoadedFeatureDataType.LOADED_STRUCTURE);
@ -92,6 +115,11 @@ import com.jme3.scene.plugins.ogre.AnimData;
this.applyAnimData(currentSpatial, oma, spaces[i], animData.anims.get(0)); this.applyAnimData(currentSpatial, oma, spaces[i], animData.anims.get(0));
} }
} }
} else {
LOGGER.warning("Couldn't find target object for constraint: " + name +
". Make sure that the target is on layer that is defined to be loaded in blender key!");
}
}
} }
} }

@ -50,6 +50,7 @@ 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.ConstraintHelper; import com.jme3.scene.plugins.blender.constraints.ConstraintHelper;
import com.jme3.scene.plugins.blender.curves.CurvesHelper; import com.jme3.scene.plugins.blender.curves.CurvesHelper;
@ -216,6 +217,7 @@ public class ObjectHelper extends AbstractBlenderHelper {
//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);
armature.setUserData(ArmatureHelper.ARMETURE_NODE_MARKER, Boolean.TRUE);
//TODO: modifiers for armature ???? //TODO: modifiers for armature ????
if(parent instanceof Node) { if(parent instanceof Node) {
((Node)parent).attachChild(armature); ((Node)parent).attachChild(armature);

Loading…
Cancel
Save