three#TextureLoader TypeScript Examples
The following examples show how to use
three#TextureLoader.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UIPackage.ts From FairyGUI-threejs with MIT License | 6 votes |
function loadTexture(pi: PackageItem, onProgress?: (event: ProgressEvent) => void): Promise<void> {
return new Promise((resolve, reject) => {
new TextureLoader().load(pi.file,
texture => {
texture.generateMipmaps = false;
texture.magFilter = LinearFilter;
texture.minFilter = LinearFilter;
pi.texture = new NTexture(texture);
resolve();
},
onProgress,
ev => {
reject(ev.message);
});
});
}
Example #2
Source File: Arrow.tsx From spacesvr with MIT License | 6 votes |
export function Arrow(props: ArrowProps) {
const { dark, ...rest } = props;
const texture = useLoader(TextureLoader, dark ? IMAGE_SRC_DARK : IMAGE_SRC);
return (
<group name="spacesvr-arrow" {...rest}>
<mesh scale={0.004}>
<planeBufferGeometry attach="geometry" args={[98, 51]} />
<meshStandardMaterial
map={texture}
attach="material"
alphaTest={0.5}
transparent={true}
normalMap={texture}
/>
</mesh>
</group>
);
}
Example #3
Source File: useTextures.ts From trois with MIT License | 6 votes |
export default function useTextures(): TexturesInterface {
const obj: TexturesInterface = {
loader: new TextureLoader(),
count: 0,
textures: [],
loadProgress: 0,
loadTextures,
dispose,
}
return obj
function loadTextures(images: TextureConfigInterface[], cb: {() : void}) {
obj.count = images.length
obj.textures.splice(0)
obj.loadProgress = 0
Promise.all(images.map(loadTexture)).then(cb)
}
function loadTexture(img: TextureConfigInterface, index: number) {
return new Promise(resolve => {
obj.loader.load(
img.src,
texture => {
obj.loadProgress += 1 / obj.count
obj.textures[index] = texture
resolve(texture)
}
)
})
}
function dispose() {
obj.textures.forEach(t => t.dispose())
}
}
Example #4
Source File: GLoader.ts From FairyGUI-threejs with MIT License | 5 votes |
protected loadExternal(): void {
let url = this._url;
new TextureLoader().load(this._url, tex => {
if (url == this._url)
this.onExternalLoadSuccess(new NTexture(tex));
});
}