-
Notifications
You must be signed in to change notification settings - Fork 1
Add support to load KTX2 compressed texture #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: point-cloud-support
Are you sure you want to change the base?
Add support to load KTX2 compressed texture #1
Conversation
|
I take it that the texture is KTX compressed? What happens when the texture is not KTX compressed? |
|
This is with the original GLTF model (PNG textures): Then loaded the ktx2 compressed textures with glTF Viewer Another thing is the validator of this viewer give warnings about From glTF-Validator {
"uri": "Cube.gltf",
"mimeType": "model/gltf+json",
"validatorVersion": "2.0.0-dev.3.8",
"validatedAt": "2023-12-04T07:22:46.398Z",
"issues": {
"numErrors": 3,
"numWarnings": 2,
"numInfos": 4,
"numHints": 0,
"messages": [
{
"code": "UNSUPPORTED_EXTENSION",
"message": "Cannot validate an extension as it is not supported by the validator: 'KHR_texture_basisu'.",
"severity": 2,
"pointer": "/extensionsUsed/0"
},
{
"code": "VALUE_NOT_IN_LIST",
"message": "Invalid value 'image/ktx2'. Valid values are ('image/jpeg', 'image/png').",
"severity": 1,
"pointer": "/images/0/mimeType"
},
{
"code": "VALUE_NOT_IN_LIST",
"message": "Invalid value 'image/ktx2'. Valid values are ('image/jpeg', 'image/png').",
"severity": 1,
"pointer": "/images/1/mimeType"
},
{
"code": "UNUSED_MESH_TANGENT",
"message": "Tangents are not used because the material has no normal texture.",
"severity": 2,
"pointer": "/meshes/0/primitives/0/attributes/TANGENT"
},
{
"code": "UNUSED_OBJECT",
"message": "This object may be unused.",
"severity": 2,
"pointer": "/images/0"
},
{
"code": "UNUSED_OBJECT",
"message": "This object may be unused.",
"severity": 2,
"pointer": "/images/1"
},
{
"code": "IO_ERROR",
"message": "Resource not found (Cube.bin).",
"severity": 0,
"pointer": "/buffers/0/uri"
},
{
"code": "IO_ERROR",
"message": "Resource not found (Cube_BaseColor.ktx2).",
"severity": 0,
"pointer": "/images/0/uri"
},
{
"code": "IO_ERROR",
"message": "Resource not found (Cube_MetallicRoughness.ktx2).",
"severity": 0,
"pointer": "/images/1/uri"
}
],
"truncated": false
},
"info": {
"version": "2.0",
"generator": "VKTS glTF 2.0 exporter",
"extensionsUsed": [
"KHR_texture_basisu"
],
"extensionsRequired": [
"KHR_texture_basisu"
],
"resources": [
{
"pointer": "/buffers/0",
"mimeType": "application/gltf-buffer",
"storage": "external",
"uri": "Cube.bin"
},
{
"pointer": "/images/0",
"storage": "external",
"uri": "Cube_BaseColor.ktx2"
},
{
"pointer": "/images/1",
"storage": "external",
"uri": "Cube_MetallicRoughness.ktx2"
}
],
"animationCount": 0,
"materialCount": 1,
"hasMorphTargets": false,
"hasSkins": false,
"hasTextures": true,
"hasDefaultScene": true,
"drawCallCount": 1,
"totalVertexCount": 36,
"totalTriangleCount": 12,
"maxUVs": 1,
"maxInfluences": 0,
"maxAttributes": 4
}
} |
|
Ah the gltf itseld seems invalid with 3 errors: Resource not found (Cube.bin) I strongly suspect that's the issue here |
|
Yep, the validator complains, but the three-gltf-viewer could load it. I found what I missed here 7b4c432, it's because I didn't set the texture sampler, I noticed a hint when one of the cube face has the correct texture, but not all the other 5 faces. |
|
So I take it the problem is now fixed? |
|
For this particular context of loading KTX2 texture, yes. For the invalid GLTF format is a bit out of scope as the exported GLTF that I tested here comes from Khronos compressor itself, and likely the online validator is out of date. While with 3D scanner we can change the code, not so much for other exporters. |
|
Can you share the invalid GLTF file with me? |
7b4c432 to
c9eb0e9
Compare
|
Here's a few, but all of these are available from glTF-Sample-Models by compressing it with glTF-Compressor: |
|
Those asset are actually valid with some warnings, it's just I need to drop all the files {
"uri": "BoxTextured.gltf",
"mimeType": "model/gltf+json",
"validatorVersion": "2.0.0-dev.3.8",
"validatedAt": "2023-12-05T08:49:11.406Z",
"issues": {
"numErrors": 0,
"numWarnings": 2,
"numInfos": 2,
"numHints": 0,
"messages": [
{
"code": "UNSUPPORTED_EXTENSION",
"message": "Cannot validate an extension as it is not supported by the validator: 'KHR_texture_basisu'.",
"severity": 2,
"pointer": "/extensionsUsed/0"
},
{
"code": "VALUE_NOT_IN_LIST",
"message": "Invalid value 'image/ktx2'. Valid values are ('image/jpeg', 'image/png').",
"severity": 1,
"pointer": "/images/0/mimeType"
},
{
"code": "UNUSED_OBJECT",
"message": "This object may be unused.",
"severity": 2,
"pointer": "/images/0"
},
{
"code": "IMAGE_UNRECOGNIZED_FORMAT",
"message": "Image format not recognized.",
"severity": 1,
"pointer": "/images/0"
}
],
"truncated": false
},
"info": {
"version": "2.0",
"generator": "COLLADA2GLTF",
"extensionsUsed": [
"KHR_texture_basisu"
],
"extensionsRequired": [
"KHR_texture_basisu"
],
"resources": [
{
"pointer": "/buffers/0",
"mimeType": "application/gltf-buffer",
"storage": "external",
"uri": "BoxTextured0.bin",
"byteLength": 840
},
{
"pointer": "/images/0",
"storage": "external",
"uri": "CesiumLogoFlat.ktx2"
}
],
"animationCount": 0,
"materialCount": 1,
"hasMorphTargets": false,
"hasSkins": false,
"hasTextures": true,
"hasDefaultScene": true,
"drawCallCount": 1,
"totalVertexCount": 24,
"totalTriangleCount": 12,
"maxUVs": 1,
"maxInfluences": 0,
"maxAttributes": 3
}
} |
a14e8dd to
918f429
Compare
* Load Cube with KTX2 compressed texture by default * Assign MTLTexture directly to SCNMaterial diffuse property contents * Detect image mime type when loading KTX2 texture * Add universal framework for libktx
918f429 to
872f8f9
Compare





SCNMaterial