Skip to content

Commit

Permalink
feat: add cube texture loader
Browse files Browse the repository at this point in the history
  • Loading branch information
Chau Tran authored and Chau Tran committed Apr 3, 2023
1 parent 2af0443 commit 8bee310
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions libs/angular-three-soba/loaders/src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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<string[]>,
path: string
): Observable<THREE.CubeTexture> {
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]));
}

0 comments on commit 8bee310

Please # to comment.