From a32c34939a3db118740de362141da97651a4135f Mon Sep 17 00:00:00 2001 From: Nehon Date: Tue, 26 Dec 2017 09:48:34 +0100 Subject: [PATCH] Display origin of the Armature debugger --- .../debug/custom/ArmatureInterJointsWire.java | 20 ++++++++++++++----- .../jme3/scene/debug/custom/ArmatureNode.java | 19 ++++++++++-------- .../java/jme3test/model/TestGltfLoading.java | 4 ++-- .../model/anim/TestAnimMigration.java | 8 ++++---- 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/scene/debug/custom/ArmatureInterJointsWire.java b/jme3-core/src/main/java/com/jme3/scene/debug/custom/ArmatureInterJointsWire.java index 01c24cb49..b1c62a55b 100644 --- a/jme3-core/src/main/java/com/jme3/scene/debug/custom/ArmatureInterJointsWire.java +++ b/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); } } diff --git a/jme3-core/src/main/java/com/jme3/scene/debug/custom/ArmatureNode.java b/jme3-core/src/main/java/com/jme3/scene/debug/custom/ArmatureNode.java index 52bafa771..121366b1a 100644 --- a/jme3-core/src/main/java/com/jme3/scene/debug/custom/ArmatureNode.java +++ b/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 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) { diff --git a/jme3-examples/src/main/java/jme3test/model/TestGltfLoading.java b/jme3-examples/src/main/java/jme3test/model/TestGltfLoading.java index 66e06e13e..ad85f3efe 100644 --- a/jme3-examples/src/main/java/jme3test/model/TestGltfLoading.java +++ b/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); diff --git a/jme3-examples/src/main/java/jme3test/model/anim/TestAnimMigration.java b/jme3-examples/src/main/java/jme3test/model/anim/TestAnimMigration.java index 836238e2b..5bff5fdd5 100644 --- a/jme3-examples/src/main/java/jme3test/model/anim/TestAnimMigration.java +++ b/jme3-examples/src/main/java/jme3test/model/anim/TestAnimMigration.java @@ -26,7 +26,7 @@ public class TestAnimMigration extends SimpleApplication { ArmatureDebugAppState debugAppState; AnimComposer composer; Queue 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);