Refactoring: making bone constraints to be applied from the root bone to the children and refreshing bone world vector after baking bone's constraint.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10856 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
experimental
Kae..pl 11 years ago
parent f6ca843f03
commit 1ae900023e
  1. 22
      engine/src/blender/com/jme3/scene/plugins/blender/BlenderContext.java
  2. 6
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/BoneConstraint.java
  3. 44
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/SimulationNode.java

@ -387,6 +387,16 @@ public class BlenderContext {
objectConstraints.addAll(constraints);
}
/**
* Returns constraints applied to the feature of the given OMA.
* @param ownerOMA
* the constraints' owner OMA
* @return a list of constraints or <b>null</b> if no constraints are applied to the feature
*/
public List<Constraint> getConstraints(Long ownerOMA) {
return constraints.get(ownerOMA);
}
/**
* @return all available constraints
*/
@ -418,7 +428,7 @@ public class BlenderContext {
* @return the animation data or null if none exists
*/
public AnimationData getAnimData(Long ownerOMA) {
return this.animData.get(ownerOMA);
return animData.get(ownerOMA);
}
/**
@ -430,7 +440,7 @@ public class BlenderContext {
* the skeleton specified by the given OMA
*/
public void setSkeleton(Long skeletonOMA, Skeleton skeleton) {
this.skeletons.put(skeletonOMA, skeleton);
skeletons.put(skeletonOMA, skeleton);
}
/**
@ -465,7 +475,7 @@ public class BlenderContext {
* @return the skeleton specified by the given OMA
*/
public Skeleton getSkeleton(Long skeletonOMA) {
return this.skeletons.get(skeletonOMA);
return skeletons.get(skeletonOMA);
}
/**
@ -478,7 +488,7 @@ public class BlenderContext {
* the mesh's context
*/
public void setMeshContext(Long meshOMA, MeshContext meshContext) {
this.meshContexts.put(meshOMA, meshContext);
meshContexts.put(meshOMA, meshContext);
}
/**
@ -490,7 +500,7 @@ public class BlenderContext {
* @return mesh's context
*/
public MeshContext getMeshContext(Long meshOMA) {
return this.meshContexts.get(meshOMA);
return meshContexts.get(meshOMA);
}
/**
@ -503,7 +513,7 @@ public class BlenderContext {
* the bones's context
*/
public void setBoneContext(Long boneOMA, BoneContext boneContext) {
this.boneContexts.put(boneOMA, boneContext);
boneContexts.put(boneOMA, boneContext);
}
/**

@ -64,4 +64,10 @@ import com.jme3.scene.plugins.blender.file.Structure;
}
return true;
}
@Override
public void apply(int frame) {
super.apply(frame);
blenderContext.getBoneContext(ownerOMA).getBone().updateWorldVectors();
}
}

@ -275,11 +275,12 @@ public class SimulationNode {
skeleton.updateWorldVectors();
}
// ... and then apply constraints ...
for (Constraint constraint : constraints) {
constraint.apply(frame);
if (constraint.getAlteredOmas() != null) {
alteredOmas.addAll(constraint.getAlteredOmas());
// ... and then apply constraints from the root bone to the last child ...
for (Bone rootBone : skeleton.getRoots()) {
if(skeleton.getBoneIndex(rootBone) > 0) {
//ommit the 0 - indexed root bone as it is the bone added by importer
this.applyConstraints(rootBone, alteredOmas, frame);
}
}
@ -353,6 +354,32 @@ public class SimulationNode {
}
}
/**
* Applies constraints to the given bone and its children.
* The goal is to apply constraint from root bone to the last child.
* @param bone
* the bone whose constraints will be applied
* @param alteredOmas
* the set of OMAS of the altered bones (is populated if necessary)
* @param frame
* the current frame of the animation
*/
private void applyConstraints(Bone bone, Set<Long> alteredOmas, int frame) {
BoneContext boneContext = blenderContext.getBoneContext(bone);
List<Constraint> constraints = this.findConstraints(boneContext.getBoneOma(), blenderContext);
if (constraints != null && constraints.size() > 0) {
for (Constraint constraint : constraints) {
constraint.apply(frame);
if (constraint.getAlteredOmas() != null) {
alteredOmas.addAll(constraint.getAlteredOmas());
}
}
}
for (Bone child : bone.getChildren()) {
this.applyConstraints(child, alteredOmas, frame);
}
}
/**
* Simulates the node.
*/
@ -401,9 +428,10 @@ public class SimulationNode {
*/
private List<Constraint> findConstraints(Long ownerOMA, BlenderContext blenderContext) {
List<Constraint> result = new ArrayList<Constraint>();
for (Constraint constraint : blenderContext.getAllConstraints()) {
if (constraint.ownerOMA.longValue() == ownerOMA.longValue()) {
if (constraint.isImplemented()) {
List<Constraint> constraints = blenderContext.getConstraints(ownerOMA);
if(constraints != null) {
for (Constraint constraint : constraints) {
if (constraint.isImplemented() && constraint.validate()) {
result.add(constraint);
} else {
LOGGER.log(Level.WARNING, "Constraint named: ''{0}'' of type ''{1}'' is not implemented and will NOT be applied!", new Object[] { constraint.name, constraint.getConstraintTypeName() });

Loading…
Cancel
Save