Fix critical issue with meshing

This commit is contained in:
mcrcortex
2025-03-22 15:59:37 +10:00
parent 7a2fe748ea
commit cca9ac0e56
2 changed files with 33 additions and 12 deletions

View File

@@ -332,7 +332,7 @@ public class RenderDataFactory45 {
if (Mapper.getBlockId(neighborId) != 0) {//Not air if (Mapper.getBlockId(neighborId) != 0) {//Not air
long meta = this.modelMan.getModelMetadataFromClientId(this.modelMan.getModelId(Mapper.getBlockId(neighborId))); long meta = this.modelMan.getModelMetadataFromClientId(this.modelMan.getModelId(Mapper.getBlockId(neighborId)));
if (ModelQueries.isFullyOpaque(meta)) {//Dont mesh this face if (ModelQueries.isFullyOpaque(meta)) {//Dont mesh this face
this.blockMesher.putNext(0); this.blockMesher.skip(1);
continue; continue;
} }
} }
@@ -535,6 +535,10 @@ public class RenderDataFactory45 {
} }
} }
for (var mesher : this.xAxisMeshers) {
mesher.finish();
}
//Generate the side faces, hackily, using 0 and 1 mesher //Generate the side faces, hackily, using 0 and 1 mesher
if (true) { if (true) {
var ma = this.xAxisMeshers[0]; var ma = this.xAxisMeshers[0];
@@ -543,6 +547,7 @@ public class RenderDataFactory45 {
mb.finish(); mb.finish();
ma.doAuxiliaryFaceOffset = false; ma.doAuxiliaryFaceOffset = false;
mb.doAuxiliaryFaceOffset = false; mb.doAuxiliaryFaceOffset = false;
for (int y = 0; y < 32; y++) { for (int y = 0; y < 32; y++) {
int skipA = 0; int skipA = 0;
int skipB = 0; int skipB = 0;
@@ -584,15 +589,12 @@ public class RenderDataFactory45 {
ma.skip(skipA); ma.skip(skipA);
mb.skip(skipB); mb.skip(skipB);
} }
ma.finish(); ma.finish();
mb.finish(); mb.finish();
ma.doAuxiliaryFaceOffset = true; ma.doAuxiliaryFaceOffset = true;
mb.doAuxiliaryFaceOffset = true; mb.doAuxiliaryFaceOffset = true;
} }
for (var mesher : this.xAxisMeshers) {
mesher.finish();
}
} }
/* /*
@@ -607,11 +609,26 @@ public class RenderDataFactory45 {
//section is already acquired and gets released by the parent //section is already acquired and gets released by the parent
public BuiltSection generateMesh(WorldSection section) { public BuiltSection generateMesh(WorldSection section) {
//TODO: FIXME: because of the exceptions that are thrown when aquiring modelId
// this can result in the state of all block meshes and well _everything_ from being incorrect
//THE EXCEPTION THAT THIS THROWS CAUSES MAJOR ISSUES
//Copy section data to end of array so that can mutate array while reading safely //Copy section data to end of array so that can mutate array while reading safely
section.copyDataTo(this.sectionData, 32*32*32); section.copyDataTo(this.sectionData, 32*32*32);
//We must reset _everything_ that could have changed as we dont exactly know the state due to how the model id exception
// throwing system works
this.quadCount = 0; this.quadCount = 0;
{//Reset all the block meshes
this.blockMesher.reset();
this.blockMesher.doAuxiliaryFaceOffset = true;
for (var mesher : this.xAxisMeshers) {
mesher.reset();
mesher.doAuxiliaryFaceOffset = true;
}
}
this.minX = Integer.MAX_VALUE; this.minX = Integer.MAX_VALUE;
this.minY = Integer.MAX_VALUE; this.minY = Integer.MAX_VALUE;
this.minZ = Integer.MAX_VALUE; this.minZ = Integer.MAX_VALUE;

View File

@@ -100,15 +100,18 @@ public abstract class ScanMesher2D {
if (count == 0) return; if (count == 0) return;
//TODO: replace with much better method, TODO: check this is right!! //TODO: replace with much better method, TODO: check this is right!!
this.putNext(0); this.putNext(0);
if (1<count) {
this.emitRanged(((1 << (count - 1)) - 1) << (this.currentIndex & 31)); this.emitRanged(((1 << (count - 1)) - 1) << (this.currentIndex & 31));
this.currentIndex += count - 1; this.currentIndex += count - 1;
}
/* /*
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
this.putNext(0); this.putNext(0);
}*/ }*/
} }
public final void resetScanlineRowIndex() { public final void reset() {
this.rowBitset = 0;
this.currentSum = 0; this.currentSum = 0;
this.currentData = 0; this.currentData = 0;
this.currentIndex = 0; this.currentIndex = 0;
@@ -132,12 +135,13 @@ public abstract class ScanMesher2D {
for (int i = 0; i < 32; i++) { for (int i = 0; i < 32; i++) {
this.putNext(0); this.putNext(0);
}*/ }*/
//TODO: check this is correct //TODO: check this is correct
if (this.currentIndex != 0) {
this.skip(32 - (this.currentIndex & 31)); this.skip(32 - (this.currentIndex & 31));
this.emitRanged(-1); this.emitRanged(-1);
}
this.resetScanlineRowIndex(); this.reset();
} }
protected abstract void emitQuad(int x, int z, int length, int width, long data); protected abstract void emitQuad(int x, int z, int length, int width, long data);