@@ -1777,6 +1777,8 @@ const applySampler = function (texture, gltfSampler) {
1777
1777
}
1778
1778
} ;
1779
1779
1780
+ let gltfTextureUniqueId = 0 ;
1781
+
1780
1782
// load an image
1781
1783
const loadImageAsync = function ( gltfImage , index , bufferViews , urlBase , registry , options , callback ) {
1782
1784
const preprocess = options && options . image && options . image . preprocess ;
@@ -1800,39 +1802,16 @@ const loadImageAsync = function (gltfImage, index, bufferViews, urlBase, registr
1800
1802
'image/vnd-ms.dds' : 'dds'
1801
1803
} ;
1802
1804
1803
- const loadTexture = function ( url , mimeType , crossOrigin , isBlobUrl ) {
1804
- const name = gltfImage . name || 'gltf-texture' ;
1805
-
1806
- // construct the asset file
1807
- const file = { url : url } ;
1808
- if ( mimeType ) {
1809
- const extension = mimeTypeFileExtensions [ mimeType ] ;
1810
- if ( extension ) {
1811
- file . filename = name + '-' + index + '.' + extension ;
1812
- }
1813
- }
1814
-
1815
- // create and load the asset
1816
- const asset = new Asset ( 'texture_' + index , 'texture' , file , null , { crossOrigin : crossOrigin } ) ;
1817
- asset . on ( 'load' , function ( ) {
1818
- if ( isBlobUrl ) {
1819
- URL . revokeObjectURL ( url ) ;
1820
- }
1821
- onLoad ( asset ) ;
1822
- } ) ;
1823
- asset . on ( 'error' , callback ) ;
1824
- registry . add ( asset ) ;
1825
- registry . load ( asset ) ;
1826
- } ;
1827
-
1828
- const loadTextureFromData = function ( mimeType , bufferView ) {
1829
- const name = gltfImage . name || 'gltf-texture' ;
1805
+ const loadTexture = function ( url , bufferView , mimeType , options ) {
1806
+ const name = ( gltfImage . name || 'gltf-texture' ) + '-' + gltfTextureUniqueId ++ ;
1830
1807
1831
1808
// construct the asset file
1832
1809
const file = {
1833
- url : name + '-' + index ,
1834
- contents : bufferView
1810
+ url : url || name
1835
1811
} ;
1812
+ if ( bufferView ) {
1813
+ file . contents = bufferView ;
1814
+ }
1836
1815
if ( mimeType ) {
1837
1816
const extension = mimeTypeFileExtensions [ mimeType ] ;
1838
1817
if ( extension ) {
@@ -1841,7 +1820,7 @@ const loadImageAsync = function (gltfImage, index, bufferViews, urlBase, registr
1841
1820
}
1842
1821
1843
1822
// create and load the asset
1844
- const asset = new Asset ( name , 'texture' , file , null ) ;
1823
+ const asset = new Asset ( name , 'texture' , file , null , options ) ;
1845
1824
asset . on ( 'load' , onLoad ) ;
1846
1825
asset . on ( 'error' , callback ) ;
1847
1826
registry . add ( asset ) ;
@@ -1861,13 +1840,13 @@ const loadImageAsync = function (gltfImage, index, bufferViews, urlBase, registr
1861
1840
if ( gltfImage . hasOwnProperty ( 'uri' ) ) {
1862
1841
// uri specified
1863
1842
if ( isDataURI ( gltfImage . uri ) ) {
1864
- loadTexture ( gltfImage . uri , getDataURIMimeType ( gltfImage . uri ) ) ;
1843
+ loadTexture ( gltfImage . uri , null , getDataURIMimeType ( gltfImage . uri ) , null ) ;
1865
1844
} else {
1866
- loadTexture ( path . join ( urlBase , gltfImage . uri ) , null , "anonymous" ) ;
1845
+ loadTexture ( path . join ( urlBase , gltfImage . uri ) , null , null , { crossOrigin : "anonymous" } ) ;
1867
1846
}
1868
1847
} else if ( gltfImage . hasOwnProperty ( 'bufferView' ) && gltfImage . hasOwnProperty ( 'mimeType' ) ) {
1869
1848
// bufferview
1870
- loadTextureFromData ( gltfImage . mimeType , bufferViews [ gltfImage . bufferView ] ) ;
1849
+ loadTexture ( null , bufferViews [ gltfImage . bufferView ] , gltfImage . mimeType , null ) ;
1871
1850
} else {
1872
1851
// fail
1873
1852
callback ( "Invalid image found in gltf (neither uri or bufferView found). index=" + index ) ;
0 commit comments