aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/texture.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/texture.js')
-rw-r--r--js/lib/rdge/texture.js631
1 files changed, 316 insertions, 315 deletions
diff --git a/js/lib/rdge/texture.js b/js/lib/rdge/texture.js
index 30452489..70f337d4 100644
--- a/js/lib/rdge/texture.js
+++ b/js/lib/rdge/texture.js
@@ -1,24 +1,25 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License.
5 4
6Redistribution and use in source and binary forms, with or without 5Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 6modification, are permitted provided that the following conditions are met:
8 7
9 - Redistributions of source code must retain the above copyright notice, 8* Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer. 9 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright 10
12 notice, this list of conditions and the following disclaimer in the 11* Redistributions in binary form must reproduce the above copyright notice,
13 documentation and/or other materials provided with the distribution. 12 this list of conditions and the following disclaimer in the documentation
14 - Neither the name of Motorola Mobility nor the names of its contributors 13 and/or other materials provided with the distribution.
15 may be used to endorse or promote products derived from this software 14
16 without specific prior written permission. 15* Neither the name of Motorola Mobility LLC nor the names of its
16 contributors may be used to endorse or promote products derived from this
17 software without specific prior written permission.
17 18
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -38,311 +39,311 @@ var __textureCounter = 0;
38/////////////////////////////////////////////////////////////////////// 39///////////////////////////////////////////////////////////////////////
39function Texture( dstWorld, texMapName, wrap, mips ) 40function Texture( dstWorld, texMapName, wrap, mips )
40{ 41{
41 /////////////////////////////////////////////////////////////////////// 42 ///////////////////////////////////////////////////////////////////////
42 // Instance variables 43 // Instance variables
43 /////////////////////////////////////////////////////////////////////// 44 ///////////////////////////////////////////////////////////////////////
44 this._texture; 45 this._texture;
45 46
46 // the canvas generating the texture map (if there is one) 47 // the canvas generating the texture map (if there is one)
47 this._srcCanvas; 48 this._srcCanvas;
48 this._srcWorld; 49 this._srcWorld;
49 50
50 // texture attributes 51 // texture attributes
51 if (typeof texMapName === "string") 52 if (typeof texMapName === "string")
52 this._texMapName = texMapName.slice(); 53 this._texMapName = texMapName.slice();
53 else 54 else
54 this._srcCanvas = texMapName; 55 this._srcCanvas = texMapName;
55 56
56 57
57 // set default values for wrap and mips 58 // set default values for wrap and mips
58 if (wrap === undefined) 59 if (wrap === undefined)
59 wrap = "REPEAT"; 60 wrap = "REPEAT";
60 if (mips === undefined) 61 if (mips === undefined)
61 mips = true; 62 mips = true;
62 this._wrap = wrap; 63 this._wrap = wrap;
63 this._mips = mips; 64 this._mips = mips;
64 65
65 // cache whether or not the source is animated 66 // cache whether or not the source is animated
66 this._isAnimated = false; 67 this._isAnimated = false;
67 68
68 // the destination world that will use the texture map 69 // the destination world that will use the texture map
69 this._dstWorld = dstWorld; 70 this._dstWorld = dstWorld;
70 71
71 this._texCount = __textureCounter; 72 this._texCount = __textureCounter;
72 __textureCounter++; 73 __textureCounter++;
73 74
74 /////////////////////////////////////////////////////////////////////// 75 ///////////////////////////////////////////////////////////////////////
75 // Property Accessors 76 // Property Accessors
76 /////////////////////////////////////////////////////////////////////// 77 ///////////////////////////////////////////////////////////////////////
77 this.getTexture = function() { return this._texture; } 78 this.getTexture = function() { return this._texture; }
78 79
79 this.setSrcWorld = function(w) { this._srcWorld = w; } 80 this.setSrcWorld = function(w) { this._srcWorld = w; }
80 this.getSrcWorld = function() { return this._srcWorld; } 81 this.getSrcWorld = function() { return this._srcWorld; }
81 82
82 this.setDstWorld = function(w) { this._dstWorld = w; } 83 this.setDstWorld = function(w) { this._dstWorld = w; }
83 this.getDstWorld = function() { return this._dstWorld; } 84 this.getDstWorld = function() { return this._dstWorld; }
84 85
85 this.isAnimated = function() { return this._isAnimated; } 86 this.isAnimated = function() { return this._isAnimated; }
86 87
87 /////////////////////////////////////////////////////////////////////// 88 ///////////////////////////////////////////////////////////////////////
88 // Methods 89 // Methods
89 /////////////////////////////////////////////////////////////////////// 90 ///////////////////////////////////////////////////////////////////////
90 91
91 this.init = function() 92 this.init = function()
92 { 93 {
93 // determine if the source is a canvas or an image file 94 // determine if the source is a canvas or an image file
94 var viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils; 95 var viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils;
95 //var root = viewUtils.application.ninja.currentDocument.documentRoot; 96 //var root = viewUtils.application.ninja.currentDocument.documentRoot;
96 var root; 97 var root;
97 if (viewUtils.application.ninja.currentDocument) 98 if (viewUtils.application.ninja.currentDocument)
98 root = viewUtils.application.ninja.currentDocument.model.documentRoot; 99 root = viewUtils.application.ninja.currentDocument.model.documentRoot;
99 var srcCanvas = this._srcCanvas; 100 var srcCanvas = this._srcCanvas;
100 if (!srcCanvas && root) 101 if (!srcCanvas && root)
101 srcCanvas = this.findCanvas( this._texMapName, root ); 102 srcCanvas = this.findCanvas( this._texMapName, root );
102 if (srcCanvas) 103 if (srcCanvas)
103 { 104 {
104 this._srcCanvas = srcCanvas; 105 this._srcCanvas = srcCanvas;
105 var srcWorld 106 var srcWorld
106 if (srcCanvas.elementModel && srcCanvas.elementModel.shapeModel && srcCanvas.elementModel.shapeModel.GLWorld) 107 if (srcCanvas.elementModel && srcCanvas.elementModel.shapeModel && srcCanvas.elementModel.shapeModel.GLWorld)
107 srcWorld = srcCanvas.elementModel.shapeModel.GLWorld; 108 srcWorld = srcCanvas.elementModel.shapeModel.GLWorld;
108 if (!srcWorld) srcWorld = srcCanvas.__GLWorld; 109 if (!srcWorld) srcWorld = srcCanvas.__GLWorld;
109 if (srcWorld) 110 if (srcWorld)
110 { 111 {
111 this._srcWorld = srcWorld; 112 this._srcWorld = srcWorld;
112 113
113 // add a notifier to the world 114 // add a notifier to the world
114 srcWorld.addListener( this, this.worldCallback, { srcWorld: this._srcWorld } ); 115 srcWorld.addListener( this, this.worldCallback, { srcWorld: this._srcWorld } );
115 116
116 // check if the source is animated 117 // check if the source is animated
117 this._isAnimated = srcWorld._hasAnimatedMaterials; 118 this._isAnimated = srcWorld._hasAnimatedMaterials;
118 } 119 }
119 120
120 this.loadFromCanvas(); 121 this.loadFromCanvas();
121 } 122 }
122 else 123 else
123 { 124 {
124 this.loadFromFile(); 125 this.loadFromFile();
125 } 126 }
126 } 127 }
127 128
128 this.worldCallback = function( type, callbackObj, calleeData, callerData ) 129 this.worldCallback = function( type, callbackObj, calleeData, callerData )
129 { 130 {
130 console.log( "texture callback, type: " + type ); 131 console.log( "texture callback, type: " + type );
131 if (calleeData.srcWorld) 132 if (calleeData.srcWorld)
132 { 133 {
133 var srcWorld = callbackObj.getSrcWorld(); 134 var srcWorld = callbackObj.getSrcWorld();
134 var dstWorld = callbackObj.getDstWorld(); 135 var dstWorld = callbackObj.getDstWorld();
135 var notifier = srcWorld._notifier; 136 var notifier = srcWorld._notifier;
136 var texture = this.callbackObj; 137 var texture = this.callbackObj;
137 if (texture) 138 if (texture)
138 { 139 {
139 switch (type) 140 switch (type)
140 { 141 {
141 case notifier.OBJECT_DELETE: 142 case notifier.OBJECT_DELETE:
142 texture.rebuildSrcLocally(); 143 texture.rebuildSrcLocally();
143 break; 144 break;
144 145
145 case notifier.OBJECT_REINSTANTIATE: 146 case notifier.OBJECT_REINSTANTIATE:
146 break; 147 break;
147 148
148 case notifier.OBJECT_CHANGE: 149 case notifier.OBJECT_CHANGE:
149 break; 150 break;
150 151
151 case notifier.FIRST_RENDER: 152 case notifier.FIRST_RENDER:
152 texture._isAnimated = srcWorld.hasAnimatedMaterials(); 153 texture._isAnimated = srcWorld.hasAnimatedMaterials();
153 break; 154 break;
154 155
155 default: 156 default:
156 throw new Exception( "unrecognized texture callback type: " + type ); 157 throw new Exception( "unrecognized texture callback type: " + type );
157 break; 158 break;
158 }