diff options
Diffstat (limited to 'js/lib/rdge/texture.js')
-rw-r--r-- | js/lib/rdge/texture.js | 600 |
1 files changed, 300 insertions, 300 deletions
diff --git a/js/lib/rdge/texture.js b/js/lib/rdge/texture.js index 30452489..dc0da247 100644 --- a/js/lib/rdge/texture.js +++ b/js/lib/rdge/texture.js | |||
@@ -38,311 +38,311 @@ var __textureCounter = 0; | |||
38 | /////////////////////////////////////////////////////////////////////// | 38 | /////////////////////////////////////////////////////////////////////// |
39 | function Texture( dstWorld, texMapName, wrap, mips ) | 39 | function Texture( dstWorld, texMapName, wrap, mips ) |
40 | { | 40 | { |
41 | /////////////////////////////////////////////////////////////////////// | 41 | /////////////////////////////////////////////////////////////////////// |
42 | // Instance variables | 42 | // Instance variables |
43 | /////////////////////////////////////////////////////////////////////// | 43 | /////////////////////////////////////////////////////////////////////// |
44 | this._texture; | 44 | this._texture; |
45 | 45 | ||
46 | // the canvas generating the texture map (if there is one) | 46 | // the canvas generating the texture map (if there is one) |
47 | this._srcCanvas; | 47 | this._srcCanvas; |
48 | this._srcWorld; | 48 | this._srcWorld; |
49 | 49 | ||
50 | // texture attributes | 50 | // texture attributes |
51 | if (typeof texMapName === "string") | 51 | if (typeof texMapName === "string") |
52 | this._texMapName = texMapName.slice(); | 52 | this._texMapName = texMapName.slice(); |
53 | else | 53 | else |
54 | this._srcCanvas = texMapName; | 54 | this._srcCanvas = texMapName; |
55 | 55 | ||
56 | 56 | ||
57 | // set default values for wrap and mips | 57 | // set default values for wrap and mips |
58 | if (wrap === undefined) | 58 | if (wrap === undefined) |
59 | wrap = "REPEAT"; | 59 | wrap = "REPEAT"; |
60 | if (mips === undefined) | 60 | if (mips === undefined) |
61 | mips = true; | 61 | mips = true; |
62 | this._wrap = wrap; | 62 | this._wrap = wrap; |
63 | this._mips = mips; | 63 | this._mips = mips; |
64 | 64 | ||
65 | // cache whether or not the source is animated | 65 | // cache whether or not the source is animated |
66 | this._isAnimated = false; | 66 | this._isAnimated = false; |
67 | 67 | ||
68 | // the destination world that will use the texture map | 68 | // the destination world that will use the texture map |
69 | this._dstWorld = dstWorld; | 69 | this._dstWorld = dstWorld; |
70 | 70 | ||
71 | this._texCount = __textureCounter; | 71 | this._texCount = __textureCounter; |
72 | __textureCounter++; | 72 | __textureCounter++; |
73 | 73 | ||
74 | /////////////////////////////////////////////////////////////////////// | 74 | /////////////////////////////////////////////////////////////////////// |
75 | // Property Accessors | 75 | // Property Accessors |
76 | /////////////////////////////////////////////////////////////////////// | 76 | /////////////////////////////////////////////////////////////////////// |
77 | this.getTexture = function() { return this._texture; } | 77 | this.getTexture = function() { return this._texture; } |
78 | 78 | ||
79 | this.setSrcWorld = function(w) { this._srcWorld = w; } | 79 | this.setSrcWorld = function(w) { this._srcWorld = w; } |
80 | this.getSrcWorld = function() { return this._srcWorld; } | 80 | this.getSrcWorld = function() { return this._srcWorld; } |
81 | 81 | ||
82 | this.setDstWorld = function(w) { this._dstWorld = w; } | 82 | this.setDstWorld = function(w) { this._dstWorld = w; } |
83 | this.getDstWorld = function() { return this._dstWorld; } | 83 | this.getDstWorld = function() { return this._dstWorld; } |
84 | 84 | ||
85 | this.isAnimated = function() { return this._isAnimated; } | 85 | this.isAnimated = function() { return this._isAnimated; } |
86 | 86 | ||
87 | /////////////////////////////////////////////////////////////////////// | 87 | /////////////////////////////////////////////////////////////////////// |
88 | // Methods | 88 | // Methods |
89 | /////////////////////////////////////////////////////////////////////// | 89 | /////////////////////////////////////////////////////////////////////// |
90 | 90 | ||
91 | this.init = function() | 91 | this.init = function() |
92 | { | 92 | { |
93 | // determine if the source is a canvas or an image file | 93 | // determine if the source is a canvas or an image file |
94 | var viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils; | 94 | var viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils; |
95 | //var root = viewUtils.application.ninja.currentDocument.documentRoot; | 95 | //var root = viewUtils.application.ninja.currentDocument.documentRoot; |
96 | var root; | 96 | var root; |
97 | if (viewUtils.application.ninja.currentDocument) | 97 | if (viewUtils.application.ninja.currentDocument) |
98 | root = viewUtils.application.ninja.currentDocument.model.documentRoot; | 98 | root = viewUtils.application.ninja.currentDocument.model.documentRoot; |
99 | var srcCanvas = this._srcCanvas; | 99 | var srcCanvas = this._srcCanvas; |
100 | if (!srcCanvas && root) | 100 | if (!srcCanvas && root) |
101 | srcCanvas = this.findCanvas( this._texMapName, root ); | 101 | srcCanvas = this.findCanvas( this._texMapName, root ); |
102 | if (srcCanvas) | 102 | if (srcCanvas) |
103 | { | 103 | { |
104 | this._srcCanvas = srcCanvas; | 104 | this._srcCanvas = srcCanvas; |
105 | var srcWorld | 105 | var srcWorld |
106 | if (srcCanvas.elementModel && srcCanvas.elementModel.shapeModel && srcCanvas.elementModel.shapeModel.GLWorld) | 106 | if (srcCanvas.elementModel && srcCanvas.elementModel.shapeModel && srcCanvas.elementModel.shapeModel.GLWorld) |
107 | srcWorld = srcCanvas.elementModel.shapeModel.GLWorld; | 107 | srcWorld = srcCanvas.elementModel.shapeModel.GLWorld; |
108 | if (!srcWorld) srcWorld = srcCanvas.__GLWorld; | 108 | if (!srcWorld) srcWorld = srcCanvas.__GLWorld; |
109 | if (srcWorld) | 109 | if (srcWorld) |
110 | { | 110 | { |
111 | this._srcWorld = srcWorld; | 111 | this._srcWorld = srcWorld; |
112 | 112 | ||
113 | // add a notifier to the world | 113 | // add a notifier to the world |
114 | srcWorld.addListener( this, this.worldCallback, { srcWorld: this._srcWorld } ); | 114 | srcWorld.addListener( this, this.worldCallback, { srcWorld: this._srcWorld } ); |
115 | 115 | ||
116 | // check if the source is animated | 116 | // check if the source is animated |
117 | this._isAnimated = srcWorld._hasAnimatedMaterials; | 117 | this._isAnimated = srcWorld._hasAnimatedMaterials; |
118 | } | 118 | } |
119 | 119 | ||
120 | this.loadFromCanvas(); | 120 | this.loadFromCanvas(); |
121 | } | 121 | } |
122 | else | 122 | else |
123 | { | 123 | { |
124 | this.loadFromFile(); | 124 | this.loadFromFile(); |
125 | } | 125 | } |
126 | } | 126 | } |
127 | 127 | ||
128 | this.worldCallback = function( type, callbackObj, calleeData, callerData ) | 128 | this.worldCallback = function( type, callbackObj, calleeData, callerData ) |
129 | { | 129 | { |
130 | console.log( "texture callback, type: " + type ); | 130 | console.log( "texture callback, type: " + type ); |
131 | if (calleeData.srcWorld) | 131 | if (calleeData.srcWorld) |
132 | { | 132 | { |
133 | var srcWorld = callbackObj.getSrcWorld(); | 133 | var srcWorld = callbackObj.getSrcWorld(); |
134 | var dstWorld = callbackObj.getDstWorld(); | 134 | var dstWorld = callbackObj.getDstWorld(); |
135 | var notifier = srcWorld._notifier; | 135 | var notifier = srcWorld._notifier; |
136 | var texture = this.callbackObj; | 136 | var texture = this.callbackObj; |
137 | if (texture) | 137 | if (texture) |
138 | { | 138 | { |
139 | switch (type) | 139 | switch (type) |
140 | { | 140 | { |
141 | case notifier.OBJECT_DELETE: | 141 | case notifier.OBJECT_DELETE: |
142 | texture.rebuildSrcLocally(); | 142 | texture.rebuildSrcLocally(); |
143 | break; | 143 | break; |
144 | 144 | ||
145 | case notifier.OBJECT_REINSTANTIATE: | 145 | case notifier.OBJECT_REINSTANTIATE: |
146 | break; | 146 | break; |
147 | 147 | ||
148 | case notifier.OBJECT_CHANGE: | 148 | case notifier.OBJECT_CHANGE: |
149 | break; | 149 | break; |
150 | 150 | ||
151 | case notifier.FIRST_RENDER: | 151 | case notifier.FIRST_RENDER: |
152 | texture._isAnimated = srcWorld.hasAnimatedMaterials(); | 152 | texture._isAnimated = srcWorld.hasAnimatedMaterials(); |
153 | break; | 153 | break; |
154 | 154 | ||
155 | default: | 155 | default: |
156 | throw new Exception( "unrecognized texture callback type: " + type ); | 156 | throw new Exception( "unrecognized texture callback type: " + type ); |
157 | break; | 157 | break; |
158 | } | 158 | } |
159 | } | 159 | } |
160 | } | 160 | } |
161 | } | 161 | } |
162 | 162 | ||
163 | this.rebuildSrcLocally = function() | 163 | this.rebuildSrcLocally = function() |
164 | { | 164 | { |
165 | var srcWorld = this._srcWorld; | 165 | var srcWorld = this._srcWorld; |
166 | if (srcWorld) | 166 | if (srcWorld) |
167 | { | 167 | { |
168 | // get the data from the old world | 168 | // get the data from the old world |
169 | var jStr = srcWorld.exportJSON(); | 169 | var jStr = srcWorld.exportJSON(); |
170 | var index = jStr.indexOf( ';' ); | 170 | var index = jStr.indexOf( ';' ); |
171 | if ((jStr[0] === 'v') && (index < 24)) | 171 | if ((jStr[0] === 'v') && (index < 24)) |
172 | jStr = jStr.substr( index+1 ); | 172 | jStr = jStr.substr( index+1 ); |
173 | var jObj = JSON.parse( jStr ); | 173 | var jObj = JSON.parse( jStr ); |
174 | var oldCanvas = srcWorld.getCanvas(); | 174 | var oldCanvas = srcWorld.getCanvas(); |
175 | 175 | ||
176 | // create a new canvas | 176 | // create a new canvas |
177 | var NJUtils = require("js/lib/NJUtils").NJUtils; | 177 | var NJUtils = require("js/lib/NJUtils").NJUtils; |
178 | this._srcCanvas = NJUtils.makeNJElement("canvas", "texture_internal_canvas", "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true); | 178 | this._srcCanvas = NJUtils.makeNJElement("canvas", "texture_internal_canvas", "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true); |
179 | srcCanvas = this._srcCanvas; | 179 | srcCanvas = this._srcCanvas; |
180 | srcCanvas.width = oldCanvas.width; | 180 | srcCanvas.width = oldCanvas.width; |
181 | srcCanvas.height = oldCanvas.height; | 181 | srcCanvas.height = oldCanvas.height; |
182 | 182 | ||
183 | // rebuild the world | 183 | // rebuild the world |
184 | var GLWorld = require( |