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
This commit is contained in:
@@ -769,19 +769,29 @@ public class ModelMesh extends TriMesh
|
|||||||
d = radius - a*mc.x - b*mc.y - c*mc.z,
|
d = radius - a*mc.x - b*mc.y - c*mc.z,
|
||||||
dscale = 65535f / (radius * 2);
|
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
|
// encode the model's triangles into integers such that the
|
||||||
// high 16 bits represent the original triangle index and the
|
// high 16 bits represent the original triangle index and the
|
||||||
// low 16 bits represent the distance to the plane. also
|
// low 16 bits represent the distance to the plane. also
|
||||||
// increment the byte counts used for radix sorting
|
// increment the byte counts used for radix sorting
|
||||||
int tcount = getTriangleCount(), idx, idist;
|
int tcount = getTriangleCount(), idist;
|
||||||
if (_tcodes == null || _tcodes.length < tcount) {
|
if (_tcodes == null || _tcodes.length < tcount) {
|
||||||
_tcodes = new int[tcount];
|
_tcodes = new int[tcount];
|
||||||
}
|
}
|
||||||
FloatBuffer vbuf = getVertexBuffer();
|
int i1, i2, i3;
|
||||||
for (int ii = 0; ii < tcount; ii++) {
|
for (int ii = 0, idx = 0; ii < tcount; ii++) {
|
||||||
idx = _oibuf[ii*3] * 3;
|
i1 = _oibuf[idx++] * 3;
|
||||||
idist = (int)((a*_vbuf[idx++] + b*_vbuf[idx++] +
|
i2 = _oibuf[idx++] * 3;
|
||||||
c*_vbuf[idx] + d) * dscale);
|
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;
|
_tcodes[ii] = (ii << 16) | idist;
|
||||||
_bcounts[idist & 0xFF]++;
|
_bcounts[idist & 0xFF]++;
|
||||||
}
|
}
|
||||||
@@ -791,7 +801,7 @@ public class ModelMesh extends TriMesh
|
|||||||
|
|
||||||
// reorder the triangles as dictated by the sorted codes, furthest
|
// reorder the triangles as dictated by the sorted codes, furthest
|
||||||
// triangles first
|
// triangles first
|
||||||
int icount = tcount * 3;
|
int icount = tcount * 3, idx;
|
||||||
if (_sibuf == null || _sibuf.length < icount) {
|
if (_sibuf == null || _sibuf.length < icount) {
|
||||||
_sibuf = new int[icount];
|
_sibuf = new int[icount];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -366,6 +366,7 @@ public class ModelViewer extends JmeCanvasApp
|
|||||||
{
|
{
|
||||||
super.initDisplay();
|
super.initDisplay();
|
||||||
_ctx.getRenderer().setBackgroundColor(ColorRGBA.gray);
|
_ctx.getRenderer().setBackgroundColor(ColorRGBA.gray);
|
||||||
|
_ctx.getRenderer().getQueue().setTwoPassTransparency(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // documentation inherited
|
@Override // documentation inherited
|
||||||
|
|||||||
Reference in New Issue
Block a user