TimLee9024 / MCglTF

glTF library for Minecraft Modding
MIT License
7 stars 12 forks source link

GLTF Textures not binding #1

Closed Protoxy22 closed 2 years ago

Protoxy22 commented 2 years ago

Hello, I really like your work it's amazing ! I tested yesterday and had missing textures on my model, the console has no errors and I correctly added "extras" with "resourceLocation" in each "images"/"buffer".

Another question, how can I use an embedded .glb without setting this extras parameters and having the textures binded in game ?

Thank you

image

TimLee9024 commented 2 years ago

Did you have properly setup "extras" properties like "baseColorTexture", "normalTexture"... in the materials? https://github.com/TimLee9024/MCglTF-Example/blob/308ea752a5d74f826da20adcf2c42fbeb43c0f29/src/main/resources/assets/mcgltf/models/item/water_bottle.gltf#L158

It will not use default material properties provided by glTF spec, because of the shader pack's special texture packing. For example BSL's SEUS: "baseColorTexture" as albedo map, "normalTexture" as DirectX normal map, "specularTexture" as (R)glossiness/(G)metallic/(B)emissive stregth map https://github.com/TheDuckCow/MCprep/issues/78 BTW: You will need to fix materialGbuffers.glsl in BSL ShaderPack. Detailed tutorial will be avalible in the Wiki page later.

As for .glb, you won't need to setup those extras properties. The embedded resources like images and buffers will be load from uri as usual.

But anyway, I am still dealing with some compatibilty issues with ShaderMod by Optifine. I really should finish documentation before I publish source code and release on curseforge. I am sorry about that...

Protoxy22 commented 2 years ago

Ok thank you very much for your answer.

I think I will use your library to make a new version of my gun mod if I am allowed to.

Actually I have two problems and a suggestion:

I am sorry for If I wrote too many, I am really enthusiast of your work since I'm searching for a library like this for years !

Greets Protoxy

TimLee9024 commented 2 years ago

Hope these answer your questions :)

  1. Did you have mutiple animations in glTF? The example code provided is to play every animation in "animations" simultaneously, you can change to what you want. If this is not the issue, maybe try out the FBX2glTF and convert the .gltf into .glb by VSCode's glTF tools extension. This is the workflow I use, because some exporter seem to have werid problems on exported model. (Previously I use babylon.js glTF exporter for 3ds Max, but it cause game BSOD for unknown reason during early development)

  2. It seem like jglTF allocate indirect ByteBuffer for binary chunk in RawBinaryGltfDataReaderV1 and RawBinaryGltfDataReaderV2 which cause the errors. I forget to testing .glb after recent change made by jglTF few month ago...

  3. It sound like you want a procedural generated animation "C" which is created from last frame of "A" and first frame "B". In theory you can done this in your Renderer class which have implements IGltfModelReceiver like pseudo code below:

    
    protected List<Runnable> commands;

protected List animations;

protected List<NodeModel[]> nodeThatNeedToApplyTransform;

protected List<float[]> transformLastFrameA;

protected List<float[]> transformFirstFrameB;

protected float transitionTime; //This field can be desrialize from "extras" inside everywhere of glTF

@Override public void onModelLoaded(RenderedGltfModel renderedModel) { GltfModel gltfModel = renderedModel.gltfModel; animations = GltfAnimations.createModelAnimations(gltfModel.getAnimationModels());

// Your Code Here: Find the required NodeModel for transformation from gltfModel.getSceneModels()

Animation animA = animations.get(0); //Get Animation A
animA.update(animA.getEndTimeS()); //Set gltfModel's current transformations from Animation A

// Your Code Here: Find every current transform values needed from nodeThatNeedToApplyTransform and "copy" those float array into transformLastFrameA

Animation animB = animations.get(1); //Get Animation B
animB.update(0.0F); //Set gltfModel's current transformations from Animation B

// Your Code Here: Find every current transform values needed from nodeThatNeedToApplyTransform and "copy" those float array into transformFirstFrameB

}

@Override public void render() { // Your Code Here: Based on current time from tick and partial tick or some conditions, // set every NodeModel's transform in nodeThatNeedToApplyTransform with interpolated values from transformLastFrameA, transformFirstFrameB, and transitionTime.

commands.forEach((command) -> command.run()); //Run render command

}

Protoxy22 commented 2 years ago

Thank you very much, I keep you tuned :)

Protoxy22 commented 2 years ago

Hello, I have difficulties registering the shader and the model bakes at the init of mcgltf in 1.18.2 It seems the OpenGL contexts are not accessible at the mod init thread

