Editor: Missing textures while importing draco
Hello guys, I have following problem:
I am using my cloned repo of editor, in file src/editor/scene/scene-importer.ts I added a method that is being called on menu item click. It is supposed to load compressed draco file (made from obj) and load textures from mtl file. Both are hosted on local server. The point is that the draco file is being loaded without problem but when I try to load texture from mtl this does not affect material at all.
Thanks in advance (Please don’t judge the code itself, it deserves refactor I am not capable of doing right now)
public static async ImportDraco (editor: Editor): Promise<void> {
$('#draco').click();
const files: File[] = await new Promise<File[]>(res => {
$('#draco').on('change', (e: ChangeEvent<HTMLInputElement>) => {
$('#draco').off('change');
const files: File[] = [];
for (let i = 0; i < (e.target.files || []).length; i++) {
files.push(e.target.files[i]);
}
res(files);
});
});
if (files.length == 0) {
return;
}
const fd = new FormData();
fd.append('files', files[0]);
const baseURL = 'http://localhost:5000/';
BABYLON.DracoCompression.Configuration = {
decoder: {
wasmUrl: "https://cdn.jsdelivr.net/gh/google/draco/javascript/draco_decoder.js",
wasmBinaryUrl: "https://cdn.jsdelivr.net/gh/google/draco/javascript/draco_decoder.wasm",
fallbackUrl: "https://cdn.jsdelivr.net/gh/google/draco/javascript/draco_wasm_wrapper.js",
}
};
BABYLON.Tools.LoadFile('http://localhost:5000/tree.drc', async function(data: ArrayBuffer) {
const dracoCompression = new BABYLON.DracoCompression();
const attributes = {
// [BABYLON.VertexBuffer.UVKind]: 'uv',
// [BABYLON.VertexBuffer.NormalKind]: 'normal',
// [BABYLON.VertexBuffer.ColorKind]: 'color',
[BABYLON.VertexBuffer.PositionKind]: 'position'
};
const scene = editor.core.scene as unknown as BABYLON.Scene;
const vertexData = await dracoCompression.decodeMeshAsync(data, attributes as any);
const mesh = new BABYLON.Mesh("dracoMesh", scene);
const geometry = new BABYLON.Geometry("dracoGeometry", scene, vertexData);
geometry.applyToMesh(mesh);
console.log(mesh);
editor.graph.add({
data: mesh,
id: 'tree',
text: 'tree'
}, editor.graph.root);
const mtl = new BABYLON.MTLFileLoader();
const mtlData = await axios.get('/strazky_tree_bright.mtl', {baseURL});
mtl.parseMTL(scene, mtlData.data, baseURL);
mtl.materials[0].backFaceCulling = false;
mesh.material = mtl.materials[0];
console.log(mesh.getBoundingInfo());
scene.addMesh(mesh as any);
}, undefined, undefined, true);
}

About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 18 (10 by maintainers)
Hey! I don’t know anything about draco for now so I’m getting some informations about and have a look asap! 😃