Selaa lähdekoodia

Display origin of the Armature debugger

Nehon 7 vuotta sitten
vanhempi
commit
f1a3593070

+ 15 - 5
jme3-core/src/main/java/com/jme3/scene/debug/custom/ArmatureInterJointsWire.java

@@ -98,17 +98,27 @@ public class ArmatureInterJointsWire extends Mesh {
     /**
      * Update the start and end points of the line.
      */
-    public void updatePoints(Vector3f start, Vector3f end) {
+    public void updatePoints(Vector3f start, Vector3f[] ends) {
         VertexBuffer posBuf = getBuffer(Type.Position);
-
         FloatBuffer fb = (FloatBuffer) posBuf.getData();
         fb.rewind();
         fb.put(start.x).put(start.y).put(start.z);
-        fb.put(end.x).put(end.y).put(end.z);
-
+        for (int i = 0; i < ends.length; i++) {
+            fb.put(ends[i].x);
+            fb.put(ends[i].y);
+            fb.put(ends[i].z);
+        }
         posBuf.updateData(fb);
 
-        updateBound();
+        VertexBuffer normBuf = getBuffer(Type.Normal);
+        fb = (FloatBuffer) normBuf.getData();
+        fb.rewind();
+        for (int i = 0; i < ends.length * 3 + 3; i += 3) {
+            fb.put(start.x);
+            fb.put(start.y);
+            fb.put(start.z);
+        }
+        normBuf.updateData(fb);
     }
 
 }

+ 11 - 8
jme3-core/src/main/java/com/jme3/scene/debug/custom/ArmatureNode.java

@@ -79,6 +79,10 @@ public class ArmatureNode extends Node {
     public ArmatureNode(Armature armature, Node joints, Node wires, Node outlines, List<Joint> deformingJoints) {
         this.armature = armature;
 
+        Geometry origin = new Geometry("Armature Origin", new JointShape());
+        setColor(origin, ColorRGBA.Green);
+        attach(joints, true, origin);
+
         for (Joint joint : armature.getRoots()) {
             createSkeletonGeoms(joint, joints, wires, outlines, deformingJoints);
         }
@@ -253,14 +257,13 @@ public class ArmatureNode extends Node {
         return nbCol;
     }
 
-    private void updateBoneMesh(Geometry bGeom, Vector3f start, Vector3f[] ends) {
-        VertexBuffer pos = bGeom.getMesh().getBuffer(VertexBuffer.Type.Position);
-        FloatBuffer fb = (FloatBuffer) pos.getData();
-        fb.rewind();
-        fb.put(new float[]{start.x, start.y, start.z,
-                ends[0].x, ends[0].y, ends[0].z,});
-        pos.updateData(fb);
-        bGeom.updateModelBound();
+    private void updateBoneMesh(Geometry geom, Vector3f start, Vector3f[] ends) {
+        if (geom.getMesh() instanceof ArmatureInterJointsWire) {
+            ((ArmatureInterJointsWire) geom.getMesh()).updatePoints(start, ends);
+        } else if (geom.getMesh() instanceof Line) {
+            ((Line) geom.getMesh()).updatePoints(start, ends[0]);
+        }
+        geom.updateModelBound();
     }
 
     private void setColor(Geometry g, ColorRGBA color) {

+ 2 - 2
jme3-examples/src/main/java/jme3test/model/TestGltfLoading.java

@@ -116,12 +116,12 @@ public class TestGltfLoading extends SimpleApplication {
         //loadModel("Models/gltf/elephant/scene.gltf", new Vector3f(0, -1, 0), 0.01f);
         //loadModel("Models/gltf/buffalo/scene.gltf", new Vector3f(0, -1, 0), 0.1f);
         //loadModel("Models/gltf/war/scene.gltf", new Vector3f(0, -1, 0), 0.1f);
-        //loadModel("Models/gltf/ganjaarl/scene.gltf", new Vector3f(0, -1, 0), 0.01f);
+        loadModel("Models/gltf/ganjaarl/scene.gltf", new Vector3f(0, -1, 0), 0.01f);
         //loadModel("Models/gltf/hero/scene.gltf", new Vector3f(0, -1, 0), 0.1f);
         //loadModel("Models/gltf/mercy/scene.gltf", new Vector3f(0, -1, 0), 0.01f);
         //loadModel("Models/gltf/crab/scene.gltf", Vector3f.ZERO, 1);
         //loadModel("Models/gltf/manta/scene.gltf", Vector3f.ZERO, 0.2f);
-//        loadModel("Models/gltf/bone/scene.gltf", Vector3f.ZERO, 0.1f);
+        //loadModel("Models/gltf/bone/scene.gltf", Vector3f.ZERO, 0.1f);
 //        loadModel("Models/gltf/box/box.gltf", Vector3f.ZERO, 1);
 //        loadModel("Models/gltf/duck/Duck.gltf", new Vector3f(0, -1, 0), 1);
 //        loadModel("Models/gltf/damagedHelmet/damagedHelmet.gltf", Vector3f.ZERO, 1);

+ 4 - 4
jme3-examples/src/main/java/jme3test/model/anim/TestAnimMigration.java

@@ -26,7 +26,7 @@ public class TestAnimMigration extends SimpleApplication {
     ArmatureDebugAppState debugAppState;
     AnimComposer composer;
     Queue<String> anims = new LinkedList<>();
-    boolean playAnim = false;
+    boolean playAnim = true;
 
     public static void main(String... argv) {
         TestAnimMigration app = new TestAnimMigration();
@@ -41,10 +41,10 @@ public class TestAnimMigration extends SimpleApplication {
         rootNode.addLight(new DirectionalLight(new Vector3f(-1, -1, -1).normalizeLocal()));
         rootNode.addLight(new AmbientLight(ColorRGBA.DarkGray));
 
-        //Spatial model = assetManager.loadModel("Models/Jaime/Jaime.j3o");
-        //Spatial model = assetManager.loadModel("Models/Oto/Oto.mesh.xml").scale(0.2f).move(0, 1, 0);
+//        Spatial model = assetManager.loadModel("Models/Jaime/Jaime.j3o");
+        Spatial model = assetManager.loadModel("Models/Oto/Oto.mesh.xml").scale(0.2f).move(0, 1, 0);
         //Spatial model = assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml");
-        Spatial model = assetManager.loadModel("Models/Elephant/Elephant.mesh.xml").scale(0.02f);
+        //  Spatial model = assetManager.loadModel("Models/Elephant/Elephant.mesh.xml").scale(0.02f);
 
         AnimMigrationUtils.migrate(model);