git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7230 75d07b2b-3a1a-0410-a2c5-0572b91ccdca3.0
parent
3b9cf4cd35
commit
1f286f424f
@ -0,0 +1,99 @@ |
|||||||
|
/* |
||||||
|
* To change this template, choose Tools | Templates |
||||||
|
* and open the template in the editor. |
||||||
|
*/ |
||||||
|
package com.jme3.bullet.control; |
||||||
|
|
||||||
|
import com.jme3.math.FastMath; |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @author Nehon |
||||||
|
*/ |
||||||
|
public class HumanoidRagdollPreset extends RagdollPreset { |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void initBoneMap() { |
||||||
|
boneMap.put("head", new JointPreset(FastMath.QUARTER_PI, -FastMath.QUARTER_PI, FastMath.QUARTER_PI, -FastMath.QUARTER_PI, FastMath.QUARTER_PI, -FastMath.QUARTER_PI)); |
||||||
|
|
||||||
|
boneMap.put("torso", new JointPreset(FastMath.QUARTER_PI, -FastMath.QUARTER_PI, 0, 0, FastMath.QUARTER_PI, -FastMath.QUARTER_PI)); |
||||||
|
|
||||||
|
boneMap.put("upperleg", new JointPreset(FastMath.PI, -FastMath.QUARTER_PI, FastMath.QUARTER_PI, -FastMath.QUARTER_PI, FastMath.QUARTER_PI, -FastMath.QUARTER_PI)); |
||||||
|
|
||||||
|
boneMap.put("lowerleg", new JointPreset(0, -FastMath.PI, 0, 0, 0, 0)); |
||||||
|
|
||||||
|
boneMap.put("foot", new JointPreset(0, -FastMath.QUARTER_PI, FastMath.QUARTER_PI, -FastMath.QUARTER_PI, FastMath.QUARTER_PI, -FastMath.QUARTER_PI)); |
||||||
|
|
||||||
|
boneMap.put("upperarm", new JointPreset(FastMath.HALF_PI, -FastMath.QUARTER_PI, 0, 0, FastMath.QUARTER_PI, -FastMath.HALF_PI)); |
||||||
|
|
||||||
|
boneMap.put("lowerarm", new JointPreset(FastMath.PI, 0, 0, 0, 0, 0)); |
||||||
|
|
||||||
|
boneMap.put("hand", new JointPreset(FastMath.QUARTER_PI, -FastMath.QUARTER_PI, FastMath.QUARTER_PI, -FastMath.QUARTER_PI, FastMath.QUARTER_PI, -FastMath.QUARTER_PI)); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void initLexicon() { |
||||||
|
LexiconEntry entry = new LexiconEntry(); |
||||||
|
entry.addSynonym("head", 100); |
||||||
|
lexicon.put("head", entry); |
||||||
|
|
||||||
|
entry = new LexiconEntry(); |
||||||
|
entry.addSynonym("torso", 100); |
||||||
|
entry.addSynonym("chest", 100); |
||||||
|
entry.addSynonym("spine", 45); |
||||||
|
entry.addSynonym("high", 25); |
||||||
|
lexicon.put("torso", entry); |
||||||
|
|
||||||
|
entry = new LexiconEntry(); |
||||||
|
entry.addSynonym("upperleg", 100); |
||||||
|
entry.addSynonym("thigh", 100); |
||||||
|
entry.addSynonym("hip", 75); |
||||||
|
entry.addSynonym("leg", 40); |
||||||
|
entry.addSynonym("high", 10); |
||||||
|
entry.addSynonym("up", 15); |
||||||
|
entry.addSynonym("upper", 15); |
||||||
|
lexicon.put("upperleg", entry); |
||||||
|
|
||||||
|
entry = new LexiconEntry(); |
||||||
|
entry.addSynonym("lowerleg", 100); |
||||||
|
entry.addSynonym("calf", 100); |
||||||
|
entry.addSynonym("knee", 75); |
||||||
|
entry.addSynonym("leg", 50); |
||||||
|
entry.addSynonym("low", 10); |
||||||
|
entry.addSynonym("lower", 10); |
||||||
|
lexicon.put("lowerleg", entry); |
||||||
|
|
||||||
|
entry = new LexiconEntry(); |
||||||
|
entry.addSynonym("foot", 100); |
||||||
|
entry.addSynonym("ankle", 75); |
||||||
|
lexicon.put("foot", entry); |
||||||
|
|
||||||
|
|
||||||
|
entry = new LexiconEntry(); |
||||||
|
entry.addSynonym("upperarm", 100); |
||||||
|
entry.addSynonym("humerus", 100); |
||||||
|
entry.addSynonym("shoulder", 50); |
||||||
|
entry.addSynonym("arm", 40); |
||||||
|
entry.addSynonym("high", 10); |
||||||
|
entry.addSynonym("up", 15); |
||||||
|
entry.addSynonym("upper", 15); |
||||||
|
lexicon.put("upperarm", entry); |
||||||
|
|
||||||
|
entry = new LexiconEntry(); |
||||||
|
entry.addSynonym("lowerarm", 100); |
||||||
|
entry.addSynonym("ulna", 100); |
||||||
|
entry.addSynonym("elbow", 75); |
||||||
|
entry.addSynonym("arm", 50); |
||||||
|
entry.addSynonym("low", 10); |
||||||
|
entry.addSynonym("lower", 10); |
||||||
|
lexicon.put("lowerarm", entry); |
||||||
|
|
||||||
|
entry = new LexiconEntry(); |
||||||
|
entry.addSynonym("hand", 100); |
||||||
|
entry.addSynonym("fist", 100); |
||||||
|
entry.addSynonym("wrist", 75); |
||||||
|
lexicon.put("hand", entry); |
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,108 @@ |
|||||||
|
/* |
||||||
|
* To change this template, choose Tools | Templates |
||||||
|
* and open the template in the editor. |
||||||
|
*/ |
||||||
|
package com.jme3.bullet.control; |
||||||
|
|
||||||
|
import com.jme3.bullet.joints.SixDofJoint; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.logging.Level; |
||||||
|
import java.util.logging.Logger; |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @author Nehon |
||||||
|
*/ |
||||||
|
public abstract class RagdollPreset { |
||||||
|
|
||||||
|
protected static final Logger logger = Logger.getLogger(RagdollPreset.class.getName()); |
||||||
|
protected Map<String, JointPreset> boneMap = new HashMap<String, JointPreset>(); |
||||||
|
protected Map<String, LexiconEntry> lexicon = new HashMap<String, LexiconEntry>(); |
||||||
|
|
||||||
|
protected abstract void initBoneMap(); |
||||||
|
|
||||||
|
protected abstract void initLexicon(); |
||||||
|
|
||||||
|
public void setupJointForBone(String boneName, SixDofJoint joint) { |
||||||
|
|
||||||
|
if (boneMap.isEmpty()) { |
||||||
|
initBoneMap(); |
||||||
|
} |
||||||
|
if (lexicon.isEmpty()) { |
||||||
|
initLexicon(); |
||||||
|
} |
||||||
|
String resultName = ""; |
||||||
|
int resultScore = 0; |
||||||
|
|
||||||
|
System.out.println("-------------- " +boneName); |
||||||
|
for (String key : lexicon.keySet()) { |
||||||
|
|
||||||
|
int score = lexicon.get(key).getScore(boneName); |
||||||
|
System.out.println(key+" " +score); |
||||||
|
if (score > resultScore) { |
||||||
|
resultScore = score; |
||||||
|
resultName = key; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
System.out.println("-------------- "); |
||||||
|
JointPreset preset = boneMap.get(resultName); |
||||||
|
|
||||||
|
if (preset != null && resultScore >= 50) { |
||||||
|
logger.log(Level.INFO, "Found matching joint for bone {0} : {1} with score {2}", new Object[]{boneName, resultName, resultScore}); |
||||||
|
preset.setupJoint(joint); |
||||||
|
} else { |
||||||
|
logger.log(Level.INFO, "No joint match found for bone {0}", boneName); |
||||||
|
if (resultScore > 0) { |
||||||
|
logger.log(Level.INFO, "Best match found is {0} with score {1}", new Object[]{resultName, resultScore}); |
||||||
|
} |
||||||
|
new JointPreset().setupJoint(joint); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
protected class JointPreset { |
||||||
|
|
||||||
|
private float maxX, minX, maxY, minY, maxZ, minZ; |
||||||
|
|
||||||
|
public JointPreset() { |
||||||
|
} |
||||||
|
|
||||||
|
public JointPreset(float maxX, float minX, float maxY, float minY, float maxZ, float minZ) { |
||||||
|
this.maxX = maxX; |
||||||
|
this.minX = minX; |
||||||
|
this.maxY = maxY; |
||||||
|
this.minY = minY; |
||||||
|
this.maxZ = maxZ; |
||||||
|
this.minZ = minZ; |
||||||
|
} |
||||||
|
|
||||||
|
public void setupJoint(SixDofJoint joint) { |
||||||
|
joint.getRotationalLimitMotor(0).setHiLimit(maxX); |
||||||
|
joint.getRotationalLimitMotor(0).setLoLimit(minX); |
||||||
|
joint.getRotationalLimitMotor(1).setHiLimit(maxY); |
||||||
|
joint.getRotationalLimitMotor(1).setLoLimit(minY); |
||||||
|
joint.getRotationalLimitMotor(2).setHiLimit(maxZ); |
||||||
|
joint.getRotationalLimitMotor(2).setLoLimit(minZ); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected class LexiconEntry extends HashMap<String, Integer> { |
||||||
|
|
||||||
|
public void addSynonym(String word, int score) { |
||||||
|
put(word.toLowerCase(), score); |
||||||
|
} |
||||||
|
|
||||||
|
public int getScore(String word) { |
||||||
|
int score = 0; |
||||||
|
String searchWord = word.toLowerCase(); |
||||||
|
for (String key : this.keySet()) { |
||||||
|
if (searchWord.indexOf(key) >= 0) { |
||||||
|
score += get(key); |
||||||
|
} |
||||||
|
} |
||||||
|
return score; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue