aboutsummaryrefslogtreecommitdiff
path: root/js/panels/Materials/materials-popup.reel
diff options
context:
space:
mode:
authorArmen Kesablyan2012-06-20 15:00:34 -0700
committerArmen Kesablyan2012-06-20 15:00:34 -0700
commit38f571d1fdf02d36c3816637af7b2ca2493809da (patch)
tree69b97839be8b2b6fb65e9150d4dc02856041fb1d /js/panels/Materials/materials-popup.reel
parentf7c14e54c52bce8875cde81db621dde6f4ff1e34 (diff)
parent120e31dcf1e11eed11ee430d77c438e7b073e9f8 (diff)
downloadninja-38f571d1fdf02d36c3816637af7b2ca2493809da.tar.gz
Merge branch 'refs/heads/master' into binding
Diffstat (limited to 'js/panels/Materials/materials-popup.reel')
-rwxr-xr-xjs/panels/Materials/materials-popup.reel/materials-popup.js181
1 files changed, 155 insertions, 26 deletions
diff --git a/js/panels/Materials/materials-popup.reel/materials-popup.js b/js/panels/Materials/materials-popup.reel/materials-popup.js
index 0a32447e..40f07509 100755
--- a/js/panels/Materials/materials-popup.reel/materials-popup.js
+++ b/js/panels/Materials/materials-popup.reel/materials-popup.js
@@ -33,12 +33,17 @@ exports.MaterialsPopup = Montage.create(Component, {
33 value: "" 33 value: ""
34 }, 34 },
35 35
36 _useSelection: { value: false, enumerable: true },
37 _whichMaterial: { value: "fill", enumerable: true },
38 _originalValues: {value: null, enumerable: true },
39
36 captureAction: { 40 captureAction: {
37 value:function(event) { 41 value:function(event) {
38 switch(event._currentTarget.label) 42 switch(event._currentTarget.label)
39 { 43 {
40 case "Cancel": 44 case "Cancel":
41 console.log("Cancel material edit"); 45 console.log("Cancel material edit");
46 this.revertToOriginalValues();
42 break; 47 break;
43 case "OK": 48 case "OK":
44 console.log("Committing material with the following values:"); 49 console.log("Committing material with the following values:");
@@ -67,6 +72,46 @@ exports.MaterialsPopup = Montage.create(Component, {
67 } 72 }
68 }, 73 },
69 74
75 revertToOriginalValues:
76 {
77 value: function()
78 {
79 if (this._originalValues)
80 {
81 this._material.importJSON( this._originalValues );
82
83 if (this._useSelection)
84 {
85 var selection = this.application.ninja.selectedElements;
86 if (selection && (selection.length > 0))
87 {
88 var nObjs = selection.length;
89 for (var iObj=0; iObj<nObjs; iObj++)
90 {
91 var canvas = selection[iObj];
92 var obj;
93 if (canvas.elementModel && canvas.elementModel.shapeModel) obj = canvas.elementModel.shapeModel.GLGeomObj;
94 if (obj)
95 {
96 var matArray = obj._materialArray;
97 var matTypeArray = obj._materialTypeArray;
98 var nMats = matArray.length;
99 for (var iMat=0; iMat<nMats; iMat++)
100 {
101 if (matTypeArray[iMat] === this._whichMaterial)
102 matArray[iMat].importJSON( this._originalValues );
103 }
104 var world = obj.getWorld();
105 if (world)
106 world.restartRenderLoop();
107 }
108 }
109 }
110 }
111 }
112 }
113 },
114
70 updatePreview: 115 updatePreview:
71 { 116 {
72 value: function(event) 117 value: function(event)
@@ -103,8 +148,9 @@ exports.MaterialsPopup = Montage.create(Component, {
103 148
104 _handlePropertyChange: 149 _handlePropertyChange:
105 { 150 {
106 value: function(event) 151 value: function(theEvent)
107 { 152 {
153 var event = theEvent._event;
108 if(typeof event.propertyValue === "object") 154 if(typeof event.propertyValue === "object")
109 { 155 {
110 console.log(event.propertyLabel + " changed to "); 156 console.log(event.propertyLabel + " changed to ");
@@ -148,6 +194,37 @@ exports.MaterialsPopup = Montage.create(Component, {
148 var value = this.decodeValue( this._propTypes[index], propValue ); 194 var value = this.decodeValue( this._propTypes[index], propValue );
149 this._material.setProperty( this._propNames[index], value ); 195 this._material.setProperty( this._propNames[index], value );
150 } 196 }
197
198 if (this._useSelection)
199 {
200 console.log( "apply to selection" );
201
202 var selection = this.application.ninja.selectedElements;
203 if (selection && (selection.length > 0))
204 {
205 var nObjs = selection.length;
206 for (var iObj=0; iObj<nObjs; iObj++)
207 {
208 var canvas = selection[iObj];
209 var obj;
210 if (canvas.elementModel && canvas.elementModel.shapeModel) obj = canvas.elementModel.shapeModel.GLGeomObj;
211 if (obj)
212 {
213 var matArray = obj._materialArray;
214 var matTypeArray = obj._materialTypeArray;
215 var nMats = matArray.length;
216 for (var iMat=0; iMat<nMats; iMat++)
217 {
218 if (matTypeArray[iMat] === this._whichMaterial)
219 matArray[iMat].setProperty( this._propNames[index], value );
220 }
221 var world = obj.getWorld();
222 if (world)
223 world.restartRenderLoop();
224 }
225 }
226 }
227 }
151 } 228 }
152 } 229 }
153 }, 230 },
@@ -173,14 +250,20 @@ exports.MaterialsPopup = Montage.create(Component, {
173 rtnValue = value; 250 rtnValue = value;
174 break; 251 break;
175 252
253 case "angle":
254 rtnValue = value*3.14159/180.0;
255 break;
256
176 case "file": 257 case "file":
177 if (value && (value.length > 0)) 258 if (value && (value.length > 0))
178 { 259 {
179 var index = value.lastIndexOf( "/" ); 260 var index = value.lastIndexOf( "/" );
180 if (index < 0) index = value.lastIndexOf( "\\" ); 261 if (index < 0) index = value.lastIndexOf( "\\" );
181 if (index >= 0) 262 if (index >= 0)
263 {
182 value = value.substr( index+1 ); 264 value = value.substr( index+1 );
183 value = "assets\\images\\" + value; 265 value = "assets/images/" + value;
266 }
184 rtnValue = value.slice(0); 267 rtnValue = value.slice(0);
185 } 268 }
186 break; 269 break;
@@ -227,32 +310,74 @@ exports.MaterialsPopup = Montage.create(Component, {
227 loadMaterials: 310 loadMaterials:
228 { 311 {
229 enumerable: true, 312 enumerable: true,
230 value: function(materialID) 313 value: function(materialID, useSelection, whichMaterial)
231 { 314 {
232 //TODO - Hack to force repetition to draw. Setting .length = 0 did not work. 315 //TODO - Hack to force repetition to draw. Setting .length = 0 did not work.
233 this.materialsData = []; 316 this.materialsData = [];
234 317
235 this._materialName = materialID; 318 var material;
236 if( 319 this._materialName = materialID;
237 (materialID === "UberMaterial") || 320 if (useSelection)
238 (materialID === "FlatMaterial") ||
239 (materialID === "BumpMetalMaterial") ||
240 (materialID === "LinearGradientMaterial") ||
241 (materialID === "RadialGradientMaterial")
242 )
243 { 321 {
244 var material = MaterialsModel.getMaterial( materialID ); 322 this._useSelection = true;
245 if (material) 323 var selection = this.application.ninja.selectedElements;
324 if (selection && (selection.length > 0))
246 { 325 {
247 this._material = material; 326 var canvas = selection[0];
248 this.materialsData = this.getMaterialData( material );