aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/line.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom/line.js')
-rwxr-xr-xjs/lib/geom/line.js112
1 files changed, 44 insertions, 68 deletions
diff --git a/js/lib/geom/line.js b/js/lib/geom/line.js
index 4a935de8..8ee39098 100755
--- a/js/lib/geom/line.js
+++ b/js/lib/geom/line.js
@@ -44,7 +44,7 @@ var Line = function GLLine( world, xOffset, yOffset, width, height, slope, strok
44 44
45 this._slope = slope; 45 this._slope = slope;
46 this._strokeWidth = strokeSize; 46 this._strokeWidth = strokeSize;
47 if (strokeColor) this._strokeColor = strokeColor.slice(); 47 this._strokeColor = strokeColor;
48 48
49 this._strokeStyle = strokeStyle; 49 this._strokeStyle = strokeStyle;
50 this._scaleX = (world.getViewportWidth())/(world.getViewportHeight()); 50 this._scaleX = (world.getViewportWidth())/(world.getViewportHeight());
@@ -99,77 +99,53 @@ var Line = function GLLine( world, xOffset, yOffset, width, height, slope, strok
99 99
100 this.geomType = function() { return this.GEOM_TYPE_LINE; } 100 this.geomType = function() { return this.GEOM_TYPE_LINE; }
101 101
102 /////////////////////////////////////////////////////////////////////// 102 ///////////////////////////////////////////////////////////////////////
103 // Methods 103 // Methods
104 /////////////////////////////////////////////////////////////////////// 104 ///////////////////////////////////////////////////////////////////////
105 this.export = function() { 105 this.exportJSON = function()
106 var rtnStr = "type: " + this.geomType() + "\n"; 106 {
107 107 var jObj =
108 rtnStr += "xoff: " + this._xOffset + "\n"; 108 {
109 rtnStr += "yoff: " + this._yOffset + "\n"; 109 'type' : this.geomType(),
110 rtnStr += "width: " + this._width + "\n"; 110 'xoff' : this._xOffset,
111 rtnStr += "height: " + this._height + "\n"; 111 'yoff' : this._yOffset,
112 rtnStr += "xAdj: " + this._xAdj + "\n"; 112 'width' : this._width,
113 rtnStr += "yAdj: " + this._yAdj + "\n"; 113 'height' : this._height,
114 rtnStr += "strokeWidth: " + this._strokeWidth + "\n"; 114 'xAdj' : this._xAdj,
115 115 'yAdj' : this._yAdj,
116 if(this._strokeColor.gradientMode) { 116 'slope' : this._slope,
117 rtnStr += "strokeGradientMode: " + this._strokeColor.gradientMode + "\n"; 117 'strokeWidth' : this._strokeWidth,
118 rtnStr += "strokeColor: " + this.gradientToString(this._strokeColor.color) + "\n"; 118 'strokeColor' : this._strokeColor,
119 } else { 119 'strokeStyle' : this._strokeStyle,
120 rtnStr += "strokeColor: " + String(this._strokeColor) + "\n"; 120 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(),
121 } 121 'materials' : this.exportMaterialsJSON()
122 122 };
123 rtnStr += "strokeStyle: " + this._strokeStyle + "\n"; 123
124 rtnStr += "slope: " + String(this._slope) + "\n"; 124 return jObj;
125
126 rtnStr += "strokeMat: ";
127 if (this._strokeMaterial) {
128 rtnStr += this._strokeMaterial.getName();
129 } else {
130 rtnStr += "flatMaterial";
131 }
132
133 rtnStr += "\n";
134 return rtnStr;
135 }; 125 };
136 126
137 this.import = function( importStr ) { 127 this.importJSON = function( jObj )
138 this._xOffset = Number( this.getPropertyFromString( "xoff: ", importStr ) ); 128 {
139 this._yOffset = Number( this.getPropertyFromString( "yoff: ", importStr ) ); 129 this._xOffset = jObj.xoff;
140 this._width = Number( this.getPropertyFromString( "width: ", importStr ) ); 130 this._yOffset = jObj.yoff;
141 this._height = Number( this.getPropertyFromString( "height: ", importStr ) ); 131 this._width = jObj.width;
142 this._xAdj = Number( this.getPropertyFromString( "xAdj: ", importStr ) ); 132 this._height = jObj.height;
143 this._yAdj = Number( this.getPropertyFromString( "yAdj: ", importStr ) ); 133 this._xAdj = jObj.xAdj;
144 this._strokeWidth = Number( this.getPropertyFromString( "strokeWidth: ", importStr ) ); 134 this._yAdj = jObj.yAdj;
145 var slope = this.getPropertyFromString( "slope: ", importStr ); 135 this._strokeWidth = jObj.strokeWidth;
146 136 this._slope = jObj.slope;
147 if(isNaN(Number(slope))) { 137 this._strokeStyle = jObj.strokeStyle;
148 this._slope = slope; 138 this._strokeColor = jObj.strokeColor;
149 } else { 139 var strokeMaterialName = jObj.strokeMat;
150 this._slope = Number(slope); 140
151 } 141 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName );
152 142 if (!strokeMat) {
153 var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr ); 143 console.log( "object material not found in library: " + strokeMaterialName );
154 this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr ); 144 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
155
156 if(importStr.indexOf("strokeGradientMode: ") < 0)
157 {
158 this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" );
159 } else {
160 this._strokeColor = {};
161 this._strokeColor.gradientMode = this.getPropertyFromString( "strokeGradientMode: ", importStr );
162 this._strokeColor.color = this.stringToGradient(this.getPropertyFromString( "strokeColor: ", importStr ));
163 } 145 }
146 this._strokeMaterial = strokeMat;
164 147
165 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); 148 this.importMaterialsJSON( jObj.materials );
166 if (!strokeMat) {
167 console.log( "object material not found in library: " + strokeMaterialName );
168 strokeMat = MaterialsModel.exportFlatMaterial();
169 }
170
171 this._strokeMaterial = strokeMat;
172
173 }; 149 };
174 150
175 /////////////////////////////////////////////////////////////////////// 151 ///////////////////////////////////////////////////////////////////////
@@ -182,7 +158,7 @@ var Line = function GLLine( world, xOffset, yOffset, width, height, slope, strok
182 if (!world._useWebGL) return; 158 if (!world._useWebGL) return;
183 159
184 // make sure RDGE has the correct context 160 // make sure RDGE has the correct context
185 g_Engine.setContext( world.getCanvas().rdgeid ); 161 RDGE.globals.engine.setContext( world.getCanvas().rdgeid );
186 162
187 // create the gl buffer 163 // create the gl buffer
188 var gl = world.getGLContext(); 164 var gl = world.getGLContext();
@@ -343,7 +319,7 @@ var Line = function GLLine( world, xOffset, yOffset, width, height, slope, strok
343 indices.push( index ); index++; 319 indices.push( index ); index++;
344 } 320 }
345 321
346 var prim = ShapePrimitive.create(strokeVertices, strokeNormals, strokeTextures, indices, g_Engine.getContext().renderer.TRIANGLES, indices.length); 322 var prim = ShapePrimitive.create(strokeVertices, strokeNormals, strokeTextures, indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, indices.length);
347 323
348 var strokeMaterial = this.makeStrokeMaterial(); 324 var strokeMaterial = this.makeStrokeMaterial();
349 325