Skip to content

Commit

Permalink
fixed texture flip
Browse files Browse the repository at this point in the history
  • Loading branch information
elalish committed Jan 11, 2024
1 parent 2acefd8 commit 000526b
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/model-viewer/src/three-components/TextureUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

import {GainMapDecoderMaterial, HDRJPGLoader, QuadRenderer} from '@monogrid/gainmap-js';
import {BackSide, BoxGeometry, CubeCamera, CubeTexture, DataTexture, EquirectangularReflectionMapping, HalfFloatType, LinearSRGBColorSpace, Loader, Mesh, NoBlending, NoToneMapping, RGBAFormat, Scene, ShaderMaterial, SRGBColorSpace, Texture, Vector3, WebGLCubeRenderTarget, WebGLRenderer} from 'three';
import {BackSide, BoxGeometry, CubeCamera, CubeTexture, DataTexture, EquirectangularReflectionMapping, HalfFloatType, LinearSRGBColorSpace, Loader, Mesh, NoBlending, NoToneMapping, RGBAFormat, Scene, ShaderMaterial, SRGBColorSpace, Texture, TextureLoader, Vector3, WebGLCubeRenderTarget, WebGLRenderer} from 'three';
import {RGBELoader} from 'three/examples/jsm/loaders/RGBELoader.js';

import {deserializeUrl, timePasses} from '../utilities.js';
Expand All @@ -37,6 +37,7 @@ export default class TextureUtils {
public lottieLoaderUrl = '';
public withCredentials = false;

private _ldrLoader: TextureLoader|null = null;
private _imageLoader: HDRJPGLoader|null = null;
private _hdrLoader: RGBELoader|null = null;
private _lottieLoader: Loader|null = null;
Expand All @@ -52,6 +53,14 @@ export default class TextureUtils {
constructor(private threeRenderer: WebGLRenderer) {
}

get ldrLoader(): TextureLoader {
if (this._ldrLoader == null) {
this._ldrLoader = new TextureLoader();
}
this._ldrLoader.setWithCredentials(this.withCredentials);
return this._ldrLoader;
}

get imageLoader(): HDRJPGLoader {
if (this._imageLoader == null) {
this._imageLoader = new HDRJPGLoader(this.threeRenderer);
Expand Down Expand Up @@ -81,11 +90,8 @@ export default class TextureUtils {

async loadImage(url: string): Promise<Texture> {
const texture: Texture = await new Promise<Texture>(
(resolve, reject) => this.imageLoader.load(url, (result) => {
const {texture} = result.renderTarget;
result.dispose(false);
resolve(texture)
}, () => {}, reject));
(resolve, reject) =>
this.ldrLoader.load(url, resolve, () => {}, reject));
texture.name = url;
texture.flipY = false;

Expand Down

0 comments on commit 000526b

Please sign in to comment.