import {
  TextureLoader,
  ObjectLoader,
} from "three";

import "three/examples/js/loaders/ColladaLoader.js";
import "three/examples/js/loaders/OBJLoader.js";

import Loader from "../utils/Loader.js";

let PROMISES = Loader.promises;

export default class THREELoader {
  static get onLoad() {
    return Loader.onLoad;
  }

  static load(value) {
    let loader;

    if(/\.(png|jpg)$/.test(value)) {
      loader = new TextureLoader();
    }
    else if(/\.(dae)$/.test(value)) {
      loader = new THREE.ColladaLoader();
    }
    else if(/\.(obj)$/.test(value)) {
      loader = new THREE.OBJLoader();
    }
    else if(/\.(json)$/.test(value)) {
      loader = new ObjectLoader();
    }

    let promise = new Promise((resolve) => {
      value = loader.load(value, (data) => {
        PROMISES.delete(value);
        resolve(data);
      });
    });

    PROMISES.set(value, promise);

    return loader instanceof TextureLoader ? value : promise;
  }
}

@@ -35,16 +35,24 @@
 Loader,%0A
+  Mesh,%0A
 %7D from %22
@@ -238,16 +238,861 @@
 mises;%0A%0A
+function fixColladaLoaderData(data) %7B%0A  let meshContainers = %5B%5D;%0A  data.scene.traverse((object3D) =%3E %7B%0A    if(object3D.children%5B0%5D instanceof Mesh) %7B%0A      meshContainers.push(object3D);%0A    %7D%0A    %5Bobject3D.position.y, object3D.position.z%5D = %5Bobject3D.position.z, -object3D.position.y%5D;%0A    %5Bobject3D.rotation.y, object3D.rotation.z%5D = %5Bobject3D.rotation.z, -object3D.rotation.y%5D;%0A    %5Bobject3D.scale.y, object3D.scale.z%5D = %5Bobject3D.scale.z, object3D.scale.y%5D;%0A  %7D);%0A  for (let object3D of meshContainers) %7B%0A    let mesh = object3D.children%5B0%5D;%0A    object3D.remove(mesh);%0A    mesh.name = object3D.name;%0A    mesh.position.copy(object3D.position);%0A    mesh.rotation.copy(object3D.rotation);%0A    mesh.scale.copy(object3D.scale);%0A    mesh.geometry.rotateX(-Math.PI * .5);%0A    object3D.parent.add(mesh);%0A    object3D.parent.remove(object3D);%0A  %7D%0A%7D%0A%0A
 export d
@@ -1211,16 +1211,33 @@
  loader;
+%0A    let texture;
 %0A%0A    if
@@ -1609,20 +1609,22 @@
 %7B%0A      
-valu
+textur
 e = load
@@ -1678,24 +1678,109 @@
 ete(value);%0A
+        if(/%5C.(dae)$/.test(value)) %7B%0A          fixColladaLoaderData(data);%0A        %7D%0A
         reso
@@ -1889,20 +1889,22 @@
 oader ? 
-valu
+textur
 e : prom

add colladaLoader data fix