@@ -34,31 +34,31 @@ JsonNodeMaterialParser.prototype.initialize = function (material, data) {
34
34
var i = 0 ;
35
35
var material_ready = true ;
36
36
// input or output or constant variables - all node material types have this block
37
- if ( data . graphData . iocVars ) {
38
- for ( i = 0 ; i < Object . keys ( data . graphData . iocVars ) . length ; i ++ ) {
39
- if ( data . graphData . iocVars [ i ] . type === 'sampler2D' && data . graphData . iocVars [ i ] . valueTex ) {
40
- if ( typeof ( data . graphData . iocVars [ i ] . valueTex ) === 'number' && data . graphData . iocVars [ i ] . valueTex > 0 ) {
37
+ if ( data . graphData . graphVars ) {
38
+ for ( i = 0 ; i < Object . keys ( data . graphData . graphVars ) . length ; i ++ ) {
39
+ if ( data . graphData . graphVars [ i ] . type === 'sampler2D' && data . graphData . graphVars [ i ] . valueTex ) {
40
+ if ( typeof ( data . graphData . graphVars [ i ] . valueTex ) === 'number' && data . graphData . graphVars [ i ] . valueTex > 0 ) {
41
41
// texture asset not loaded yet - deal with in node material binder
42
- if ( ! ( material . graphData . iocVars [ i ] && material . graphData . iocVars [ i ] . valueTex ) ) {
42
+ if ( ! ( material . graphData . graphVars [ i ] && material . graphData . graphVars [ i ] . valueTex ) ) {
43
43
// seems no placeholder is set yet
44
44
material_ready = false ;
45
45
}
46
46
} else {
47
47
// texture asset loaded - assign
48
- material . graphData . iocVars [ i ] = { } ;
49
- Object . assign ( material . graphData . iocVars [ i ] , data . graphData . iocVars [ i ] ) ;
48
+ material . graphData . graphVars [ i ] = { } ;
49
+ Object . assign ( material . graphData . graphVars [ i ] , data . graphData . graphVars [ i ] ) ;
50
50
}
51
51
} else {
52
52
// assign directly - we (probably) don't need to convert to Vec2/3/4 objects?
53
- material . graphData . iocVars [ i ] = { } ;
54
- Object . assign ( material . graphData . iocVars [ i ] , data . graphData . iocVars [ i ] ) ;
55
-
56
- // deal with 0 being undefined (TODO: find better way?)
57
- var var_type = material . graphData . iocVars [ i ] . type ;
58
- if ( material . graphData . iocVars [ i ] . valueW === undefined && var_type === 'vec4' ) material . graphData . iocVars [ i ] . valueW = 0 ;
59
- if ( material . graphData . iocVars [ i ] . valueZ === undefined && ( var_type === 'vec4' || var_type === 'vec3' ) ) material . graphData . iocVars [ i ] . valueZ = 0 ;
60
- if ( material . graphData . iocVars [ i ] . valueY === undefined && ( var_type === 'vec4' || var_type === 'vec3' || var_type === 'vec2' ) ) material . graphData . iocVars [ i ] . valueY = 0 ;
61
- if ( material . graphData . iocVars [ i ] . valueX === undefined && ( var_type === 'vec4' || var_type === 'vec3' || var_type === 'vec2' || var_type === 'float' ) ) material . graphData . iocVars [ i ] . valueX = 0 ;
53
+ material . graphData . graphVars [ i ] = { } ;
54
+ Object . assign ( material . graphData . graphVars [ i ] , data . graphData . graphVars [ i ] ) ;
55
+
56
+ // deal with 0 being undefined if default or optional
57
+ var var_type = material . graphData . graphVars [ i ] . type ;
58
+ if ( material . graphData . graphVars [ i ] . valueW === undefined && var_type === 'vec4' ) material . graphData . graphVars [ i ] . valueW = 0 ;
59
+ if ( material . graphData . graphVars [ i ] . valueZ === undefined && ( var_type === 'vec4' || var_type === 'vec3' ) ) material . graphData . graphVars [ i ] . valueZ = 0 ;
60
+ if ( material . graphData . graphVars [ i ] . valueY === undefined && ( var_type === 'vec4' || var_type === 'vec3' || var_type === 'vec2' ) ) material . graphData . graphVars [ i ] . valueY = 0 ;
61
+ if ( material . graphData . graphVars [ i ] . valueX === undefined && ( var_type === 'vec4' || var_type === 'vec3' || var_type === 'vec2' || var_type === 'float' ) ) material . graphData . graphVars [ i ] . valueX = 0 ;
62
62
}
63
63
}
64
64
}
@@ -80,23 +80,19 @@ JsonNodeMaterialParser.prototype.initialize = function (material, data) {
80
80
// this means asset is not loaded yet - cannot assign
81
81
material_ready = false ;
82
82
} else {
83
- // shader asset loaded - assign and generate matching iocVars
83
+ // shader asset loaded - assign and generate matching graphVars
84
84
material . graphData . customFuncGlsl = data . graphData . customFuncGlsl ;
85
- material . graphData . iocVars . length = 0 ;
86
- material . genCustomFuncIocVars ( ) ;
87
-
88
- // copy values that match into new iocVars - if not matching reset
89
- // TODO: make this more robust (match even if index doesn't match)?
90
- if ( material . graphData . iocVars ) {
91
- for ( i = 0 ; i < material . graphData . iocVars . length ; i ++ ) {
92
- // if (data.graphData.iocVars && i<data.graphData.iocVars .length && material.graphData.iocVars [i].name===data.graphData.iocVars [i].name && material.graphData.iocVars [i].type===data.graphData.iocVars [i].type )
93
- if ( data . graphData . iocVars && i < Object . keys ( data . graphData . iocVars ) . length && material . graphData . iocVars [ i ] . name === data . graphData . iocVars [ i ] . name && material . graphData . iocVars [ i ] . type === data . graphData . iocVars [ i ] . type ) {
85
+ material . graphData . graphVars . length = 0 ;
86
+ material . genCustomFuncVars ( ) ;
87
+
88
+ // copy values that match into new graph variables - if not matching reset
89
+ // TODO: make this more robust (match name even if index doesn't match)?
90
+ if ( material . graphData . graphVars ) {
91
+ for ( i = 0 ; i < material . graphData . graphVars . length ; i ++ ) {
92
+ // if (data.graphData.graphVars && i<data.graphData.graphVars .length && material.graphData.graphVars [i].name===data.graphData.graphVars [i].name && material.graphData.graphVars [i].type===data.graphData.graphVars [i].type )
93
+ if ( data . graphData . graphVars && i < Object . keys ( data . graphData . graphVars ) . length && material . graphData . graphVars [ i ] . name === data . graphData . graphVars [ i ] . name && material . graphData . graphVars [ i ] . type === data . graphData . graphVars [ i ] . type ) {
94
94
// exists and matches copy what is already set in the asset
95
- Object . assign ( material . graphData . iocVars [ i ] , data . graphData . iocVars [ i ] ) ;
96
- } else {
97
- // reset and copy material into data.graphData
98
- // data.graphData.iocVars[i]={};
99
- // Object.assign(data.graphData.iocVars[i], material.graphData.iocVars[i]);
95
+ Object . assign ( material . graphData . graphVars [ i ] , data . graphData . graphVars [ i ] ) ;
100
96
}
101
97
}
102
98
}
@@ -113,9 +109,9 @@ JsonNodeMaterialParser.prototype.initialize = function (material, data) {
113
109
material . graphData . connections [ i ] = { } ;
114
110
Object . assign ( material . graphData . connections [ i ] , data . graphData . connections [ i ] ) ;
115
111
116
- // deal with 0 index problem
117
- if ( material . graphData . connections [ i ] . inVarName && material . graphData . connections [ i ] . inNodeIndex === undefined ) material . graphData . connections [ i ] . inNodeIndex = 0 ;
118
- if ( material . graphData . connections [ i ] . outVarName && material . graphData . connections [ i ] . outNodeIndex === undefined ) material . graphData . connections [ i ] . outNodeIndex = 0 ;
112
+ // deal with optional value problem (should no longer happen?)
113
+ // if (material.graphData.connections[i].dstVarName && material.graphData.connections[i].dstIndex === undefined) material.graphData.connections[i].dstIndex = -1 ;
114
+ // if (material.graphData.connections[i].srcVarName && material.graphData.connections[i].srcIndex === undefined) material.graphData.connections[i].srcIndex = -1 ;
119
115
}
120
116
}
121
117
@@ -126,18 +122,19 @@ JsonNodeMaterialParser.prototype.initialize = function (material, data) {
126
122
127
123
for ( i = 0 ; i < Object . keys ( data . graphData . subGraphs ) . length ; i ++ ) {
128
124
if ( typeof ( data . graphData . subGraphs [ i ] ) === 'number' && data . graphData . subGraphs [ i ] > 0 ) {
129
- material . graphData . subGraphs [ i ] = data . graphData . subGraphs [ i ] ;
130
- // this means sub graph asset is not loaded yet - cannot assign
125
+ // this means sub graph asset is not loaded yet
131
126
material_ready = false ;
127
+ // set to something so that validation doesn't pass on all loaded sub graphs
128
+ material . graphData . subGraphs [ i ] = i ;
132
129
} else {
133
130
material . graphData . subGraphs [ i ] = data . graphData . subGraphs [ i ] ;
134
131
}
135
132
}
136
133
}
137
134
} else {
138
- if ( data . graphData . iocVars ) {
135
+ if ( data . graphData . graphVars ) {
139
136
// no custom glsl or sub graphs - this means this is a node material instance?
140
- // TODO: support material instances properly
137
+ // TODO: support material instances properly?
141
138
material_ready = false ;
142
139
} else {
143
140
// completely empty?
@@ -147,29 +144,23 @@ JsonNodeMaterialParser.prototype.initialize = function (material, data) {
147
144
148
145
// only mark for update if ready dependent assets (with no placeholders) are loaded
149
146
if ( material_ready ) {
150
- // data._material_ready=true;
151
147
material . dirtyShader = true ;
152
148
material . update ( ) ;
153
149
} else {
154
- // data._material_ready = false;
155
150
material . setPlaceHolderShader ( this . _placeholderNodeMat ) ;
156
151
}
157
152
} ;
158
153
159
154
// convert any properties that are out of date
160
155
// or from old versions into current version
161
156
JsonNodeMaterialParser . prototype . migrate = function ( data ) {
162
-
163
157
// no conversion needed (yet)
164
-
165
158
return data ;
166
159
} ;
167
160
168
161
// check for invalid properties
169
162
JsonNodeMaterialParser . prototype . _validate = function ( data ) {
170
-
171
163
// no validation needed (yet)
172
-
173
164
return data ;
174
165
} ;
175
166
0 commit comments