Imagem de textura de atualização Three.js
Estou usando o three.js para criar um editor de textura de minecraft, semelhante aoisto. Eu só estou tentando baixar a funcionalidade básica de clicar e pintar, mas não consigo entender. Atualmente, tenho texturas para cada face de cada cubo e aplico-as ao fazer materiais de sombreamento com as seguintes funções.
this.createBodyShaderTexture = function(part, update)
{
sides = ['left', 'right', 'top', 'bottom', 'front', 'back'];
images = [];
for (i = 0; i < sides.length; i++)
{
images[i] = 'img/'+part+'/'+sides[i]+'.png';
}
texCube = new THREE.ImageUtils.loadTextureCube(images);
texCube.magFilter = THREE.NearestFilter;
texCube.minFilter = THREE.LinearMipMapLinearFilter;
if (update)
{
texCube.needsUpdate = true;
console.log(texCube);
}
return texCube;
}
this.createBodyShaderMaterial = function(part, update)
{
shader = THREE.ShaderLib['cube'];
shader.uniforms['tCube'].value = this.createBodyShaderTexture(part, update);
shader.fragmentShader = document.getElementById("fshader").innerHTML;
shader.vertexShader = document.getElementById("vshader").innerHTML;
material = new THREE.ShaderMaterial({fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: shader.uniforms});
return material;
}
SkinApp.prototype.onClick =
function(event)
{
event.preventDefault();
this.change(); //makes texture file a simple red square for testing
this.avatar.remove(this.HEAD);
this.HEAD = new THREE.Mesh(new THREE.CubeGeometry(8, 8, 8), this.createBodyShaderMaterial('head', false));
this.HEAD.position.y = 10;
this.avatar.add(this.HEAD);
this.HEAD.material.needsUpdate = true;
this.HEAD.dynamic = true;
}
Então, quando o usuário clica em qualquer local da malha, o próprio arquivo de textura é atualizado usando a tela. A atualização ocorre, mas a alteração não está aparecendo no navegador, a menos que a página seja atualizada. Eu encontrei muitos exemplos de como alterar a imagem de textura para um novo arquivo, mas não sobre como mostrar alterações no mesmo arquivo de textura durante o tempo de execução, ou mesmo se é possível. Isso é possível e, se não, que alternativas existem?