diff options
Diffstat (limited to 'js/panels/Materials/materials-popup.reel')
-rwxr-xr-x | js/panels/Materials/materials-popup.reel/materials-popup.js | 196 |
1 files changed, 170 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 a4f758cf..40f07509 100755 --- a/js/panels/Materials/materials-popup.reel/materials-popup.js +++ b/js/panels/Materials/materials-popup.reel/materials-popup.js | |||
@@ -12,18 +12,38 @@ var Montage = require("montage/core/core").Montage, | |||
12 | //Exporting as MaterialsPopup | 12 | //Exporting as MaterialsPopup |
13 | exports.MaterialsPopup = Montage.create(Component, { | 13 | exports.MaterialsPopup = Montage.create(Component, { |
14 | //////////////////////////////////////////////////////////////////// | 14 | //////////////////////////////////////////////////////////////////// |
15 | okButton: { | ||
16 | value: null, | ||
17 | serializable: true | ||
18 | }, | ||
19 | |||
20 | cancelButton: { | ||
21 | value: null, | ||
22 | serializable: true | ||
23 | }, | ||
24 | |||
25 | materialTitle: { | ||
26 | value: null, | ||
27 | serializable: true | ||
28 | }, | ||
29 | |||
15 | // Material Properties | 30 | // Material Properties |
16 | _materialName: { | 31 | _materialName: { |
17 | enumerable: true, | 32 | enumerable: true, |
18 | value: "" | 33 | value: "" |
19 | }, | 34 | }, |
20 | 35 | ||
36 | _useSelection: { value: false, enumerable: true }, | ||
37 | _whichMaterial: { value: "fill", enumerable: true }, | ||
38 | _originalValues: {value: null, enumerable: true }, | ||
39 | |||
21 | captureAction: { | 40 | captureAction: { |
22 | value:function(event) { | 41 | value:function(event) { |
23 | switch(event._currentTarget.label) | 42 | switch(event._currentTarget.label) |
24 | { | 43 | { |
25 | case "Cancel": | 44 | case "Cancel": |
26 | console.log("Cancel material edit"); | 45 | console.log("Cancel material edit"); |
46 | this.revertToOriginalValues(); | ||
27 | break; | 47 | break; |
28 | case "OK": | 48 | case "OK": |
29 | console.log("Committing material with the following values:"); | 49 | console.log("Committing material with the following values:"); |
@@ -52,6 +72,46 @@ exports.MaterialsPopup = Montage.create(Component, { | |||
52 | } | 72 | } |
53 | }, | 73 | }, |
54 | 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 | |||
55 | updatePreview: | 115 | updatePreview: |
56 | { | 116 | { |
57 | value: function(event) | 117 | value: function(event) |
@@ -88,8 +148,9 @@ exports.MaterialsPopup = Montage.create(Component, { | |||
88 | 148 | ||
89 | _handlePropertyChange: | 149 | _handlePropertyChange: |
90 | { | 150 | { |
91 | value: function(event) | 151 | value: function(theEvent) |
92 | { | 152 | { |
153 | var event = theEvent._event; | ||
93 | if(typeof event.propertyValue === "object") | 154 | if(typeof event.propertyValue === "object") |
94 | { | 155 | { |
95 | console.log(event.propertyLabel + " changed to "); | 156 | console.log(event.propertyLabel + " changed to "); |
@@ -133,6 +194,37 @@ exports.MaterialsPopup = Montage.create(Component, { | |||
133 | var value = this.decodeValue( this._propTypes[index], propValue ); | 194 | var value = this.decodeValue( this._propTypes[index], propValue ); |
134 | this._material.setProperty( this._propNames[index], value ); | 195 | this._material.setProperty( this._propNames[index], value ); |
135 | } | 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 | } | ||
136 | } | 228 | } |
137 | } | 229 | } |
138 | }, | 230 | }, |
@@ -158,14 +250,20 @@ exports.MaterialsPopup = Montage.create(Component, { | |||
158 | rtnValue = value; | 250 | rtnValue = value; |
159 | break; | 251 | break; |
160 | 252 | ||
253 | case "angle": | ||
254 | rtnValue = value*3.14159/180.0; | ||
255 | break; | ||
256 | |||
161 | case "file": | 257 | case "file": |
162 | if (value && (value.length > 0)) | 258 | if (value && (value.length > 0)) |
163 | { | 259 | { |
164 | var index = value.lastIndexOf( "/" ); | 260 | var index = value.lastIndexOf( "/" ); |
165 | if (index < 0) index = value.lastIndexOf( "\\" ); | 261 | if (index < 0) index = value.lastIndexOf( "\\" ); |
166 | if (index >= 0) | 262 | if (index >= 0) |
263 | { | ||
167 | value = value.substr( index+1 ); | 264 | value = value.substr( index+1 ); |
168 | value = "assets\\images\\" + value; | 265 | value = "assets/images/" + value; |
266 | } | ||
169 | rtnValue = value.slice(0); | 267 | rtnValue = value.slice(0); |
170 | } | 268 | } |
171 | break; | 269 | break; |
@@ -212,32 +310,74 @@ exports.MaterialsPopup = Montage.create(Component, { | |||
212 | loadMaterials: | 310 | loadMaterials: |
213 | { | 311 | { |
214 | enumerable: true, | 312 | enumerable: true, |
215 | value: function(materialID) | 313 | value: function(materialID, useSelection, whichMaterial) |
216 | { | 314 | { |
217 | //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. |
218 | this.materialsData = []; | 316 | this.materialsData = []; |
219 | 317 | ||
220 | this._materialName = materialID; | 318 | var material; |
221 | if( | 319 | this._materialName = materialID; |
222 | (materialID === "UberMaterial") || | 320 | if (useSelection) |
223 | (materialID === "FlatMaterial") |