Coder Social home page Coder Social logo

Comments (6)

vpenades avatar vpenades commented on June 12, 2024

Could it be possible to share one of these models?

Without seeing the models I suspect the issue is happening because the materials require more texture uv channels than what the mesh primitives provide

from sharpgltf.

mhwlng avatar mhwlng commented on June 12, 2024

Try this file

https://habufa-res.cloudinary.com/image/upload/v1691148553/bad.glb

with this viewer

https://gltf-viewer.donmccurdy.com/

from sharpgltf.

mhwlng avatar mhwlng commented on June 12, 2024

f.y.i. I edited the first post, because I initially misinterpreted the problem:

It seems that to fix the problem, you need to simply REMOVE "texCoord": 1 from the materials\occlusionTexture in the json

because there is no TEXCOORD_1 defined in any of the mesh primitives

from sharpgltf.

vpenades avatar vpenades commented on June 12, 2024

Well... the model is malformed, and if the library is unable to detect that it is malformed then there's a bug in the validator.

Another thing is if the library should fix it or decide whether the model is fixable.

In this particular case, most probably the material's occlusion requires its own UV channel, because that's how occlusion maps work, so fixing it by using the UVs of channel 0 would cause the occlusion maps to be rendered incorrecly... the only solution, as you mentioned, is to completely remove the occlusion from the materials.

from sharpgltf.

mhwlng avatar mhwlng commented on June 12, 2024

I don't know if this is the best way to do it, but this is how I fixed the .glb file:

for (var i = 0; i < rootObject.LogicalMaterials.Count; i++)
{
  var material = rootObject.LogicalMaterials[i];
  
  var hasOcclusion = material.Channels
  .FirstOrDefault(o => o.Key == "Occlusion" && o.TextureCoordinate > 0).Key != null;
  
  if (hasOcclusion)
  {
    var materialBuilder = material.ToMaterialBuilder();
    materialBuilder.RemoveChannel(KnownChannel.Occlusion);
    materialBuilder.Name = "Repair_" + material.Name;
    
    var newMaterial = rootObject.CreateMaterial(materialBuilder);
    
    foreach (var mesh in rootObject.LogicalMeshes)
    {
      foreach (var meshPrimitive in mesh.Primitives)
      {
        if (meshPrimitive.Material == material)
        {
          meshPrimitive.Material = newMaterial;
        }
      }
    }
  }
}

rootObject.SaveGLB("test.glb", new WriteSettings()
{
  Validation = ValidationMode.TryFix
}
);

Of course, There are now one or more unused materials in the GLB. So, the new GLB file is bigger.

from sharpgltf.

vpenades avatar vpenades commented on June 12, 2024

Yes, right now that would be the way to do it.

from sharpgltf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.