diff options
Diffstat (limited to 'js/lib/geom/circle.js')
-rwxr-xr-x | js/lib/geom/circle.js | 145 |
1 files changed, 52 insertions, 93 deletions
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js index 4b155b4c..1073c2db 100755 --- a/js/lib/geom/circle.js +++ b/js/lib/geom/circle.js | |||
@@ -42,8 +42,8 @@ var Circle = function GLCircle() { | |||
42 | 42 | ||
43 | this._strokeWidth = strokeSize; | 43 | this._strokeWidth = strokeSize; |
44 | this._innerRadius = innerRadius; | 44 | this._innerRadius = innerRadius; |
45 | if (strokeColor) this._strokeColor = strokeColor; | 45 | this._strokeColor = strokeColor; |
46 | if (fillColor) this._fillColor = fillColor; | 46 | this._fillColor = fillColor; |
47 | 47 | ||
48 | this._strokeStyle = strokeStyle; | 48 | this._strokeStyle = strokeStyle; |
49 | } | 49 | } |
@@ -53,16 +53,14 @@ var Circle = function GLCircle() { | |||
53 | if(strokeMaterial){ | 53 | if(strokeMaterial){ |
54 | this._strokeMaterial = strokeMaterial; | 54 | this._strokeMaterial = strokeMaterial; |
55 | } else { | 55 | } else { |
56 | this._strokeMaterial = MaterialsModel.exportFlatMaterial(); | 56 | this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); |
57 | } | 57 | } |
58 | 58 | ||
59 | if(fillMaterial) { | 59 | if(fillMaterial) { |
60 | this._fillMaterial = fillMaterial; | 60 | this._fillMaterial = fillMaterial; |
61 | } else { | 61 | } else { |
62 | this._fillMaterial = MaterialsModel.exportFlatMaterial(); | 62 | this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); |
63 | } | 63 | } |
64 | |||
65 | this.exportMaterials(); | ||
66 | }; | 64 | }; |
67 | 65 | ||
68 | /////////////////////////////////////////////////////////////////////// | 66 | /////////////////////////////////////////////////////////////////////// |
@@ -178,7 +176,7 @@ var Circle = function GLCircle() { | |||
178 | if (!world._useWebGL) return; | 176 | if (!world._useWebGL) return; |
179 | 177 | ||
180 | // make sure RDGE has the correct context | 178 | // make sure RDGE has the correct context |
181 | g_Engine.setContext( world.getCanvas().rdgeid ); | 179 | RDGE.globals.engine.setContext( world.getCanvas().rdgeid ); |
182 | 180 | ||
183 | // create the gl buffer | 181 | // create the gl buffer |
184 | var gl = world.getGLContext(); | 182 | var gl = world.getGLContext(); |
@@ -350,7 +348,7 @@ var Circle = function GLCircle() { | |||
350 | 348 | ||
351 | this.recalcTexMapCoords( vrts, uvs ); | 349 | this.recalcTexMapCoords( vrts, uvs ); |
352 | 350 | ||
353 | return ShapePrimitive.create(vrts, nrms, uvs, indices, g_Engine.getContext().renderer.TRIANGLES, index); | 351 | return ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, index); |
354 | }; | 352 | }; |
355 | 353 | ||
356 | this.generateOvalRing = function(xOff, yOff, rotationMat, innerScaleMat, outerScaleMat, nTriangles) { | 354 | this.generateOvalRing = function(xOff, yOff, rotationMat, innerScaleMat, outerScaleMat, nTriangles) { |
@@ -407,7 +405,7 @@ var Circle = function GLCircle() { | |||
407 | 405 | ||
408 | this.recalcTexMapCoords( vrts, uvs ); | 406 | this.recalcTexMapCoords( vrts, uvs ); |
409 | 407 | ||
410 | return ShapePrimitive.create(vrts, nrms, uvs, indices, g_Engine.getContext().renderer.TRIANGLE_STRIP, indices.length); | 408 | return ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLE_STRIP, indices.length); |
411 | }; | 409 | }; |
412 | 410 | ||
413 | this.render = function() { | 411 | this.render = function() { |
@@ -598,96 +596,57 @@ var Circle = function GLCircle() { | |||
598 | } | 596 | } |
599 | }; | 597 | }; |
600 | 598 | ||
601 | this.export = function() { | 599 | this.exportJSON = function() |
602 | var rtnStr = "type: " + this.geomType() + "\n"; | 600 | { |
603 | 601 | var jObj = | |
604 | rtnStr += "xoff: " + this._xOffset + "\n"; | 602 | { |
605 | rtnStr += "yoff: " + this._yOffset + "\n"; | 603 | 'type' : this.geomType(), |
606 | rtnStr += "width: " + this._width + "\n"; | 604 | 'xoff' : this._xOffset, |
607 | rtnStr += "height: " + this._height + "\n"; | 605 | 'yoff' : this._yOffset, |
608 | rtnStr += "strokeWidth: " + this._strokeWidth + "\n"; | 606 | 'width' : this._width, |
609 | rtnStr += "innerRadius: " + this._innerRadius + "\n"; | 607 | 'height' : this._height, |
610 | rtnStr += "strokeStyle: " + this._strokeStyle + "\n"; | 608 | 'strokeWidth' : this._strokeWidth, |
611 | 609 | 'strokeColor' : this._strokeColor, | |
612 | if(this._strokeColor.gradientMode) { | 610 | 'fillColor' : this._fillColor, |
613 | rtnStr += "strokeGradientMode: " + this._strokeColor.gradientMode + "\n"; | 611 | 'innerRadius' : this._innerRadius, |
614 | rtnStr += "strokeColor: " + this.gradientToString(this._strokeColor.color) + "\n"; | 612 | 'strokeStyle' : this._strokeStyle, |
615 | } else { | 613 | 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(), |
616 | rtnStr += "strokeColor: " + String(this._strokeColor) + "\n"; | 614 | 'fillMat' : this._fillMaterial ? this._fillMaterial.getName() : MaterialsModel.getDefaultMaterialName(), |
617 | } | 615 | 'materials' : this.exportMaterialsJSON() |
618 | 616 | }; | |
619 | if(this._fillColor.gradientMode) { | 617 | |
620 | rtnStr += "fillGradientMode: " + this._fillColor.gradientMode + "\n"; | 618 | return jObj; |
621 | rtnStr += "fillColor: " + this.gradientToString(this._fillColor.color) + "\n"; | ||
622 | } else { | ||
623 | rtnStr += "fillColor: " + String(this._fillColor) + "\n"; | ||
624 | } | ||
625 | |||
626 | rtnStr += "strokeMat: "; | ||
627 | if (this._strokeMaterial) { | ||
628 | rtnStr += this._strokeMaterial.getName(); | ||
629 | } else { | ||
630 | rtnStr += "flatMaterial"; | ||
631 | } | ||
632 | |||
633 | rtnStr += "\n"; | ||
634 | |||
635 | rtnStr += "fillMat: "; | ||
636 | if (this._fillMaterial) { | ||
637 | rtnStr += this._fillMaterial.getName(); | ||
638 | } else { | ||
639 | rtnStr += "flatMaterial"; | ||
640 | } | ||
641 | rtnStr += "\n"; | ||
642 | |||
643 | rtnStr += this.exportMaterials(); | ||
644 | |||
645 | return rtnStr; | ||
646 | }; | 619 | }; |
647 | 620 | ||
648 | this.import = function( importStr ) { | 621 | this.importJSON = function( jObj ) |
649 | this._xOffset = Number( this.getPropertyFromString( "xoff: ", importStr ) ); | 622 | { |
650 | this._yOffset = Number( this.getPropertyFromString( "yoff: ", importStr ) ); | 623 | this._xOffset = jObj.xoff; |
651 | this._width = Number( this.getPropertyFromString( "width: ", importStr ) ); | 624 | this._yOffset = jObj.yoff; |
652 | this._height = Number( this.getPropertyFromString( "height: ", importStr ) ); | 625 | this._width = jObj.width; |
653 | this._strokeWidth = Number( this.getPropertyFromString( "strokeWidth: ", importStr ) ); | 626 | this._height = jObj.height; |
654 | this._innerRadius = Number( this.getPropertyFromString( "innerRadius: ", importStr ) ); | 627 | this._strokeWidth = jObj.strokeWidth; |
655 | this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr ); | 628 | this._strokeColor = jObj.strokeColor; |
656 | var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr ); | 629 | this._fillColor = jObj.fillColor; |
657 | var fillMaterialName = this.getPropertyFromString( "fillMat: ", importStr ); | 630 | this._innerRadius = jObj.innerRadius; |
658 | if(importStr.indexOf("fillGradientMode: ") < 0) { | 631 | this._strokeStyle = jObj.strokeStyle; |
659 | this._fillColor = eval( "[" + this.getPropertyFromString( "fillColor: ", importStr ) + "]" ); | 632 | var strokeMaterialName = jObj.strokeMat; |
660 | } else { | 633 | var fillMaterialName = jObj.fillMat; |
661 | this._fillColor = {}; | 634 | |
662 | this._fillColor.gradientMode = this.getPropertyFromString( "fillGradientMode: ", importStr ); | 635 | var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); |
663 | this._fillColor.color = this.stringToGradient(this.getPropertyFromString( "fillColor: ", importStr )); | 636 | if (!strokeMat) { |
637 | console.log( "object material not found in library: " + strokeMaterialName ); | ||
638 | strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | ||
664 | } | 639 | } |
640 | this._strokeMaterial = strokeMat; | ||
665 | 641 | ||
666 | if(importStr.indexOf("strokeGradientMode: ") < 0) | 642 | var fillMat = MaterialsModel.getMaterial( fillMaterialName ); |
667 | { | 643 | if (!fillMat) { |
668 | this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" ); | 644 | console.log( "object material not found in library: " + fillMaterialName ); |
669 | } else { | 645 | fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); |
670 | this._strokeColor = {}; | ||
671 | this._strokeColor.gradientMode = this.getPropertyFromString( "strokeGradientMode: ", importStr ); | ||
672 | this._strokeColor.color = this.stringToGradient(this.getPropertyFromString( "strokeColor: ", importStr )); | ||
673 | } | 646 | } |
647 | this._fillMaterial = fillMat; | ||
674 | 648 | ||
675 | var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); | 649 | this.importMaterialsJSON( jObj.materials ); |
676 | if (!strokeMat) { | ||
677 | console.log( "object material not found in library: " + strokeMaterialName ); | ||
678 | strokeMat = MaterialsModel.exportFlatMaterial(); | ||
679 | } | ||
680 | |||
681 | this._strokeMaterial = strokeMat; | ||
682 | |||
683 | var fillMat = MaterialsModel.getMaterial( fillMaterialName ); | ||
684 | if (!fillMat) { | ||
685 | console.log( "object material not found in library: " + fillMaterialName ); | ||
686 | fillMat = MaterialsModel.exportFlatMaterial(); | ||
687 | } | ||
688 | this._fillMaterial = fillMat; | ||
689 | |||
690 | this.importMaterials( importStr ); | ||
691 | }; | 650 | }; |
692 | 651 | ||
693 | this.collidesWithPoint = function( x, y ) { | 652 | this.collidesWithPoint = function( x, y ) { |