From 679a0746bedab9c5871a83a5fea6a06ac6a4f41c Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 2 Apr 2012 10:17:48 -0700 Subject: texture abstraction --- js/lib/drawing/world.js | 6 +++--- js/lib/geom/geom-obj.js | 4 ++++ js/lib/rdge/texture.js | 29 ++++++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 4 deletions(-) (limited to 'js/lib') diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index a489110f..402563e9 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js @@ -1051,9 +1051,9 @@ World.prototype.importSubObject = function( objStr, parentNode ) { function Notifier() { // notification types supported - this.OBJECT_DELETE = 1; - this.OBJECT_REANIMATE = 2; // the object has come back after a deletion - as in undo - this.OBJECT_CHANGE = 3; + this.OBJECT_DELETE = 1; + this.OBJECT_REINSTANTIATE = 2; // the object has come back after a deletion - as in undo + this.OBJECT_CHANGE = 3; // the array of listener objects diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index a87bdbf5..11b9303a 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js @@ -220,6 +220,8 @@ var GeomObj = function GLGeomObj() { this.setStrokeColor(this._strokeColor); } + this._strokeMaterial = strokeMaterial; + return strokeMaterial; }; @@ -242,6 +244,8 @@ var GeomObj = function GLGeomObj() { this.setFillColor(this._fillColor); } + this._fillMaterial = fillMaterial; + return fillMaterial; }; diff --git a/js/lib/rdge/texture.js b/js/lib/rdge/texture.js index d67c65d2..83509f80 100644 --- a/js/lib/rdge/texture.js +++ b/js/lib/rdge/texture.js @@ -69,7 +69,7 @@ function Texture( dstWorld, texMapName, wrap, mips ) this._srcWorld = srcCanvas.elementModel.shapeModel.GLWorld; // add a notifier to the world - this._srcWorld.addListener( this, this.worldCallback, { myObj: 'anything' } ); + this._srcWorld.addListener( this, this.worldCallback, { srcWorld: this._srcWorld } ); // check if the source is animated if (srcCanvas.elementModel && srcCanvas.elementModel.shapeModel && srcCanvas.elementModel.shapeModel.GLWorld) @@ -87,6 +87,33 @@ function Texture( dstWorld, texMapName, wrap, mips ) this.worldCallback = function( type, callbackObj, calleeData, callerData ) { console.log( "texture callback, type: " + type ); + if (calleeData.srcWorld) + { + var srcWorld = calleeData.srcWorld; + var notifier = srcWorld._notifier; + var texture = this.callbackObj; + if (texture) + { + switch (type) + { + case notifier.OBJECT_DELETE: + break; + + case notifier.OBJECT_REINSTANTIATE: + break; + + case notifier.OBJECT_CHANGE: + if (!texture.isAnimated()) + texture.rerender(); + texture.getDstWorld().restartRenderLoop(); + break; + + default: + throw new Exception( "unrecognized texture callback type: " + type ); + break; + } + } + } } this.loadFromFile = function() -- cgit v1.2.3