-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FRAPI improvements: context getters, full removal of fallback consume…
…rs, small enhancements (#3287) * Add cull check and item transformation mode getter to FRAPI * Terminally deprecate `fallbackConsumer` and `bakedModelConsumer` * Fix uvs in octagonal column test mod * Review comments (cherry picked from commit 39a511b)
- Loading branch information
1 parent
bbfadae
commit 2034447
Showing
11 changed files
with
255 additions
and
134 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
85 changes: 85 additions & 0 deletions
85
...enderer-api-v1/src/client/java/net/fabricmc/fabric/impl/renderer/VanillaModelEncoder.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,85 @@ | ||
/* | ||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.fabricmc.fabric.impl.renderer; | ||
|
||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import net.minecraft.block.BlockState; | ||
import net.minecraft.client.render.model.BakedModel; | ||
import net.minecraft.client.render.model.BakedQuad; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.util.math.random.Random; | ||
|
||
import net.fabricmc.fabric.api.renderer.v1.Renderer; | ||
import net.fabricmc.fabric.api.renderer.v1.RendererAccess; | ||
import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial; | ||
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter; | ||
import net.fabricmc.fabric.api.renderer.v1.model.ModelHelper; | ||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; | ||
import net.fabricmc.fabric.api.util.TriState; | ||
|
||
/** | ||
* Routines for adaptation of vanilla {@link BakedModel}s to FRAPI pipelines. | ||
* Even though Indigo calls them directly, they are not for use by third party renderers, and might change at any time. | ||
*/ | ||
public class VanillaModelEncoder { | ||
private static final Renderer RENDERER = RendererAccess.INSTANCE.getRenderer(); | ||
private static final RenderMaterial MATERIAL_STANDARD = RENDERER.materialFinder().find(); | ||
private static final RenderMaterial MATERIAL_NO_AO = RENDERER.materialFinder().ambientOcclusion(TriState.FALSE).find(); | ||
|
||
// Separate QuadEmitter parameter so that Indigo can pass its own emitter that handles vanilla quads differently. | ||
public static void emitBlockQuads(BakedModel model, @Nullable BlockState state, Supplier<Random> randomSupplier, RenderContext context, QuadEmitter emitter) { | ||
final RenderMaterial defaultMaterial = model.useAmbientOcclusion() ? MATERIAL_STANDARD : MATERIAL_NO_AO; | ||
|
||
for (int i = 0; i <= ModelHelper.NULL_FACE_ID; i++) { | ||
final Direction cullFace = ModelHelper.faceFromIndex(i); | ||
|
||
if (!context.hasTransform() && context.isFaceCulled(cullFace)) { | ||
// Skip entire quad list if possible. | ||
continue; | ||
} | ||
|
||
final List<BakedQuad> quads = model.getQuads(state, cullFace, randomSupplier.get()); | ||
final int count = quads.size(); | ||
|
||
for (int j = 0; j < count; j++) { | ||
final BakedQuad q = quads.get(j); | ||
emitter.fromVanilla(q, defaultMaterial, cullFace); | ||
emitter.emit(); | ||
} | ||
} | ||
} | ||
|
||
public static void emitItemQuads(BakedModel model, @Nullable BlockState state, Supplier<Random> randomSupplier, RenderContext context) { | ||
QuadEmitter emitter = context.getEmitter(); | ||
|
||
for (int i = 0; i <= ModelHelper.NULL_FACE_ID; i++) { | ||
final Direction cullFace = ModelHelper.faceFromIndex(i); | ||
final List<BakedQuad> quads = model.getQuads(state, cullFace, randomSupplier.get()); | ||
final int count = quads.size(); | ||
|
||
for (int j = 0; j < count; j++) { | ||
final BakedQuad q = quads.get(j); | ||
emitter.fromVanilla(q, MATERIAL_STANDARD, cullFace); | ||
emitter.emit(); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.