|
@@ -33,14 +33,13 @@ package com.jme3.bullet.control.ragdoll;
|
|
|
|
|
|
import com.jme3.animation.Bone;
|
|
import com.jme3.animation.Bone;
|
|
import com.jme3.animation.Skeleton;
|
|
import com.jme3.animation.Skeleton;
|
|
|
|
+import com.jme3.animation.SkeletonControl;
|
|
import com.jme3.bullet.collision.shapes.HullCollisionShape;
|
|
import com.jme3.bullet.collision.shapes.HullCollisionShape;
|
|
import com.jme3.bullet.joints.SixDofJoint;
|
|
import com.jme3.bullet.joints.SixDofJoint;
|
|
import com.jme3.math.Quaternion;
|
|
import com.jme3.math.Quaternion;
|
|
import com.jme3.math.Transform;
|
|
import com.jme3.math.Transform;
|
|
import com.jme3.math.Vector3f;
|
|
import com.jme3.math.Vector3f;
|
|
-import com.jme3.scene.Geometry;
|
|
|
|
import com.jme3.scene.Mesh;
|
|
import com.jme3.scene.Mesh;
|
|
-import com.jme3.scene.Node;
|
|
|
|
import com.jme3.scene.Spatial;
|
|
import com.jme3.scene.Spatial;
|
|
import com.jme3.scene.VertexBuffer.Type;
|
|
import com.jme3.scene.VertexBuffer.Type;
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.ByteBuffer;
|
|
@@ -90,21 +89,14 @@ public class RagdollUtils {
|
|
* @return a new map (not null)
|
|
* @return a new map (not null)
|
|
*/
|
|
*/
|
|
public static Map<Integer, List<Float>> buildPointMap(Spatial model) {
|
|
public static Map<Integer, List<Float>> buildPointMap(Spatial model) {
|
|
|
|
+ Map<Integer, List<Float>> map = new HashMap<>();
|
|
|
|
|
|
-
|
|
|
|
- Map<Integer, List<Float>> map = new HashMap<Integer, List<Float>>();
|
|
|
|
- if (model instanceof Geometry) {
|
|
|
|
- Geometry g = (Geometry) model;
|
|
|
|
- buildPointMapForMesh(g.getMesh(), map);
|
|
|
|
- } else if (model instanceof Node) {
|
|
|
|
- Node node = (Node) model;
|
|
|
|
- for (Spatial s : node.getChildren()) {
|
|
|
|
- if (s instanceof Geometry) {
|
|
|
|
- Geometry g = (Geometry) s;
|
|
|
|
- buildPointMapForMesh(g.getMesh(), map);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ SkeletonControl skeletonCtrl = model.getControl(SkeletonControl.class);
|
|
|
|
+ Mesh[] targetMeshes = skeletonCtrl.getTargets();
|
|
|
|
+ for (Mesh mesh : targetMeshes) {
|
|
|
|
+ buildPointMapForMesh(mesh, map);
|
|
}
|
|
}
|
|
|
|
+
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -221,24 +213,18 @@ public class RagdollUtils {
|
|
* @param weightThreshold minimum weight for inclusion
|
|
* @param weightThreshold minimum weight for inclusion
|
|
* @return a new shape
|
|
* @return a new shape
|
|
*/
|
|
*/
|
|
- public static HullCollisionShape makeShapeFromVerticeWeights(Spatial model, List<Integer> boneIndices, Vector3f initialScale, Vector3f initialPosition, float weightThreshold) {
|
|
|
|
-
|
|
|
|
- ArrayList<Float> points = new ArrayList<Float>();
|
|
|
|
- if (model instanceof Geometry) {
|
|
|
|
- Geometry g = (Geometry) model;
|
|
|
|
|
|
+ public static HullCollisionShape makeShapeFromVerticeWeights(Spatial model,
|
|
|
|
+ List<Integer> boneIndices, Vector3f initialScale,
|
|
|
|
+ Vector3f initialPosition, float weightThreshold) {
|
|
|
|
+ List<Float> points = new ArrayList<>(100);
|
|
|
|
+
|
|
|
|
+ SkeletonControl skeletonCtrl = model.getControl(SkeletonControl.class);
|
|
|
|
+ Mesh[] targetMeshes = skeletonCtrl.getTargets();
|
|
|
|
+ for (Mesh mesh : targetMeshes) {
|
|
for (Integer index : boneIndices) {
|
|
for (Integer index : boneIndices) {
|
|
- points.addAll(getPoints(g.getMesh(), index, initialScale, initialPosition, weightThreshold));
|
|
|
|
- }
|
|
|
|
- } else if (model instanceof Node) {
|
|
|
|
- Node node = (Node) model;
|
|
|
|
- for (Spatial s : node.getChildren()) {
|
|
|
|
- if (s instanceof Geometry) {
|
|
|
|
- Geometry g = (Geometry) s;
|
|
|
|
- for (Integer index : boneIndices) {
|
|
|
|
- points.addAll(getPoints(g.getMesh(), index, initialScale, initialPosition, weightThreshold));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ List<Float> bonePoints = getPoints(mesh, index, initialScale,
|
|
|
|
+ initialPosition, weightThreshold);
|
|
|
|
+ points.addAll(bonePoints);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|