/** * Creates buffers for points. Each line has POINT_AMOUNT of points. * @param skeleton * the skeleton that will be showed * @param boneLengths * the lengths of the bones */ public SkeletonInterBoneWire(Skeleton skeleton, Map<Integer, Float> boneLengths) { this.skeleton = skeleton; for (Bone bone : skeleton.getRoots()) { this.countConnections(bone); } this.setMode(Mode.Points); this.boneLengths = boneLengths; VertexBuffer pb = new VertexBuffer(Type.Position); FloatBuffer fpb = BufferUtils.createFloatBuffer(POINT_AMOUNT * connectionsAmount * 3); pb.setupData(Usage.Stream, 3, Format.Float, fpb); this.setBuffer(pb); this.updateCounts(); }
@Override public void updateLogicalState(float tpf) { super.updateLogicalState(tpf); wires.updateGeometry(); points.updateGeometry(); if(interBoneWires != null) { interBoneWires.updateGeometry(); } }
/** * The method updates the geometry according to the poitions of the bones. */ public void updateGeometry() { VertexBuffer vb = this.getBuffer(Type.Position); FloatBuffer posBuf = this.getFloatBuffer(Type.Position); posBuf.clear(); for (int i = 0; i < skeleton.getBoneCount(); ++i) { Bone bone = skeleton.getBone(i); Vector3f parentTail = bone.getModelSpacePosition().add(bone.getModelSpaceRotation().mult(Vector3f.UNIT_Y.mult(boneLengths.get(i)))); for (Bone child : bone.getChildren()) { Vector3f childHead = child.getModelSpacePosition(); Vector3f v = childHead.subtract(parentTail); float pointDelta = v.length() / POINT_AMOUNT; v.normalizeLocal().multLocal(pointDelta); Vector3f pointPosition = parentTail.clone(); for (int j = 0; j < POINT_AMOUNT; ++j) { posBuf.put(pointPosition.getX()).put(pointPosition.getY()).put(pointPosition.getZ()); pointPosition.addLocal(v); } } } posBuf.flip(); vb.updateData(posBuf); this.updateBound(); }
/** * Th method couns the connections between bones. * @param bone * the bone where counting starts */ private void countConnections(Bone bone) { for (Bone child : bone.getChildren()) { ++connectionsAmount; this.countConnections(child); } } }
/** * Creates a debugger with bone lengths data. If the data is supplied then the wires will show each full bone (from head to tail), * the points will display both heads and tails of the bones and dotted lines between bones will be seen. * @param name * the name of the debugger's node * @param skeleton * the skeleton that will be shown * @param boneLengths * a map between the bone's index and the bone's length */ public SkeletonDebugger(String name, Skeleton skeleton, Map<Integer, Float> boneLengths) { super(name); wires = new SkeletonWire(skeleton, boneLengths); points = new SkeletonPoints(skeleton, boneLengths); this.attachChild(new Geometry(name + "_wires", wires)); this.attachChild(new Geometry(name + "_points", points)); if (boneLengths != null) { interBoneWires = new SkeletonInterBoneWire(skeleton, boneLengths); this.attachChild(new Geometry(name + "_interwires", interBoneWires)); } this.setQueueBucket(Bucket.Transparent); }
/** * The method updates the geometry according to the poitions of the bones. */ public void updateGeometry() { VertexBuffer vb = this.getBuffer(Type.Position); FloatBuffer posBuf = this.getFloatBuffer(Type.Position); posBuf.clear(); for (int i = 0; i < skeleton.getBoneCount(); ++i) { Bone bone = skeleton.getBone(i); Vector3f parentTail = bone.getModelSpacePosition().add(bone.getModelSpaceRotation().mult(Vector3f.UNIT_Y.mult(boneLengths.get(i)))); for (Bone child : bone.getChildren()) { Vector3f childHead = child.getModelSpacePosition(); Vector3f v = childHead.subtract(parentTail); float pointDelta = v.length() / POINT_AMOUNT; v.normalizeLocal().multLocal(pointDelta); Vector3f pointPosition = parentTail.clone(); for (int j = 0; j < POINT_AMOUNT; ++j) { posBuf.put(pointPosition.getX()).put(pointPosition.getY()).put(pointPosition.getZ()); pointPosition.addLocal(v); } } } posBuf.flip(); vb.updateData(posBuf); this.updateBound(); }
/** * Th method couns the connections between bones. * @param bone * the bone where counting starts */ private void countConnections(Bone bone) { for (Bone child : bone.getChildren()) { ++connectionsAmount; this.countConnections(child); } } }
/** * Creates a debugger with bone lengths data. If the data is supplied then the wires will show each full bone (from head to tail), * the points will display both heads and tails of the bones and dotted lines between bones will be seen. * @param name * the name of the debugger's node * @param skeleton * the skeleton that will be shown * @param boneLengths * a map between the bone's index and the bone's length */ public SkeletonDebugger(String name, Skeleton skeleton, Map<Integer, Float> boneLengths) { super(name); wires = new SkeletonWire(skeleton, boneLengths); points = new SkeletonPoints(skeleton, boneLengths); this.attachChild(new Geometry(name + "_wires", wires)); this.attachChild(new Geometry(name + "_points", points)); if (boneLengths != null) { interBoneWires = new SkeletonInterBoneWire(skeleton, boneLengths); this.attachChild(new Geometry(name + "_interwires", interBoneWires)); } this.setQueueBucket(Bucket.Transparent); }
/** * Creates buffers for points. Each line has POINT_AMOUNT of points. * @param skeleton * the skeleton that will be showed * @param boneLengths * the lengths of the bones */ public SkeletonInterBoneWire(Skeleton skeleton, Map<Integer, Float> boneLengths) { this.skeleton = skeleton; for (Bone bone : skeleton.getRoots()) { this.countConnections(bone); } this.setMode(Mode.Points); this.boneLengths = boneLengths; VertexBuffer pb = new VertexBuffer(Type.Position); FloatBuffer fpb = BufferUtils.createFloatBuffer(POINT_AMOUNT * connectionsAmount * 3); pb.setupData(Usage.Stream, 3, Format.Float, fpb); this.setBuffer(pb); this.updateCounts(); }
@Override public void updateLogicalState(float tpf) { super.updateLogicalState(tpf); wires.updateGeometry(); points.updateGeometry(); if(interBoneWires != null) { interBoneWires.updateGeometry(); } }