diff options
Diffstat (limited to 'js/lib/rdge')
-rw-r--r-- | js/lib/rdge/materials/flag-material.js | 6 | ||||
-rwxr-xr-x | js/lib/rdge/materials/material.js | 5 | ||||
-rw-r--r-- | js/lib/rdge/materials/twist-vert-material.js | 1 | ||||
-rw-r--r-- | js/lib/rdge/texture.js | 527 |
4 files changed, 273 insertions, 266 deletions
diff --git a/js/lib/rdge/materials/flag-material.js b/js/lib/rdge/materials/flag-material.js index 77991a8c..8d4d1ee3 100644 --- a/js/lib/rdge/materials/flag-material.js +++ b/js/lib/rdge/materials/flag-material.js | |||
@@ -23,6 +23,8 @@ var FlagMaterial = function FlagMaterial() { | |||
23 | this._defaultWaveWidth = 1.0; | 23 | this._defaultWaveWidth = 1.0; |
24 | this._defaultWaveHeight = 1.0; | 24 | this._defaultWaveHeight = 1.0; |
25 | 25 | ||
26 | this._hasVertexDeformation = true; | ||
27 | |||
26 | /////////////////////////////////////////////////////////////////////// | 28 | /////////////////////////////////////////////////////////////////////// |
27 | // Properties | 29 | // Properties |
28 | /////////////////////////////////////////////////////////////////////// | 30 | /////////////////////////////////////////////////////////////////////// |
@@ -37,6 +39,10 @@ var FlagMaterial = function FlagMaterial() { | |||
37 | this._propValues[ this._propNames[1] ] = this._defaultWaveWidth; | 39 | this._propValues[ this._propNames[1] ] = this._defaultWaveWidth; |
38 | this._propValues[ this._propNames[2] ] = this._defaultWaveHeight; | 40 | this._propValues[ this._propNames[2] ] = this._defaultWaveHeight; |
39 | 41 | ||
42 | // a material can be animated or not. default is not. | ||
43 | // Any material needing continuous rendering should override this method | ||
44 | this.isAnimated = function() { return true; }; | ||
45 | |||
40 | /////////////////////////////////////////////////////////////////////// | 46 | /////////////////////////////////////////////////////////////////////// |
41 | // Methods | 47 | // Methods |
42 | /////////////////////////////////////////////////////////////////////// | 48 | /////////////////////////////////////////////////////////////////////// |
diff --git a/js/lib/rdge/materials/material.js b/js/lib/rdge/materials/material.js index 13251ce8..a81ca18f 100755 --- a/js/lib/rdge/materials/material.js +++ b/js/lib/rdge/materials/material.js | |||
@@ -38,6 +38,11 @@ var Material = function GLMaterial( world ) { | |||
38 | this._shader = null; | 38 | this._shader = null; |
39 | this._materialNode = null; | 39 | this._materialNode = null; |
40 | 40 | ||
41 | // vertex deformation variables | ||
42 | this._hasVertexDeformation = false; | ||
43 | this._vertexDeformationRange = [0, 0, 1, 1]; // (xMin, yMin, xMax, yMax) | ||
44 | this._vertexDeformationTolerance = 0.02; | ||
45 | |||
41 | /////////////////////////////////////////////////////////////////////// | 46 | /////////////////////////////////////////////////////////////////////// |
42 | // Property Accessors | 47 | // Property Accessors |
43 | /////////////////////////////////////////////////////////////////////// | 48 | /////////////////////////////////////////////////////////////////////// |
diff --git a/js/lib/rdge/materials/twist-vert-material.js b/js/lib/rdge/materials/twist-vert-material.js index 2d2cdcc5..802690a2 100644 --- a/js/lib/rdge/materials/twist-vert-material.js +++ b/js/lib/rdge/materials/twist-vert-material.js | |||
@@ -36,6 +36,7 @@ function TwistVertMaterial() | |||
36 | this.getShaderName = function() { return this._shaderName; } | 36 | this.getShaderName = function() { return this._shaderName; } |
37 | 37 | ||
38 | this.isAnimated = function() { return true; } | 38 | this.isAnimated = function() { return true; } |
39 | |||
39 | this.hasVertexDeformation = function() { return this._hasVertexDeformation; } | 40 | this.hasVertexDeformation = function() { return this._hasVertexDeformation; } |
40 | this._hasVertexDeformation = true; | 41 | this._hasVertexDeformation = true; |
41 | this._vertexDeformationTolerance = 0.02; // should be a property | 42 | this._vertexDeformationTolerance = 0.02; // should be a property |
diff --git a/js/lib/rdge/texture.js b/js/lib/rdge/texture.js index 83509f80..2e76f2c0 100644 --- a/js/lib/rdge/texture.js +++ b/js/lib/rdge/texture.js | |||
@@ -12,264 +12,259 @@ var Material = require("js/lib/rdge/materials/material").Material; | |||
12 | /////////////////////////////////////////////////////////////////////// | 12 | /////////////////////////////////////////////////////////////////////// |
13 | function Texture( dstWorld, texMapName, wrap, mips ) | 13 | function Texture( dstWorld, texMapName, wrap, mips ) |
14 | { | 14 | { |
15 | /////////////////////////////////////////////////////////////////////// | 15 | /////////////////////////////////////////////////////////////////////// |
16 | // Instance variables | 16 | // Instance variables |
17 | /////////////////////////////////////////////////////////////////////// | 17 | /////////////////////////////////////////////////////////////////////// |
18 | this._texture; | 18 | this._texture; |
19 | 19 | ||
20 | // texture attributes | 20 | // texture attributes |
21 | this._texMapName = texMapName.slice(); | 21 | this._texMapName = texMapName.slice(); |
22 | 22 | ||
23 | // set default values for wrap and mips | 23 | // set default values for wrap and mips |
24 | if (wrap === undefined) | 24 | if (wrap === undefined) |
25 | wrap = "REPEAT"; | 25 | wrap = "REPEAT"; |
26 | if (mips === undefined) | 26 | if (mips === undefined) |
27 | mips = true; | 27 | mips = true; |
28 | this._wrap = wrap; | 28 | this._wrap = wrap; |
29 | this._mips = mips; | 29 | this._mips = mips; |
30 | 30 | ||
31 | // the canvas generating the texture map (if there is one) | 31 | // the canvas generating the texture map (if there is one) |
32 | this._srcCanvas; | 32 | this._srcCanvas; |
33 | this._srcWorld; | 33 | this._srcWorld; |
34 | 34 | ||
35 | // cache whether or not the source is animated | 35 | // cache whether or not the source is animated |
36 | this._isAnimated = false; | 36 | this._isAnimated = false; |
37 | 37 | ||
38 | // the destination world that will use the texture map | 38 | // the destination world that will use the texture map |
39 | this._dstWorld = dstWorld; | 39 | this._dstWorld = dstWorld; |
40 | 40 | ||
41 | /////////////////////////////////////////////////////////////////////// | 41 | /////////////////////////////////////////////////////////////////////// |
42 | // Property Accessors | 42 | // Property Accessors |
43 | /////////////////////////////////////////////////////////////////////// | 43 | /////////////////////////////////////////////////////////////////////// |
44 | this.getTexture = function() { return this._texture; } | 44 | this.getTexture = function() { return this._texture; } |
45 | 45 | ||
46 | this.setSrcWorld = function(w) { this._srcWorld = w; } | 46 | this.setSrcWorld = function(w) { this._srcWorld = w; } |
47 | this.getSrcWorld = function() { return this._srcWorld; } | 47 | this.getSrcWorld = function() { return this._srcWorld; } |
48 | 48 | ||
49 | this.setDstWorld = function(w) { this._dstWorld = w; } | 49 | this.setDstWorld = function(w) { this._dstWorld = w; } |
50 | this.getDstWorld = function() { return this._dstWorld; } | 50 | this.getDstWorld = function() { return this._dstWorld; } |
51 | 51 | ||
52 | this.isAnimated = function() { return this._isAnimated; } | 52 | this.isAnimated = function() { return this._isAnimated; } |
53 | 53 | ||
54 | /////////////////////////////////////////////////////////////////////// | 54 | /////////////////////////////////////////////////////////////////////// |
55 | // Methods | 55 | // Methods |
56 | /////////////////////////////////////////////////////////////////////// | 56 | /////////////////////////////////////////////////////////////////////// |
57 | 57 | ||
58 | this.init = function() | 58 | this.init = function() |
59 | { | 59 | { |
60 | // determine if the source is a canvas or an image file | 60 | // determine if the source is a canvas or an image file |
61 | var viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils; | 61 | var viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils; |
62 | var root = viewUtils.application.ninja.currentDocument.documentRoot; | 62 | var root = viewUtils.application.ninja.currentDocument.documentRoot; |
63 | var srcCanvas = this.findCanvas( this._texMapName, root ); | 63 | var srcCanvas = this.findCanvas( this._texMapName, root ); |
64 | if (srcCanvas) | 64 | if (srcCanvas) |
65 | { | 65 | { |
66 | this._srcCanvas = srcCanvas; | 66 | this._srcCanvas = srcCanvas; |
67 | if (srcCanvas.elementModel && srcCanvas.elementModel.shapeModel && srcCanvas.elementModel.shapeModel.GLWorld) | 67 | if (srcCanvas.elementModel && srcCanvas.elementModel.shapeModel && srcCanvas.elementModel.shapeModel.GLWorld) |
68 | { | 68 | { |
69 | this._srcWorld = srcCanvas.elementModel.shapeModel.GLWorld; | 69 | this._srcWorld = srcCanvas.elementModel.shapeModel.GLWorld; |
70 | 70 | ||
71 | // add a notifier to the world | 71 | // add a notifier to the world |
72 | this._srcWorld.addListener( this, this.worldCallback, { srcWorld: this._srcWorld } ); | 72 | this._srcWorld.addListener( this, this.worldCallback, { srcWorld: this._srcWorld } ); |
73 | 73 | ||
74 | // check if the source is animated | 74 | // check if the source is animated |
75 | if (srcCanvas.elementModel && srcCanvas.elementModel.shapeModel && srcCanvas.elementModel.shapeModel.GLWorld) | 75 | if (srcCanvas.elementModel && srcCanvas.elementModel.shapeModel && srcCanvas.elementModel.shapeModel.GLWorld) |
76 | this._isAnimated = this._srcWorld._hasAnimatedMaterials; | 76 | this._isAnimated = this._srcWorld._hasAnimatedMaterials; |
77 | } | 77 | } |
78 | 78 | ||
79 | this.loadFromCanvas(); | 79 | this.loadFromCanvas(); |
80 | } | 80 | } |
81 | else | 81 | else |
82 | { | 82 | { |
83 | this.loadFromFile(); | 83 | this.loadFromFile(); |
84 | } | 84 | } |
85 | } | 85 | } |
86 | 86 | ||
87 | this.worldCallback = function( type, callbackObj, calleeData, callerData ) | 87 | this.worldCallback = function( type, callbackObj, calleeData, callerData ) |
88 | { | 88 | { |
89 | console.log( "texture callback, type: " + type ); | 89 | console.log( "texture callback, type: " + type ); |
90 | if (calleeData.srcWorld) | 90 | if (calleeData.srcWorld) |
91 | { | 91 | { |
92 | var srcWorld = calleeData.srcWorld; | 92 | var srcWorld = calleeData.srcWorld; |
93 | var notifier = srcWorld._notifier; | 93 | var notifier = srcWorld._notifier; |
94 | var texture = this.callbackObj; | 94 | var texture = this.callbackObj; |
95 | if (texture) | 95 | if (texture) |
96 | { | 96 | { |
97 | switch (type) | 97 | switch (type) |
98 | { | 98 | { |
99 | case notifier.OBJECT_DELETE: | 99 | case notifier.OBJECT_DELETE: |
100 | break; | 100 | break; |
101 | 101 | ||
102 | case notifier.OBJECT_REINSTANTIATE: | 102 | case notifier.OBJECT_REINSTANTIATE: |
103 | break; | 103 | break; |
104 | 104 | ||
105 | case notifier.OBJECT_CHANGE: | 105 | case notifier.OBJECT_CHANGE: |
106 | if (!texture.isAnimated()) | 106 | if (!texture.isAnimated()) |
107 | texture.rerender(); | 107 | texture.rerender(); |
108 | texture.getDstWorld().restartRenderLoop(); | 108 | texture.getDstWorld().restartRenderLoop(); |
109 | break; | 109 | break; |
110 | 110 | ||
111 | default: | 111 | default: |
112 | throw new Exception( "unrecognized texture callback type: " + type ); | 112 | throw new Exception( "unrecognized texture callback type: " + type ); |
113 | break; | 113 | break; |
114 | } | 114 | } |
115 | } | 115 | } |
116 | } | 116 | } |
117 | } | 117 | } |
118 | 118 | ||
119 | this.loadFromFile = function() | 119 | this.loadFromFile = function() |
120 | { |