uinosoft / t3d.js

ThingJS 3D Engine (t3d) is a lightweight, web-first, and extendable 3D rendering library.
BSD 3-Clause "New" or "Revised" License
184 stars 23 forks source link

KTX2 textures loading black #24

Closed VanderSP closed 7 months ago

VanderSP commented 7 months ago

Im one week stopped because i can´t load test ktx2, it parses black...

I packed a rspack project with both t3d and threejs tests

Thanks in advance (please help me!!!)

TestProject.zip

shawn0326 commented 7 months ago

I've successfully reproduced the bug and I'm now working on a solution.

shawn0326 commented 7 months ago

It’s just that the interface usage of t3d is different. ktx2Loader returns Object instead of Texture2D instance. KTX2Loader needs to be used like this:

ktx2Loader.load('1.ktx2', (data) => {
  const texture = new t3d.Texture2D();
  const { image, mipmaps, type, format, minFilter, magFilter, generateMipmaps, encoding, premultiplyAlpha } = data;
  texture.image = image;
  texture.mipmaps = mipmaps;
  texture.type = type;
  texture.format = format;
  texture.minFilter = minFilter;
  texture.magFilter = magFilter;
  texture.generateMipmaps = generateMipmaps;
  texture.encoding = encoding;
  texture.premultiplyAlpha = premultiplyAlpha;

  material.diffuseMap = texture;
  material.needsUpdate = true;
});

I originally wanted to make a pure texture data downloader, but currently it seems that it will cause confusion in use~ However, this is another topic and this issues is closed.