-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for replacing textures in ModelCluster
- Loading branch information
Showing
16 changed files
with
228 additions
and
97 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
42 changes: 42 additions & 0 deletions
42
common/src/main/java/cn/zbx1425/mtrsteamloco/mixin/ModelSimpleTrainBaseAccessor.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,42 @@ | ||
package cn.zbx1425.mtrsteamloco.mixin; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.mojang.blaze3d.vertex.VertexConsumer; | ||
import mtr.model.ModelSimpleTrainBase; | ||
import mtr.model.ModelTrainBase; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Invoker; | ||
|
||
@Mixin(ModelSimpleTrainBase.class) | ||
public interface ModelSimpleTrainBaseAccessor { | ||
|
||
@Invoker | ||
void invokeRender(PoseStack matrices, VertexConsumer vertices, ModelTrainBase.RenderStage renderStage, int light, float doorLeftX, float doorRightX, float doorLeftZ, float doorRightZ, int currentCar, int trainCars, boolean head1IsFront, boolean renderDetails); | ||
|
||
@Invoker | ||
void invokeRenderWindowPositions(PoseStack matrices, VertexConsumer vertices, ModelTrainBase.RenderStage renderStage, int light, int position, boolean renderDetails, float doorLeftX, float doorRightX, float doorLeftZ, float doorRightZ, boolean isEnd1Head, boolean isEnd2Head); | ||
|
||
@Invoker | ||
void invokeRenderDoorPositions(PoseStack matrices, VertexConsumer vertices, ModelTrainBase.RenderStage renderStage, int light, int position, boolean renderDetails, float doorLeftX, float doorRightX, float doorLeftZ, float doorRightZ, boolean isEnd1Head, boolean isEnd2Head); | ||
|
||
@Invoker | ||
void invokeRenderHeadPosition1(PoseStack matrices, VertexConsumer vertices, ModelTrainBase.RenderStage renderStage, int light, int position, boolean renderDetails, float doorLeftX, float doorRightX, float doorLeftZ, float doorRightZ, boolean useHeadlights); | ||
|
||
@Invoker | ||
void invokeRenderHeadPosition2(PoseStack matrices, VertexConsumer vertices, ModelTrainBase.RenderStage renderStage, int light, int position, boolean renderDetails, float doorLeftX, float doorRightX, float doorLeftZ, float doorRightZ, boolean useHeadlights); | ||
|
||
@Invoker | ||
void invokeRenderEndPosition1(PoseStack matrices, VertexConsumer vertices, ModelTrainBase.RenderStage renderStage, int light, int position, boolean renderDetails, float doorLeftX, float doorRightX, float doorLeftZ, float doorRightZ); | ||
|
||
@Invoker | ||
void invokeRenderEndPosition2(PoseStack matrices, VertexConsumer vertices, ModelTrainBase.RenderStage renderStage, int light, int position, boolean renderDetails, float doorLeftX, float doorRightX, float doorLeftZ, float doorRightZ); | ||
|
||
@Invoker(remap = false) | ||
int[] invokeGetWindowPositions(); | ||
|
||
@Invoker(remap = false) | ||
int[] invokeGetDoorPositions(); | ||
|
||
@Invoker(remap = false) | ||
int[] invokeGetEndPositions(); | ||
} |
15 changes: 0 additions & 15 deletions
15
common/src/main/java/cn/zbx1425/mtrsteamloco/mixin/ModelTrainBaseAccessor.java
This file was deleted.
Oops, something went wrong.
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
90 changes: 74 additions & 16 deletions
90
common/src/main/java/cn/zbx1425/mtrsteamloco/render/integration/TrainModelCapture.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 |
---|---|---|
@@ -1,35 +1,93 @@ | ||
package cn.zbx1425.mtrsteamloco.render.integration; | ||
|
||
import cn.zbx1425.mtrsteamloco.mixin.ModelTrainBaseAccessor; | ||
import cn.zbx1425.mtrsteamloco.mixin.ModelSimpleTrainBaseAccessor; | ||
import cn.zbx1425.sowcer.math.Vector3f; | ||
import cn.zbx1425.sowcerext.model.RawModel; | ||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import mtr.model.ModelTrainBase; | ||
import net.minecraft.client.renderer.LightTexture; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import java.util.Arrays; | ||
import java.util.Map; | ||
|
||
public class TrainModelCapture { | ||
|
||
public static final float DOOR_OFFSET = 2048; | ||
|
||
public static RawModel[] captureModels(ModelTrainBase mtrModel, ResourceLocation texture, int currentCar, int trainCars) { | ||
CapturingVertexConsumer vertexConsumer = new CapturingVertexConsumer(); | ||
PoseStack emptyPose = new PoseStack(); | ||
for (ModelTrainBase.RenderStage stage : ModelTrainBase.RenderStage.values()) { | ||
vertexConsumer.beginStage(texture, stage); | ||
((ModelTrainBaseAccessor)mtrModel).invokeRender( | ||
emptyPose, vertexConsumer, stage, LightTexture.FULL_BRIGHT, | ||
0, 0, DOOR_OFFSET * 16, DOOR_OFFSET * 16, | ||
currentCar, trainCars, true, true | ||
); | ||
public static CaptureResult captureModels(ModelTrainBase mtrModel, ResourceLocation texture) { | ||
CaptureResult result = new CaptureResult(); | ||
|
||
CapturingVertexConsumer vertices = new CapturingVertexConsumer(); | ||
PoseStack matrices = new PoseStack(); | ||
int light = LightTexture.FULL_BRIGHT; | ||
float doorLeftX = 0, doorRightX = 0, doorLeftZ = DOOR_OFFSET * 16, doorRightZ = DOOR_OFFSET * 16; | ||
boolean renderDetails = true, isEnd1Head = false, isEnd2Head = false, head1IsFront = true; | ||
|
||
vertices.reset(); | ||
for (ModelTrainBase.RenderStage renderStage : ModelTrainBase.RenderStage.values()) { | ||
vertices.beginStage(texture, renderStage); | ||
for (final int position : ((ModelSimpleTrainBaseAccessor) mtrModel).invokeGetWindowPositions()) { | ||
((ModelSimpleTrainBaseAccessor) mtrModel).invokeRenderWindowPositions(matrices, vertices, renderStage, light, position, renderDetails, doorLeftX, doorRightX, doorLeftZ, doorRightZ, isEnd1Head, isEnd2Head); | ||
} | ||
for (final int position : ((ModelSimpleTrainBaseAccessor) mtrModel).invokeGetDoorPositions()) { | ||
((ModelSimpleTrainBaseAccessor) mtrModel).invokeRenderDoorPositions(matrices, vertices, renderStage, light, position, renderDetails, doorLeftX, doorRightX, doorLeftZ, doorRightZ, isEnd1Head, isEnd2Head); | ||
} | ||
} | ||
for (RawModel model : vertexConsumer.models) { | ||
model.applyRotation(Vector3f.XP, 180); | ||
for (RawModel model : vertices.models) model.applyRotation(Vector3f.XP, 180); | ||
result.modelBody = vertices.models[0]; | ||
result.modelDoors = Arrays.copyOfRange(vertices.models, 1, 5); | ||
|
||
vertices.reset(); | ||
for (ModelTrainBase.RenderStage renderStage : ModelTrainBase.RenderStage.values()) { | ||
if (renderStage == ModelTrainBase.RenderStage.ALWAYS_ON_LIGHTS) continue; | ||
vertices.beginStage(texture, renderStage); | ||
((ModelSimpleTrainBaseAccessor)mtrModel).invokeRenderHeadPosition2(matrices, vertices, renderStage, light, ((ModelSimpleTrainBaseAccessor) mtrModel).invokeGetEndPositions()[1], renderDetails, doorLeftX, doorRightX, doorLeftZ, doorRightZ, head1IsFront); | ||
} | ||
for (RawModel model : vertices.models) model.applyRotation(Vector3f.XP, 180); | ||
result.modelHead = vertices.models[0]; | ||
|
||
vertices.reset(); | ||
for (ModelTrainBase.RenderStage renderStage : ModelTrainBase.RenderStage.values()) { | ||
if (renderStage == ModelTrainBase.RenderStage.ALWAYS_ON_LIGHTS) continue; | ||
vertices.beginStage(texture, renderStage); | ||
((ModelSimpleTrainBaseAccessor)mtrModel).invokeRenderEndPosition1(matrices, vertices, renderStage, light, ((ModelSimpleTrainBaseAccessor) mtrModel).invokeGetEndPositions()[0], renderDetails, doorLeftX, doorRightX, doorLeftZ, doorRightZ); | ||
} | ||
return vertexConsumer.models; | ||
for (RawModel model : vertices.models) model.applyRotation(Vector3f.XP, 180); | ||
result.modelEnd = vertices.models[0]; | ||
|
||
vertices.reset(); | ||
vertices.beginStage(texture, ModelTrainBase.RenderStage.ALWAYS_ON_LIGHTS); | ||
((ModelSimpleTrainBaseAccessor)mtrModel).invokeRenderHeadPosition2(matrices, vertices, ModelTrainBase.RenderStage.ALWAYS_ON_LIGHTS, light, ((ModelSimpleTrainBaseAccessor) mtrModel).invokeGetEndPositions()[1], renderDetails, doorLeftX, doorRightX, doorLeftZ, doorRightZ, true); | ||
for (RawModel model : vertices.models) model.applyRotation(Vector3f.XP, 180); | ||
result.modelHeadlight = vertices.models[0]; | ||
|
||
vertices.reset(); | ||
vertices.beginStage(texture, ModelTrainBase.RenderStage.ALWAYS_ON_LIGHTS); | ||
((ModelSimpleTrainBaseAccessor)mtrModel).invokeRenderHeadPosition2(matrices, vertices, ModelTrainBase.RenderStage.ALWAYS_ON_LIGHTS, light, ((ModelSimpleTrainBaseAccessor) mtrModel).invokeGetEndPositions()[1], renderDetails, doorLeftX, doorRightX, doorLeftZ, doorRightZ, false); | ||
for (RawModel model : vertices.models) model.applyRotation(Vector3f.XP, 180); | ||
result.modelTaillight = vertices.models[0]; | ||
|
||
return result; | ||
} | ||
|
||
public static ModelTrainBase getBuiltinTrainModel(String modelName) throws ReflectiveOperationException { | ||
return (ModelTrainBase)Class.forName("mtr.model." + modelName).getConstructor().newInstance(); | ||
public static class CaptureResult { | ||
|
||
public RawModel modelBody; | ||
public RawModel[] modelDoors; | ||
public RawModel modelHead; | ||
public RawModel modelEnd; | ||
public RawModel modelHeadlight; | ||
public RawModel modelTaillight; | ||
|
||
public Map<String, RawModel> getNamedModels() { | ||
return Map.of( | ||
"body", modelBody, | ||
"doorXPZN", modelDoors[0], "doorXPZP", modelDoors[1], | ||
"doorXNZN", modelDoors[2], "doorXNZP", modelDoors[3], | ||
"head", modelHead, "end", modelEnd, | ||
"headlight", modelHeadlight, "taillight", modelTaillight | ||
); | ||
} | ||
} | ||
} |
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.