-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to compatible with MCglTF-1.2.0.0
- Loading branch information
1 parent
d11ee95
commit 1942ffa
Showing
11 changed files
with
232 additions
and
146 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
23 changes: 0 additions & 23 deletions
23
src/main/java/com/timlee9024/mcgltf/example/AbstractItemGltfModelReceiver.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
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
105 changes: 105 additions & 0 deletions
105
src/main/java/com/timlee9024/mcgltf/example/ItemRendererExample.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,105 @@ | ||
package com.timlee9024.mcgltf.example; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.lwjgl.opengl.GL11; | ||
import org.lwjgl.opengl.GL15; | ||
import org.lwjgl.opengl.GL30; | ||
|
||
import com.timlee9024.mcgltf.IGltfModelReceiver; | ||
import com.timlee9024.mcgltf.ItemCameraTransformsHelper; | ||
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.minecraftforge.client.model.animation.Animation; | ||
|
||
public abstract class ItemRendererExample implements IGltfModelReceiver { | ||
|
||
protected RenderedGltfScene renderedScene; | ||
|
||
protected List<List<InterpolatedChannel>> animations; | ||
|
||
@Override | ||
public void onReceiveSharedModel(RenderedGltfModel renderedModel) { | ||
renderedScene = renderedModel.renderedGltfScenes.get(0); | ||
List<AnimationModel> animationModels = renderedModel.gltfModel.getAnimationModels(); | ||
animations = new ArrayList<List<InterpolatedChannel>>(animationModels.size()); | ||
for(AnimationModel animationModel : animationModels) { | ||
animations.add(GltfAnimationCreator.createGltfAnimation(animationModel)); | ||
} | ||
} | ||
|
||
public void render() { | ||
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); | ||
GL11.glShadeModel(GL11.GL_SMOOTH); | ||
|
||
float time = Animation.getWorldTime(Minecraft.getMinecraft().world, Animation.getPartialTickTime()); | ||
for(List<InterpolatedChannel> animation : animations) { | ||
animation.parallelStream().forEach((channel) -> { | ||
float[] keys = channel.getKeys(); | ||
channel.update(time % keys[keys.length - 1]); | ||
}); | ||
} | ||
|
||
if(MCglTF.getInstance().isShaderModActive()) { | ||
renderedScene.renderForShaderMod(); | ||
} | ||
else { | ||
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(); | ||
} | ||
|
||
/** | ||
* Require {@link ItemCameraTransformsHelper#registerDummyModelToAccessCurrentTransformTypeForTEISR(net.minecraft.item.Item) ItemCameraTransformsHelper#registerDummyModelToAccessCurrentTransformTypeForTEISR(yourItem)} during | ||
* {@link net.minecraftforge.client.event.ModelRegistryEvent ModelRegistryEvent} to make {@link ItemCameraTransformsHelper#getCurrentTransformType()} work | ||
*/ | ||
public void renderWithItemCameraTransformsHelper() { | ||
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); | ||
GL11.glShadeModel(GL11.GL_SMOOTH); | ||
|
||
float time = Animation.getWorldTime(Minecraft.getMinecraft().world, Animation.getPartialTickTime()); | ||
//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]); | ||
}); | ||
} | ||
|
||
switch(ItemCameraTransformsHelper.getCurrentTransformType()) { | ||
case GUI: | ||
GL11.glEnable(GL11.GL_LIGHTING); | ||
renderedScene.renderForVanilla(); | ||
break; | ||
default: | ||
if(MCglTF.getInstance().isShaderModActive()) { | ||
renderedScene.renderForShaderMod(); | ||
} | ||
else { | ||
renderedScene.renderForVanilla(); | ||
} | ||
break; | ||
} | ||
|
||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); | ||
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); | ||
GL30.glBindVertexArray(0); | ||
RenderedGltfModel.nodeGlobalTransformLookup.clear(); | ||
|
||
GL11.glPopAttrib(); | ||
} | ||
|
||
} |
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.