I am trying to make ShaderMaterial work with a compressed model.
Here is how I compress the model:
npx gltfpack -i model.gltf -o model.glb -kn -at 24 -ar 16 -as 24 -ac -af 60 -cc
Here is how it looks for not-compressed and compressed models:
It works with other types of materials.
Does anyone have any ideas as to the cause and possible solutions? Many thanks for considering my request.
Code snippet:
const loader = new GLTFLoader();
loader.setMeshoptDecoder(MeshoptDecoder);
const textureLoader = new THREE.TextureLoader();
const map = textureLoader.load("assets/fox/Texture.png");
map.colorSpace = THREE.SRGBColorSpace;
map.encoding = THREE.sRGBEncoding;
map.flipY = false;
loader.load("assets/fox/model_compressed.gltf", function (gltf) {
const model = gltf.scene.children[0];
const mesh = gltf.scene.getObjectByName("mesh_0");
const modelMaterial = mesh.material;
map.repeat.copy(modelMaterial.map.repeat);
map.offset.copy(modelMaterial.map.offset);
map.needsUpdate = true;
const shader = SubsurfaceScatteringShader;
const uniforms = THREE.UniformsUtils.clone(shader.uniforms);
uniforms["map"].value = map;
const material = new THREE.ShaderMaterial({
uniforms: uniforms,
vertexShader: shader.vertexShader,
fragmentShader: shader.fragmentShader,
lights: true,
});
material.map = map;
material.needsUpdate = true;
mesh.material = material;
scene.add(model);
});
Sandbox:
https://codesandbox.io/p/sandbox/compressed-model-with-shadermaterial-cf52j8