Comments (6)
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.
Try this file
https://habufa-res.cloudinary.com/image/upload/v1691148553/bad.glb
with this viewer
https://gltf-viewer.donmccurdy.com/
from sharpgltf.
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.
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.
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.
Yes, right now that would be the way to do it.
from sharpgltf.
Related Issues (20)
- [QUESTION] Could you please help me with fixing the model viewer rendering issue in the code? HOT 5
- [BUG] Accessors with sparse storage but without bufferView fail validation HOT 2
- [Feature Request] Only material file HOT 2
- [QUESTION] Is there a more propper way to generate a mesh which contains primitives that have different vertex fragment types? HOT 3
- [QUESTION] Any reason morph targets count is sometimes 0 on a mesh? HOT 6
- Reflection Problems for Trimming HOT 15
- AttenuationDistance incorrect default value HOT 1
- [BUG] Extras data lost during load HOT 3
- Satellite image file name incorrect when the gltf file contains extra dot HOT 1
- [Question] Vertex Normals HOT 1
- [Feature request] Export image with its name rather than just the GLTF's name + number HOT 1
- Automaticaly Generate Normals HOT 1
- Expose accessor bounds
- FileLoadException in Navisworks plug-in HOT 3
- [enhancement] make LogicalBufferIndex field public in file gltf.BufferView.cs
- Use generated C# files from CodeGen HOT 6
- [Question] Mesh Vertex with UVW are exploded HOT 2
- CodeGen Tool generates JsonNode not the object itself HOT 1
- No tag for the alpha0031 release from nuget.org HOT 2
- [Questions] Some questions regarding correct procedure for reading HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sharpgltf.