From 8127772804d487be588919e868eb2e312f2554b1 Mon Sep 17 00:00:00 2001 From: Scrappers Date: Sat, 13 Nov 2021 21:01:31 -0600 Subject: [PATCH 01/11] Pie chart blend space --- .../jme3/anim/tween/action/PieChartSpace.java | 174 ++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 jme3-core/src/main/java/com/jme3/anim/tween/action/PieChartSpace.java diff --git a/jme3-core/src/main/java/com/jme3/anim/tween/action/PieChartSpace.java b/jme3-core/src/main/java/com/jme3/anim/tween/action/PieChartSpace.java new file mode 100644 index 0000000000..cfc6c6f759 --- /dev/null +++ b/jme3-core/src/main/java/com/jme3/anim/tween/action/PieChartSpace.java @@ -0,0 +1,174 @@ +package com.jme3.anim.tween.action; + +import com.jme3.math.FastMath; + +/** + * A mathematical space used for blending between 2 successive {@link com.jme3.anim.tween.action.BlendableAction}s + * based on a circle sector area {@link PieChartSpace#sectorArea} calculated from {@link PieChartSpace#radius} and {@link PieChartSpace#angle}, + * the sector area is scaled by the scaleFactor (userCircleArea / unitCircleArea) at the last step before applying values, + * and the step value represents a fraction from 0 to 1 (when the area of the circle sector reaches the areaOfUnitCircle), it means by how much the + * sectorArea approximates the unit circle area. + * + * @author pavl_g. + */ +public class PieChartSpace implements BlendSpace{ + + protected BlendAction action; + //pie-chart radius -- max is 1f + protected float radius; + //sector angle -- max is 360f in degrees + protected float angle; + //pie-chart area + protected float area; + //pie-chart sector area + protected float sectorArea; + protected int firstActionIndex; + protected boolean sectorAreaManualAdjustment; + + /** + * Instantiates a default pie chart space implementation. + * Default radius = 1f. + * Default angle = 45 degrees. + * Default area = 0.125 of unit circle area. + */ + public PieChartSpace(){ + this(1f, 45f); + } + + /** + * Instantiates a pie chart space with a radius and a sector angle, + * radius is clamped in the range [0, 1] and angle is clamped + * in the range [0, 360]. + * @param radius circle radius. + * @param angle sector angle in degrees. + */ + public PieChartSpace(final float radius, final float angle){ + //implicit suppression to extrapolation + //clamp values in the range : r = [0, 1] and angle = [0, 360]. + this.radius = radius % 1.1f; + this.angle = angle % 360.1f; + } + + @Override + public void setBlendAction(BlendAction action) { + this.action = action; + //calculate the area of the pieChart + area = FastMath.PI * FastMath.pow(radius, 2f); + //calculate the sector area + sectorArea = (angle / 360f) * area; + } + + @Override + public float getWeight() { + //keep the values updated with the loop (coherent update) as long as the manual adjustment is false. + if(!sectorAreaManualAdjustment) { + setBlendAction(action); + } + //calculate the unit circle area. + final float areaOfUnitCircle = FastMath.PI; + //the scaleFactor is the factor of ratio between the user's area and the unit circle area. + final float scaleFactor = area / areaOfUnitCircle; + //scaling the pieChart sector area with respect to the unitCircleArea. + final float scaledSector = sectorArea * scaleFactor; + //converting the step value to percentage from 0% (no stepping) to 100% (unitCircleArea). + final float step = scaledSector / areaOfUnitCircle; + //assign 2 successive actions to blend between them using the step value. + //successive actions can be altered using setFirstActionIndex(int firstActionIndex). + if(firstActionIndex < action.getActions().length - 1) { + action.setFirstActiveIndex(firstActionIndex++); + action.setSecondActiveIndex(firstActionIndex); + }else{ + firstActionIndex = 0; + } + return step; + } + + /** + * Manually alters the value of the sector area. + * Notes : + * - Altering the value of the sector area manually would + * ignore both {@link PieChartSpace#radius} and {@link PieChartSpace#angle}. + * + * - Adjust {@link PieChartSpace#setSectorAreaManualAdjustment(boolean)} to false + * to neutralize the manual effect and return back to using both (the radius and the angle). + * + * @param sectorArea a sector area to use. + */ + @Override + public void setValue(float sectorArea) { + this.sectorArea = sectorArea; + //activates sector area adjustment ignoring the angle and radius + this.sectorAreaManualAdjustment = true; + } + + /** + * Enables/Disables the manual area adjustment flag. + * + * @param sectorAreaManualAdjustment true to enable manual adjustment of the sector area ignoring both the radius and the angle, + * false to use the radius and the angle to calculate the sector area and ignore {@link PieChartSpace#setValue(float)}. + */ + public void setSectorAreaManualAdjustment(boolean sectorAreaManualAdjustment) { + this.sectorAreaManualAdjustment = sectorAreaManualAdjustment; + } + + /** + * Tests whether the manual adjustment is activated. + * @return true if manual adjustment is enabled, false otherwise. + */ + public boolean isSectorAreaManualAdjustment() { + return sectorAreaManualAdjustment; + } + + /** + * Alters the angle value of the pie-chart sector. + * Values are internally clamped in the range of [0, 360]. + * @param angle the angle in degrees. + */ + public void setAngle(float angle) { + this.angle = angle % 360.1f; + } + + /** + * Gets the angle value of the pie-chart sector in degrees. + * @return the angle in degrees. + */ + public float getAngle() { + return angle; + } + + /** + * Alters the radius of the pie-chart. + * Values are internally clamped in the range of [0, 1]. + * @param radius the circle radius. + */ + public void setRadius(float radius) { + this.radius = radius % 1.1f; + } + + /** + * Gets the radius of the pie-chart. + * @return the radius of the circle. + */ + public float getRadius() { + return radius; + } + + /** + * Explicitly alters the index of the first action. + * Usually values represented here depends on the number of {@link com.jme3.anim.tween.action.BlendableAction}s used within + * {@link com.jme3.anim.tween.action.BlendAction} arguments. + * Indices of other actions are auto obtained by the {@link PieChartSpace#getWeight()}. + * @param firstActionIndex the index of the first action. + */ + public void setFirstActionIndex(int firstActionIndex) { + this.firstActionIndex = firstActionIndex; + } + + /** + * Gets the index of the first action. + * @return the index of first action in integers. + */ + public int getFirstActionIndex() { + return firstActionIndex; + } +} From 312cb5dbc275c8056c8a5416d312e695fd3e8925 Mon Sep 17 00:00:00 2001 From: Scrappers Date: Sun, 14 Nov 2021 14:29:43 -0600 Subject: [PATCH 02/11] Added jme3 copyright --- .../jme3/anim/tween/action/PieChartSpace.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/jme3-core/src/main/java/com/jme3/anim/tween/action/PieChartSpace.java b/jme3-core/src/main/java/com/jme3/anim/tween/action/PieChartSpace.java index cfc6c6f759..857eb75bfb 100644 --- a/jme3-core/src/main/java/com/jme3/anim/tween/action/PieChartSpace.java +++ b/jme3-core/src/main/java/com/jme3/anim/tween/action/PieChartSpace.java @@ -1,3 +1,34 @@ +/* + * Copyright (c) 2009-2021 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ package com.jme3.anim.tween.action; import com.jme3.math.FastMath; From a7e0d5f4eb456a580ce8b99ab5689ba09bfd32a7 Mon Sep 17 00:00:00 2001 From: Scrappers Date: Sun, 14 Nov 2021 14:30:42 -0600 Subject: [PATCH 03/11] Added a testcase for pie chart blend space --- .../model/anim/TestPieChartSpace.java | 155 ++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java diff --git a/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java b/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java new file mode 100644 index 0000000000..ea0d50f44f --- /dev/null +++ b/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2009-2021 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package jme3test.model.anim; + +import com.jme3.anim.AnimClip; +import com.jme3.anim.AnimComposer; +import com.jme3.anim.AnimTrack; +import com.jme3.anim.TransformTrack; +import com.jme3.anim.tween.action.BlendAction; +import com.jme3.anim.tween.action.ClipAction; +import com.jme3.anim.tween.action.PieChartSpace; +import com.jme3.app.SimpleApplication; +import com.jme3.input.ChaseCamera; +import com.jme3.material.Material; +import com.jme3.math.ColorRGBA; +import com.jme3.math.FastMath; +import com.jme3.math.Quaternion; +import com.jme3.math.Vector3f; +import com.jme3.scene.Geometry; +import com.jme3.scene.Node; +import com.jme3.scene.shape.Cylinder; + +/** + * Tests {@link com.jme3.anim.tween.action.PieChartSpace} on a primitive geometry. + * + * The test increments the angle (starting from angle 180 degrees) and the radius (starting from 0.5) on each run based on the time per frames and + * the progressive time {@link TestPieChartSpace#progress}. + * + * The sector angle is clamped in the range [0, 360] in degrees and the pie chart radius is + * clamped in the range [0, 1]. + * + * @author pavl_g. + */ +public class TestPieChartSpace extends SimpleApplication { + + private final AnimComposer composer = new AnimComposer(); + private PieChartSpace pieChartSpace; + private float progress = 0f; + private BlendAction blendAction; + private final Node bambooNode = new Node(); + + public static void main(String[] args) { + new TestPieChartSpace().start(); + } + + @Override + public void simpleInitApp() { + //the mesh + final Cylinder cylinder = new Cylinder(100,10,1,5f, true); + final Geometry bamboo = new Geometry("Bamboo Plant", cylinder); + final Material material = new Material(assetManager, "Common/MatDefs/Misc/fakeLighting.j3md"); + material.setColor("Color", new ColorRGBA(0f, 0.15f, 0f, 1f)); + bamboo.setMaterial(material); + bambooNode.attachChild(bamboo); + bambooNode.setLocalRotation(new Quaternion().fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_Y)); + + //the camera + final ChaseCamera chaseCamera = new ChaseCamera(cam, bamboo, inputManager); + chaseCamera.setDefaultDistance(-10f); + chaseCamera.setDefaultHorizontalRotation(-FastMath.HALF_PI); + chaseCamera.setDefaultVerticalRotation(FastMath.PI/3f); + chaseCamera.setEnabled(true); + chaseCamera.setSmoothMotion(true); + + //add the composer control + bamboo.addControl(composer); + composer.setEnabled(true); + + rootNode.attachChild(bambooNode); + //do the blending between 2 actions + startBlendAction(); + } + private void startBlendAction(){ + //key frames timings + final float[] times = new float[]{2, 4, 8, 16}; + + //first action -- vertical traction + final Quaternion[] verticalTraction = new Quaternion[] { + new Quaternion().fromAngleAxis(0, Vector3f.UNIT_Z), + bambooNode.getLocalRotation().fromAngleAxis((float)Math.toRadians(120), Vector3f.UNIT_Z), + bambooNode.getLocalRotation().fromAngleAxis((float)Math.toRadians(120), Vector3f.UNIT_Z), + bambooNode.getLocalRotation().fromAngleAxis((float)Math.toRadians(120), Vector3f.UNIT_Z) + }; + final TransformTrack bambooVerticalTraction = new TransformTrack(bambooNode, times, null, verticalTraction, null); + final AnimClip verticalTractionClip = new AnimClip("Bamboo Rotation"); + verticalTractionClip.setTracks(new AnimTrack[]{ bambooVerticalTraction }); + final ClipAction verticalTractionAction = new ClipAction(verticalTractionClip); + verticalTractionAction.setSpeed(8f); + verticalTractionAction.setLength(10f); + + //second action -- horizontal traction + final Quaternion[] traction = new Quaternion[] { + new Quaternion().fromAngleAxis(0, Vector3f.UNIT_X), + bambooNode.getLocalRotation().fromAngleAxis((float)Math.toRadians(30), Vector3f.UNIT_X), + bambooNode.getLocalRotation().fromAngleAxis((float)Math.toRadians(30), Vector3f.UNIT_X), + bambooNode.getLocalRotation().fromAngleAxis((float)Math.toRadians(30), Vector3f.UNIT_X) + }; + final TransformTrack bambooHorizontalTraction = new TransformTrack(bambooNode, times, null, traction, null); + final AnimClip tractionClip = new AnimClip("Bamboo Traction"); + tractionClip.setTracks(new AnimTrack[]{ bambooHorizontalTraction }); + final ClipAction horizontalTractionAction = new ClipAction(tractionClip); + horizontalTractionAction.setSpeed(5f); + horizontalTractionAction.setLength(10f); + + //apply the pie chart blend space + pieChartSpace = new PieChartSpace(0.5f, 180f); + blendAction = new BlendAction(pieChartSpace, verticalTractionAction, horizontalTractionAction); + composer.addAction("Bamboo Clip", blendAction); + composer.setCurrentAction("Bamboo Clip", AnimComposer.DEFAULT_LAYER); + } + @Override + public void simpleUpdate(float tpf) { + progress += tpf; + if(progress >= blendAction.getLength()){ + //advance the angles and the radius + //the angle would increase the sector area of the step + //the radius would increase the scale factor applied to the sector area + //the radius approximates the scaleFactor from 1.0 + final float newAngle = pieChartSpace.getAngle() + (progress * 4); + final float newRadius = pieChartSpace.getRadius() + (tpf * 2); + pieChartSpace.setAngle(newAngle); + pieChartSpace.setRadius(newRadius); + progress = 0; + } + } +} From 38c8046bd566559137591c215e4e7911e62eea17 Mon Sep 17 00:00:00 2001 From: Scrappers Date: Sun, 14 Nov 2021 14:36:50 -0600 Subject: [PATCH 04/11] Rephrased some comments --- .../model/anim/TestPieChartSpace.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java b/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java index ea0d50f44f..b6e7003acf 100644 --- a/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java +++ b/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java @@ -74,7 +74,7 @@ public static void main(String[] args) { @Override public void simpleInitApp() { - //the mesh + //the mesh. final Cylinder cylinder = new Cylinder(100,10,1,5f, true); final Geometry bamboo = new Geometry("Bamboo Plant", cylinder); final Material material = new Material(assetManager, "Common/MatDefs/Misc/fakeLighting.j3md"); @@ -83,7 +83,7 @@ public void simpleInitApp() { bambooNode.attachChild(bamboo); bambooNode.setLocalRotation(new Quaternion().fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_Y)); - //the camera + //the camera. final ChaseCamera chaseCamera = new ChaseCamera(cam, bamboo, inputManager); chaseCamera.setDefaultDistance(-10f); chaseCamera.setDefaultHorizontalRotation(-FastMath.HALF_PI); @@ -91,19 +91,19 @@ public void simpleInitApp() { chaseCamera.setEnabled(true); chaseCamera.setSmoothMotion(true); - //add the composer control + //add the composer control. bamboo.addControl(composer); composer.setEnabled(true); rootNode.attachChild(bambooNode); - //do the blending between 2 actions + //do the blending between 2 actions. startBlendAction(); } private void startBlendAction(){ //key frames timings final float[] times = new float[]{2, 4, 8, 16}; - //first action -- vertical traction + //first action -- vertical traction. final Quaternion[] verticalTraction = new Quaternion[] { new Quaternion().fromAngleAxis(0, Vector3f.UNIT_Z), bambooNode.getLocalRotation().fromAngleAxis((float)Math.toRadians(120), Vector3f.UNIT_Z), @@ -117,7 +117,7 @@ private void startBlendAction(){ verticalTractionAction.setSpeed(8f); verticalTractionAction.setLength(10f); - //second action -- horizontal traction + //second action -- horizontal traction. final Quaternion[] traction = new Quaternion[] { new Quaternion().fromAngleAxis(0, Vector3f.UNIT_X), bambooNode.getLocalRotation().fromAngleAxis((float)Math.toRadians(30), Vector3f.UNIT_X), @@ -141,10 +141,11 @@ private void startBlendAction(){ public void simpleUpdate(float tpf) { progress += tpf; if(progress >= blendAction.getLength()){ - //advance the angles and the radius - //the angle would increase the sector area of the step - //the radius would increase the scale factor applied to the sector area - //the radius approximates the scaleFactor from 1.0 + //advances the angles and the radius when the blend action finishes. + //incrementing the angle would increase the sector area of the step. + //the sector area represents an unscaled blending step. + //incrementing the radius would increase the scale factor applied to the sector area . + //the radius approximates the scaleFactor to 1.0. final float newAngle = pieChartSpace.getAngle() + (progress * 4); final float newRadius = pieChartSpace.getRadius() + (tpf * 2); pieChartSpace.setAngle(newAngle); From 98e9a314e25d00dd2bc139bef04b0ce3d67bdc61 Mon Sep 17 00:00:00 2001 From: Scrappers Date: Sun, 14 Nov 2021 19:22:58 -0600 Subject: [PATCH 05/11] Added a getter method to the sector area --- .../com/jme3/anim/tween/action/PieChartSpace.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/jme3-core/src/main/java/com/jme3/anim/tween/action/PieChartSpace.java b/jme3-core/src/main/java/com/jme3/anim/tween/action/PieChartSpace.java index 857eb75bfb..f11d307073 100644 --- a/jme3-core/src/main/java/com/jme3/anim/tween/action/PieChartSpace.java +++ b/jme3-core/src/main/java/com/jme3/anim/tween/action/PieChartSpace.java @@ -60,7 +60,7 @@ public class PieChartSpace implements BlendSpace{ * Instantiates a default pie chart space implementation. * Default radius = 1f. * Default angle = 45 degrees. - * Default area = 0.125 of unit circle area. + * Default area = 0.125 of unit circle area (0.125 * PI). */ public PieChartSpace(){ this(1f, 45f); @@ -184,6 +184,16 @@ public float getRadius() { return radius; } + /** + * Gets the sector area, sector area depends on both {@link PieChartSpace#angle}, {@link PieChartSpace#radius}. + * To change the sector area on runtime use : {@link PieChartSpace#setAngle(float)} and {@link PieChartSpace#setRadius(float)} + * or use {@link PieChartSpace#setValue(float)} to directly alter the sector area. + * @return the sector area. + */ + public float getSectorArea() { + return sectorArea; + } + /** * Explicitly alters the index of the first action. * Usually values represented here depends on the number of {@link com.jme3.anim.tween.action.BlendableAction}s used within From 1f2c1babf23c540d7462e973e0f0c4ad9cb05071 Mon Sep 17 00:00:00 2001 From: Scrappers Date: Sun, 14 Nov 2021 19:23:37 -0600 Subject: [PATCH 06/11] Changed quaternion degree angles to radians explicitly --- .../java/jme3test/model/anim/TestPieChartSpace.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java b/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java index b6e7003acf..1c7a33bc4a 100644 --- a/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java +++ b/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java @@ -106,9 +106,9 @@ private void startBlendAction(){ //first action -- vertical traction. final Quaternion[] verticalTraction = new Quaternion[] { new Quaternion().fromAngleAxis(0, Vector3f.UNIT_Z), - bambooNode.getLocalRotation().fromAngleAxis((float)Math.toRadians(120), Vector3f.UNIT_Z), - bambooNode.getLocalRotation().fromAngleAxis((float)Math.toRadians(120), Vector3f.UNIT_Z), - bambooNode.getLocalRotation().fromAngleAxis((float)Math.toRadians(120), Vector3f.UNIT_Z) + bambooNode.getLocalRotation().fromAngleAxis(0.6667f * FastMath.PI, Vector3f.UNIT_Z), + bambooNode.getLocalRotation().fromAngleAxis(0.6667f * FastMath.PI, Vector3f.UNIT_Z), + bambooNode.getLocalRotation().fromAngleAxis(0.6667f * FastMath.PI, Vector3f.UNIT_Z) }; final TransformTrack bambooVerticalTraction = new TransformTrack(bambooNode, times, null, verticalTraction, null); final AnimClip verticalTractionClip = new AnimClip("Bamboo Rotation"); @@ -120,9 +120,9 @@ private void startBlendAction(){ //second action -- horizontal traction. final Quaternion[] traction = new Quaternion[] { new Quaternion().fromAngleAxis(0, Vector3f.UNIT_X), - bambooNode.getLocalRotation().fromAngleAxis((float)Math.toRadians(30), Vector3f.UNIT_X), - bambooNode.getLocalRotation().fromAngleAxis((float)Math.toRadians(30), Vector3f.UNIT_X), - bambooNode.getLocalRotation().fromAngleAxis((float)Math.toRadians(30), Vector3f.UNIT_X) + bambooNode.getLocalRotation().fromAngleAxis(0.1667f * FastMath.PI, Vector3f.UNIT_X), + bambooNode.getLocalRotation().fromAngleAxis(0.1667f * FastMath.PI, Vector3f.UNIT_X), + bambooNode.getLocalRotation().fromAngleAxis(0.1667f * FastMath.PI, Vector3f.UNIT_X) }; final TransformTrack bambooHorizontalTraction = new TransformTrack(bambooNode, times, null, traction, null); final AnimClip tractionClip = new AnimClip("Bamboo Traction"); From 7595a04565dc8b2d13f23a549a93fca3fbed511c Mon Sep 17 00:00:00 2001 From: Scrappers Date: Mon, 15 Nov 2021 20:00:52 -0600 Subject: [PATCH 07/11] Exposed altering the indices of both the firstAction and the secondAction + some more getters --- .../jme3/anim/tween/action/PieChartSpace.java | 103 +++++++++++++----- 1 file changed, 77 insertions(+), 26 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/anim/tween/action/PieChartSpace.java b/jme3-core/src/main/java/com/jme3/anim/tween/action/PieChartSpace.java index f11d307073..62e944f910 100644 --- a/jme3-core/src/main/java/com/jme3/anim/tween/action/PieChartSpace.java +++ b/jme3-core/src/main/java/com/jme3/anim/tween/action/PieChartSpace.java @@ -53,8 +53,10 @@ public class PieChartSpace implements BlendSpace{ protected float area; //pie-chart sector area protected float sectorArea; - protected int firstActionIndex; protected boolean sectorAreaManualAdjustment; + //exposing the action indices + private int firstActionIndex = 0; + private int secondActionIndex = 0; /** * Instantiates a default pie chart space implementation. @@ -62,7 +64,7 @@ public class PieChartSpace implements BlendSpace{ * Default angle = 45 degrees. * Default area = 0.125 of unit circle area (0.125 * PI). */ - public PieChartSpace(){ + public PieChartSpace() { this(1f, 45f); } @@ -73,7 +75,7 @@ public PieChartSpace(){ * @param radius circle radius. * @param angle sector angle in degrees. */ - public PieChartSpace(final float radius, final float angle){ + public PieChartSpace(final float radius, final float angle) { //implicit suppression to extrapolation //clamp values in the range : r = [0, 1] and angle = [0, 360]. this.radius = radius % 1.1f; @@ -83,17 +85,16 @@ public PieChartSpace(final float radius, final float angle){ @Override public void setBlendAction(BlendAction action) { this.action = action; - //calculate the area of the pieChart - area = FastMath.PI * FastMath.pow(radius, 2f); - //calculate the sector area - sectorArea = (angle / 360f) * area; + //use default actions indices + action.setFirstActiveIndex(action.getActions().length - 2); + action.setSecondActiveIndex(action.getActions().length - 1); } @Override public float getWeight() { - //keep the values updated with the loop (coherent update) as long as the manual adjustment is false. + calculatePieChartTotalArea(); if(!sectorAreaManualAdjustment) { - setBlendAction(action); + calculateSectorArea(); } //calculate the unit circle area. final float areaOfUnitCircle = FastMath.PI; @@ -103,25 +104,34 @@ public float getWeight() { final float scaledSector = sectorArea * scaleFactor; //converting the step value to percentage from 0% (no stepping) to 100% (unitCircleArea). final float step = scaledSector / areaOfUnitCircle; - //assign 2 successive actions to blend between them using the step value. - //successive actions can be altered using setFirstActionIndex(int firstActionIndex). - if(firstActionIndex < action.getActions().length - 1) { - action.setFirstActiveIndex(firstActionIndex++); - action.setSecondActiveIndex(firstActionIndex); - }else{ - firstActionIndex = 0; - } + //use the step as a delta value of interpolation return step; } + /** + * Calculate the sector area from {@link PieChartSpace#area} and {@link PieChartSpace#angle}. + */ + protected void calculateSectorArea() { + //calculate the sector area + sectorArea = (angle / 360f) * area; + } + + /** + * Calculate pie chart total area from {@link PieChartSpace#radius}. + */ + protected void calculatePieChartTotalArea() { + //calculate the area of the pieChart + area = FastMath.PI * FastMath.pow(radius, 2f); + } + /** * Manually alters the value of the sector area. * Notes : * - Altering the value of the sector area manually would - * ignore both {@link PieChartSpace#radius} and {@link PieChartSpace#angle}. + * ignore both {@link PieChartSpace#area} and {@link PieChartSpace#angle}. * * - Adjust {@link PieChartSpace#setSectorAreaManualAdjustment(boolean)} to false - * to neutralize the manual effect and return back to using both (the radius and the angle). + * to neutralize the manual effect and return back to using both (the pie chart area and the angle). * * @param sectorArea a sector area to use. */ @@ -135,8 +145,8 @@ public void setValue(float sectorArea) { /** * Enables/Disables the manual area adjustment flag. * - * @param sectorAreaManualAdjustment true to enable manual adjustment of the sector area ignoring both the radius and the angle, - * false to use the radius and the angle to calculate the sector area and ignore {@link PieChartSpace#setValue(float)}. + * @param sectorAreaManualAdjustment true to enable manual adjustment of the sector area ignoring both the pie chart area and the angle, + * false to use the pie chart area and the angle to calculate the sector area and ignore {@link PieChartSpace#setValue(float)}. */ public void setSectorAreaManualAdjustment(boolean sectorAreaManualAdjustment) { this.sectorAreaManualAdjustment = sectorAreaManualAdjustment; @@ -195,21 +205,62 @@ public float getSectorArea() { } /** - * Explicitly alters the index of the first action. + * Alters the index of the first action. * Usually values represented here depends on the number of {@link com.jme3.anim.tween.action.BlendableAction}s used within * {@link com.jme3.anim.tween.action.BlendAction} arguments. - * Indices of other actions are auto obtained by the {@link PieChartSpace#getWeight()}. + * Default index of the second action is : action.getActions().length - 2 * @param firstActionIndex the index of the first action. */ - public void setFirstActionIndex(int firstActionIndex) { + public void setFirstAction(int firstActionIndex) { + //sanity check the inputs + if(action == null){ + throw new IllegalStateException("A BlendAction instance hasn't been assigned to this blendSpace yet, use this setter after instantiating a BlendAction on this space !"); + } + assert (firstActionIndex < action.getActions().length); + action.setFirstActiveIndex(firstActionIndex); this.firstActionIndex = firstActionIndex; } /** - * Gets the index of the first action. - * @return the index of first action in integers. + * Alters the index of the second action. + * Usually values represented here depends on the number of {@link com.jme3.anim.tween.action.BlendableAction}s used within + * {@link com.jme3.anim.tween.action.BlendAction} arguments. + * Default index of the second action is : action.getActions().length - 1 + * @param secondActionIndex the index of the second action. + */ + public void setSecondAction(int secondActionIndex) { + //sanity check the inputs + if(action == null){ + throw new IllegalStateException("A BlendAction instance hasn't been assigned to this blendSpace yet, use this setter after instantiating a BlendAction on this space!"); + } + assert (secondActionIndex < action.getActions().length); + action.setSecondActiveIndex(secondActionIndex); + this.secondActionIndex = secondActionIndex; + } + + /** + * Gets the actions involved in the space blend action. + * @return the actions of the space blend action. + */ + public Action[] getActions(){ + return action.getActions(); + } + + /** + * Gets the first action index. + * Default index of the first action is : action.getActions().length - 2 + * @return the first action index. */ public int getFirstActionIndex() { return firstActionIndex; } + + /** + * Gets the second action index. + * Default index of the second action is : action.getActions().length - 1 + * @return the second action index. + */ + public int getSecondActionIndex() { + return secondActionIndex; + } } From 3f8a09e060d190b63a0851ac59a67dc7a60c454b Mon Sep 17 00:00:00 2001 From: Scrappers Date: Mon, 15 Nov 2021 20:01:50 -0600 Subject: [PATCH 08/11] Supported blending between more than 2 actions (4 actions) --- .../model/anim/TestPieChartSpace.java | 67 +++++++++++++++++-- 1 file changed, 61 insertions(+), 6 deletions(-) diff --git a/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java b/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java index 1c7a33bc4a..4c905213a3 100644 --- a/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java +++ b/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java @@ -52,7 +52,10 @@ /** * Tests {@link com.jme3.anim.tween.action.PieChartSpace} on a primitive geometry. * - * The test increments the angle (starting from angle 180 degrees) and the radius (starting from 0.5) on each run based on the time per frames and + * This test blends between 4 successive blendable actions, by changing the firstActionIndex and the secondActionIndex when the track times finishes + * using the exposed functions of the pie chart blend space {@link PieChartSpace#setFirstAction(int)}, {@link PieChartSpace#setSecondAction(int)}. + * + * It increments the angle (starting from angle 180 degrees) and the radius (starting from 0.5) on each run based on the time per frames and * the progressive time {@link TestPieChartSpace#progress}. * * The sector angle is clamped in the range [0, 360] in degrees and the pie chart radius is @@ -67,6 +70,11 @@ public class TestPieChartSpace extends SimpleApplication { private float progress = 0f; private BlendAction blendAction; private final Node bambooNode = new Node(); + private float progressToSwitch = 0f; + private final Vector3f originalScale = new Vector3f(); + private final Vector3f originalTranslation = new Vector3f(); + //key frames timings in seconds + private final float[] times = new float[]{1, 2, 3, 4}; public static void main(String[] args) { new TestPieChartSpace().start(); @@ -94,14 +102,14 @@ public void simpleInitApp() { //add the composer control. bamboo.addControl(composer); composer.setEnabled(true); + originalScale.set(bambooNode.getLocalScale()); + originalTranslation.set(bambooNode.getLocalTranslation()); rootNode.attachChild(bambooNode); //do the blending between 2 actions. startBlendAction(); } private void startBlendAction(){ - //key frames timings - final float[] times = new float[]{2, 4, 8, 16}; //first action -- vertical traction. final Quaternion[] verticalTraction = new Quaternion[] { @@ -115,7 +123,6 @@ private void startBlendAction(){ verticalTractionClip.setTracks(new AnimTrack[]{ bambooVerticalTraction }); final ClipAction verticalTractionAction = new ClipAction(verticalTractionClip); verticalTractionAction.setSpeed(8f); - verticalTractionAction.setLength(10f); //second action -- horizontal traction. final Quaternion[] traction = new Quaternion[] { @@ -129,16 +136,64 @@ private void startBlendAction(){ tractionClip.setTracks(new AnimTrack[]{ bambooHorizontalTraction }); final ClipAction horizontalTractionAction = new ClipAction(tractionClip); horizontalTractionAction.setSpeed(5f); - horizontalTractionAction.setLength(10f); + + //third action -- scales action. + final Vector3f[] scales = new Vector3f[]{ + originalScale, + bambooNode.getLocalScale().add(0.5f, 0.5f, 0.5f), + bambooNode.getLocalScale().add(0.5f, 0.5f, 0.5f), + bambooNode.getLocalScale().add(0.5f, 0.5f, 0.5f), + }; + final TransformTrack bambooScales = new TransformTrack(bambooNode, times, null, null, scales); + final AnimClip bambooScalesClip = new AnimClip("Bamboo Scales"); + bambooScalesClip.setTracks(new AnimTrack[]{ bambooScales }); + final ClipAction scalesAction = new ClipAction(bambooScalesClip); + scalesAction.setSpeed(2f); + + //forth action -- translation action. + final Vector3f[] translations = new Vector3f[]{ + originalTranslation, + bambooNode.getLocalTranslation().add(0,0, -0.1f), + bambooNode.getLocalTranslation().add(0,0, -0.2f), + bambooNode.getLocalTranslation().add(0, 0, -0.5f), + }; + final TransformTrack bambooTranslations = new TransformTrack(bambooNode, times, null, null, translations); + final AnimClip bambooTranslationsClip = new AnimClip("Bamboo Translations"); + bambooTranslationsClip.setTracks(new AnimTrack[]{ bambooTranslations }); + final ClipAction translationsAction = new ClipAction(bambooTranslationsClip); + translationsAction.setSpeed(2f); //apply the pie chart blend space pieChartSpace = new PieChartSpace(0.5f, 180f); - blendAction = new BlendAction(pieChartSpace, verticalTractionAction, horizontalTractionAction); + blendAction = new BlendAction(pieChartSpace, verticalTractionAction, horizontalTractionAction, scalesAction, translationsAction); + //setup the initial firstActionIndex and the initial secondActionIndex + pieChartSpace.setFirstAction(0); + pieChartSpace.setSecondAction(1); composer.addAction("Bamboo Clip", blendAction); composer.setCurrentAction("Bamboo Clip", AnimComposer.DEFAULT_LAYER); } @Override public void simpleUpdate(float tpf) { + progressToSwitch += tpf; + //manipulate actions manually when the time passes the last frame times + if(pieChartSpace.getFirstActionIndex() == 0 && pieChartSpace.getSecondActionIndex() == 1) { + // 5 seconds represents more than the times[] of the transform tracks + if (progressToSwitch >= times[times.length - 1] + 1f) { + //re-switch them + pieChartSpace.setFirstAction(2); + pieChartSpace.setSecondAction(3); + progressToSwitch = 0f; + } + } else if (pieChartSpace.getFirstActionIndex() == 2 && pieChartSpace.getSecondActionIndex() == 3) { + // 5 seconds represents more than the times[] of the transform tracks + if (progressToSwitch >= times[times.length - 1] + 1f) { + //switch the actions + pieChartSpace.setFirstAction(0); + pieChartSpace.setSecondAction(1); + progressToSwitch = 0f; + } + } + progress += tpf; if(progress >= blendAction.getLength()){ //advances the angles and the radius when the blend action finishes. From 88a16ac595f8327d2963a662f66640721a5f5fad Mon Sep 17 00:00:00 2001 From: Scrappers Date: Mon, 15 Nov 2021 20:10:52 -0600 Subject: [PATCH 09/11] Spaces correction --- .../java/jme3test/model/anim/TestPieChartSpace.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java b/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java index 4c905213a3..22807a7a41 100644 --- a/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java +++ b/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java @@ -74,7 +74,7 @@ public class TestPieChartSpace extends SimpleApplication { private final Vector3f originalScale = new Vector3f(); private final Vector3f originalTranslation = new Vector3f(); //key frames timings in seconds - private final float[] times = new float[]{1, 2, 3, 4}; + private final float[] times = new float[] {1, 2, 3, 4}; public static void main(String[] args) { new TestPieChartSpace().start(); @@ -109,8 +109,8 @@ public void simpleInitApp() { //do the blending between 2 actions. startBlendAction(); } - private void startBlendAction(){ + private void startBlendAction() { //first action -- vertical traction. final Quaternion[] verticalTraction = new Quaternion[] { new Quaternion().fromAngleAxis(0, Vector3f.UNIT_Z), @@ -138,7 +138,7 @@ private void startBlendAction(){ horizontalTractionAction.setSpeed(5f); //third action -- scales action. - final Vector3f[] scales = new Vector3f[]{ + final Vector3f[] scales = new Vector3f[] { originalScale, bambooNode.getLocalScale().add(0.5f, 0.5f, 0.5f), bambooNode.getLocalScale().add(0.5f, 0.5f, 0.5f), @@ -151,7 +151,7 @@ private void startBlendAction(){ scalesAction.setSpeed(2f); //forth action -- translation action. - final Vector3f[] translations = new Vector3f[]{ + final Vector3f[] translations = new Vector3f[] { originalTranslation, bambooNode.getLocalTranslation().add(0,0, -0.1f), bambooNode.getLocalTranslation().add(0,0, -0.2f), @@ -159,7 +159,7 @@ private void startBlendAction(){ }; final TransformTrack bambooTranslations = new TransformTrack(bambooNode, times, null, null, translations); final AnimClip bambooTranslationsClip = new AnimClip("Bamboo Translations"); - bambooTranslationsClip.setTracks(new AnimTrack[]{ bambooTranslations }); + bambooTranslationsClip.setTracks(new AnimTrack[] {bambooTranslations}); final ClipAction translationsAction = new ClipAction(bambooTranslationsClip); translationsAction.setSpeed(2f); @@ -172,6 +172,7 @@ private void startBlendAction(){ composer.addAction("Bamboo Clip", blendAction); composer.setCurrentAction("Bamboo Clip", AnimComposer.DEFAULT_LAYER); } + @Override public void simpleUpdate(float tpf) { progressToSwitch += tpf; @@ -195,7 +196,7 @@ public void simpleUpdate(float tpf) { } progress += tpf; - if(progress >= blendAction.getLength()){ + if (progress >= blendAction.getLength()) { //advances the angles and the radius when the blend action finishes. //incrementing the angle would increase the sector area of the step. //the sector area represents an unscaled blending step. From fe38f14692c248a5f17191967f6524fe0494945b Mon Sep 17 00:00:00 2001 From: Scrappers Date: Mon, 15 Nov 2021 20:15:33 -0600 Subject: [PATCH 10/11] Comments corrections --- .../src/main/java/jme3test/model/anim/TestPieChartSpace.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java b/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java index 22807a7a41..1e1c6f9470 100644 --- a/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java +++ b/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java @@ -106,7 +106,7 @@ public void simpleInitApp() { originalTranslation.set(bambooNode.getLocalTranslation()); rootNode.attachChild(bambooNode); - //do the blending between 2 actions. + //do the blending between 4 actions. startBlendAction(); } From 44a1c64b2bf6d024668883e33a5b9bc448c7c2ce Mon Sep 17 00:00:00 2001 From: Scrappers Date: Tue, 23 Nov 2021 16:52:15 -0600 Subject: [PATCH 11/11] Reformatted code (white spaces) --- .../jme3/anim/tween/action/PieChartSpace.java | 58 +++++++++++-------- .../model/anim/TestPieChartSpace.java | 42 +++++++------- 2 files changed, 56 insertions(+), 44 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/anim/tween/action/PieChartSpace.java b/jme3-core/src/main/java/com/jme3/anim/tween/action/PieChartSpace.java index 62e944f910..f116e871a7 100644 --- a/jme3-core/src/main/java/com/jme3/anim/tween/action/PieChartSpace.java +++ b/jme3-core/src/main/java/com/jme3/anim/tween/action/PieChartSpace.java @@ -42,7 +42,7 @@ * * @author pavl_g. */ -public class PieChartSpace implements BlendSpace{ +public class PieChartSpace implements BlendSpace { protected BlendAction action; //pie-chart radius -- max is 1f @@ -72,8 +72,9 @@ public PieChartSpace() { * Instantiates a pie chart space with a radius and a sector angle, * radius is clamped in the range [0, 1] and angle is clamped * in the range [0, 360]. + * * @param radius circle radius. - * @param angle sector angle in degrees. + * @param angle sector angle in degrees. */ public PieChartSpace(final float radius, final float angle) { //implicit suppression to extrapolation @@ -93,7 +94,7 @@ public void setBlendAction(BlendAction action) { @Override public float getWeight() { calculatePieChartTotalArea(); - if(!sectorAreaManualAdjustment) { + if (!sectorAreaManualAdjustment) { calculateSectorArea(); } //calculate the unit circle area. @@ -129,7 +130,7 @@ protected void calculatePieChartTotalArea() { * Notes : * - Altering the value of the sector area manually would * ignore both {@link PieChartSpace#area} and {@link PieChartSpace#angle}. - * + *

* - Adjust {@link PieChartSpace#setSectorAreaManualAdjustment(boolean)} to false * to neutralize the manual effect and return back to using both (the pie chart area and the angle). * @@ -142,6 +143,15 @@ public void setValue(float sectorArea) { this.sectorAreaManualAdjustment = true; } + /** + * Tests whether the manual adjustment is activated. + * + * @return true if manual adjustment is enabled, false otherwise. + */ + public boolean isSectorAreaManualAdjustment() { + return sectorAreaManualAdjustment; + } + /** * Enables/Disables the manual area adjustment flag. * @@ -153,16 +163,18 @@ public void setSectorAreaManualAdjustment(boolean sectorAreaManualAdjustment) { } /** - * Tests whether the manual adjustment is activated. - * @return true if manual adjustment is enabled, false otherwise. + * Gets the angle value of the pie-chart sector in degrees. + * + * @return the angle in degrees. */ - public boolean isSectorAreaManualAdjustment() { - return sectorAreaManualAdjustment; + public float getAngle() { + return angle; } /** * Alters the angle value of the pie-chart sector. * Values are internally clamped in the range of [0, 360]. + * * @param angle the angle in degrees. */ public void setAngle(float angle) { @@ -170,34 +182,29 @@ public void setAngle(float angle) { } /** - * Gets the angle value of the pie-chart sector in degrees. - * @return the angle in degrees. + * Gets the radius of the pie-chart. + * + * @return the radius of the circle. */ - public float getAngle() { - return angle; + public float getRadius() { + return radius; } /** * Alters the radius of the pie-chart. * Values are internally clamped in the range of [0, 1]. + * * @param radius the circle radius. */ public void setRadius(float radius) { this.radius = radius % 1.1f; } - /** - * Gets the radius of the pie-chart. - * @return the radius of the circle. - */ - public float getRadius() { - return radius; - } - /** * Gets the sector area, sector area depends on both {@link PieChartSpace#angle}, {@link PieChartSpace#radius}. * To change the sector area on runtime use : {@link PieChartSpace#setAngle(float)} and {@link PieChartSpace#setRadius(float)} * or use {@link PieChartSpace#setValue(float)} to directly alter the sector area. + * * @return the sector area. */ public float getSectorArea() { @@ -209,11 +216,12 @@ public float getSectorArea() { * Usually values represented here depends on the number of {@link com.jme3.anim.tween.action.BlendableAction}s used within * {@link com.jme3.anim.tween.action.BlendAction} arguments. * Default index of the second action is : action.getActions().length - 2 + * * @param firstActionIndex the index of the first action. */ public void setFirstAction(int firstActionIndex) { //sanity check the inputs - if(action == null){ + if (action == null) { throw new IllegalStateException("A BlendAction instance hasn't been assigned to this blendSpace yet, use this setter after instantiating a BlendAction on this space !"); } assert (firstActionIndex < action.getActions().length); @@ -226,11 +234,12 @@ public void setFirstAction(int firstActionIndex) { * Usually values represented here depends on the number of {@link com.jme3.anim.tween.action.BlendableAction}s used within * {@link com.jme3.anim.tween.action.BlendAction} arguments. * Default index of the second action is : action.getActions().length - 1 + * * @param secondActionIndex the index of the second action. */ public void setSecondAction(int secondActionIndex) { //sanity check the inputs - if(action == null){ + if (action == null) { throw new IllegalStateException("A BlendAction instance hasn't been assigned to this blendSpace yet, use this setter after instantiating a BlendAction on this space!"); } assert (secondActionIndex < action.getActions().length); @@ -240,15 +249,17 @@ public void setSecondAction(int secondActionIndex) { /** * Gets the actions involved in the space blend action. + * * @return the actions of the space blend action. */ - public Action[] getActions(){ + public Action[] getActions() { return action.getActions(); } /** * Gets the first action index. * Default index of the first action is : action.getActions().length - 2 + * * @return the first action index. */ public int getFirstActionIndex() { @@ -258,6 +269,7 @@ public int getFirstActionIndex() { /** * Gets the second action index. * Default index of the second action is : action.getActions().length - 1 + * * @return the second action index. */ public int getSecondActionIndex() { diff --git a/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java b/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java index 1e1c6f9470..17bfbc700b 100644 --- a/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java +++ b/jme3-examples/src/main/java/jme3test/model/anim/TestPieChartSpace.java @@ -51,13 +51,13 @@ /** * Tests {@link com.jme3.anim.tween.action.PieChartSpace} on a primitive geometry. - * + *

* This test blends between 4 successive blendable actions, by changing the firstActionIndex and the secondActionIndex when the track times finishes * using the exposed functions of the pie chart blend space {@link PieChartSpace#setFirstAction(int)}, {@link PieChartSpace#setSecondAction(int)}. - * + *

* It increments the angle (starting from angle 180 degrees) and the radius (starting from 0.5) on each run based on the time per frames and * the progressive time {@link TestPieChartSpace#progress}. - * + *

* The sector angle is clamped in the range [0, 360] in degrees and the pie chart radius is * clamped in the range [0, 1]. * @@ -66,15 +66,15 @@ public class TestPieChartSpace extends SimpleApplication { private final AnimComposer composer = new AnimComposer(); - private PieChartSpace pieChartSpace; - private float progress = 0f; - private BlendAction blendAction; private final Node bambooNode = new Node(); - private float progressToSwitch = 0f; private final Vector3f originalScale = new Vector3f(); private final Vector3f originalTranslation = new Vector3f(); //key frames timings in seconds - private final float[] times = new float[] {1, 2, 3, 4}; + private final float[] times = new float[]{1, 2, 3, 4}; + private PieChartSpace pieChartSpace; + private float progress = 0f; + private BlendAction blendAction; + private float progressToSwitch = 0f; public static void main(String[] args) { new TestPieChartSpace().start(); @@ -83,7 +83,7 @@ public static void main(String[] args) { @Override public void simpleInitApp() { //the mesh. - final Cylinder cylinder = new Cylinder(100,10,1,5f, true); + final Cylinder cylinder = new Cylinder(100, 10, 1, 5f, true); final Geometry bamboo = new Geometry("Bamboo Plant", cylinder); final Material material = new Material(assetManager, "Common/MatDefs/Misc/fakeLighting.j3md"); material.setColor("Color", new ColorRGBA(0f, 0.15f, 0f, 1f)); @@ -95,7 +95,7 @@ public void simpleInitApp() { final ChaseCamera chaseCamera = new ChaseCamera(cam, bamboo, inputManager); chaseCamera.setDefaultDistance(-10f); chaseCamera.setDefaultHorizontalRotation(-FastMath.HALF_PI); - chaseCamera.setDefaultVerticalRotation(FastMath.PI/3f); + chaseCamera.setDefaultVerticalRotation(FastMath.PI / 3f); chaseCamera.setEnabled(true); chaseCamera.setSmoothMotion(true); @@ -112,7 +112,7 @@ public void simpleInitApp() { private void startBlendAction() { //first action -- vertical traction. - final Quaternion[] verticalTraction = new Quaternion[] { + final Quaternion[] verticalTraction = new Quaternion[]{ new Quaternion().fromAngleAxis(0, Vector3f.UNIT_Z), bambooNode.getLocalRotation().fromAngleAxis(0.6667f * FastMath.PI, Vector3f.UNIT_Z), bambooNode.getLocalRotation().fromAngleAxis(0.6667f * FastMath.PI, Vector3f.UNIT_Z), @@ -120,12 +120,12 @@ private void startBlendAction() { }; final TransformTrack bambooVerticalTraction = new TransformTrack(bambooNode, times, null, verticalTraction, null); final AnimClip verticalTractionClip = new AnimClip("Bamboo Rotation"); - verticalTractionClip.setTracks(new AnimTrack[]{ bambooVerticalTraction }); + verticalTractionClip.setTracks(new AnimTrack[]{bambooVerticalTraction}); final ClipAction verticalTractionAction = new ClipAction(verticalTractionClip); verticalTractionAction.setSpeed(8f); //second action -- horizontal traction. - final Quaternion[] traction = new Quaternion[] { + final Quaternion[] traction = new Quaternion[]{ new Quaternion().fromAngleAxis(0, Vector3f.UNIT_X), bambooNode.getLocalRotation().fromAngleAxis(0.1667f * FastMath.PI, Vector3f.UNIT_X), bambooNode.getLocalRotation().fromAngleAxis(0.1667f * FastMath.PI, Vector3f.UNIT_X), @@ -133,12 +133,12 @@ private void startBlendAction() { }; final TransformTrack bambooHorizontalTraction = new TransformTrack(bambooNode, times, null, traction, null); final AnimClip tractionClip = new AnimClip("Bamboo Traction"); - tractionClip.setTracks(new AnimTrack[]{ bambooHorizontalTraction }); + tractionClip.setTracks(new AnimTrack[]{bambooHorizontalTraction}); final ClipAction horizontalTractionAction = new ClipAction(tractionClip); horizontalTractionAction.setSpeed(5f); //third action -- scales action. - final Vector3f[] scales = new Vector3f[] { + final Vector3f[] scales = new Vector3f[]{ originalScale, bambooNode.getLocalScale().add(0.5f, 0.5f, 0.5f), bambooNode.getLocalScale().add(0.5f, 0.5f, 0.5f), @@ -146,20 +146,20 @@ private void startBlendAction() { }; final TransformTrack bambooScales = new TransformTrack(bambooNode, times, null, null, scales); final AnimClip bambooScalesClip = new AnimClip("Bamboo Scales"); - bambooScalesClip.setTracks(new AnimTrack[]{ bambooScales }); + bambooScalesClip.setTracks(new AnimTrack[]{bambooScales}); final ClipAction scalesAction = new ClipAction(bambooScalesClip); scalesAction.setSpeed(2f); //forth action -- translation action. - final Vector3f[] translations = new Vector3f[] { + final Vector3f[] translations = new Vector3f[]{ originalTranslation, - bambooNode.getLocalTranslation().add(0,0, -0.1f), - bambooNode.getLocalTranslation().add(0,0, -0.2f), + bambooNode.getLocalTranslation().add(0, 0, -0.1f), + bambooNode.getLocalTranslation().add(0, 0, -0.2f), bambooNode.getLocalTranslation().add(0, 0, -0.5f), }; final TransformTrack bambooTranslations = new TransformTrack(bambooNode, times, null, null, translations); final AnimClip bambooTranslationsClip = new AnimClip("Bamboo Translations"); - bambooTranslationsClip.setTracks(new AnimTrack[] {bambooTranslations}); + bambooTranslationsClip.setTracks(new AnimTrack[]{bambooTranslations}); final ClipAction translationsAction = new ClipAction(bambooTranslationsClip); translationsAction.setSpeed(2f); @@ -177,7 +177,7 @@ private void startBlendAction() { public void simpleUpdate(float tpf) { progressToSwitch += tpf; //manipulate actions manually when the time passes the last frame times - if(pieChartSpace.getFirstActionIndex() == 0 && pieChartSpace.getSecondActionIndex() == 1) { + if (pieChartSpace.getFirstActionIndex() == 0 && pieChartSpace.getSecondActionIndex() == 1) { // 5 seconds represents more than the times[] of the transform tracks if (progressToSwitch >= times[times.length - 1] + 1f) { //re-switch them