lingo3d
Version:
Lingo3D is a React/Vue 3d game development framework that ships with a complete visual editor
29 lines • 1.4 kB
JavaScript
import { TextureLoader, RepeatWrapping } from "three";
import { forceGet } from "@lincode/utils";
import { handleProgress } from "./utils/bytesLoaded";
import { RGBELoader } from "three/examples/jsm/loaders/RGBELoader.js";
import Events from "@lincode/events";
import { decreaseLoadingAssetsCount, increaseLoadingAssetsCount } from "../../../states/useLoadingAssetsCount";
import { assetsPathPtr } from "../../../pointers/assetsPathPointers";
const cache = new Map();
const textureLoader = new TextureLoader();
const rgbeLoader = new RGBELoader();
const loaded = new Events();
export default (url, onLoad) => {
onLoad && loaded.once(url, () => queueMicrotask(onLoad));
const texture = forceGet(cache, url, () => {
const isAssets = url.startsWith(assetsPathPtr[0]);
isAssets && increaseLoadingAssetsCount();
const hdr = url.toLowerCase().endsWith(".hdr");
const loader = hdr ? rgbeLoader : textureLoader;
return loader.load(url, (texture) => {
texture.wrapS = texture.wrapT = RepeatWrapping;
texture.flipY = texture.userData.flipY ? false : true;
texture.userData.flipped = true;
loaded.setState(url);
isAssets && decreaseLoadingAssetsCount();
}, handleProgress(url));
});
return "isDataTexture" in texture ? texture : texture.clone();
};
//# sourceMappingURL=loadTexture.js.map