TimLee9024 commented 2 years ago

This is most likely the answer: https://gist.github.com/50ap5ud5/beebcf056cbdd3c922cc8993689428f4#shader-based-rendering

Minecraft has moved to OpenGL 3.2 Core, which brings with it shader-based rendering.

https://www.khronos.org/opengl/wiki/OpenGL_Context#Context_types

OpenGL version 3.0 introduced the idea of deprecating functionality. Many OpenGL functions were declared deprecated, which means that users should avoid using them because they may be removed from later API versions. OpenGL 3.1 removed almost all of the functionality deprecated in OpenGL 3.0. This includes the Fixed Function Pipeline.

For example, things like GL11.glPushAttrib, GL11.glPopAttrib, GL11.glVertexPointer, glClientActiveTexture from early OpenGL version are no longer available. There will have a lots of internal change made to MCglTF, in order to adapt into new rendering system of Minecraft since 1.17.

Currently, I have no schedule about to porting MCglTF into 1.18.2. (Maybe finish documentations in MCglTF wiki first? Or just waiting Forge and Optifine become more stable as they claim)

BTW: MCglTF is now available on curseforge https://www.curseforge.com/minecraft/mc-mods/mcgltf

Protoxy22 commented 2 years ago

Thank you very much for your detailed answers

Protoxy22 commented 2 years ago

The GLB files loads fine, but the textures (colorMap) still doesn't work (tested in 1.12.2) .glb file (exported from Blender): akm.zip

Preview: https://streamable.com/yml9hd

TimLee9024 commented 2 years ago

Seem like you forgot to add "extras" properties in materials again.

akm_fix.zip Fix

Protoxy22 commented 2 years ago

Ok, I thought it was not necessary, because you said:

As for .glb, you won't need to setup those extras properties. The embedded resources like images and buffers will be load from uri as usual.

Now I understand, materials index (colorMap, normalMap, specularMap) need to be defined manually.

It would be good to find a way to import .glb without this extra parameters, because it's a bit of pain to manually add those.

Suggestion: for example the colorMap index will be automatically took from the default pbrMetallicRoughness if there is no extras parameter set :)

      "pbrMetallicRoughness": {
        "baseColorTexture": {
          "index": 0
        }
      }

Another suggestion is to be able to apply opengl matrix transformation (translation, rotation, scale) for specific NodeModel on the scene when the Runnable of the rendering is triggered, it would help me a lot.

I am sorry if I suggest too much things, I'll try to continue on a fork repo and make pull requests if you want

TimLee9024 commented 2 years ago

Suggestion: for example the colorMap index will be automatically took from if there is no extras parameter set :)

Unfortunately not. There are two reasons:

  1. glTF V1 and glTF V2 have a lot's of different in "materials". You can't not dircetly define those V2 properties into V1 material, it won't pass glTF V1 validator and will not be deserialized by jglTF.
  2. "Normal Map" and "Specular Map" from Optifine/Shader Pack should not directly map to any of glTF V2 PBR texture properties like "normalTexture" and "metallicRoughnessTexture". They have different diffinition in each RGBA channels.

Lastly, glTF seems to encoruge people to put those application-specific properites inside "extras".

Another suggestion is to be able to apply opengl matrix transformation (translation, rotation, scale) for specific NodeModel on the scene when the Runnable of the rendering is triggered, it would help me a lot.

Can you provide me more detailed reason for not using things like NodeModel#setTranslation, NodeModel#setMatrix?

Protoxy22 commented 2 years ago

Because moving the matrix of a node is permanent. With GL calls, it is only moved during the render frame and goes back to the original transform.

Well, I can save the initial transform of each nodes and apply it before the rendering ..

Do you accept donation ? I want to donate you for your amazing work If you want my discord (if you have access): Protoxy#9631

TimLee9024 commented 2 years ago

Because moving the matrix of a node is permanent. With GL calls, it is only moved during the render frame and goes back to the original transform.

But when you want to control a bone(NodeModel) for a skinned mesh, this will not work.

Well, I can save the initial transform of each nodes and apply it before the rendering ..

AFAIK, this is much efficiant than have a OpenGL call. There are a lots of topics on internet talking about reuducing draw calls, that is why Vanilla using MatrixStack instead of glPushMatrix in 1.16.5. Beside, I have done this before in another Unity project when using with GLTFUtility.

Do you accept donation ? I want to donate you for your amazing work

Thank you for your kindness, but I cannot take your money.