From cd45332885eac66ec47aff6aa724ab69bd69cf83 Mon Sep 17 00:00:00 2001 From: YTimLee Date: Sun, 7 Aug 2022 10:43:46 +0800 Subject: [PATCH] Update to compatible with MCglTF-1.2.0.0 --- README.md | 2 +- build.gradle | 2 +- .../AbstractItemGltfModelReceiver.java | 26 ---- .../timlee9024/mcgltf/example/Example.java | 138 ++--------------- .../mcgltf/example/ExampleEntityRenderer.java | 103 +++++++------ .../mcgltf/example/ExampleItemRenderer.java | 124 ++++++++++++++++ .../example/ExampleTileEntityRenderer.java | 140 ++++++++++-------- src/main/resources/META-INF/mods.toml | 28 +++- src/main/resources/icon.png | Bin 0 -> 3729 bytes updates.json | 5 +- 10 files changed, 303 insertions(+), 265 deletions(-) delete mode 100644 src/main/java/com/timlee9024/mcgltf/example/AbstractItemGltfModelReceiver.java create mode 100644 src/main/java/com/timlee9024/mcgltf/example/ExampleItemRenderer.java create mode 100644 src/main/resources/icon.png diff --git a/README.md b/README.md index f9d6e97..35341a5 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0#gltf-20-sampl In order to adapt into BSL Shaders' SEUS/Old PBR format, some change were made: - All normal textures had been converted from OpenGL format (Y+) to DirectX format (Y-) by flipping green channel. -- `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. +- `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. Build MCglTF with "gradlew jar" to create a [deobuscated version](https://forums.minecraftforge.net/topic/81617-1152-eclipse-and-gradle-how-to-use-jar-from-another-project-and-import-solved) of MCglTF. 2. Create a folder named `libs` in the same dir level as `src`. diff --git a/build.gradle b/build.gradle index 05d88bc..c1a968a 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ apply plugin: 'net.minecraftforge.gradle' apply plugin: 'eclipse' apply plugin: 'maven-publish' -version = '1.16.5-Forge-1.1.0.1' +version = '1.16.5-Forge-1.2.0.0' group = 'com.timlee9024.mcgltf.example' // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = 'MCglTF-Example' diff --git a/src/main/java/com/timlee9024/mcgltf/example/AbstractItemGltfModelReceiver.java b/src/main/java/com/timlee9024/mcgltf/example/AbstractItemGltfModelReceiver.java deleted file mode 100644 index 9a230fc..0000000 --- a/src/main/java/com/timlee9024/mcgltf/example/AbstractItemGltfModelReceiver.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.timlee9024.mcgltf.example; - -import java.util.List; - -import com.timlee9024.mcgltf.IGltfModelReceiver; -import com.timlee9024.mcgltf.RenderedGltfModel; - -import de.javagl.jgltf.model.GltfAnimations; -import de.javagl.jgltf.model.animation.Animation; - -public abstract class AbstractItemGltfModelReceiver implements IGltfModelReceiver { - - public List vanillaCommands; - - public List shaderModCommands; - - public List animations; - - @Override - public void onReceiveSharedModel(RenderedGltfModel renderedModel) { - vanillaCommands = renderedModel.vanillaSceneCommands.get(0); - shaderModCommands = renderedModel.shaderModSceneCommands.get(0); - animations = GltfAnimations.createModelAnimations(renderedModel.gltfModel.getAnimationModels()); - } - -} diff --git a/src/main/java/com/timlee9024/mcgltf/example/Example.java b/src/main/java/com/timlee9024/mcgltf/example/Example.java index 4a72c55..dbd7d66 100644 --- a/src/main/java/com/timlee9024/mcgltf/example/Example.java +++ b/src/main/java/com/timlee9024/mcgltf/example/Example.java @@ -1,24 +1,16 @@ package com.timlee9024.mcgltf.example; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL12; -import org.lwjgl.opengl.GL13; -import org.lwjgl.opengl.GL20; - import com.mojang.blaze3d.matrix.MatrixStack; -import com.mojang.blaze3d.systems.RenderSystem; import com.timlee9024.mcgltf.MCglTF; -import de.javagl.jgltf.model.animation.Animation; import net.minecraft.block.AbstractBlock; import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; -import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.client.renderer.entity.EntityRendererManager; -import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType; +import net.minecraft.client.renderer.model.ItemCameraTransforms; import net.minecraft.client.renderer.tileentity.ItemStackTileEntityRenderer; import net.minecraft.entity.EntityClassification; import net.minecraft.entity.EntityType; @@ -68,7 +60,7 @@ public static void onTileEntityTypeRegistryEvent(final RegistryEvent.Register> event) { EXAMPLE_ENTITY_TYPE = EntityType.Builder.of(ExampleEntity::new, EntityClassification.MISC) @@ -86,7 +78,7 @@ public static void onItemRegistryEvent(final RegistryEvent.Register event) event.getRegistry().register(item); BlockItem blockItem = new BlockItem(EXAMPLE_BLOCK, new Item.Properties().tab(ItemGroup.TAB_MISC)); - item.setRegistryName(EXAMPLE_BLOCK.getRegistryName()); + blockItem.setRegistryName(EXAMPLE_BLOCK.getRegistryName()); event.getRegistry().register(blockItem); ForgeSpawnEggItem spawnEggItem = new ForgeSpawnEggItem(() -> EXAMPLE_ENTITY_TYPE, 12422002, 5651507, new Item.Properties().tab(ItemGroup.TAB_MISC)); @@ -105,7 +97,7 @@ public static class Client { private static Item item; private static BlockItem blockItem; - + @SubscribeEvent public static void onBlockRegistryEvent(final RegistryEvent.Register event) { EXAMPLE_BLOCK = new ExampleBlock(AbstractBlock.Properties.of(Material.STONE).strength(0.3F) @@ -125,7 +117,7 @@ public static void onTileEntityTypeRegistryEvent(final RegistryEvent.Register> event) { EXAMPLE_ENTITY_TYPE = EntityType.Builder.of(ExampleEntity::new, EntityClassification.MISC) @@ -138,139 +130,37 @@ public static void onEntityTypeRegistryEvent(final RegistryEvent.Register event) { - AbstractItemGltfModelReceiver itemModelReceiver = new AbstractItemGltfModelReceiver() { + ExampleItemRenderer itemRenderer = new ExampleItemRenderer() { @Override public ResourceLocation getModelLocation() { return new ResourceLocation("mcgltf", "models/item/water_bottle.gltf"); } }; - MCglTF.getInstance().addGltfModelReceiver(itemModelReceiver); + MCglTF.getInstance().addGltfModelReceiver(itemRenderer); - AbstractItemGltfModelReceiver blockItemModelReceiver = new AbstractItemGltfModelReceiver() { + ExampleItemRenderer blockItemRenderer = new ExampleItemRenderer() { @Override public ResourceLocation getModelLocation() { return new ResourceLocation("mcgltf", "models/block/boom_box.gltf"); } }; - MCglTF.getInstance().addGltfModelReceiver(blockItemModelReceiver); + MCglTF.getInstance().addGltfModelReceiver(blockItemRenderer); //According to Forge Doc "Each mod should only have one instance of a custom TEISR/ISTER/BEWLR.", due to creating an instance will also initiate unused fields inside the class which waste a lots of memory. ItemStackTileEntityRenderer ister = new ItemStackTileEntityRenderer() { @Override - public void renderByItem(ItemStack p_239207_1_, TransformType p_239207_2_, MatrixStack p_239207_3_, IRenderTypeBuffer p_239207_4_, int p_239207_5_, int p_239207_6_) { - GL11.glPushMatrix(); - GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); - - GL11.glEnable(GL11.GL_LIGHTING); - GL11.glShadeModel(GL11.GL_SMOOTH); - GL11.glEnable(GL11.GL_COLOR_MATERIAL); - - RenderSystem.multMatrix(p_239207_3_.last().pose()); - - switch(p_239207_2_) { - case THIRD_PERSON_LEFT_HAND: - case THIRD_PERSON_RIGHT_HAND: - case HEAD: - GL11.glEnable(GL12.GL_RESCALE_NORMAL); - GL11.glEnable(GL11.GL_DEPTH_TEST); - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - - GL13.glMultiTexCoord2s(GL13.GL_TEXTURE1, (short)(p_239207_6_ & '\uffff'), (short)(p_239207_6_ >> 16 & '\uffff')); - GL13.glMultiTexCoord2s(GL13.GL_TEXTURE2, (short)(p_239207_5_ & '\uffff'), (short)(p_239207_5_ >> 16 & '\uffff')); - - MCglTF.CURRENT_PROGRAM = GL11.glGetInteger(GL20.GL_CURRENT_PROGRAM); - if(MCglTF.CURRENT_PROGRAM == 0) { - GL13.glActiveTexture(GL13.GL_TEXTURE1); - GL11.glEnable(GL11.GL_TEXTURE_2D); - GL13.glActiveTexture(GL13.GL_TEXTURE2); - GL11.glEnable(GL11.GL_TEXTURE_2D); - GL13.glActiveTexture(GL13.GL_TEXTURE0); - - renderWithVanillaCommands(p_239207_1_); - } - else { - renderWithShaderModCommands(p_239207_1_); - } - break; - case FIRST_PERSON_LEFT_HAND: - case FIRST_PERSON_RIGHT_HAND: - case GROUND: - case FIXED: - GL11.glEnable(GL12.GL_RESCALE_NORMAL); - GL11.glEnable(GL11.GL_DEPTH_TEST); - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - - GL13.glMultiTexCoord2s(GL13.GL_TEXTURE2, (short)(p_239207_5_ & '\uffff'), (short)(p_239207_5_ >> 16 & '\uffff')); - - MCglTF.CURRENT_PROGRAM = GL11.glGetInteger(GL20.GL_CURRENT_PROGRAM); - if(MCglTF.CURRENT_PROGRAM == 0) { - GL13.glActiveTexture(GL13.GL_TEXTURE2); - GL11.glEnable(GL11.GL_TEXTURE_2D); - GL13.glActiveTexture(GL13.GL_TEXTURE0); - - renderWithVanillaCommands(p_239207_1_); - } - else { - renderWithShaderModCommands(p_239207_1_); - } - break; - default: - MCglTF.CURRENT_PROGRAM = GL11.glGetInteger(GL20.GL_CURRENT_PROGRAM); - if(MCglTF.CURRENT_PROGRAM == 0) { - renderWithVanillaCommands(p_239207_1_); - } - else { - renderWithShaderModCommands(p_239207_1_); - } - break; - } - - GL11.glPopAttrib(); - GL11.glPopMatrix(); - } - - private void renderWithVanillaCommands(ItemStack itemStack) { - Item currentItem = itemStack.getItem(); - if(currentItem == item) { - Minecraft mc = Minecraft.getInstance(); - //Play every animation clips simultaneously - for(Animation animation : itemModelReceiver.animations) { - animation.update(net.minecraftforge.client.model.animation.Animation.getWorldTime(mc.level, net.minecraftforge.client.model.animation.Animation.getPartialTickTime()) % animation.getEndTimeS()); - } - itemModelReceiver.vanillaCommands.forEach(Runnable::run); - } - else if(currentItem == blockItem) { - Minecraft mc = Minecraft.getInstance(); - for(Animation animation : blockItemModelReceiver.animations) { - animation.update(net.minecraftforge.client.model.animation.Animation.getWorldTime(mc.level, net.minecraftforge.client.model.animation.Animation.getPartialTickTime()) % animation.getEndTimeS()); - } - blockItemModelReceiver.vanillaCommands.forEach(Runnable::run); - } - } - - private void renderWithShaderModCommands(ItemStack itemStack) { - Item currentItem = itemStack.getItem(); + public void renderByItem(ItemStack p_239207_1_, ItemCameraTransforms.TransformType p_239207_2_, MatrixStack p_239207_3_, IRenderTypeBuffer p_239207_4_, int p_239207_5_, int p_239207_6_) { + Item currentItem = p_239207_1_.getItem(); if(currentItem == item) { - Minecraft mc = Minecraft.getInstance(); - for(Animation animation : itemModelReceiver.animations) { - animation.update(net.minecraftforge.client.model.animation.Animation.getWorldTime(mc.level, net.minecraftforge.client.model.animation.Animation.getPartialTickTime()) % animation.getEndTimeS()); - } - itemModelReceiver.shaderModCommands.forEach(Runnable::run); + itemRenderer.render(p_239207_2_, p_239207_3_, p_239207_4_, p_239207_5_, p_239207_6_); } else if(currentItem == blockItem) { - Minecraft mc = Minecraft.getInstance(); - for(Animation animation : blockItemModelReceiver.animations) { - animation.update(net.minecraftforge.client.model.animation.Animation.getWorldTime(mc.level, net.minecraftforge.client.model.animation.Animation.getPartialTickTime()) % animation.getEndTimeS()); - } - blockItemModelReceiver.shaderModCommands.forEach(Runnable::run); + blockItemRenderer.render(p_239207_2_, p_239207_3_, p_239207_4_, p_239207_5_, p_239207_6_); } } - }; item = new Item(new Item.Properties().tab(ItemGroup.TAB_MISC).setISTER(() -> () -> ister)); @@ -285,7 +175,7 @@ else if(currentItem == blockItem) { spawnEggItem.setRegistryName(new ResourceLocation("mcgltf", "example_entity_spawn_egg")); event.getRegistry().register(spawnEggItem); } - + @SubscribeEvent public static void onEvent(final EntityAttributeCreationEvent event) { event.put(EXAMPLE_ENTITY_TYPE, ExampleEntity.createAttributes().build()); diff --git a/src/main/java/com/timlee9024/mcgltf/example/ExampleEntityRenderer.java b/src/main/java/com/timlee9024/mcgltf/example/ExampleEntityRenderer.java index b266d86..4063f1c 100644 --- a/src/main/java/com/timlee9024/mcgltf/example/ExampleEntityRenderer.java +++ b/src/main/java/com/timlee9024/mcgltf/example/ExampleEntityRenderer.java @@ -1,34 +1,36 @@ package com.timlee9024.mcgltf.example; +import java.util.ArrayList; import java.util.List; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; import org.lwjgl.opengl.GL13; -import org.lwjgl.opengl.GL20; +import org.lwjgl.opengl.GL15; +import org.lwjgl.opengl.GL30; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; import com.timlee9024.mcgltf.IGltfModelReceiver; import com.timlee9024.mcgltf.MCglTF; import com.timlee9024.mcgltf.RenderedGltfModel; +import com.timlee9024.mcgltf.RenderedGltfScene; +import com.timlee9024.mcgltf.animation.GltfAnimationCreator; +import com.timlee9024.mcgltf.animation.InterpolatedChannel; -import de.javagl.jgltf.model.GltfAnimations; -import de.javagl.jgltf.model.animation.Animation; -import net.minecraft.client.Minecraft; +import de.javagl.jgltf.model.AnimationModel; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.client.renderer.entity.EntityRendererManager; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.MathHelper; +import net.minecraftforge.client.model.animation.Animation; public class ExampleEntityRenderer extends EntityRenderer implements IGltfModelReceiver { - protected List vanillaCommands; + protected RenderedGltfScene renderedScene; - protected List shaderModCommands; - - protected List animations; + protected List> animations; protected ExampleEntityRenderer(EntityRendererManager p_i46179_1_) { super(p_i46179_1_); @@ -41,9 +43,12 @@ public ResourceLocation getModelLocation() { @Override public void onReceiveSharedModel(RenderedGltfModel renderedModel) { - vanillaCommands = renderedModel.vanillaSceneCommands.get(0); - shaderModCommands = renderedModel.shaderModSceneCommands.get(0); - animations = GltfAnimations.createModelAnimations(renderedModel.gltfModel.getAnimationModels()); + renderedScene = renderedModel.renderedGltfScenes.get(0); + List animationModels = renderedModel.gltfModel.getAnimationModels(); + animations = new ArrayList>(animationModels.size()); + for(AnimationModel animationModel : animationModels) { + animations.add(GltfAnimationCreator.createGltfAnimation(animationModel)); + } } @Override @@ -53,42 +58,48 @@ public ResourceLocation getTextureLocation(ExampleEntity p_110775_1_) { @Override public void render(ExampleEntity p_225623_1_, float p_225623_2_, float p_225623_3_, MatrixStack p_225623_4_, IRenderTypeBuffer p_225623_5_, int p_225623_6_) { - if(vanillaCommands != null) { - GL11.glPushMatrix(); - GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); - - GL11.glEnable(GL11.GL_LIGHTING); - GL11.glShadeModel(GL11.GL_SMOOTH); - GL11.glEnable(GL12.GL_RESCALE_NORMAL); - GL11.glEnable(GL11.GL_DEPTH_TEST); - GL11.glEnable(GL11.GL_COLOR_MATERIAL); - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - - RenderSystem.multMatrix(p_225623_4_.last().pose()); - GL11.glRotatef(MathHelper.rotLerp(p_225623_3_, p_225623_1_.yBodyRotO, p_225623_1_.yBodyRot), 0.0F, 1.0F, 0.0F); - - Minecraft mc = Minecraft.getInstance(); - for(Animation animation : animations) { - animation.update(net.minecraftforge.client.model.animation.Animation.getWorldTime(mc.level, p_225623_3_) % animation.getEndTimeS()); - } - - GL13.glMultiTexCoord2s(GL13.GL_TEXTURE2, (short)(p_225623_6_ & '\uffff'), (short)(p_225623_6_ >> 16 & '\uffff')); - - MCglTF.CURRENT_PROGRAM = GL11.glGetInteger(GL20.GL_CURRENT_PROGRAM); - if(MCglTF.CURRENT_PROGRAM == 0) { - GL13.glActiveTexture(GL13.GL_TEXTURE2); - GL11.glEnable(GL11.GL_TEXTURE_2D); - GL13.glActiveTexture(GL13.GL_TEXTURE0); - vanillaCommands.forEach(Runnable::run); - } - else { - shaderModCommands.forEach(Runnable::run); - } - - GL11.glPopAttrib(); - GL11.glPopMatrix(); + float time = Animation.getWorldTime(p_225623_1_.level, p_225623_3_); + //Play every animation clips simultaneously + for(List animation : animations) { + animation.parallelStream().forEach((channel) -> { + float[] keys = channel.getKeys(); + channel.update(time % keys[keys.length - 1]); + }); + } + + GL11.glPushMatrix(); + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); + + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glShadeModel(GL11.GL_SMOOTH); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glEnable(GL11.GL_COLOR_MATERIAL); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + + RenderSystem.multMatrix(p_225623_4_.last().pose()); + GL11.glRotatef(MathHelper.rotLerp(p_225623_3_, p_225623_1_.yBodyRotO, p_225623_1_.yBodyRot), 0.0F, 1.0F, 0.0F); + + GL13.glMultiTexCoord2s(GL13.GL_TEXTURE2, (short)(p_225623_6_ & '\uffff'), (short)(p_225623_6_ >> 16 & '\uffff')); + + if(MCglTF.getInstance().isShaderModActive()) { + renderedScene.renderForShaderMod(); + } + else { + GL13.glActiveTexture(GL13.GL_TEXTURE2); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL13.glActiveTexture(GL13.GL_TEXTURE0); + renderedScene.renderForVanilla(); } + + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); + GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); + GL30.glBindVertexArray(0); + RenderedGltfModel.nodeGlobalTransformLookup.clear(); + + GL11.glPopAttrib(); + GL11.glPopMatrix(); super.render(p_225623_1_, p_225623_2_, p_225623_3_, p_225623_4_, p_225623_5_, p_225623_6_); } diff --git a/src/main/java/com/timlee9024/mcgltf/example/ExampleItemRenderer.java b/src/main/java/com/timlee9024/mcgltf/example/ExampleItemRenderer.java new file mode 100644 index 0000000..0b63361 --- /dev/null +++ b/src/main/java/com/timlee9024/mcgltf/example/ExampleItemRenderer.java @@ -0,0 +1,124 @@ +package com.timlee9024.mcgltf.example; + +import java.util.ArrayList; +import java.util.List; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; +import org.lwjgl.opengl.GL13; +import org.lwjgl.opengl.GL15; +import org.lwjgl.opengl.GL30; + +import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.systems.RenderSystem; +import com.timlee9024.mcgltf.IGltfModelReceiver; +import com.timlee9024.mcgltf.MCglTF; +import com.timlee9024.mcgltf.RenderedGltfModel; +import com.timlee9024.mcgltf.RenderedGltfScene; +import com.timlee9024.mcgltf.animation.GltfAnimationCreator; +import com.timlee9024.mcgltf.animation.InterpolatedChannel; + +import de.javagl.jgltf.model.AnimationModel; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.model.ItemCameraTransforms; +import net.minecraftforge.client.model.animation.Animation; + +public abstract class ExampleItemRenderer implements IGltfModelReceiver { + + protected RenderedGltfScene renderedScene; + + protected List> animations; + + @Override + public void onReceiveSharedModel(RenderedGltfModel renderedModel) { + renderedScene = renderedModel.renderedGltfScenes.get(0); + List animationModels = renderedModel.gltfModel.getAnimationModels(); + animations = new ArrayList>(animationModels.size()); + for(AnimationModel animationModel : animationModels) { + animations.add(GltfAnimationCreator.createGltfAnimation(animationModel)); + } + } + + public void render(ItemCameraTransforms.TransformType p_239207_2_, MatrixStack p_239207_3_, IRenderTypeBuffer p_239207_4_, int p_239207_5_, int p_239207_6_) { + Minecraft mc = Minecraft.getInstance(); + float time = Animation.getWorldTime(mc.level, Animation.getPartialTickTime()); + //Play every animation clips simultaneously + for(List animation : animations) { + animation.parallelStream().forEach((channel) -> { + float[] keys = channel.getKeys(); + channel.update(time % keys[keys.length - 1]); + }); + } + + GL11.glPushMatrix(); + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); + + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glShadeModel(GL11.GL_SMOOTH); + GL11.glEnable(GL11.GL_COLOR_MATERIAL); + + RenderSystem.multMatrix(p_239207_3_.last().pose()); + + switch(p_239207_2_) { + case THIRD_PERSON_LEFT_HAND: + case THIRD_PERSON_RIGHT_HAND: + case HEAD: + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + + GL13.glMultiTexCoord2s(GL13.GL_TEXTURE1, (short)(p_239207_6_ & '\uffff'), (short)(p_239207_6_ >> 16 & '\uffff')); + GL13.glMultiTexCoord2s(GL13.GL_TEXTURE2, (short)(p_239207_5_ & '\uffff'), (short)(p_239207_5_ >> 16 & '\uffff')); + + if(MCglTF.getInstance().isShaderModActive()) { + renderedScene.renderForShaderMod(); + } + else { + GL13.glActiveTexture(GL13.GL_TEXTURE2); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL13.glActiveTexture(GL13.GL_TEXTURE1); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL13.glActiveTexture(GL13.GL_TEXTURE0); + renderedScene.renderForVanilla(); + } + break; + case FIRST_PERSON_LEFT_HAND: + case FIRST_PERSON_RIGHT_HAND: + case GROUND: + case FIXED: + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + + GL13.glMultiTexCoord2s(GL13.GL_TEXTURE2, (short)(p_239207_5_ & '\uffff'), (short)(p_239207_5_ >> 16 & '\uffff')); + + if(MCglTF.getInstance().isShaderModActive()) { + renderedScene.renderForShaderMod(); + } + else { + GL13.glActiveTexture(GL13.GL_TEXTURE2); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL13.glActiveTexture(GL13.GL_TEXTURE0); + renderedScene.renderForVanilla(); + } + break; + case GUI: + renderedScene.renderForVanilla(); + break; + default: + break; + } + + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); + GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); + GL30.glBindVertexArray(0); + RenderedGltfModel.nodeGlobalTransformLookup.clear(); + + GL11.glPopAttrib(); + GL11.glPopMatrix(); + } + +} diff --git a/src/main/java/com/timlee9024/mcgltf/example/ExampleTileEntityRenderer.java b/src/main/java/com/timlee9024/mcgltf/example/ExampleTileEntityRenderer.java index b054709..bed841b 100644 --- a/src/main/java/com/timlee9024/mcgltf/example/ExampleTileEntityRenderer.java +++ b/src/main/java/com/timlee9024/mcgltf/example/ExampleTileEntityRenderer.java @@ -1,36 +1,38 @@ package com.timlee9024.mcgltf.example; +import java.util.ArrayList; import java.util.List; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; import org.lwjgl.opengl.GL13; -import org.lwjgl.opengl.GL20; +import org.lwjgl.opengl.GL15; +import org.lwjgl.opengl.GL30; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; import com.timlee9024.mcgltf.IGltfModelReceiver; import com.timlee9024.mcgltf.MCglTF; import com.timlee9024.mcgltf.RenderedGltfModel; +import com.timlee9024.mcgltf.RenderedGltfScene; +import com.timlee9024.mcgltf.animation.GltfAnimationCreator; +import com.timlee9024.mcgltf.animation.InterpolatedChannel; -import de.javagl.jgltf.model.GltfAnimations; -import de.javagl.jgltf.model.animation.Animation; +import de.javagl.jgltf.model.AnimationModel; import net.minecraft.block.HorizontalBlock; -import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; +import net.minecraftforge.client.model.animation.Animation; public class ExampleTileEntityRenderer extends TileEntityRenderer implements IGltfModelReceiver { - protected List vanillaCommands; + protected RenderedGltfScene renderedScene; - protected List shaderModCommands; - - protected List animations; + protected List> animations; public ExampleTileEntityRenderer(TileEntityRendererDispatcher p_i226006_1_) { super(p_i226006_1_); @@ -43,72 +45,82 @@ public ResourceLocation getModelLocation() { @Override public void onReceiveSharedModel(RenderedGltfModel renderedModel) { - vanillaCommands = renderedModel.vanillaSceneCommands.get(0); - shaderModCommands = renderedModel.shaderModSceneCommands.get(0); - animations = GltfAnimations.createModelAnimations(renderedModel.gltfModel.getAnimationModels()); + renderedScene = renderedModel.renderedGltfScenes.get(0); + List animationModels = renderedModel.gltfModel.getAnimationModels(); + animations = new ArrayList>(animationModels.size()); + for(AnimationModel animationModel : animationModels) { + animations.add(GltfAnimationCreator.createGltfAnimation(animationModel)); + } } /** - * Since you use custom ISTER for BlockItem instead of TER, the last parameters p_225616_6_ which control overlay color is almost unused. + * Since you use custom ISTER for BlockItem instead of TER to render item form of block, + * the last parameters p_225616_6_ which control overlay color is almost unused. */ @Override public void render(ExampleTileEntity p_225616_1_, float p_225616_2_, MatrixStack p_225616_3_, IRenderTypeBuffer p_225616_4_, int p_225616_5_, int p_225616_6_) { - if(vanillaCommands != null) { - GL11.glPushMatrix(); - GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); - - GL11.glEnable(GL11.GL_LIGHTING); - GL11.glShadeModel(GL11.GL_SMOOTH); - GL11.glEnable(GL12.GL_RESCALE_NORMAL); - GL11.glEnable(GL11.GL_DEPTH_TEST); - GL11.glEnable(GL11.GL_COLOR_MATERIAL); - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - - RenderSystem.multMatrix(p_225616_3_.last().pose()); - World world = p_225616_1_.getLevel(); - if(world != null) { - GL11.glTranslatef(0.5F, 0.0F, 0.5F); //Make sure it is in the center of the block - switch(world.getBlockState(p_225616_1_.getBlockPos()).getOptionalValue(HorizontalBlock.FACING).orElse(Direction.NORTH)) { - case DOWN: - break; - case UP: - break; - case NORTH: - break; - case SOUTH: - GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F); - break; - case WEST: - GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F); - break; - case EAST: - GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F); - break; - } + GL11.glPushMatrix(); + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); + + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glShadeModel(GL11.GL_SMOOTH); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glEnable(GL11.GL_COLOR_MATERIAL); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + + RenderSystem.multMatrix(p_225616_3_.last().pose()); + World world = p_225616_1_.getLevel(); + if(world != null) { + float time = Animation.getWorldTime(world, p_225616_2_); + //Play every animation clips simultaneously + for(List animation : animations) { + animation.parallelStream().forEach((channel) -> { + float[] keys = channel.getKeys(); + channel.update(time % keys[keys.length - 1]); + }); } - Minecraft mc = Minecraft.getInstance(); - for(Animation animation : animations) { - animation.update(net.minecraftforge.client.model.animation.Animation.getWorldTime(mc.level, p_225616_2_) % animation.getEndTimeS()); + GL11.glTranslatef(0.5F, 0.0F, 0.5F); //Make sure it is in the center of the block + switch(world.getBlockState(p_225616_1_.getBlockPos()).getOptionalValue(HorizontalBlock.FACING).orElse(Direction.NORTH)) { + case DOWN: + break; + case UP: + break; + case NORTH: + break; + case SOUTH: + GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F); + break; + case WEST: + GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F); + break; + case EAST: + GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F); + break; } - - GL13.glMultiTexCoord2s(GL13.GL_TEXTURE2, (short)(p_225616_5_ & '\uffff'), (short)(p_225616_5_ >> 16 & '\uffff')); - - MCglTF.CURRENT_PROGRAM = GL11.glGetInteger(GL20.GL_CURRENT_PROGRAM); - if(MCglTF.CURRENT_PROGRAM == 0) { - GL13.glActiveTexture(GL13.GL_TEXTURE2); - GL11.glEnable(GL11.GL_TEXTURE_2D); - GL13.glActiveTexture(GL13.GL_TEXTURE0); - vanillaCommands.forEach(Runnable::run); - } - else { - shaderModCommands.forEach(Runnable::run); - } - - GL11.glPopAttrib(); - GL11.glPopMatrix(); } + + GL13.glMultiTexCoord2s(GL13.GL_TEXTURE2, (short)(p_225616_5_ & '\uffff'), (short)(p_225616_5_ >> 16 & '\uffff')); + + if(MCglTF.getInstance().isShaderModActive()) { + renderedScene.renderForShaderMod(); + } + else { + GL13.glActiveTexture(GL13.GL_TEXTURE2); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL13.glActiveTexture(GL13.GL_TEXTURE0); + renderedScene.renderForVanilla(); + } + + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); + GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); + GL30.glBindVertexArray(0); + RenderedGltfModel.nodeGlobalTransformLookup.clear(); + + GL11.glPopAttrib(); + GL11.glPopMatrix(); } } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 8f6e543..427dda8 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -27,7 +27,7 @@ updateJSONURL="https://raw.githubusercontent.com/TimLee9024/MCglTF-Example/1.16. # A URL for the "homepage" for this mod, displayed in the mod UI displayURL="https://github.com/TimLee9024/MCglTF-Example/tree/1.16.5-Forge/" #optional # A file name (in the root of the mod JAR) containing a logo for display -logoFile="examplemod.png" #optional +logoFile="icon.png" #optional # A text field displayed in the mod UI credits="Microsoft and Cesium, for providing glTF sample models" #optional # A text field displayed in the mod UI @@ -36,3 +36,29 @@ authors="TimLee9024" #optional description=''' Example mod to demonstrate the usage of MCglTF. ''' +# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. +[[dependencies.example_mcgltf_usage]] #optional + # the modid of the dependency + modId="forge" #mandatory + # Does this dependency have to exist - if not, ordering below must be specified + mandatory=true #mandatory + # The version range of the dependency + versionRange="[36,)" #mandatory + # An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory + ordering="NONE" + # Side this dependency is applied on - BOTH, CLIENT or SERVER + side="BOTH" +# Here's another dependency +[[dependencies.example_mcgltf_usage]] + modId="minecraft" + mandatory=true +# This version range declares a minimum of the current minecraft version up to but not including the next major version + versionRange="[1.16.5,1.17)" + ordering="NONE" + side="BOTH" +[[dependencies.example_mcgltf_usage]] + modId="mcgltf" + mandatory=false + versionRange="[1.16.5-Forge-1.1.0.0,)" + ordering="AFTER" + side="CLIENT" diff --git a/src/main/resources/icon.png b/src/main/resources/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..fd6bcb549ba83bb504f1f76538f733cf5566dd62 GIT binary patch literal 3729 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 AzW@LL literal 0 HcmV?d00001 diff --git a/updates.json b/updates.json index 6bac0dc..c206f85 100644 --- a/updates.json +++ b/updates.json @@ -1,12 +1,13 @@ { "homepage": "https://github.com/TimLee9024/MCglTF-Example/releases", "1.16.5": { + "1.16.5-Forge-1.2.0.0": "Update to compatible with MCglTF-1.2.0.0", "1.16.5-Forge-1.1.0.1": "Fix homepage URL and server side item registration", "1.16.5-Forge-1.1.0.0": "Update to work with MCglTF version 1.16.5-Forge-1.1.0.0", "1.16.5-Forge-1.0.0.0": "Initial release" }, "promos": { - "1.16.5-latest": "1.16.5-Forge-1.1.0.1", - "1.16.5-recommended": "1.16.5-Forge-1.1.0.1" + "1.16.5-latest": "1.16.5-Forge-1.2.0.0", + "1.16.5-recommended": "1.16.5-Forge-1.2.0.0" } } \ No newline at end of file