icy3dw/src/client/object/resource/cubemap.ts

29 lines
795 B
TypeScript
Raw Normal View History

2022-04-11 18:11:31 +00:00
import { CubeTextureLoader, CubeTexture } from 'three';
2022-04-16 06:50:46 +00:00
import { LoadingManagerWrapper } from './loading-manager';
2022-04-11 18:11:31 +00:00
2022-04-16 06:50:46 +00:00
const loader = new CubeTextureLoader(
LoadingManagerWrapper.getInstance().manager,
);
2022-04-11 18:11:31 +00:00
export class CubeMap {
constructor(public source: string, public texture: CubeTexture) {}
public static async load(base: string): Promise<CubeMap> {
return new Promise((resolve, reject) =>
loader.load(
[
`${base}/left.png`, // pos-x
`${base}/right.png`, // neg-x
`${base}/top.png`, // pos-y
`${base}/bottom.png`, // neg-y
`${base}/front.png`, // pos-z
`${base}/back.png`, // neg-z
],
(texture) => resolve(new CubeMap(base, texture)),
undefined,
reject,
),
);
}
}