From 1b04d13f3efb525d92a1f80f60703d4ae88e10cd Mon Sep 17 00:00:00 2001 From: "Kae..pl" Date: Mon, 29 Oct 2012 14:22:29 +0000 Subject: [PATCH] Bugfix: making sure that the first and last bevel line is parallel to its neighbour in curves that have bevel applied (that is how blender works) git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9912 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../plugins/blender/curves/CurvesHelper.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/curves/CurvesHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/curves/CurvesHelper.java index 6d3f5901f..332f83acb 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/curves/CurvesHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/curves/CurvesHelper.java @@ -482,6 +482,26 @@ public class CurvesHelper extends AbstractBlenderHelper { bevelPoints = this.transformBevel(bevelPoints, curvePoints[curvePoints.length - 2], curvePoints[curvePoints.length - 1], null); bevels.add(bevelPoints); + if(bevels.size() > 2) { + //changing the first and last bevel so that they are parallel to their neighbours (blender works this way) + //notice this implicates that the distances of every corresponding point in th two bevels must be identical and + //equal to the distance between the points on curve that define the bevel position + //so instead doing complicated rotations on each point we will simply properly translate each of them + + Vector3f subtractResult = new Vector3f(); + int[][] pointIndexes = new int[][] { { 0, 1 }, { curvePoints.length - 1, curvePoints.length - 2 } }; + for(int[] indexes : pointIndexes) { + float distance = curvePoints[indexes[1]].subtract(curvePoints[indexes[0]], subtractResult).length(); + Vector3f[] bevel = bevels.get(indexes[0]); + Vector3f[] nextBevel = bevels.get(indexes[1]); + for (int i = 0; i < bevel.length; ++i) { + float d = bevel[i].subtract(nextBevel[i], subtractResult).length(); + subtractResult.normalizeLocal().multLocal(distance - d); + bevel[i].addLocal(subtractResult); + } + } + } + //apply scales to the bevels float lengthAlongCurve = 0; for(int i=0;i