Skip to content

Commit

Permalink
Merge pull request #12 from TimLee9024/1.18.2-Fabric-2.0
Browse files Browse the repository at this point in the history
Update to 2.0.1.0
  • Loading branch information
Protoxy22 authored Nov 20, 2022
2 parents 3c4628c + b8bc118 commit 907f8cb
Show file tree
Hide file tree
Showing 9 changed files with 535 additions and 66 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ In order to adapt into BSL Shaders' SEUS/Old PBR format, some change were made:
- `Occlusion(R)Roughness(G)Metallic(B)` textures and `Emissive color(RGB)` textures had been edited and combined into `Glossiness(R)Metallic(G)Emissive strength(B)` textures for specular map.
## Additonal Note About Setup This Project
1. Before build MCglTF for developmental environment. There is two ways you can choose to avoid gradle compilation error for OptiFine code reference.
- Simply replace [this line](https://github.com/TimLee9024/MCglTF/blob/c774265e358387646901fedbbd89dc85ebaa987d/src/main/java/com/timlee9024/mcgltf/MCglTF.java#L280) with `return false;` in `isShaderModActive()`.
- Download OptiFine and delete everything except files and folders inside `notch/net/optifine/` of OptiFine JAR. Move all files and folders from `notch/net/optifine/` to `net/optifine/`, which means the `net` folder is now in the root of OptiFine JAR. Then put modified OptiFine JAR into a newly created folder named `libs` in the same dir level as `src` of MCglTF project.
2. Build MCglTF with "gradlew build" to create a `-dev` version of MCglTF which is inside `build/devlibs`.
3. Create a folder named `libs` in the same dir level as `src` of MCglTF-Example project.
4. Put `-dev` version of MCglTF into the `libs` folder.
5. In Eclipse IDE, add MCglTF jar as `Referenced Libraries` via `Project > Properties > Java Build Path > Libraries > Add JARs`.
- Simply remove any OptiFine code reference in MCglTF.java.
- Or download OptiFine and delete everything except files and folders inside `notch/net/optifine/` of OptiFine JAR. Move all files and folders from `notch/net/optifine/` to `net/optifine/`, which means the `net` folder is now in the root of OptiFine JAR. Then put modified OptiFine JAR into a newly created folder named `libs` in the same dir level as `src` of MCglTF project.
2. Build Iris Shaders for development environment and put into `libs` folder in the same dir level as `src` of MCglTF project.
3. Build MCglTF with "gradlew build" to create a `-dev` version of MCglTF which is inside `build/devlibs`.
4. Create a folder named `libs` in the same dir level as `src` of MCglTF-Example project.
5. Put `-dev` version of MCglTF into the `libs` folder.
6. In Eclipse IDE, add MCglTF jar as `Referenced Libraries` via `Project > Properties > Java Build Path > Libraries > Add JARs`.
### Alternative Way
Using [Curse Maven](https://www.cursemaven.com/) to add MCglTF into project via [build.gradle](https://www.cursemaven.com/fabric)
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ org.gradle.jvmargs=-Xmx4G
loader_version=0.14.10

# Mod Properties
mod_version = 1.18.2-Fabric-2.0.0.0
mod_version = 1.18.2-Fabric-2.0.1.0
maven_group = com.modularmods.mcgltf.example
archives_base_name = MCglTF-Example

# Dependencies
fabric_version=0.59.1+1.18.2
fabric_version=0.66.0+1.18.2
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public void onReceiveSharedModel(RenderedGltfModel renderedModel) {

/**
* Since you use custom BEWLR(DynamicItemRenderer) for BlockItem instead of BER to render item form of block,
* the last parameters p_112312_ which control overlay color is almost never used.
* the last parameters which control overlay color is almost never used.
*/
@Override
public void render(ExampleBlockEntity p_112307_, float p_112308_, PoseStack p_112309_, MultiBufferSource p_112310_, int p_112311_, int p_112312_) {
public void render(ExampleBlockEntity blockEntity, float tickDelta, PoseStack matrices, MultiBufferSource vertexConsumers, int light, int overlay) {
int currentVAO = GL11.glGetInteger(GL30.GL_VERTEX_ARRAY_BINDING);
int currentArrayBuffer = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING);
int currentElementArrayBuffer = GL11.glGetInteger(GL15.GL_ELEMENT_ARRAY_BUFFER_BINDING);
Expand All @@ -65,10 +65,10 @@ public void render(ExampleBlockEntity p_112307_, float p_112308_, PoseStack p_11
GL11.glEnable(GL11.GL_BLEND);
GlStateManager._blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

p_112309_.pushPose();
Level level = p_112307_.getLevel();
matrices.pushPose();
Level level = blockEntity.getLevel();
if(level != null) {
float time = (level.getGameTime() + p_112308_) / 20;
float time = (level.getGameTime() + tickDelta) / 20;
//Play every animation clips simultaneously
for(List<InterpolatedChannel> animation : animations) {
animation.parallelStream().forEach((channel) -> {
Expand All @@ -77,31 +77,31 @@ public void render(ExampleBlockEntity p_112307_, float p_112308_, PoseStack p_11
});
}

p_112309_.translate(0.5, 0.5, 0.5); //Make sure it is in the center of the block
switch(level.getBlockState(p_112307_.getBlockPos()).getOptionalValue(HorizontalDirectionalBlock.FACING).orElse(Direction.NORTH)) {
matrices.translate(0.5, 0.5, 0.5); //Make sure it is in the center of the block
switch(level.getBlockState(blockEntity.getBlockPos()).getOptionalValue(HorizontalDirectionalBlock.FACING).orElse(Direction.NORTH)) {
case DOWN:
break;
case UP:
break;
case NORTH:
break;
case SOUTH:
p_112309_.mulPose(new Quaternion(0.0F, 1.0F, 0.0F, 0.0F));
matrices.mulPose(new Quaternion(0.0F, 1.0F, 0.0F, 0.0F));
break;
case WEST:
p_112309_.mulPose(new Quaternion(0.0F, 0.7071068F, 0.0F, 0.7071068F));
matrices.mulPose(new Quaternion(0.0F, 0.7071068F, 0.0F, 0.7071068F));
break;
case EAST:
p_112309_.mulPose(new Quaternion(0.0F, -0.7071068F, 0.0F, 0.7071068F));
matrices.mulPose(new Quaternion(0.0F, -0.7071068F, 0.0F, 0.7071068F));
break;
}
}

RenderedGltfModel.CURRENT_POSE = p_112309_.last().pose();
RenderedGltfModel.CURRENT_NORMAL = p_112309_.last().normal();
p_112309_.popPose();
RenderedGltfModel.CURRENT_POSE = matrices.last().pose();
RenderedGltfModel.CURRENT_NORMAL = matrices.last().normal();
matrices.popPose();

GL30.glVertexAttribI2i(RenderedGltfModel.vaUV2, p_112311_ & '\uffff', p_112311_ >> 16 & '\uffff');
GL30.glVertexAttribI2i(RenderedGltfModel.vaUV2, light & '\uffff', light >> 16 & '\uffff');

if(MCglTF.getInstance().isShaderModActive()) {
renderedScene.renderForShaderMod();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package com.modularmods.mcgltf.example;

import java.util.List;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL30;

import com.modularmods.mcgltf.MCglTF;
import com.modularmods.mcgltf.RenderedGltfModel;
import com.modularmods.mcgltf.animation.InterpolatedChannel;
import com.modularmods.mcgltf.iris.IrisRenderingHook;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix3f;
import com.mojang.math.Matrix4f;
import com.mojang.math.Quaternion;

import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.core.Direction;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;

public class ExampleBlockEntityRendererIris extends ExampleBlockEntityRenderer {

@Override
public void render(ExampleBlockEntity blockEntity, float tickDelta, PoseStack matrices, MultiBufferSource vertexConsumers, int light, int overlay) {
RenderType renderType = RenderType.entitySolid(TextureAtlas.LOCATION_BLOCKS);
vertexConsumers.getBuffer(renderType); //Put renderType into MultiBufferSource to ensure command submit to IrisRenderingHook will be run in Iris batched entity rendering.
Matrix4f modelViewMatrix = matrices.last().pose().copy();

if(MCglTF.getInstance().isShaderModActive()) {
IrisRenderingHook.submitCommandForIrisRenderingByPhaseName("BLOCK_ENTITIES", renderType, () -> {
Level level = blockEntity.getLevel();
if(level != null) {
float time = (level.getGameTime() + tickDelta) / 20;
//Play every animation clips simultaneously
for(List<InterpolatedChannel> animation : animations) {
animation.parallelStream().forEach((channel) -> {
float[] keys = channel.getKeys();
channel.update(time % keys[keys.length - 1]);
});
}

modelViewMatrix.multiplyWithTranslation(0.5F, 0.5F, 0.5F); //Make sure it is in the center of the block
switch(level.getBlockState(blockEntity.getBlockPos()).getOptionalValue(HorizontalDirectionalBlock.FACING).orElse(Direction.NORTH)) {
case DOWN:
break;
case UP:
break;
case NORTH:
break;
case SOUTH:
modelViewMatrix.multiply(new Quaternion(0.0F, 1.0F, 0.0F, 0.0F));
break;
case WEST:
modelViewMatrix.multiply(new Quaternion(0.0F, 0.7071068F, 0.0F, 0.7071068F));
break;
case EAST:
modelViewMatrix.multiply(new Quaternion(0.0F, -0.7071068F, 0.0F, 0.7071068F));
break;
}
}

RenderedGltfModel.CURRENT_POSE = modelViewMatrix;

boolean currentBlend = GL11.glGetBoolean(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_BLEND); //Since the renderType is entity solid, we need to turn on blending manually.
GlStateManager._blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

GL30.glVertexAttribI2i(RenderedGltfModel.vaUV1, overlay & '\uffff', overlay >> 16 & '\uffff');
GL30.glVertexAttribI2i(RenderedGltfModel.vaUV2, light & '\uffff', light >> 16 & '\uffff');

renderedScene.renderForShaderMod();

GL30.glVertexAttribI2i(RenderedGltfModel.vaUV1, 0, 0);
GL30.glVertexAttribI2i(RenderedGltfModel.vaUV2, 0, 0);

if(!currentBlend) GL11.glDisable(GL11.GL_BLEND);
});
}
else {
Matrix3f normalMatrix = matrices.last().normal().copy();
IrisRenderingHook.submitCommandForIrisRenderingByPhaseName("NONE", renderType, () -> {
Level level = blockEntity.getLevel();
if(level != null) {
float time = (level.getGameTime() + tickDelta) / 20;
for(List<InterpolatedChannel> animation : animations) {
animation.parallelStream().forEach((channel) -> {
float[] keys = channel.getKeys();
channel.update(time % keys[keys.length - 1]);
});
}

modelViewMatrix.multiplyWithTranslation(0.5F, 0.5F, 0.5F);
switch(level.getBlockState(blockEntity.getBlockPos()).getOptionalValue(HorizontalDirectionalBlock.FACING).orElse(Direction.NORTH)) {
case DOWN:
break;
case UP:
break;
case NORTH:
break;
case SOUTH:
Quaternion rotation = new Quaternion(0.0F, 1.0F, 0.0F, 0.0F);
modelViewMatrix.multiply(rotation);
normalMatrix.mul(rotation);
break;
case WEST:
rotation = new Quaternion(0.0F, 0.7071068F, 0.0F, 0.7071068F);
modelViewMatrix.multiply(rotation);
normalMatrix.mul(rotation);
break;
case EAST:
rotation = new Quaternion(0.0F, -0.7071068F, 0.0F, 0.7071068F);
modelViewMatrix.multiply(rotation);
normalMatrix.mul(rotation);
break;
}
}

RenderedGltfModel.CURRENT_POSE = modelViewMatrix;
RenderedGltfModel.CURRENT_NORMAL = normalMatrix;

boolean currentBlend = GL11.glGetBoolean(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_BLEND);
GlStateManager._blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

GL30.glVertexAttribI2i(RenderedGltfModel.vaUV1, overlay & '\uffff', overlay >> 16 & '\uffff');
GL30.glVertexAttribI2i(RenderedGltfModel.vaUV2, light & '\uffff', light >> 16 & '\uffff');

renderedScene.renderForVanilla();

GL30.glVertexAttribI2i(RenderedGltfModel.vaUV1, 0, 0);
GL30.glVertexAttribI2i(RenderedGltfModel.vaUV2, 0, 0);

if(!currentBlend) GL11.glDisable(GL11.GL_BLEND);
});
}
}

}
98 changes: 67 additions & 31 deletions src/main/java/com/modularmods/mcgltf/example/ExampleClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.resources.ResourceLocation;

public class ExampleClient implements ClientModInitializer {
Expand All @@ -23,37 +24,72 @@ public void onInitializeClient() {
tickDelta = listener.tickDelta();
});

BlockEntityRendererRegistry.register(Example.INSTANCE.exampleBlockEntityType, (context) -> {
ExampleBlockEntityRenderer ber = new ExampleBlockEntityRenderer();
MCglTF.getInstance().addGltfModelReceiver(ber);
return ber;
});

EntityRendererRegistry.register(Example.INSTANCE.exampleEntityType, (context) -> {
ExampleEntityRenderer entityRenderer = new ExampleEntityRenderer(context);
MCglTF.getInstance().addGltfModelReceiver(entityRenderer);
return entityRenderer;
});

ExampleItemRenderer itemRenderer = new ExampleItemRenderer() {

@Override
public ResourceLocation getModelLocation() {
return new ResourceLocation("mcgltf", "models/item/water_bottle.gltf");
}
};
MCglTF.getInstance().addGltfModelReceiver(itemRenderer);
BuiltinItemRendererRegistry.INSTANCE.register(Example.INSTANCE.item, itemRenderer);

ExampleItemRenderer blockItemRenderer = new ExampleItemRenderer() {

@Override
public ResourceLocation getModelLocation() {
return new ResourceLocation("mcgltf", "models/block/boom_box.gltf");
}
};
MCglTF.getInstance().addGltfModelReceiver(blockItemRenderer);
BuiltinItemRendererRegistry.INSTANCE.register(Example.INSTANCE.blockItem, blockItemRenderer);
if(FabricLoader.getInstance().isModLoaded("iris")) {
BlockEntityRendererRegistry.register(Example.INSTANCE.exampleBlockEntityType, (context) -> {
ExampleBlockEntityRenderer ber = new ExampleBlockEntityRendererIris();
MCglTF.getInstance().addGltfModelReceiver(ber);
return ber;
});

EntityRendererRegistry.register(Example.INSTANCE.exampleEntityType, (context) -> {
ExampleEntityRenderer entityRenderer = new ExampleEntityRendererIris(context);
MCglTF.getInstance().addGltfModelReceiver(entityRenderer);
return entityRenderer;
});

ExampleItemRenderer itemRenderer = new ExampleItemRendererIris() {

@Override
public ResourceLocation getModelLocation() {
return new ResourceLocation("mcgltf", "models/item/water_bottle.gltf");
}
};
MCglTF.getInstance().addGltfModelReceiver(itemRenderer);
BuiltinItemRendererRegistry.INSTANCE.register(Example.INSTANCE.item, itemRenderer);

ExampleItemRenderer blockItemRenderer = new ExampleItemRendererIris() {

@Override
public ResourceLocation getModelLocation() {
return new ResourceLocation("mcgltf", "models/block/boom_box.gltf");
}
};
MCglTF.getInstance().addGltfModelReceiver(blockItemRenderer);
BuiltinItemRendererRegistry.INSTANCE.register(Example.INSTANCE.blockItem, blockItemRenderer);
}
else {
BlockEntityRendererRegistry.register(Example.INSTANCE.exampleBlockEntityType, (context) -> {
ExampleBlockEntityRenderer ber = new ExampleBlockEntityRenderer();
MCglTF.getInstance().addGltfModelReceiver(ber);
return ber;
});

EntityRendererRegistry.register(Example.INSTANCE.exampleEntityType, (context) -> {
ExampleEntityRenderer entityRenderer = new ExampleEntityRenderer(context);
MCglTF.getInstance().addGltfModelReceiver(entityRenderer);
return entityRenderer;
});

ExampleItemRenderer itemRenderer = new ExampleItemRenderer() {

@Override
public ResourceLocation getModelLocation() {
return new ResourceLocation("mcgltf", "models/item/water_bottle.gltf");
}
};
MCglTF.getInstance().addGltfModelReceiver(itemRenderer);
BuiltinItemRendererRegistry.INSTANCE.register(Example.INSTANCE.item, itemRenderer);

ExampleItemRenderer blockItemRenderer = new ExampleItemRenderer() {

@Override
public ResourceLocation getModelLocation() {
return new ResourceLocation("mcgltf", "models/block/boom_box.gltf");
}
};
MCglTF.getInstance().addGltfModelReceiver(blockItemRenderer);
BuiltinItemRendererRegistry.INSTANCE.register(Example.INSTANCE.blockItem, blockItemRenderer);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public ResourceLocation getTextureLocation(ExampleEntity p_114482_) {
}

@Override
public void render(ExampleEntity p_114485_, float p_114486_, float p_114487_, PoseStack p_114488_, MultiBufferSource p_114489_, int p_114490_) {
float time = (p_114485_.level.getGameTime() + p_114487_) / 20;
public void render(ExampleEntity entity, float yRotDelta, float tickDelta, PoseStack matrices, MultiBufferSource vertexConsumers, int light) {
float time = (entity.level.getGameTime() + tickDelta) / 20;
//Play every animation clips simultaneously
for(List<InterpolatedChannel> animation : animations) {
animation.parallelStream().forEach((channel) -> {
Expand All @@ -78,13 +78,13 @@ public void render(ExampleEntity p_114485_, float p_114486_, float p_114487_, Po
GL11.glEnable(GL11.GL_BLEND);
GlStateManager._blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

p_114488_.pushPose();
p_114488_.mulPose(new Quaternion(0.0F, Mth.rotLerp(p_114487_, p_114485_.yBodyRotO, p_114485_.yBodyRot), 0.0F, true));
RenderedGltfModel.CURRENT_POSE = p_114488_.last().pose();
RenderedGltfModel.CURRENT_NORMAL = p_114488_.last().normal();
p_114488_.popPose();
matrices.pushPose();
matrices.mulPose(new Quaternion(0.0F, Mth.rotLerp(tickDelta, entity.yBodyRotO, entity.yBodyRot), 0.0F, true));
RenderedGltfModel.CURRENT_POSE = matrices.last().pose();
RenderedGltfModel.CURRENT_NORMAL = matrices.last().normal();
matrices.popPose();

GL30.glVertexAttribI2i(RenderedGltfModel.vaUV2, p_114490_ & '\uffff', p_114490_ >> 16 & '\uffff');
GL30.glVertexAttribI2i(RenderedGltfModel.vaUV2, light & '\uffff', light >> 16 & '\uffff');

if(MCglTF.getInstance().isShaderModActive()) {
renderedScene.renderForShaderMod();
Expand Down Expand Up @@ -122,7 +122,11 @@ public void render(ExampleEntity p_114485_, float p_114486_, float p_114487_, Po
GL30.glBindVertexArray(currentVAO);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, currentArrayBuffer);
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, currentElementArrayBuffer);
super.render(p_114485_, p_114486_, p_114487_, p_114488_, p_114489_, p_114490_);
super.render(entity, yRotDelta, tickDelta, matrices, vertexConsumers, light);
}

protected void checkAndRenderNameTag(ExampleEntity entity, float yRotDelta, float tickDelta, PoseStack matrices, MultiBufferSource vertexConsumers, int light) {
super.render(entity, yRotDelta, tickDelta, matrices, vertexConsumers, light);
}

}
Loading

0 comments on commit 907f8cb

Please sign in to comment.