From 22b867bb61dd76764a577570d2ce48f49d0cc19b Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 24 Aug 2006 23:27:42 +0000 Subject: [PATCH] Use the average of the three triangle vertices (rather than the first vertex) to compute the depth used for sorting. There are still annoying artifacts, but I've already spent too much time exploring all the ways to sort these things. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@31 ed5b42cb-e716-0410-a449-f6a68f950b19 --- .../com/threerings/jme/model/ModelMesh.java | 24 +++++++++++++------ .../com/threerings/jme/tools/ModelViewer.java | 1 + 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/java/com/threerings/jme/model/ModelMesh.java b/src/java/com/threerings/jme/model/ModelMesh.java index 800f7494..c91d1c22 100644 --- a/src/java/com/threerings/jme/model/ModelMesh.java +++ b/src/java/com/threerings/jme/model/ModelMesh.java @@ -769,19 +769,29 @@ public class ModelMesh extends TriMesh d = radius - a*mc.x - b*mc.y - c*mc.z, dscale = 65535f / (radius * 2); + // premultiply the scale and averaging factor + a *= dscale / 3f; + b *= dscale / 3f; + c *= dscale / 3f; + d *= dscale; + // encode the model's triangles into integers such that the // high 16 bits represent the original triangle index and the // low 16 bits represent the distance to the plane. also // increment the byte counts used for radix sorting - int tcount = getTriangleCount(), idx, idist; + int tcount = getTriangleCount(), idist; if (_tcodes == null || _tcodes.length < tcount) { _tcodes = new int[tcount]; } - FloatBuffer vbuf = getVertexBuffer(); - for (int ii = 0; ii < tcount; ii++) { - idx = _oibuf[ii*3] * 3; - idist = (int)((a*_vbuf[idx++] + b*_vbuf[idx++] + - c*_vbuf[idx] + d) * dscale); + int i1, i2, i3; + for (int ii = 0, idx = 0; ii < tcount; ii++) { + i1 = _oibuf[idx++] * 3; + i2 = _oibuf[idx++] * 3; + i3 = _oibuf[idx++] * 3; + idist = (int)( + a * (_vbuf[i1++] + _vbuf[i2++] + _vbuf[i3++]) + + b * (_vbuf[i1++] + _vbuf[i2++] + _vbuf[i3++]) + + c * (_vbuf[i1++] + _vbuf[i2++] + _vbuf[i3++]) + d); _tcodes[ii] = (ii << 16) | idist; _bcounts[idist & 0xFF]++; } @@ -791,7 +801,7 @@ public class ModelMesh extends TriMesh // reorder the triangles as dictated by the sorted codes, furthest // triangles first - int icount = tcount * 3; + int icount = tcount * 3, idx; if (_sibuf == null || _sibuf.length < icount) { _sibuf = new int[icount]; } diff --git a/src/java/com/threerings/jme/tools/ModelViewer.java b/src/java/com/threerings/jme/tools/ModelViewer.java index 8408ef9d..7b3228c3 100644 --- a/src/java/com/threerings/jme/tools/ModelViewer.java +++ b/src/java/com/threerings/jme/tools/ModelViewer.java @@ -366,6 +366,7 @@ public class ModelViewer extends JmeCanvasApp { super.initDisplay(); _ctx.getRenderer().setBackgroundColor(ColorRGBA.gray); + _ctx.getRenderer().getQueue().setTwoPassTransparency(false); } @Override // documentation inherited