@@ -13749,6 +13749,7 @@ THREE.BufferGeometryLoader.prototype = {
13749
13749
THREE.MaterialLoader = function ( manager ) {
13750
13750
13751
13751
this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
13752
+ this.textures = {};
13752
13753
13753
13754
};
13754
13755
@@ -13776,10 +13777,32 @@ THREE.MaterialLoader.prototype = {
13776
13777
13777
13778
},
13778
13779
13780
+ setTextures: function ( value ) {
13781
+
13782
+ this.textures = value;
13783
+
13784
+ },
13785
+
13786
+ getTexture: function ( name ) {
13787
+
13788
+ var textures = this.textures;
13789
+
13790
+ if ( textures[ name ] === undefined ) {
13791
+
13792
+ console.warn( 'THREE.MaterialLoader: Undefined texture', name );
13793
+
13794
+ }
13795
+
13796
+ return textures[ name ];
13797
+
13798
+ },
13799
+
13779
13800
parse: function ( json ) {
13780
13801
13781
13802
var material = new THREE[ json.type ];
13803
+ material.uuid = json.uuid;
13782
13804
13805
+ if ( json.name !== undefined ) material.name = json.name;
13783
13806
if ( json.color !== undefined ) material.color.setHex( json.color );
13784
13807
if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
13785
13808
if ( json.specular !== undefined ) material.specular.setHex( json.specular );
@@ -13794,13 +13817,55 @@ THREE.MaterialLoader.prototype = {
13794
13817
if ( json.opacity !== undefined ) material.opacity = json.opacity;
13795
13818
if ( json.transparent !== undefined ) material.transparent = json.transparent;
13796
13819
if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
13820
+ if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
13821
+ if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
13797
13822
if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
13798
13823
if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
13799
13824
13800
13825
// for PointCloudMaterial
13801
13826
if ( json.size !== undefined ) material.size = json.size;
13802
13827
if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
13803
13828
13829
+ // maps
13830
+
13831
+ if ( json.map !== undefined ) material.map = this.getTexture( json.map );
13832
+
13833
+ if ( json.alphaMap !== undefined ) {
13834
+
13835
+ material.alphaMap = this.getTexture( json.alphaMap );
13836
+ material.transparent = true;
13837
+
13838
+ }
13839
+
13840
+ if ( json.bumpMap !== undefined ) material.bumpMap = this.getTexture( json.bumpMap );
13841
+ if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
13842
+
13843
+ if ( json.normalMap !== undefined ) material.normalMap = this.getTexture( json.normalMap );
13844
+ if ( json.normalScale ) material.normalScale = new THREE.Vector2( json.normalScale, json.normalScale );
13845
+
13846
+ if ( json.displacementMap !== undefined ) material.displacementMap = this.getTexture( json.displacementMap );
13847
+ if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
13848
+ if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
13849
+
13850
+ if ( json.specularMap !== undefined ) material.specularMap = this.getTexture( json.specularMap );
13851
+
13852
+ if ( json.envMap !== undefined ) {
13853
+
13854
+ material.envMap = this.getTexture( json.envMap );
13855
+ material.combine = THREE.MultiplyOperation;
13856
+
13857
+ }
13858
+
13859
+ if ( json.reflectivity ) material.reflectivity = json.reflectivity;
13860
+
13861
+ if ( json.lightMap !== undefined ) material.lightMap = this.getTexture( json.lightMap );
13862
+ if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
13863
+
13864
+ if ( json.aoMap !== undefined ) material.aoMap = this.getTexture( json.aoMap );
13865
+ if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
13866
+
13867
+ // MeshFaceMaterial
13868
+
13804
13869
if ( json.materials !== undefined ) {
13805
13870
13806
13871
for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
@@ -14121,69 +14186,13 @@ THREE.ObjectLoader.prototype = {
14121
14186
14122
14187
if ( json !== undefined ) {
14123
14188
14124
- var getTexture = function ( name ) {
14125
-
14126
- if ( textures[ name ] === undefined ) {
14127
-
14128
- console.warn( 'THREE.ObjectLoader: Undefined texture', name );
14129
-
14130
- }
14131
-
14132
- return textures[ name ];
14133
-
14134
- };
14135
-
14136
14189
var loader = new THREE.MaterialLoader();
14190
+ loader.setTextures( textures );
14137
14191
14138
14192
for ( var i = 0, l = json.length; i < l; i ++ ) {
14139
14193
14140
- var data = json[ i ];
14141
- var material = loader.parse( data );
14142
-
14143
- material.uuid = data.uuid;
14144
-
14145
- if ( data.depthTest !== undefined ) material.depthTest = data.depthTest;
14146
- if ( data.depthWrite !== undefined ) material.depthWrite = data.depthWrite;
14147
-
14148
- if ( data.name !== undefined ) material.name = data.name;
14149
-
14150
- if ( data.map !== undefined ) material.map = getTexture( data.map );
14151
-
14152
- if ( data.alphaMap !== undefined ) {
14153
-
14154
- material.alphaMap = getTexture( data.alphaMap );
14155
- material.transparent = true;
14156
-
14157
- }
14158
-
14159
- if ( data.bumpMap !== undefined ) material.bumpMap = getTexture( data.bumpMap );
14160
- if ( data.bumpScale !== undefined ) material.bumpScale = data.bumpScale;
14161
-
14162
- if ( data.normalMap !== undefined ) material.normalMap = getTexture( data.normalMap );
14163
- if ( data.normalScale ) material.normalScale = new THREE.Vector2( data.normalScale, data.normalScale );
14164
-
14165
- if ( data.displacementMap !== undefined ) material.displacementMap = getTexture( data.displacementMap );
14166
- if ( data.displacementScale !== undefined ) material.displacementScale = data.displacementScale;
14167
- if ( data.displacementBias !== undefined ) material.displacementBias = data.displacementBias;
14168
-
14169
- if ( data.specularMap !== undefined ) material.specularMap = getTexture( data.specularMap );
14170
-
14171
- if ( data.envMap !== undefined ) {
14172
-
14173
- material.envMap = getTexture( data.envMap );
14174
- material.combine = THREE.MultiplyOperation;
14175
-
14176
- }
14177
-
14178
- if ( data.reflectivity ) material.reflectivity = data.reflectivity;
14179
-
14180
- if ( data.lightMap !== undefined ) material.lightMap = getTexture( data.lightMap );
14181
- if ( data.lightMapIntensity !== undefined ) material.lightMapIntensity = data.lightMapIntensity;
14182
-
14183
- if ( data.aoMap !== undefined ) material.aoMap = getTexture( data.aoMap );
14184
- if ( data.aoMapIntensity !== undefined ) material.aoMapIntensity = data.aoMapIntensity;
14185
-
14186
- materials[ data.uuid ] = material;
14194
+ var material = loader.parse( json[ i ] );
14195
+ materials[ material.uuid ] = material;
14187
14196
14188
14197
}
14189
14198
0 commit comments