diff options
author | Nivesh Rajbhandari | 2012-02-08 14:24:48 -0800 |
---|---|---|
committer | Nivesh Rajbhandari | 2012-02-08 14:24:48 -0800 |
commit | 2d68f944e93b201deb46015392e706b7a24201c9 (patch) | |
tree | 55367f4efb8a49447753e473af52f878f1584b64 | |
parent | 79ef4e4f51f8981feac3f3bddb6a06aa37407542 (diff) | |
download | ninja-2d68f944e93b201deb46015392e706b7a24201c9.tar.gz |
Fixed several typos in Materials import/export code to support toggling between 2d and 3d shape modes.
Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com>
-rw-r--r-- | js/controllers/elements/shapes-controller.js | 25 | ||||
-rw-r--r-- | js/helper-classes/RDGE/GLMaterial.js | 2 | ||||
-rw-r--r-- | js/helper-classes/RDGE/GLRectangle.js | 4 | ||||
-rw-r--r-- | js/helper-classes/RDGE/Materials/BumpMetalMaterial.js | 10 | ||||
-rw-r--r-- | js/helper-classes/RDGE/Materials/FlatMaterial.js | 48 | ||||
-rw-r--r-- | js/helper-classes/RDGE/Materials/UberMaterial.js | 6 | ||||
-rw-r--r-- | js/helper-classes/RDGE/MaterialsLibrary.js | 2 |
7 files changed, 64 insertions, 33 deletions
diff --git a/js/controllers/elements/shapes-controller.js b/js/controllers/elements/shapes-controller.js index e764de4e..b9c033aa 100644 --- a/js/controllers/elements/shapes-controller.js +++ b/js/controllers/elements/shapes-controller.js | |||
@@ -63,11 +63,11 @@ exports.ShapesController = Montage.create(CanvasController, { | |||
63 | canvas.height = el.height; | 63 | canvas.height = el.height; |
64 | this.application.ninja.elementMediator.replaceElement(el, canvas); | 64 | this.application.ninja.elementMediator.replaceElement(el, canvas); |
65 | NJevent("elementDeleted", el); | 65 | NJevent("elementDeleted", el); |
66 | this.application.ninja.selectionController.selectElement(canvas); | ||
67 | el = canvas; | 66 | el = canvas; |
68 | this.toggleWebGlMode(el, value); | 67 | this.toggleWebGlMode(el, value); |
69 | el.elementModel.shapeModel.GLGeomObj.buildBuffers(); | 68 | el.elementModel.shapeModel.GLWorld.render(); |
70 | break; | 69 | this.application.ninja.selectionController.selectElement(el); |
70 | return; | ||
71 | case "strokeMaterial": | 71 | case "strokeMaterial": |
72 | var sm = Object.create(MaterialsLibrary.getMaterial(value)); | 72 | var sm = Object.create(MaterialsLibrary.getMaterial(value)); |
73 | if(sm) | 73 | if(sm) |
@@ -338,13 +338,26 @@ exports.ShapesController = Montage.create(CanvasController, { | |||
338 | { | 338 | { |
339 | return; | 339 | return; |
340 | } | 340 | } |
341 | var world, | 341 | var sm, |
342 | fm, | ||
343 | world, | ||
342 | worldData = el.elementModel.shapeModel.GLWorld.export(); | 344 | worldData = el.elementModel.shapeModel.GLWorld.export(); |
343 | if(worldData) | 345 | if(worldData) |
344 | { | 346 | { |
345 | world = new GLWorld(el, true); | 347 | world = new GLWorld(el, true); |
346 | el.elementModel.shapeModel.GLWorld = world; | 348 | el.elementModel.shapeModel.GLWorld = world; |
349 | el.elementModel.shapeModel.GLGeomObj.setWorld(world); | ||
347 | el.elementModel.shapeModel.useWebGl = true; | 350 | el.elementModel.shapeModel.useWebGl = true; |
351 | sm = Object.create(MaterialsLibrary.getMaterial("FlatMaterial")); | ||
352 | fm = Object.create(MaterialsLibrary.getMaterial("FlatMaterial")); | ||
353 | if(sm && fm) | ||
354 | { | ||
355 | el.elementModel.shapeModel.GLGeomObj.setStrokeMaterial(sm); | ||
356 | el.elementModel.shapeModel.GLGeomObj.setFillMaterial(fm); | ||
357 | el.elementModel.shapeModel.strokeMaterial = sm; | ||
358 | el.elementModel.shapeModel.fillMaterial = fm; | ||
359 | el.elementModel.shapeModel.GLGeomObj.buildBuffers(); | ||
360 | } | ||
348 | world.import(worldData); | 361 | world.import(worldData); |
349 | } | 362 | } |
350 | 363 | ||
@@ -365,6 +378,10 @@ exports.ShapesController = Montage.create(CanvasController, { | |||
365 | world = new GLWorld(el, false); | 378 | world = new GLWorld(el, false); |
366 | el.elementModel.shapeModel.GLWorld = world; | 379 | el.elementModel.shapeModel.GLWorld = world; |
367 | el.elementModel.shapeModel.useWebGl = false; | 380 | el.elementModel.shapeModel.useWebGl = false; |
381 | el.elementModel.shapeModel.GLGeomObj.setStrokeMaterial(null); | ||
382 | el.elementModel.shapeModel.GLGeomObj.setFillMaterial(null); | ||
383 | el.elementModel.shapeModel.strokeMaterial = null; | ||
384 | el.elementModel.shapeModel.fillMaterial = null; | ||
368 | world.import(worldData); | 385 | world.import(worldData); |
369 | } | 386 | } |
370 | 387 | ||
diff --git a/js/helper-classes/RDGE/GLMaterial.js b/js/helper-classes/RDGE/GLMaterial.js index 51c27ace..e1a68abd 100644 --- a/js/helper-classes/RDGE/GLMaterial.js +++ b/js/helper-classes/RDGE/GLMaterial.js | |||
@@ -186,7 +186,7 @@ function GLMaterial( world ) | |||
186 | var endKey = "endMaterial\n"; | 186 | var endKey = "endMaterial\n"; |
187 | var index = importStr.indexOf( endKey ); | 187 | var index = importStr.indexOf( endKey ); |
188 | index += endKey.length; | 188 | index += endKey.length; |
189 | rtnStr = importStr.substr( index ); | 189 | var rtnStr = importStr.substr( index ); |
190 | 190 | ||
191 | return rtnStr; | 191 | return rtnStr; |
192 | } | 192 | } |
diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js index 8535a683..b88ecc71 100644 --- a/js/helper-classes/RDGE/GLRectangle.js +++ b/js/helper-classes/RDGE/GLRectangle.js | |||
@@ -177,8 +177,8 @@ function GLRectangle() | |||
177 | this._strokeWidth = Number( this.getPropertyFromString( "strokeWidth: ", importStr ) ); | 177 | this._strokeWidth = Number( this.getPropertyFromString( "strokeWidth: ", importStr ) ); |
178 | this._innerRadius = Number( this.getPropertyFromString( "innerRadius: ", importStr ) ); | 178 | this._innerRadius = Number( this.getPropertyFromString( "innerRadius: ", importStr ) ); |
179 | this._strokeStyle = Number( this.getPropertyFromString( "strokeStyle: ", importStr ) ); | 179 | this._strokeStyle = Number( this.getPropertyFromString( "strokeStyle: ", importStr ) ); |
180 | var strokeMaterialName = Number( this.getPropertyFromString( "strokeMat: ", importStr ) ); | 180 | var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr ); |
181 | var fillMaterialName = Number( this.getPropertyFromString( "fillMat: ", importStr ) ); | 181 | var fillMaterialName = this.getPropertyFromString( "fillMat: ", importStr ); |
182 | this._strokeStyle = Number( this.getPropertyFromString( "strokeColor: ", importStr ) ); | 182 | this._strokeStyle = Number( this.getPropertyFromString( "strokeColor: ", importStr ) ); |
183 | this._fillColor = eval( "[" + this.getPropertyFromString( "fillColor: ", importStr ) + "]" ); | 183 | this._fillColor = eval( "[" + this.getPropertyFromString( "fillColor: ", importStr ) + "]" ); |
184 | this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" ); | 184 | this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" ); |
diff --git a/js/helper-classes/RDGE/Materials/BumpMetalMaterial.js b/js/helper-classes/RDGE/Materials/BumpMetalMaterial.js index 0aa3ee78..59720611 100644 --- a/js/helper-classes/RDGE/Materials/BumpMetalMaterial.js +++ b/js/helper-classes/RDGE/Materials/BumpMetalMaterial.js | |||
@@ -52,7 +52,7 @@ function BumpMetalMaterial() | |||
52 | /////////////////////////////////////////////////////////////////////// | 52 | /////////////////////////////////////////////////////////////////////// |
53 | // Material Property Accessors | 53 | // Material Property Accessors |
54 | /////////////////////////////////////////////////////////////////////// | 54 | /////////////////////////////////////////////////////////////////////// |
55 | this._propNames = ["lightDiff", "diffuseMap", "normalMap", "specularMap"]; | 55 | this._propNames = ["lightDiff", "diffuseTexture", "normalMap", "specularTexture"]; |
56 | this._propLabels = ["Diffuse Color", "Diffuse Map", "Bump Map", "Specular Map"]; | 56 | this._propLabels = ["Diffuse Color", "Diffuse Map", "Bump Map", "Specular Map"]; |
57 | this._propTypes = ["color", "file", "file", "file"]; | 57 | this._propTypes = ["color", "file", "file", "file"]; |
58 | this._propValues = []; | 58 | this._propValues = []; |
@@ -122,7 +122,7 @@ function BumpMetalMaterial() | |||
122 | exportStr += "lightDiff: " + this.getLightDiff() + "\n"; | 122 | exportStr += "lightDiff: " + this.getLightDiff() + "\n"; |
123 | exportStr += "diffuseTexture: " + this.getDiffuseTexture() + "\n"; | 123 | exportStr += "diffuseTexture: " + this.getDiffuseTexture() + "\n"; |
124 | exportStr += "specularTexture: " + this.getSpecularTexture() + "\n"; | 124 | exportStr += "specularTexture: " + this.getSpecularTexture() + "\n"; |
125 | exportStr += "normalTexture: " + this.getNormalTexture() + "\n"; | 125 | exportStr += "normalMap: " + this.getNormalTexture() + "\n"; |
126 | 126 | ||
127 | // every material needs to terminate like this | 127 | // every material needs to terminate like this |
128 | exportStr += "endMaterial\n"; | 128 | exportStr += "endMaterial\n"; |
@@ -143,12 +143,12 @@ function BumpMetalMaterial() | |||
143 | var lightDiff = eval( "[" + pu.nextValue( "lightDiff: " ) + "]" ), | 143 | var lightDiff = eval( "[" + pu.nextValue( "lightDiff: " ) + "]" ), |
144 | dt = pu.nextValue( "diffuseTexture: " ), | 144 | dt = pu.nextValue( "diffuseTexture: " ), |
145 | st = pu.nextValue( "specularTexture: " ), | 145 | st = pu.nextValue( "specularTexture: " ), |
146 | nt = pu.nextValue( "normalTexture: " ); | 146 | nt = pu.nextValue( "normalMap: " ); |
147 | 147 | ||
148 | this.setProperty( "lightDiff", lightDif); | 148 | this.setProperty( "lightDiff", lightDiff); |
149 | this.setProperty( "diffuseTexture", dt ); | 149 | this.setProperty( "diffuseTexture", dt ); |
150 | this.setProperty( "specularTexture", st ); | 150 | this.setProperty( "specularTexture", st ); |
151 | this.setProperty( "normalTexture", nt ); | 151 | this.setProperty( "normalMap", nt ); |
152 | 152 | ||
153 | var endKey = "endMaterial\n"; | 153 | var endKey = "endMaterial\n"; |
154 | var index = importStr.indexOf( endKey ); | 154 | var index = importStr.indexOf( endKey ); |
diff --git a/js/helper-classes/RDGE/Materials/FlatMaterial.js b/js/helper-classes/RDGE/Materials/FlatMaterial.js index 5177a8a0..a5c079a8 100644 --- a/js/helper-classes/RDGE/Materials/FlatMaterial.js +++ b/js/helper-classes/RDGE/Materials/FlatMaterial.js | |||
@@ -63,11 +63,12 @@ function FlatMaterial() | |||
63 | 63 | ||
64 | this.setProperty = function( prop, value ) | 64 | this.setProperty = function( prop, value ) |
65 | { | 65 | { |
66 | // make sure we have legitimate imput | 66 | // make sure we have legitimate input |
67 | if (this.validateProperty( prop, value )) | 67 | if (this.validateProperty( prop, value )) |
68 | { | 68 | { |
69 | this._color = value.slice(0); | 69 | this._propValues[prop] = value; |
70 | this._shader.colorMe[prop].set(value); | 70 | if (this._shader && this._shader.colorMe) |
71 | this._shader.colorMe[prop].set(value); | ||
71 | } | 72 | } |
72 | } | 73 | } |
73 | /////////////////////////////////////////////////////////////////////// | 74 | /////////////////////////////////////////////////////////////////////// |
@@ -76,7 +77,7 @@ function FlatMaterial() | |||
76 | { | 77 | { |
77 | // this function should be overridden by subclasses | 78 | // this function should be overridden by subclasses |
78 | var exportStr = "material: " + this.getShaderName() + "\n"; | 79 | var exportStr = "material: " + this.getShaderName() + "\n"; |
79 | exportStr = "name: " + this.getName() + "\n"; | 80 | exportStr += "name: " + this.getName() + "\n"; |
80 | 81 | ||
81 | if (this._shader) | 82 | if (this._shader) |
82 | exportStr += "color: " + String(this._shader.colorMe.color) + "\n"; | 83 | exportStr += "color: " + String(this._shader.colorMe.color) + "\n"; |
@@ -87,19 +88,32 @@ function FlatMaterial() | |||
87 | return exportStr; | 88 | return exportStr; |
88 | } | 89 | } |
89 | 90 | ||
90 | this.import = function( importStr ) | 91 | this.import = function( importStr ) |
91 | { | 92 | { |
92 | var pu = new ParseUtils( importStr ); | 93 | var pu = new ParseUtils( importStr ); |
93 | var material = pu.nextValue( "material: " ); | 94 | var material = pu.nextValue( "material: " ); |
94 | if (material != this.getShaderName()) throw new Error( "ill-formed material" ); | 95 | if (material != this.getShaderName()) throw new Error( "ill-formed material" ); |
95 | this.setName( pu.nextValue( "material: ") ); | 96 | this.setName( pu.nextValue( "name: ") ); |
96 | var color = pu.nextValue( "color: " ); | 97 | |
97 | 98 | var rtnStr; | |
98 | var endKey = "endMaterial\n"; | 99 | try |
99 | var index = importStr.indexOf( endKey ) + endKey.len; | 100 | { |
100 | var rtnStr = importStr.substr( index ); |