I’m reading a binary file that contains mesh and textures in js. The file structure is like the following:
1.binaryMesh
1.binayTexture
2.BinaryMesh
2.BinaryTexture
If my file contains only one mesh/texture there is no problem. My code is working well, I can create a mesh with texture successfully. But if I want to create multiple meshes and texture sequentially my textures fail.
To understand easily, I go through the conversion parts and simply add the code below.
for(var i=0; i<frameNumber; i++)
...
...
console.log("for");
var drcMesh = reader.result.slice(offset,offset+myNumber);
allTextures.push(url);
dracoLoader.decodeDracoFile(drcMesh, function(bufferGeometry) {
tI++;
var textureLoader = new THREE.TextureLoader();
textureLoader.load(allTextures[tI],function(texture){
var material = new THREE.MeshBasicMaterial({map:texture});
var geometry;
geometry = new THREE.Mesh(bufferGeometry, material);
}
meshes.push(geometry);
}
First problem is dracoLoader.decodeDracoFile
. The for loop is working well reading first mesh then reading texture but then dracoLoader.decodeDracoFile(drcMesh, function(bufferGeometry) is working after the for ended.
I mean; if my number frame is 2
output:
for
for
decodeDracoFile
decodeDracoFile
And results:
Sometimes, it can create meshes with textures
But sometimes, fails :