aboutsummaryrefslogtreecommitdiff
path: root/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainPatch.java
diff options
context:
space:
mode:
authorScott Barta <sbarta@google.com>2012-03-09 13:52:20 -0800
committerScott Barta <sbarta@google.com>2012-03-09 14:13:24 -0800
commita6b44658eb1c55295f132a36233a11aa2bd8f9cf (patch)
tree4006b29d319de8635ca7cc2384782618f6c80ee7 /engine/src/terrain/com/jme3/terrain/geomipmap/TerrainPatch.java
parent59b2e6871c65f58fdad78cd7229c292f6a177578 (diff)
downloadjmonkeyengine-jb-mr1-dev-plus-aosp.tar.gz
New drop of the jmonkeyengine libraryHEADandroid-wear-n-preview-3android-wear-n-preview-2android-wear-n-preview-1android-sdk-support_r11android-sdk-4.4.2_r1.0.1android-sdk-4.4.2_r1android-n-preview-5android-n-preview-4android-n-preview-3android-n-preview-2android-n-preview-1android-n-mr2-preview-2android-n-mr2-preview-1android-n-mr1-preview-2android-n-mr1-preview-1android-n-iot-release-smart-display-r2android-n-iot-release-smart-displayandroid-n-iot-release-polk-at1android-n-iot-release-lg-thinq-wk7android-n-iot-release-ihome-igv1android-n-iot-preview-4android-l-preview_r2android-cts-6.0_r9android-cts-6.0_r8android-cts-6.0_r7android-cts-6.0_r6android-cts-6.0_r5android-cts-6.0_r4android-cts-6.0_r32android-cts-6.0_r31android-cts-6.0_r30android-cts-6.0_r3android-cts-6.0_r29android-cts-6.0_r28android-cts-6.0_r27android-cts-6.0_r26android-cts-6.0_r25android-cts-6.0_r24android-cts-6.0_r23android-cts-6.0_r22android-cts-6.0_r21android-cts-6.0_r20android-cts-6.0_r2android-cts-6.0_r19android-cts-6.0_r18android-cts-6.0_r17android-cts-6.0_r16android-cts-6.0_r15android-cts-6.0_r14android-cts-6.0_r13android-cts-6.0_r12android-cts-6.0_r1android-cts-4.4_r4android-cts-4.4_r1android-cts-4.2_r2android-cts-4.2_r1android-cts-4.1_r4android-cts-4.1_r2android-cts-4.1_r1android-7.1.2_r9android-7.1.2_r8android-7.1.2_r6android-7.1.2_r5android-7.1.2_r4android-7.1.2_r39android-7.1.2_r38android-7.1.2_r37android-7.1.2_r36android-7.1.2_r33android-7.1.2_r32android-7.1.2_r30android-7.1.2_r3android-7.1.2_r29android-7.1.2_r28android-7.1.2_r27android-7.1.2_r25android-7.1.2_r24android-7.1.2_r23android-7.1.2_r2android-7.1.2_r19android-7.1.2_r18android-7.1.2_r17android-7.1.2_r16android-7.1.2_r15android-7.1.2_r14android-7.1.2_r13android-7.1.2_r12android-7.1.2_r11android-7.1.2_r10android-7.1.2_r1android-6.0.1_r9android-6.0.1_r81android-6.0.1_r80android-6.0.1_r8android-6.0.1_r79android-6.0.1_r78android-6.0.1_r77android-6.0.1_r74android-6.0.1_r73android-6.0.1_r72android-6.0.1_r70android-6.0.1_r7android-6.0.1_r69android-6.0.1_r68android-6.0.1_r67android-6.0.1_r66android-6.0.1_r65android-6.0.1_r63android-6.0.1_r62android-6.0.1_r61android-6.0.1_r60android-6.0.1_r59android-6.0.1_r58android-6.0.1_r57android-6.0.1_r56android-6.0.1_r55android-6.0.1_r54android-6.0.1_r53android-6.0.1_r52android-6.0.1_r51android-6.0.1_r50android-6.0.1_r5android-6.0.1_r49android-6.0.1_r48android-6.0.1_r47android-6.0.1_r46android-6.0.1_r45android-6.0.1_r43android-6.0.1_r42android-6.0.1_r41android-6.0.1_r40android-6.0.1_r4android-6.0.1_r33android-6.0.1_r32android-6.0.1_r31android-6.0.1_r30android-6.0.1_r3android-6.0.1_r28android-6.0.1_r27android-6.0.1_r26android-6.0.1_r25android-6.0.1_r24android-6.0.1_r22android-6.0.1_r21android-6.0.1_r20android-6.0.1_r18android-6.0.1_r17android-6.0.1_r16android-6.0.1_r13android-6.0.1_r12android-6.0.1_r11android-6.0.1_r10android-6.0.1_r1android-6.0.0_r7android-6.0.0_r6android-6.0.0_r5android-6.0.0_r41android-6.0.0_r4android-6.0.0_r3android-6.0.0_r26android-6.0.0_r25android-6.0.0_r24android-6.0.0_r23android-6.0.0_r2android-6.0.0_r13android-6.0.0_r12android-6.0.0_r11android-6.0.0_r1android-4.4w_r1android-4.4_r1.2.0.1android-4.4_r1.2android-4.4_r1.1.0.1android-4.4_r1.1android-4.4_r1.0.1android-4.4_r1android-4.4_r0.9android-4.4_r0.8android-4.4_r0.7android-4.4.4_r2.0.1android-4.4.4_r2android-4.4.4_r1.0.1android-4.4.4_r1android-4.4.3_r1.1.0.1android-4.4.3_r1.1android-4.4.3_r1.0.1android-4.4.3_r1android-4.4.2_r2.0.1android-4.4.2_r2android-4.4.2_r1.0.1android-4.4.2_r1android-4.4.1_r1.0.1android-4.4.1_r1android-4.3_r3.1android-4.3_r3android-4.3_r2.3android-4.3_r2.2android-4.3_r2.1android-4.3_r2android-4.3_r1.1android-4.3_r1android-4.3_r0.9.1android-4.3_r0.9android-4.3.1_r1android-4.2_r1android-4.2.2_r1.2android-4.2.2_r1.1android-4.2.2_r1android-4.2.1_r1.2android-4.2.1_r1.1android-4.2.1_r1android-4.1.2_r2.1android-4.1.2_r2android-4.1.2_r1android-4.1.1_r6.1android-4.1.1_r6android-4.1.1_r5android-4.1.1_r4android-4.1.1_r3android-4.1.1_r2android-4.1.1_r1.1android-4.1.1_r1tools_r22.2tools_r22tools_r21nougat-mr2.3-releasenougat-mr2.2-releasenougat-mr2.1-releasenougat-mr2-security-releasenougat-mr2-releasenougat-mr2-pixel-releasenougat-mr2-devnougat-iot-releasen-iot-preview-4mastermarshmallow-releasemarshmallow-mr3-releasemarshmallow-mr2-releasemarshmallow-mr1-releasemarshmallow-mr1-devmarshmallow-dr1.6-releasemarshmallow-dr1.5-releasemarshmallow-dr1.5-devmarshmallow-dr-releasemarshmallow-dr-dragon-releasemarshmallow-dr-devmarshmallow-devmarshmallow-cts-releasemainl-previewkitkat-wearkitkat-releasekitkat-mr2.2-releasekitkat-mr2.1-releasekitkat-mr2-releasekitkat-mr1.1-releasekitkat-mr1-releasekitkat-devkitkat-cts-releasekitkat-cts-devjb-releasejb-mr2.0.0-releasejb-mr2.0-releasejb-mr2-releasejb-mr2-devjb-mr1.1-releasejb-mr1.1-dev-plus-aospjb-mr1.1-devjb-mr1-releasejb-mr1-dev-plus-aospjb-mr1-devjb-mr0-releasejb-devidea133-weekly-releaseidea133
A new drop of the jmonkeyengine library sources, based on a 2012-03-05 snapshot. Fixes a few unnecessary memory allocations in the main rendering loop. Change-Id: I51ac0942fe87204df102cfdce746b59a5cb5ff85
Diffstat (limited to 'engine/src/terrain/com/jme3/terrain/geomipmap/TerrainPatch.java')
-rw-r--r--engine/src/terrain/com/jme3/terrain/geomipmap/TerrainPatch.java248
1 files changed, 106 insertions, 142 deletions
diff --git a/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainPatch.java b/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainPatch.java
index 40cf190..83537af 100644
--- a/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainPatch.java
+++ b/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainPatch.java
@@ -314,13 +314,25 @@ public class TerrainPatch extends Geometry {
getMesh().getBuffer(Type.Normal).updateData(newNormalBuffer);
FloatBuffer newTangentBuffer = null;
FloatBuffer newBinormalBuffer = null;
- FloatBuffer[] tb = geomap.writeTangentArray(newTangentBuffer, newBinormalBuffer, (FloatBuffer)getMesh().getBuffer(Type.TexCoord).getData(), getWorldScale());
+ FloatBuffer[] tb = geomap.writeTangentArray(newNormalBuffer, newTangentBuffer, newBinormalBuffer, (FloatBuffer)getMesh().getBuffer(Type.TexCoord).getData(), getWorldScale());
newTangentBuffer = tb[0];
newBinormalBuffer = tb[1];
getMesh().getBuffer(Type.Tangent).updateData(newTangentBuffer);
getMesh().getBuffer(Type.Binormal).updateData(newBinormalBuffer);
}
+ private void setInBuffer(Mesh mesh, int index, Vector3f normal, Vector3f tangent, Vector3f binormal) {
+ VertexBuffer NB = mesh.getBuffer(Type.Normal);
+ VertexBuffer TB = mesh.getBuffer(Type.Tangent);
+ VertexBuffer BB = mesh.getBuffer(Type.Binormal);
+ BufferUtils.setInBuffer(normal, (FloatBuffer)NB.getData(), index);
+ BufferUtils.setInBuffer(tangent, (FloatBuffer)TB.getData(), index);
+ BufferUtils.setInBuffer(binormal, (FloatBuffer)BB.getData(), index);
+ NB.setUpdateNeeded();
+ TB.setUpdateNeeded();
+ BB.setUpdateNeeded();
+ }
+
/**
* Matches the normals along the edge of the patch with the neighbours.
* Computes the normals for the right, bottom, left, and top edges of the
@@ -357,158 +369,122 @@ public class TerrainPatch extends Geometry {
Vector3f binormal = new Vector3f();
Vector3f normal = new Vector3f();
+
int s = this.getSize()-1;
if (right != null) { // right side, works its way down
for (int i=0; i<s+1; i++) {
- rootPoint.set(s, this.getHeightmapHeight(s,i), i);
- leftPoint.set(s-1, this.getHeightmapHeight(s-1,i), i);
- rightPoint.set(s+1, right.getHeightmapHeight(1,i), i);
+ rootPoint.set(0, this.getHeightmapHeight(s,i), 0);
+ leftPoint.set(-1, this.getHeightmapHeight(s-1,i), 0);
+ rightPoint.set(1, right.getHeightmapHeight(1,i), 0);
if (i == 0) { // top point
+ bottomPoint.set(0, this.getHeightmapHeight(s,i+1), 1);
+
if (top == null) {
- bottomPoint.set(s, this.getHeightmapHeight(s,i+1), i+1);
-
- averageNormalsTangents(null, rootPoint, leftPoint, bottomPoint, rightPoint, null, null, null, null, null, normal, tangent, binormal);
- VertexBuffer tpNB = this.getMesh().getBuffer(Type.Normal);
- VertexBuffer rightNB = right.getMesh().getBuffer(Type.Normal);
- BufferUtils.setInBuffer(normal, (FloatBuffer)tpNB.getData(), s);
- BufferUtils.setInBuffer(normal, (FloatBuffer)rightNB.getData(), 0);
+ averageNormalsTangents(null, rootPoint, leftPoint, bottomPoint, rightPoint, normal, tangent, binormal);
+ setInBuffer(this.getMesh(), s, normal, tangent, binormal);
+ setInBuffer(right.getMesh(), 0, normal, tangent, binormal);
} else {
- topPoint.set(s, top.getHeightmapHeight(s,s-1), i-1);
- bottomPoint.set(s, this.getHeightmapHeight(s,i+1), i+1);
+ topPoint.set(0, top.getHeightmapHeight(s,s-1), -1);
- averageNormalsTangents(topPoint, rootPoint, leftPoint, bottomPoint, rightPoint, null, null, null, null, null, normal, tangent, binormal);
- VertexBuffer tpNB = this.getMesh().getBuffer(Type.Normal);
- VertexBuffer rightNB = right.getMesh().getBuffer(Type.Normal);
- BufferUtils.setInBuffer(normal, (FloatBuffer)tpNB.getData(), s);
- BufferUtils.setInBuffer(normal, (FloatBuffer)rightNB.getData(), 0);
+ averageNormalsTangents(topPoint, rootPoint, leftPoint, bottomPoint, rightPoint,normal, tangent, binormal);
+ setInBuffer(this.getMesh(), s, normal, tangent, binormal);
+ setInBuffer(right.getMesh(), 0, normal, tangent, binormal);
+ setInBuffer(top.getMesh(), (s+1)*(s+1)-1, normal, tangent, binormal);
if (topRight != null) {
- VertexBuffer topRightNB = topRight.getMesh().getBuffer(Type.Normal);
- BufferUtils.setInBuffer(normal, (FloatBuffer)topRightNB.getData(), (s+1)*s);
- topRightNB.setUpdateNeeded();
+ // setInBuffer(topRight.getMesh(), (s+1)*s, normal, tangent, binormal);
}
}
} else if (i == s) { // bottom point
+ topPoint.set(0, this.getHeightmapHeight(s,s-1), -1);
+
if (bottom == null) {
- topPoint.set(s, this.getHeightmapHeight(s,i-1), i-1);
-
- averageNormalsTangents(topPoint, rootPoint, leftPoint, null, rightPoint, null, null, null, null, null, normal, tangent, binormal);
- VertexBuffer tpNB = this.getMesh().getBuffer(Type.Normal);
- VertexBuffer rightNB = right.getMesh().getBuffer(Type.Normal);
- BufferUtils.setInBuffer(normal, (FloatBuffer)tpNB.getData(), (s+1)*(i+1)-1);
- BufferUtils.setInBuffer(normal, (FloatBuffer)rightNB.getData(), (s+1)*(s));
+ averageNormalsTangents(topPoint, rootPoint, leftPoint, null, rightPoint, normal, tangent, binormal);
+ setInBuffer(this.getMesh(), (s+1)*(s+1)-1, normal, tangent, binormal);
+ setInBuffer(right.getMesh(), (s+1)*(s), normal, tangent, binormal);
} else {
- topPoint.set(s, this.getHeightmapHeight(s,i-1), i-1);
- bottomPoint.set(s, bottom.getHeightmapHeight(s,1), i+1);
- averageNormalsTangents(topPoint, rootPoint, leftPoint, bottomPoint, rightPoint, null, null, null, null, null, normal, tangent, binormal);
- VertexBuffer tpNB = this.getMesh().getBuffer(Type.Normal);
- VertexBuffer rightNB = right.getMesh().getBuffer(Type.Normal);
- VertexBuffer downNB = bottom.getMesh().getBuffer(Type.Normal);
-
- BufferUtils.setInBuffer(normal, (FloatBuffer)tpNB.getData(), (s+1)*(s+1)-1);
- BufferUtils.setInBuffer(normal, (FloatBuffer)rightNB.getData(), (s+1)*s);
- BufferUtils.setInBuffer(normal, (FloatBuffer)downNB.getData(), s);
+ bottomPoint.set(0, bottom.getHeightmapHeight(s,1), 1);
+ averageNormalsTangents(topPoint, rootPoint, leftPoint, bottomPoint, rightPoint, normal, tangent, binormal);
+ setInBuffer(this.getMesh(), (s+1)*(s+1)-1, normal, tangent, binormal);
+ setInBuffer(right.getMesh(), (s+1)*s, normal, tangent, binormal);
+ setInBuffer(bottom.getMesh(), s, normal, tangent, binormal);
if (bottomRight != null) {
- VertexBuffer bottomRightNB = bottomRight.getMesh().getBuffer(Type.Normal);
- BufferUtils.setInBuffer(normal, (FloatBuffer)bottomRightNB.getData(), 0);
- bottomRightNB.setUpdateNeeded();
+ // setInBuffer(bottomRight.getMesh(), 0, normal, tangent, binormal);
}
- downNB.setUpdateNeeded();
}
} else { // all in the middle
- topPoint.set(s, this.getHeightmapHeight(s,i-1), i-1);
- bottomPoint.set(s, this.getHeightmapHeight(s,i+1), i+1);
- averageNormalsTangents(topPoint, rootPoint, leftPoint, bottomPoint, rightPoint, null, null, null, null, null, normal, tangent, binormal);
- VertexBuffer tpNB = this.getMesh().getBuffer(Type.Normal);
- VertexBuffer rightNB = right.getMesh().getBuffer(Type.Normal);
- BufferUtils.setInBuffer(normal, (FloatBuffer)tpNB.getData(), (s+1)*(i+1)-1);
- BufferUtils.setInBuffer(normal, (FloatBuffer)rightNB.getData(), (s+1)*(i));
+ topPoint.set(0, this.getHeightmapHeight(s,i-1), -1);
+ bottomPoint.set(0, this.getHeightmapHeight(s,i+1), 1);
+ averageNormalsTangents(topPoint, rootPoint, leftPoint, bottomPoint, rightPoint, normal, tangent, binormal);
+ setInBuffer(this.getMesh(), (s+1)*(i+1)-1, normal, tangent, binormal);
+ setInBuffer(right.getMesh(), (s+1)*(i), normal, tangent, binormal);
}
}
- right.getMesh().getBuffer(Type.Normal).setUpdateNeeded();
}
if (left != null) { // left side, works its way down
for (int i=0; i<s+1; i++) {
- rootPoint.set(0, this.getHeightmapHeight(0,i), i);
- leftPoint.set(-1, left.getHeightmapHeight(s-1,i), i);
- rightPoint.set(1, this.getHeightmapHeight(1,i), i);
+ rootPoint.set(0, this.getHeightmapHeight(0,i), 0);
+ leftPoint.set(-1, left.getHeightmapHeight(s-1,i), 0);
+ rightPoint.set(1, this.getHeightmapHeight(1,i), 0);
if (i == 0) { // top point
+ bottomPoint.set(0, this.getHeightmapHeight(0,i+1), 1);
+
if (top == null) {
- bottomPoint.set(0, this.getHeightmapHeight(0,i+1), i+1);
- averageNormalsTangents(null, rootPoint, leftPoint, bottomPoint, rightPoint, null, null, null, null, null, normal, tangent, binormal);
- VertexBuffer tpNB = this.getMesh().getBuffer(Type.Normal);
- VertexBuffer leftNB = left.getMesh().getBuffer(Type.Normal);
- BufferUtils.setInBuffer(normal, (FloatBuffer)tpNB.getData(), 0);
- BufferUtils.setInBuffer(normal, (FloatBuffer)leftNB.getData(), s);
+ averageNormalsTangents(null, rootPoint, leftPoint, bottomPoint, rightPoint, normal, tangent, binormal);
+ setInBuffer(this.getMesh(), 0, normal, tangent, binormal);
+ setInBuffer(left.getMesh(), s, normal, tangent, binormal);
} else {
- topPoint.set(0, top.getHeightmapHeight(0,s-1), i-1);
- bottomPoint.set(0, this.getHeightmapHeight(0,i+1), i+1);
+ topPoint.set(0, top.getHeightmapHeight(0,s-1), -1);
- averageNormalsTangents(topPoint, rootPoint, leftPoint, bottomPoint, rightPoint, null, null, null, null, null, normal, tangent, binormal);
- VertexBuffer tpNB = this.getMesh().getBuffer(Type.Normal);
- VertexBuffer leftNB = left.getMesh().getBuffer(Type.Normal);
- BufferUtils.setInBuffer(normal, (FloatBuffer)tpNB.getData(), 0);
- BufferUtils.setInBuffer(normal, (FloatBuffer)leftNB.getData(), s);
+ averageNormalsTangents(topPoint, rootPoint, leftPoint, bottomPoint, rightPoint, normal, tangent, binormal);
+ setInBuffer(this.getMesh(), 0, normal, tangent, binormal);
+ setInBuffer(left.getMesh(), s, normal, tangent, binormal);
+ setInBuffer(top.getMesh(), (s+1)*s, normal, tangent, binormal);
if (topLeft != null) {
- VertexBuffer topLeftNB = topLeft.getMesh().getBuffer(Type.Normal);
- BufferUtils.setInBuffer(normal, (FloatBuffer)topLeftNB.getData(), (s+1)*(s+1)-1);
- topLeftNB.setUpdateNeeded();
+ // setInBuffer(topLeft.getMesh(), (s+1)*(s+1)-1, normal, tangent, binormal);
}
}
} else if (i == s) { // bottom point
+ topPoint.set(0, this.getHeightmapHeight(0,i-1), -1);
+
if (bottom == null) {
- topPoint.set(0, this.getHeightmapHeight(0,i-1), i-1);
-
- averageNormalsTangents(topPoint, rootPoint, leftPoint, null, rightPoint, null, null, null, null, null, normal, tangent, binormal);
- VertexBuffer tpNB = this.getMesh().getBuffer(Type.Normal);
- VertexBuffer leftNB = left.getMesh().getBuffer(Type.Normal);
- BufferUtils.setInBuffer(normal, (FloatBuffer)tpNB.getData(), (s+1)*(s));
- BufferUtils.setInBuffer(normal, (FloatBuffer)leftNB.getData(), (s+1)*(i+1)-1);
+ averageNormalsTangents(topPoint, rootPoint, leftPoint, null, rightPoint, normal, tangent, binormal);
+ setInBuffer(this.getMesh(), (s+1)*(s), normal, tangent, binormal);
+ setInBuffer(left.getMesh(), (s+1)*(s+1)-1, normal, tangent, binormal);
} else {
- topPoint.set(0, this.getHeightmapHeight(0,i-1), i-1);
- bottomPoint.set(0, bottom.getHeightmapHeight(0,1), i+1);
+ bottomPoint.set(0, bottom.getHeightmapHeight(0,1), 1);
- averageNormalsTangents(topPoint, rootPoint, leftPoint, bottomPoint, rightPoint, null, null, null, null, null, normal, tangent, binormal);
- VertexBuffer tpNB = this.getMesh().getBuffer(Type.Normal);
- VertexBuffer leftNB = left.getMesh().getBuffer(Type.Normal);
- VertexBuffer downNB = bottom.getMesh().getBuffer(Type.Normal);
-
- BufferUtils.setInBuffer(normal, (FloatBuffer)tpNB.getData(), (s+1)*(s));
- BufferUtils.setInBuffer(normal, (FloatBuffer)leftNB.getData(), (s+1)*(i+1)-1);
- BufferUtils.setInBuffer(normal, (FloatBuffer)downNB.getData(), 0);
+ averageNormalsTangents(topPoint, rootPoint, leftPoint, bottomPoint, rightPoint, normal, tangent, binormal);
+ setInBuffer(this.getMesh(), (s+1)*(s), normal, tangent, binormal);
+ setInBuffer(left.getMesh(), (s+1)*(s+1)-1, normal, tangent, binormal);
+ setInBuffer(bottom.getMesh(), 0, normal, tangent, binormal);
if (bottomLeft != null) {
- VertexBuffer bottomLeftNB = bottomLeft.getMesh().getBuffer(Type.Normal);
- BufferUtils.setInBuffer(normal, (FloatBuffer)bottomLeftNB.getData(), s);
- bottomLeftNB.setUpdateNeeded();
+ // setInBuffer(bottomLeft.getMesh(), s, normal, tangent, binormal);
}
- downNB.setUpdateNeeded();
}
} else { // all in the middle
- topPoint.set(0, this.getHeightmapHeight(0,i-1), i-1);
- bottomPoint.set(0, this.getHeightmapHeight(0,i+1), i+1);
+ topPoint.set(0, this.getHeightmapHeight(0,i-1), -1);
+ bottomPoint.set(0, this.getHeightmapHeight(0,i+1), 1);
- averageNormalsTangents(topPoint, rootPoint, leftPoint, bottomPoint, rightPoint, null, null, null, null, null, normal, tangent, binormal);
- VertexBuffer tpNB = this.getMesh().getBuffer(Type.Normal);
- VertexBuffer leftNB = left.getMesh().getBuffer(Type.Normal);
- BufferUtils.setInBuffer(normal, (FloatBuffer)tpNB.getData(), (s+1)*(i));
- BufferUtils.setInBuffer(normal, (FloatBuffer)leftNB.getData(), (s+1)*(i+1)-1);
+ averageNormalsTangents(topPoint, rootPoint, leftPoint, bottomPoint, rightPoint, normal, tangent, binormal);
+ setInBuffer(this.getMesh(), (s+1)*(i), normal, tangent, binormal);
+ setInBuffer(left.getMesh(), (s+1)*(i+1)-1, normal, tangent, binormal);
}
}
- left.getMesh().getBuffer(Type.Normal).setUpdateNeeded();
}
-
+
if (top != null) { // top side, works its way right
for (int i=0; i<s+1; i++) {
- rootPoint.set(i, this.getHeightmapHeight(i,0), 0);
- topPoint.set(i, top.getHeightmapHeight(i,s-1), -1);
- bottomPoint.set(i, this.getHeightmapHeight(i,1), 1);
+ rootPoint.set(0, this.getHeightmapHeight(i,0), 0);
+ topPoint.set(0, top.getHeightmapHeight(i,s-1), -1);
+ bottomPoint.set(0, this.getHeightmapHeight(i,1), 1);
if (i == 0) { // left corner
// handled by left side pass
@@ -518,49 +494,39 @@ public class TerrainPatch extends Geometry {
// handled by this patch when it does its right side
} else { // all in the middle
- leftPoint.set(i-1, this.getHeightmapHeight(i-1,0), 0);
- rightPoint.set(i+1, this.getHeightmapHeight(i+1,0), 0);
- averageNormalsTangents(topPoint, rootPoint, leftPoint, bottomPoint, rightPoint, null, null, null, null, null, normal, tangent, binormal);
- VertexBuffer tpNB = this.getMesh().getBuffer(Type.Normal);
- BufferUtils.setInBuffer(normal, (FloatBuffer)tpNB.getData(), i);
- VertexBuffer topNB = top.getMesh().getBuffer(Type.Normal);
- BufferUtils.setInBuffer(normal, (FloatBuffer)topNB.getData(), (s+1)*(s)+i);
+ leftPoint.set(-1, this.getHeightmapHeight(i-1,0), 0);
+ rightPoint.set(1, this.getHeightmapHeight(i+1,0), 0);
+ averageNormalsTangents(topPoint, rootPoint, leftPoint, bottomPoint, rightPoint, normal, tangent, binormal);
+ setInBuffer(this.getMesh(), i, normal, tangent, binormal);
+ setInBuffer(top.getMesh(), (s+1)*(s)+i, normal, tangent, binormal);
}
}
- top.getMesh().getBuffer(Type.Normal).setUpdateNeeded();
}
if (bottom != null) { // bottom side, works its way right
for (int i=0; i<s+1; i++) {
- rootPoint.set(i, this.getHeightmapHeight(i,s), s);
- topPoint.set(i, this.getHeightmapHeight(i,s-1), s-1);
- bottomPoint.set(i, bottom.getHeightmapHeight(i,1), s+1);
+ rootPoint.set(0, this.getHeightmapHeight(i,s), 0);
+ topPoint.set(0, this.getHeightmapHeight(i,s-1), -1);
+ bottomPoint.set(0, bottom.getHeightmapHeight(i,1), 1);
if (i == 0) { // left
// handled by the left side pass
} else if (i == s) { // right
- // handled by this patch when it does its right side
+ // handled by the right side pass
} else { // all in the middle
- leftPoint.set(i-1, this.getHeightmapHeight(i-1,s), s);
- rightPoint.set(i+1, this.getHeightmapHeight(i+1,s), s);
- averageNormalsTangents(topPoint, rootPoint, leftPoint, bottomPoint, rightPoint, null, null, null, null, null, normal, tangent, binormal);
- VertexBuffer tpNB = this.getMesh().getBuffer(Type.Normal);
- BufferUtils.setInBuffer(normal, (FloatBuffer)tpNB.getData(), (s+1)*(s)+i);
- VertexBuffer downNB = bottom.getMesh().getBuffer(Type.Normal);
- BufferUtils.setInBuffer(normal, (FloatBuffer)downNB.getData(), i);
+ leftPoint.set(-1, this.getHeightmapHeight(i-1,s), 0);
+ rightPoint.set(1, this.getHeightmapHeight(i+1,s), 0);
+ averageNormalsTangents(topPoint, rootPoint, leftPoint, bottomPoint, rightPoint, normal, tangent, binormal);
+ setInBuffer(this.getMesh(), (s+1)*(s)+i, normal, tangent, binormal);
+ setInBuffer(bottom.getMesh(), i, normal, tangent, binormal);
}
}
- bottom.getMesh().getBuffer(Type.Normal).setUpdateNeeded();
}
-
- this.getMesh().getBuffer(Type.Normal).setUpdateNeeded();
- this.getMesh().getBuffer(Type.Tangent).setUpdateNeeded();
- this.getMesh().getBuffer(Type.Binormal).setUpdateNeeded();
}
protected void averageNormalsTangents(
@@ -569,38 +535,36 @@ public class TerrainPatch extends Geometry {
Vector3f leftPoint,
Vector3f bottomPoint,
Vector3f rightPoint,
- Vector2f topTex,
- Vector2f rootTex,
- Vector2f leftTex,
- Vector2f bottomTex,
- Vector2f rightTex,
Vector3f normal,
Vector3f tangent,
Vector3f binormal)
{
Vector3f scale = getWorldScale();
- Vector3f n1 = Vector3f.ZERO;
+ Vector3f n1 = new Vector3f(0,0,0);
if (topPoint != null && leftPoint != null) {
- n1 = calculateNormal(topPoint.mult(scale), rootPoint.mult(scale), leftPoint.mult(scale));
+ n1.set(calculateNormal(topPoint.mult(scale), rootPoint.mult(scale), leftPoint.mult(scale)));
}
- Vector3f n2 = Vector3f.ZERO;
+ Vector3f n2 = new Vector3f(0,0,0);
if (leftPoint != null && bottomPoint != null) {
- n2 = calculateNormal(leftPoint.mult(scale), rootPoint.mult(scale), bottomPoint.mult(scale));
+ n2.set(calculateNormal(leftPoint.mult(scale), rootPoint.mult(scale), bottomPoint.mult(scale)));
}
- Vector3f n3 = Vector3f.ZERO;
+ Vector3f n3 = new Vector3f(0,0,0);
if (rightPoint != null && bottomPoint != null) {
- n3 = calculateNormal(bottomPoint.mult(scale), rootPoint.mult(scale), rightPoint.mult(scale));
+ n3.set(calculateNormal(bottomPoint.mult(scale), rootPoint.mult(scale), rightPoint.mult(scale)));
}
- Vector3f n4 = Vector3f.ZERO;
+ Vector3f n4 = new Vector3f(0,0,0);
if (rightPoint != null && topPoint != null) {
- n4 = calculateNormal(rightPoint.mult(scale), rootPoint.mult(scale), topPoint.mult(scale));
+ n4.set(calculateNormal(rightPoint.mult(scale), rootPoint.mult(scale), topPoint.mult(scale)));
}
- if (bottomPoint != null && rightPoint != null && rootTex != null && rightTex != null && bottomTex != null)
- LODGeomap.calculateTangent(new Vector3f[]{rootPoint.mult(scale),rightPoint.mult(scale),bottomPoint.mult(scale)}, new Vector2f[]{rootTex,rightTex,bottomTex}, tangent, binormal);
+ //if (bottomPoint != null && rightPoint != null && rootTex != null && rightTex != null && bottomTex != null)
+ // LODGeomap.calculateTangent(new Vector3f[]{rootPoint.mult(scale),rightPoint.mult(scale),bottomPoint.mult(scale)}, new Vector2f[]{rootTex,rightTex,bottomTex}, tangent, binormal);
- normal.set(n1.add(n2).add(n3).add(n4).normalizeLocal());
+ normal.set(n1.add(n2).add(n3).add(n4).normalize());
+
+ tangent.set(normal.cross(new Vector3f(0,0,1)).normalize());
+ binormal.set(new Vector3f(1,0,0).cross(normal).normalize());
}
private Vector3f calculateNormal(Vector3f firstPoint, Vector3f rootPoint, Vector3f secondPoint) {