-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix mesh order of models from model builders
Meshes are now always sorted by chunk layer first, then in order of how the BakedModel returned quads. This should exactly match vanilla's chunk buffering and avoid any rendering issues.
- Loading branch information
1 parent
914ce0a
commit 7ef9ce3
Showing
11 changed files
with
136 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
fabric/src/lib/java/com/jozufozu/flywheel/lib/model/baked/ChunkLayerSortedListBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.jozufozu.flywheel.lib.model.baked; | ||
|
||
import java.util.List; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
import it.unimi.dsi.fastutil.objects.ObjectArrayList; | ||
import it.unimi.dsi.fastutil.objects.Reference2ReferenceMap; | ||
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap; | ||
import net.minecraft.client.renderer.RenderType; | ||
|
||
class ChunkLayerSortedListBuilder<T> { | ||
private static final ThreadLocal<ChunkLayerSortedListBuilder<?>> THREAD_LOCAL = ThreadLocal.withInitial(ChunkLayerSortedListBuilder::new); | ||
|
||
@SuppressWarnings("unchecked") | ||
private final ObjectArrayList<T>[] lists = new ObjectArrayList[BakedModelBufferer.CHUNK_LAYER_AMOUNT]; | ||
private final Reference2ReferenceMap<RenderType, ObjectArrayList<T>> map = new Reference2ReferenceOpenHashMap<>(); | ||
|
||
private ChunkLayerSortedListBuilder() { | ||
for (int layerIndex = 0; layerIndex < BakedModelBufferer.CHUNK_LAYER_AMOUNT; layerIndex++) { | ||
RenderType renderType = BakedModelBufferer.CHUNK_LAYERS[layerIndex]; | ||
ObjectArrayList<T> list = new ObjectArrayList<>(); | ||
lists[layerIndex] = list; | ||
map.put(renderType, list); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static <T> ChunkLayerSortedListBuilder<T> getThreadLocal() { | ||
return (ChunkLayerSortedListBuilder<T>) THREAD_LOCAL.get(); | ||
} | ||
|
||
public void add(RenderType renderType, T obj) { | ||
List<T> list = map.get(renderType); | ||
if (list == null) { | ||
throw new IllegalArgumentException("RenderType '" + renderType + "' is not a chunk layer"); | ||
} | ||
list.add(obj); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public ImmutableList<T> build() { | ||
int size = 0; | ||
for (ObjectArrayList<T> list : lists) { | ||
size += list.size(); | ||
} | ||
|
||
T[] array = (T[]) new Object[size]; | ||
int destPos = 0; | ||
for (ObjectArrayList<T> list : lists) { | ||
System.arraycopy(list.elements(), 0, array, destPos, list.size()); | ||
destPos += list.size(); | ||
list.clear(); | ||
} | ||
|
||
return ImmutableList.copyOf(array); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
forge/src/lib/java/com/jozufozu/flywheel/lib/model/baked/ChunkLayerSortedListBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.jozufozu.flywheel.lib.model.baked; | ||
|
||
import java.util.List; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
import it.unimi.dsi.fastutil.objects.ObjectArrayList; | ||
import net.minecraft.client.renderer.RenderType; | ||
|
||
class ChunkLayerSortedListBuilder<T> { | ||
private static final ThreadLocal<ChunkLayerSortedListBuilder<?>> THREAD_LOCAL = ThreadLocal.withInitial(ChunkLayerSortedListBuilder::new); | ||
|
||
@SuppressWarnings("unchecked") | ||
private final ObjectArrayList<T>[] lists = new ObjectArrayList[BakedModelBufferer.CHUNK_LAYER_AMOUNT]; | ||
|
||
private ChunkLayerSortedListBuilder() { | ||
for (int layerIndex = 0; layerIndex < BakedModelBufferer.CHUNK_LAYER_AMOUNT; layerIndex++) { | ||
ObjectArrayList<T> list = new ObjectArrayList<>(); | ||
lists[layerIndex] = list; | ||
} | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static <T> ChunkLayerSortedListBuilder<T> getThreadLocal() { | ||
return (ChunkLayerSortedListBuilder<T>) THREAD_LOCAL.get(); | ||
} | ||
|
||
public void add(RenderType renderType, T obj) { | ||
int layerIndex = renderType.getChunkLayerId(); | ||
if (layerIndex == -1) { | ||
throw new IllegalArgumentException("RenderType '" + renderType + "' is not a chunk layer"); | ||
} | ||
List<T> list = lists[layerIndex]; | ||
list.add(obj); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public ImmutableList<T> build() { | ||
int size = 0; | ||
for (ObjectArrayList<T> list : lists) { | ||
size += list.size(); | ||
} | ||
|
||
T[] array = (T[]) new Object[size]; | ||
int destPos = 0; | ||
for (ObjectArrayList<T> list : lists) { | ||
System.arraycopy(list.elements(), 0, array, destPos, list.size()); | ||
destPos += list.size(); | ||
list.clear(); | ||
} | ||
|
||
return ImmutableList.copyOf(array); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters