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

Commit bf50c49

Browse files
Update multiple viewers
1 parent 5967afd commit bf50c49

File tree

12 files changed

+486
-48
lines changed

12 files changed

+486
-48
lines changed

viewers/templates/3DM Viewer.html

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,22 +1835,57 @@
18351835

18361836
URL.revokeObjectURL( fii );
18371837
});
1838-
} else if (fn_uc.endsWith('.KTX2') || fn_uc.endsWith('.SVG')) {
1839-
let loader = fn_uc.endsWith('.KTX2') ? ktx2_loader : texture_loader;
1838+
} else if (fn_uc.endsWith('.KTX2')) {
1839+
const { decompress } = await import( 'three/addons/utils/WebGLTextureUtils.min.js' );
18401840

1841-
loader.load( URL.createObjectURL( fii ) , function( texture ) {
1841+
ktx2_loader.load( URL.createObjectURL( fii ), async function( texture ) {
18421842
URL.revokeObjectURL( fii );
18431843

1844-
if (document.getElementById('equi').checked) {
1844+
// Convert to PNG so it shows on most platforms
1845+
// Unsupported KTX2 formats might log a warning
1846+
1847+
texture.colorSpace = THREE.SRGBColorSpace;
1848+
1849+
let canvas_tex = await decompress( texture );
1850+
1851+
texture.dispose();
1852+
1853+
texture_loader.load( canvas_tex.image.toDataURL( 'image/png', 1 ), function( png_tex ) {
1854+
canvas_tex.dispose();
1855+
1856+
png_tex.flipY = false;
1857+
1858+
if (equi_enabled === true) {
1859+
png_tex.mapping = THREE.EquirectangularReflectionMapping;
1860+
scene.background = png_tex.clone();
1861+
scene.environment = png_tex.clone();
1862+
} else {
1863+
scene.background = png_tex.clone();
1864+
}
1865+
1866+
mouse_wheel = true;
1867+
1868+
png_tex.dispose();
1869+
1870+
set_bgenv_message( true );
1871+
});
1872+
}, function ( xhr ) { // onProgress
1873+
}, function ( error ) { // onError
1874+
URL.revokeObjectURL( fi.files[ i ] );
1875+
handle_error( error );
1876+
});
1877+
} else if (fn_uc.endsWith('.SVG')) {
1878+
texture_loader.load( URL.createObjectURL( fii ) , function( texture ) {
1879+
URL.revokeObjectURL( fii );
1880+
1881+
if (equi_enabled === true) {
18451882
texture.mapping = THREE.EquirectangularReflectionMapping;
18461883
scene.background = texture.clone();
18471884
scene.environment = texture.clone();
18481885
} else {
18491886
scene.background = texture.clone();
18501887
}
18511888

1852-
texture.needsUpdate = true;
1853-
18541889
mouse_wheel = true;
18551890

18561891
texture.dispose();

viewers/templates/3DS Viewer.html

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,22 +1766,57 @@
17661766

17671767
URL.revokeObjectURL( fii );
17681768
});
1769-
} else if (fn_uc.endsWith('.KTX2') || fn_uc.endsWith('.SVG')) {
1770-
let loader = fn_uc.endsWith('.KTX2') ? ktx2_loader : texture_loader;
1769+
} else if (fn_uc.endsWith('.KTX2')) {
1770+
const { decompress } = await import( 'three/addons/utils/WebGLTextureUtils.min.js' );
17711771

1772-
loader.load( URL.createObjectURL( fii ) , function( texture ) {
1772+
ktx2_loader.load( URL.createObjectURL( fii ), async function( texture ) {
17731773
URL.revokeObjectURL( fii );
17741774

1775-
if (document.getElementById('equi').checked) {
1775+
// Convert to PNG so it shows on most platforms
1776+
// Unsupported KTX2 formats might log a warning
1777+
1778+
texture.colorSpace = THREE.SRGBColorSpace;
1779+
1780+
let canvas_tex = await decompress( texture );
1781+
1782+
texture.dispose();
1783+
1784+
texture_loader.load( canvas_tex.image.toDataURL( 'image/png', 1 ), function( png_tex ) {
1785+
canvas_tex.dispose();
1786+
1787+
png_tex.flipY = false;
1788+
1789+
if (equi_enabled === true) {
1790+
png_tex.mapping = THREE.EquirectangularReflectionMapping;
1791+
scene.background = png_tex.clone();
1792+
scene.environment = png_tex.clone();
1793+
} else {
1794+
scene.background = png_tex.clone();
1795+
}
1796+
1797+
mouse_wheel = true;
1798+
1799+
png_tex.dispose();
1800+
1801+
set_bgenv_message( true );
1802+
});
1803+
}, function ( xhr ) { // onProgress
1804+
}, function ( error ) { // onError
1805+
URL.revokeObjectURL( fi.files[ i ] );
1806+
handle_error( error );
1807+
});
1808+
} else if (fn_uc.endsWith('.SVG')) {
1809+
texture_loader.load( URL.createObjectURL( fii ) , function( texture ) {
1810+
URL.revokeObjectURL( fii );
1811+
1812+
if (equi_enabled === true) {
17761813
texture.mapping = THREE.EquirectangularReflectionMapping;
17771814
scene.background = texture.clone();
17781815
scene.environment = texture.clone();
17791816
} else {
17801817
scene.background = texture.clone();
17811818
}
17821819

1783-
texture.needsUpdate = true;
1784-
17851820
mouse_wheel = true;
17861821

17871822
texture.dispose();

viewers/templates/3MF Viewer.html

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,17 +1799,53 @@
17991799

18001800
URL.revokeObjectURL( fii );
18011801
});
1802-
} else if (fn_uc.endsWith('.KTX2') || fn_uc.endsWith('.SVG')) {
1803-
let loader = fn_uc.endsWith('.KTX2') ? ktx2_loader : texture_loader;
1802+
} else if (fn_uc.endsWith('.KTX2')) {
1803+
const { decompress } = await import( 'three/addons/utils/WebGLTextureUtils.min.js' );
18041804

1805-
loader.load( URL.createObjectURL( fii ) , function( texture ) {
1805+
ktx2_loader.load( URL.createObjectURL( fii ), async function( texture ) {
18061806
URL.revokeObjectURL( fii );
18071807

1808-
if (document.getElementById('equi').checked) {
1808+
// Convert to PNG so it shows on most platforms
1809+
// Unsupported KTX2 formats might log a warning
1810+
1811+
texture.colorSpace = THREE.SRGBColorSpace;
1812+
1813+
let canvas_tex = await decompress( texture );
1814+
1815+
texture.dispose();
1816+
1817+
texture_loader.load( canvas_tex.image.toDataURL( 'image/png', 1 ), function( png_tex ) {
1818+
canvas_tex.dispose();
1819+
1820+
png_tex.flipY = false;
1821+
1822+
if (equi_enabled === true) {
1823+
png_tex.mapping = THREE.EquirectangularReflectionMapping;
1824+
scene.background = png_tex.clone();
1825+
scene.environment = png_tex.clone();
1826+
} else {
1827+
scene.background = png_tex.clone();
1828+
}
1829+
1830+
mouse_wheel = true;
1831+
1832+
png_tex.dispose();
1833+
1834+
set_bgenv_message( true );
1835+
});
1836+
}, function ( xhr ) { // onProgress
1837+
}, function ( error ) { // onError
1838+
URL.revokeObjectURL( fi.files[ i ] );
1839+
handle_error( error );
1840+
});
1841+
} else if (fn_uc.endsWith('.SVG')) {
1842+
texture_loader.load( URL.createObjectURL( fii ) , function( texture ) {
1843+
URL.revokeObjectURL( fii );
1844+
1845+
if (equi_enabled === true) {
18091846
texture.mapping = THREE.EquirectangularReflectionMapping;
18101847
scene.background = texture.clone();
18111848
scene.environment = texture.clone();
1812-
if (params.setEnvMap === true) set_envMap( true );
18131849
} else {
18141850
scene.background = texture.clone();
18151851
}

viewers/templates/AMF Viewer.html

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,17 +1644,53 @@
16441644

16451645
URL.revokeObjectURL( fii );
16461646
});
1647-
} else if (fn_uc.endsWith('.KTX2') || fn_uc.endsWith('.SVG')) {
1648-
let loader = fn_uc.endsWith('.KTX2') ? ktx2_loader : texture_loader;
1647+
} else if (fn_uc.endsWith('.KTX2')) {
1648+
const { decompress } = await import( 'three/addons/utils/WebGLTextureUtils.min.js' );
16491649

1650-
loader.load( URL.createObjectURL( fii ) , function( texture ) {
1650+
ktx2_loader.load( URL.createObjectURL( fii ), async function( texture ) {
1651+
URL.revokeObjectURL( fii );
1652+
1653+
// Convert to PNG so it shows on most platforms
1654+
// Unsupported KTX2 formats might log a warning
1655+
1656+
texture.colorSpace = THREE.SRGBColorSpace;
1657+
1658+
let canvas_tex = await decompress( texture );
1659+
1660+
texture.dispose();
1661+
1662+
texture_loader.load( canvas_tex.image.toDataURL( 'image/png', 1 ), function( png_tex ) {
1663+
canvas_tex.dispose();
1664+
1665+
png_tex.flipY = false;
1666+
1667+
if (equi_enabled === true) {
1668+
png_tex.mapping = THREE.EquirectangularReflectionMapping;
1669+
scene.background = png_tex.clone();
1670+
scene.environment = png_tex.clone();
1671+
} else {
1672+
scene.background = png_tex.clone();
1673+
}
1674+
1675+
mouse_wheel = true;
1676+
1677+
png_tex.dispose();
1678+
1679+
set_bgenv_message( true );
1680+
});
1681+
}, function ( xhr ) { // onProgress
1682+
}, function ( error ) { // onError
1683+
URL.revokeObjectURL( fi.files[ i ] );
1684+
handle_error( error );
1685+
});
1686+
} else if (fn_uc.endsWith('.SVG')) {
1687+
texture_loader.load( URL.createObjectURL( fii ) , function( texture ) {
16511688
URL.revokeObjectURL( fii );
16521689

16531690
if (equi_enabled === true) {
16541691
texture.mapping = THREE.EquirectangularReflectionMapping;
16551692
scene.background = texture.clone();
16561693
scene.environment = texture.clone();
1657-
if (params.setEnvMap === true) set_envMap( true );
16581694
} else {
16591695
scene.background = texture.clone();
16601696
}

viewers/templates/ASSIMP Viewer.html

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,10 +1914,47 @@
19141914

19151915
URL.revokeObjectURL( fii );
19161916
});
1917-
} else if (fn_uc.endsWith('.KTX2') || fn_uc.endsWith('.SVG')) {
1918-
let loader = fn_uc.endsWith('.KTX2') ? ktx2_loader : texture_loader;
1917+
} else if (fn_uc.endsWith('.KTX2')) {
1918+
const { decompress } = await import( 'three/addons/utils/WebGLTextureUtils.min.js' );
19191919

1920-
loader.load( URL.createObjectURL( fii ) , function( texture ) {
1920+
ktx2_loader.load( URL.createObjectURL( fii ), async function( texture ) {
1921+
URL.revokeObjectURL( fii );
1922+
1923+
// Convert to PNG so it shows on most platforms
1924+
// Unsupported KTX2 formats might log a warning
1925+
1926+
texture.colorSpace = THREE.SRGBColorSpace;
1927+
1928+
let canvas_tex = await decompress( texture );
1929+
1930+
texture.dispose();
1931+
1932+
texture_loader.load( canvas_tex.image.toDataURL( 'image/png', 1 ), function( png_tex ) {
1933+
canvas_tex.dispose();
1934+
1935+
png_tex.flipY = false;
1936+
1937+
if (equi_enabled === true) {
1938+
png_tex.mapping = THREE.EquirectangularReflectionMapping;
1939+
scene.background = png_tex.clone();
1940+
scene.environment = png_tex.clone();
1941+
} else {
1942+
scene.background = png_tex.clone();
1943+
}
1944+
1945+
mouse_wheel = true;
1946+
1947+
png_tex.dispose();
1948+
1949+
set_bgenv_message( true );
1950+
});
1951+
}, function ( xhr ) { // onProgress
1952+
}, function ( error ) { // onError
1953+
URL.revokeObjectURL( fi.files[ i ] );
1954+
handle_error( error );
1955+
});
1956+
} else if (fn_uc.endsWith('.SVG')) {
1957+
texture_loader.load( URL.createObjectURL( fii ) , function( texture ) {
19211958
URL.revokeObjectURL( fii );
19221959

19231960
if (equi_enabled === true) {

viewers/templates/DAE Viewer.html

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,17 +1884,53 @@
18841884

18851885
URL.revokeObjectURL( fii );
18861886
});
1887-
} else if (fn_uc.endsWith('.KTX2') || fn_uc.endsWith('.SVG')) {
1888-
let loader = fn_uc.endsWith('.KTX2') ? ktx2_loader : texture_loader;
1887+
} else if (fn_uc.endsWith('.KTX2')) {
1888+
const { decompress } = await import( 'three/addons/utils/WebGLTextureUtils.min.js' );
18891889

1890-
loader.load( URL.createObjectURL( fii ) , function( texture ) {
1890+
ktx2_loader.load( URL.createObjectURL( fii ), async function( texture ) {
18911891
URL.revokeObjectURL( fii );
18921892

1893-
if (document.getElementById('equi').checked) {
1893+
// Convert to PNG so it shows on most platforms
1894+
// Unsupported KTX2 formats might log a warning
1895+
1896+
texture.colorSpace = THREE.SRGBColorSpace;
1897+
1898+
let canvas_tex = await decompress( texture );
1899+
1900+
texture.dispose();
1901+
1902+
texture_loader.load( canvas_tex.image.toDataURL( 'image/png', 1 ), function( png_tex ) {
1903+
canvas_tex.dispose();
1904+
1905+
png_tex.flipY = false;
1906+
1907+
if (equi_enabled === true) {
1908+
png_tex.mapping = THREE.EquirectangularReflectionMapping;
1909+
scene.background = png_tex.clone();
1910+
scene.environment = png_tex.clone();
1911+
} else {
1912+
scene.background = png_tex.clone();
1913+
}
1914+
1915+
mouse_wheel = true;
1916+
1917+
png_tex.dispose();
1918+
1919+
set_bgenv_message( true );
1920+
});
1921+
}, function ( xhr ) { // onProgress
1922+
}, function ( error ) { // onError
1923+
URL.revokeObjectURL( fi.files[ i ] );
1924+
handle_error( error );
1925+
});
1926+
} else if (fn_uc.endsWith('.SVG')) {
1927+
texture_loader.load( URL.createObjectURL( fii ) , function( texture ) {
1928+
URL.revokeObjectURL( fii );
1929+
1930+
if (equi_enabled === true) {
18941931
texture.mapping = THREE.EquirectangularReflectionMapping;
18951932
scene.background = texture.clone();
18961933
scene.environment = texture.clone();
1897-
if (params.setEnvMap === true) set_envMap( true );
18981934
} else {
18991935
scene.background = texture.clone();
19001936
}

0 commit comments

Comments
 (0)