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
This commit is contained in:
parent
f6ca843f03
commit
1ae900023e
@ -115,7 +115,7 @@ public class BlenderContext {
|
|||||||
/** A map og helpers that perform loading. */
|
/** A map og helpers that perform loading. */
|
||||||
private Map<String, AbstractBlenderHelper> helpers = new HashMap<String, AbstractBlenderHelper>();
|
private Map<String, AbstractBlenderHelper> helpers = new HashMap<String, AbstractBlenderHelper>();
|
||||||
/** Markers used by loading classes to store some custom data. This is made to avoid putting this data into user properties. */
|
/** Markers used by loading classes to store some custom data. This is made to avoid putting this data into user properties. */
|
||||||
private Map<String, Map<Object, Object>> markers = new HashMap<String, Map<Object,Object>>();
|
private Map<String, Map<Object, Object>> markers = new HashMap<String, Map<Object, Object>>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method sets the blender file version.
|
* This method sets the blender file version.
|
||||||
@ -387,6 +387,16 @@ public class BlenderContext {
|
|||||||
objectConstraints.addAll(constraints);
|
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
|
* @return all available constraints
|
||||||
*/
|
*/
|
||||||
@ -418,7 +428,7 @@ public class BlenderContext {
|
|||||||
* @return the animation data or null if none exists
|
* @return the animation data or null if none exists
|
||||||
*/
|
*/
|
||||||
public AnimationData getAnimData(Long ownerOMA) {
|
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
|
* the skeleton specified by the given OMA
|
||||||
*/
|
*/
|
||||||
public void setSkeleton(Long skeletonOMA, Skeleton skeleton) {
|
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
|
* @return the skeleton specified by the given OMA
|
||||||
*/
|
*/
|
||||||
public Skeleton getSkeleton(Long skeletonOMA) {
|
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
|
* the mesh's context
|
||||||
*/
|
*/
|
||||||
public void setMeshContext(Long meshOMA, MeshContext meshContext) {
|
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
|
* @return mesh's context
|
||||||
*/
|
*/
|
||||||
public MeshContext getMeshContext(Long meshOMA) {
|
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
|
* the bones's context
|
||||||
*/
|
*/
|
||||||
public void setBoneContext(Long boneOMA, BoneContext boneContext) {
|
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;
|
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();
|
skeleton.updateWorldVectors();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ... and then apply constraints ...
|
|
||||||
for (Constraint constraint : constraints) {
|
// ... and then apply constraints from the root bone to the last child ...
|
||||||
constraint.apply(frame);
|
for (Bone rootBone : skeleton.getRoots()) {
|
||||||
if (constraint.getAlteredOmas() != null) {
|
if(skeleton.getBoneIndex(rootBone) > 0) {
|
||||||
alteredOmas.addAll(constraint.getAlteredOmas());
|
//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.
|
* Simulates the node.
|
||||||
*/
|
*/
|
||||||
@ -401,9 +428,10 @@ public class SimulationNode {
|
|||||||
*/
|
*/
|
||||||
private List<Constraint> findConstraints(Long ownerOMA, BlenderContext blenderContext) {
|
private List<Constraint> findConstraints(Long ownerOMA, BlenderContext blenderContext) {
|
||||||
List<Constraint> result = new ArrayList<Constraint>();
|
List<Constraint> result = new ArrayList<Constraint>();
|
||||||
for (Constraint constraint : blenderContext.getAllConstraints()) {
|
List<Constraint> constraints = blenderContext.getConstraints(ownerOMA);
|
||||||
if (constraint.ownerOMA.longValue() == ownerOMA.longValue()) {
|
if(constraints != null) {
|
||||||
if (constraint.isImplemented()) {
|
for (Constraint constraint : constraints) {
|
||||||
|
if (constraint.isImplemented() && constraint.validate()) {
|
||||||
result.add(constraint);
|
result.add(constraint);
|
||||||
} else {
|
} 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() });
|
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…
x
Reference in New Issue
Block a user