From 8bee3107756251ecb9203c6915678c26be4cadd6 Mon Sep 17 00:00:00 2001 From: Chau Tran Date: Mon, 3 Apr 2023 00:44:59 -0500 Subject: [PATCH] feat: add cube texture loader --- libs/angular-three-soba/loaders/src/index.ts | 1 + .../cube-texture-loader/cube-texture-loader.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 libs/angular-three-soba/loaders/src/lib/cube-texture-loader/cube-texture-loader.ts diff --git a/libs/angular-three-soba/loaders/src/index.ts b/libs/angular-three-soba/loaders/src/index.ts index 885c06a..3072d32 100644 --- a/libs/angular-three-soba/loaders/src/index.ts +++ b/libs/angular-three-soba/loaders/src/index.ts @@ -1,3 +1,4 @@ +export * from './lib/cube-texture-loader/cube-texture-loader'; export * from './lib/gltf-loader/gltf-loader'; export * from './lib/loader/loader'; export * from './lib/progress/progress'; diff --git a/libs/angular-three-soba/loaders/src/lib/cube-texture-loader/cube-texture-loader.ts b/libs/angular-three-soba/loaders/src/lib/cube-texture-loader/cube-texture-loader.ts new file mode 100644 index 0000000..ab1db7a --- /dev/null +++ b/libs/angular-three-soba/loaders/src/lib/cube-texture-loader/cube-texture-loader.ts @@ -0,0 +1,16 @@ +import { injectNgtLoader } from 'angular-three'; +import { isObservable, map, Observable, of } from 'rxjs'; +import * as THREE from 'three'; + +export function injectCubeTextureLoader( + files: string[] | Observable, + path: string +): Observable { + const inputs$ = isObservable(files) ? files.pipe(map((f) => [f])) : of([files]); + return injectNgtLoader( + () => THREE.CubeTextureLoader, + // @ts-expect-error CubeTexture accepts a string[] and pass into loader as [[...]] + inputs$, + (loader) => loader.setPath(path) + ).pipe(map((textures) => (textures as THREE.CubeTexture[])[0])); +}