Skip to content
This repository was archived by the owner on Mar 8, 2025. It is now read-only.

Commit 0f77961

Browse files
Update multiple viewers
1 parent ee84725 commit 0f77961

File tree

3 files changed

+28
-40
lines changed

3 files changed

+28
-40
lines changed

viewers/templates/ASSIMP Viewer.html

+3-4
Original file line numberDiff line numberDiff line change
@@ -1959,13 +1959,14 @@
19591959
mouse_wheel = true;
19601960

19611961
let image_name = (document.getElementById('file_image_input').value).toUpperCase();
1962+
let svg = (image_name.endsWith('.SVG') === true && navigator.userAgent.indexOf('Safari') > -1);
19621963
let exr = (image_name.endsWith( '.EXR' ) === true);
19631964
let hdr = (image_name.endsWith( '.HDR' ) === true);
19641965
let hd = (exr === true || hdr === true);
19651966

19661967
let clone;
19671968

1968-
if (bg_flip === true) {
1969+
if ((bg_flip === true && svg === false) || (bg_flip === false && svg === true)) {
19691970
const options = { imageOrientation: 'flipY' };
19701971
const imageBitmap = await createImageBitmap( scene_bgnd.image, options );
19711972
clone = new THREE.CanvasTexture( imageBitmap );
@@ -2256,8 +2257,6 @@
22562257
const res = (isMobile === true ? M2K : (isNewiPad === true ? I8K : D16K));
22572258

22582259
if (fii.type.startsWith('image/') && ! (exclude_extensions.some( ext => fn_uc.endsWith( ext ) ))) {
2259-
let svg = (fn_uc.endsWith('.SVG') === true && navigator.userAgent.indexOf('Safari') > -1);
2260-
22612260
texture_loader.load( URL.createObjectURL( fii ) , async function( texture ) {
22622261
URL.revokeObjectURL( fii );
22632262

@@ -2274,7 +2273,7 @@
22742273
}
22752274

22762275
// Get canvas texture with bitmap image
2277-
texture = await resize_texture( texture, res, (svg === true), fii.type );
2276+
texture = await resize_texture( texture, res, false, fii.type );
22782277

22792278
hdrjpg_texture = false;
22802279

viewers/templates/GLTF Viewer.html

+22-32
Original file line numberDiff line numberDiff line change
@@ -1869,13 +1869,14 @@
18691869
mouse_wheel = true;
18701870

18711871
let image_name = (document.getElementById('file_image_input').value).toUpperCase();
1872+
let svg = (image_name.endsWith('.SVG') === true && navigator.userAgent.indexOf('Safari') > -1);
18721873
let exr = (image_name.endsWith( '.EXR' ) === true);
18731874
let hdr = (image_name.endsWith( '.HDR' ) === true);
18741875
let hd = (exr === true || hdr === true);
18751876

18761877
let clone;
18771878

1878-
if (bg_flip === true) {
1879+
if ((bg_flip === true && svg === false) || (bg_flip === false && svg === true)) {
18791880
const options = { imageOrientation: 'flipY' };
18801881
const imageBitmap = await createImageBitmap( scene_bgnd.image, options );
18811882
clone = new THREE.CanvasTexture( imageBitmap );
@@ -2168,8 +2169,6 @@
21682169
const res = (isMobile === true ? M2K : (isNewiPad === true ? I8K : D16K));
21692170

21702171
if (fii.type.startsWith('image/') && ! (exclude_extensions.some( ext => fn_uc.endsWith( ext ) ))) {
2171-
let svg = (fn_uc.endsWith('.SVG') === true && navigator.userAgent.indexOf('Safari') > -1);
2172-
21732172
texture_loader.load( URL.createObjectURL( fii ) , async function( texture ) {
21742173
URL.revokeObjectURL( fii );
21752174

@@ -2187,7 +2186,6 @@
21872186

21882187
// Get canvas texture with bitmap image
21892188
texture = await resize_texture( texture, res, false, fii.type );
2190-
if (svg === true) texture.flipY = false;
21912189

21922190
hdrjpg_texture = false;
21932191

@@ -2269,47 +2267,39 @@
22692267
URL.revokeObjectURL( fii );
22702268
});
22712269
} else if (fn_uc.endsWith('.KTX2')) {
2272-
try {
2273-
ktx2_loader.load( URL.createObjectURL( fii ), async function( texture ) {
2274-
URL.revokeObjectURL( fii );
2275-
2276-
// Unsupported KTX2 formats might log a warning
2270+
ktx2_loader.load( URL.createObjectURL( fii ), async function( texture ) {
2271+
URL.revokeObjectURL( fii );
22772272

2278-
if (texture.colorSpace === 'display-p3') texture.colorSpace === 'srgb';
2273+
// Unsupported KTX2 formats might log a warning
22792274

2280-
// Get canvas texture with bitmap image
2275+
if (texture.colorSpace === 'display-p3') texture.colorSpace === 'srgb';
22812276

2282-
if (texture.isCompressedTexture) {
2283-
texture = await decompress( texture );
2284-
texture = await resize_texture( texture, res, true, 'image/ktx2' );
2285-
} else {
2286-
texture = await resize_texture( texture, res, false, 'image/ktx2' );
2287-
}
2277+
// Get canvas texture with bitmap image
22882278

2289-
hdrjpg_texture = false;
2279+
if (texture.isCompressedTexture) {
2280+
texture = await decompress( texture );
2281+
texture = await resize_texture( texture, res, true, 'image/ktx2' );
2282+
} else {
2283+
texture = await resize_texture( texture, res, false, 'image/ktx2' );
2284+
}
22902285

2291-
if (scene_bgnd !== null) scene_bgnd.dispose();
2292-
scene_bgnd = texture.clone();
2293-
await set_bgnd();
2286+
hdrjpg_texture = false;
22942287

2295-
texture.dispose();
2288+
if (scene_bgnd !== null) scene_bgnd.dispose();
2289+
scene_bgnd = texture.clone();
2290+
await set_bgnd();
22962291

2297-
set_bgenv_message( true );
2298-
}, function ( xhr ) { // onProgress
2299-
}, function ( error ) { // onError
2300-
document.getElementById('div_message').innerText = 'Error loading image: ' + error.message;
2301-
console.log( 'Error loading Background Image File!' );
2302-
console.log( error );
2292+
texture.dispose();
23032293

2304-
URL.revokeObjectURL( fii );
2305-
});
2306-
} catch ( error ) {
2294+
set_bgenv_message( true );
2295+
}, function ( xhr ) { // onProgress
2296+
}, function ( error ) { // onError
23072297
document.getElementById('div_message').innerText = 'Error loading image: ' + error.message;
23082298
console.log( 'Error loading Background Image File!' );
23092299
console.log( error );
23102300

23112301
URL.revokeObjectURL( fii );
2312-
}
2302+
});
23132303
} else if (fn_uc.endsWith('.EXR') || fn_uc.endsWith('.HDR')) {
23142304
const hd_loader = fn_uc.endsWith('.EXR') ? exr_loader : rgbe_loader;
23152305

viewers/templates/GLTFS Viewer.html

+3-4
Original file line numberDiff line numberDiff line change
@@ -1924,13 +1924,14 @@
19241924
mouse_wheel = true;
19251925

19261926
let image_name = (document.getElementById('file_image_input').value).toUpperCase();
1927+
let svg = (image_name.endsWith('.SVG') === true && navigator.userAgent.indexOf('Safari') > -1);
19271928
let exr = (image_name.endsWith( '.EXR' ) === true);
19281929
let hdr = (image_name.endsWith( '.HDR' ) === true);
19291930
let hd = (exr === true || hdr === true);
19301931

19311932
let clone;
19321933

1933-
if (bg_flip === true) {
1934+
if ((bg_flip === true && svg === false) || (bg_flip === false && svg === true)) {
19341935
const options = { imageOrientation: 'flipY' };
19351936
const imageBitmap = await createImageBitmap( scene_bgnd.image, options );
19361937
clone = new THREE.CanvasTexture( imageBitmap );
@@ -2220,8 +2221,6 @@
22202221
const res = (isMobile === true ? M2K : (isNewiPad === true ? I8K : D16K));
22212222

22222223
if (fii.type.startsWith('image/') && ! (exclude_extensions.some( ext => fn_uc.endsWith( ext ) ))) {
2223-
let svg = (fn_uc.endsWith('.SVG') === true && navigator.userAgent.indexOf('Safari') > -1);
2224-
22252224
texture_loader.load( URL.createObjectURL( fii ) , async function( texture ) {
22262225
URL.revokeObjectURL( fii );
22272226

@@ -2238,7 +2237,7 @@
22382237
}
22392238

22402239
// Get canvas texture with bitmap image
2241-
texture = await resize_texture( texture, res, (svg === true), fii.type );
2240+
texture = await resize_texture( texture, res, false, fii.type );
22422241

22432242
if (scene_bgnd !== null) scene_bgnd.dispose();
22442243
scene_bgnd = texture.clone();

0 commit comments

Comments
 (0)