5
5
THREE . MaterialLoader = function ( manager ) {
6
6
7
7
this . manager = ( manager !== undefined ) ? manager : THREE . DefaultLoadingManager ;
8
+ this . textures = { } ;
8
9
9
10
} ;
10
11
@@ -32,10 +33,32 @@ THREE.MaterialLoader.prototype = {
32
33
33
34
} ,
34
35
36
+ setTextures : function ( value ) {
37
+
38
+ this . textures = value ;
39
+
40
+ } ,
41
+
42
+ getTexture : function ( name ) {
43
+
44
+ var textures = this . textures ;
45
+
46
+ if ( textures [ name ] === undefined ) {
47
+
48
+ console . warn ( 'THREE.MaterialLoader: Undefined texture' , name ) ;
49
+
50
+ }
51
+
52
+ return textures [ name ] ;
53
+
54
+ } ,
55
+
35
56
parse : function ( json ) {
36
57
37
58
var material = new THREE [ json . type ] ;
59
+ material . uuid = json . uuid ;
38
60
61
+ if ( json . name !== undefined ) material . name = json . name ;
39
62
if ( json . color !== undefined ) material . color . setHex ( json . color ) ;
40
63
if ( json . emissive !== undefined ) material . emissive . setHex ( json . emissive ) ;
41
64
if ( json . specular !== undefined ) material . specular . setHex ( json . specular ) ;
@@ -50,13 +73,55 @@ THREE.MaterialLoader.prototype = {
50
73
if ( json . opacity !== undefined ) material . opacity = json . opacity ;
51
74
if ( json . transparent !== undefined ) material . transparent = json . transparent ;
52
75
if ( json . alphaTest !== undefined ) material . alphaTest = json . alphaTest ;
76
+ if ( json . depthTest !== undefined ) material . depthTest = json . depthTest ;
77
+ if ( json . depthWrite !== undefined ) material . depthWrite = json . depthWrite ;
53
78
if ( json . wireframe !== undefined ) material . wireframe = json . wireframe ;
54
79
if ( json . wireframeLinewidth !== undefined ) material . wireframeLinewidth = json . wireframeLinewidth ;
55
80
56
81
// for PointCloudMaterial
57
82
if ( json . size !== undefined ) material . size = json . size ;
58
83
if ( json . sizeAttenuation !== undefined ) material . sizeAttenuation = json . sizeAttenuation ;
59
84
85
+ // maps
86
+
87
+ if ( json . map !== undefined ) material . map = this . getTexture ( json . map ) ;
88
+
89
+ if ( json . alphaMap !== undefined ) {
90
+
91
+ material . alphaMap = this . getTexture ( json . alphaMap ) ;
92
+ material . transparent = true ;
93
+
94
+ }
95
+
96
+ if ( json . bumpMap !== undefined ) material . bumpMap = this . getTexture ( json . bumpMap ) ;
97
+ if ( json . bumpScale !== undefined ) material . bumpScale = json . bumpScale ;
98
+
99
+ if ( json . normalMap !== undefined ) material . normalMap = this . getTexture ( json . normalMap ) ;
100
+ if ( json . normalScale ) material . normalScale = new THREE . Vector2 ( json . normalScale , json . normalScale ) ;
101
+
102
+ if ( json . displacementMap !== undefined ) material . displacementMap = this . getTexture ( json . displacementMap ) ;
103
+ if ( json . displacementScale !== undefined ) material . displacementScale = json . displacementScale ;
104
+ if ( json . displacementBias !== undefined ) material . displacementBias = json . displacementBias ;
105
+
106
+ if ( json . specularMap !== undefined ) material . specularMap = this . getTexture ( json . specularMap ) ;
107
+
108
+ if ( json . envMap !== undefined ) {
109
+
110
+ material . envMap = this . getTexture ( json . envMap ) ;
111
+ material . combine = THREE . MultiplyOperation ;
112
+
113
+ }
114
+
115
+ if ( json . reflectivity ) material . reflectivity = json . reflectivity ;
116
+
117
+ if ( json . lightMap !== undefined ) material . lightMap = this . getTexture ( json . lightMap ) ;
118
+ if ( json . lightMapIntensity !== undefined ) material . lightMapIntensity = json . lightMapIntensity ;
119
+
120
+ if ( json . aoMap !== undefined ) material . aoMap = this . getTexture ( json . aoMap ) ;
121
+ if ( json . aoMapIntensity !== undefined ) material . aoMapIntensity = json . aoMapIntensity ;
122
+
123
+ // MeshFaceMaterial
124
+
60
125
if ( json . materials !== undefined ) {
61
126
62
127
for ( var i = 0 , l = json . materials . length ; i < l ; i ++ ) {
0 commit comments