diff options
Diffstat (limited to 'js/lib')
-rwxr-xr-x | js/lib/drawing/world.js | 13 | ||||
-rwxr-xr-x | js/lib/geom/rectangle.js | 7 | ||||
-rwxr-xr-x | js/lib/math/matrix.js | 9 | ||||
-rw-r--r-- | js/lib/rdge/materials/cloud-material.js | 270 | ||||
-rw-r--r-- | js/lib/rdge/texture.js | 2 |
5 files changed, 212 insertions, 89 deletions
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index 5eca26b8..4ca738f4 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js | |||
@@ -73,6 +73,7 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) { | |||
73 | this._firstRender = true; | 73 | this._firstRender = true; |
74 | 74 | ||
75 | this._worldCount = worldCounter; | 75 | this._worldCount = worldCounter; |
76 | console.log( "creating world " + this._worldCount ); | ||
76 | worldCounter++; | 77 | worldCounter++; |
77 | 78 | ||
78 | // keep a counter for generating node names | 79 | // keep a counter for generating node names |
@@ -514,6 +515,18 @@ World.prototype.restartRenderLoop = function() { | |||
514 | } | 515 | } |
515 | }; | 516 | }; |
516 | 517 | ||
518 | World.prototype.stop = function() | ||
519 | { | ||
520 | if (this._canvas && this._canvas.task) | ||
521 | this._canvas.task.stop(); | ||
522 | } | ||
523 | |||
524 | World.prototype.start = function() | ||
525 | { | ||
526 | if (this._canvas && this._canvas.task) | ||
527 | this._canvas.task.start(); | ||
528 | } | ||
529 | |||
517 | //append to the list of objects if obj doesn't already exist | 530 | //append to the list of objects if obj doesn't already exist |
518 | //if obj exists, then don't add to list of objects | 531 | //if obj exists, then don't add to list of objects |
519 | World.prototype.addIfNewObject = function (obj) { | 532 | World.prototype.addIfNewObject = function (obj) { |
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index d4dd8033..70f6b01b 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js | |||
@@ -1294,6 +1294,7 @@ RectangleGeometry.init = function() | |||
1294 | 1294 | ||
1295 | RectangleGeometry.addQuad = function( verts, normals, uvs ) | 1295 | RectangleGeometry.addQuad = function( verts, normals, uvs ) |
1296 | { | 1296 | { |
1297 | var offset = this.vertices.length/3; | ||
1297 | for (var i=0; i<4; i++) | 1298 | for (var i=0; i<4; i++) |
1298 | { | 1299 | { |
1299 | RectangleGeometry.pushVertex( verts[i][0], verts[i][1], verts[i][2]); | 1300 | RectangleGeometry.pushVertex( verts[i][0], verts[i][1], verts[i][2]); |
@@ -1301,13 +1302,13 @@ RectangleGeometry.addQuad = function( verts, normals, uvs ) | |||
1301 | RectangleGeometry.pushUV( uvs[i] ); | 1302 | RectangleGeometry.pushUV( uvs[i] ); |
1302 | } | 1303 | } |
1303 | 1304 | ||
1304 | RectangleGeometry.pushIndices( 0, 1, 2 ); | 1305 | RectangleGeometry.pushIndices( 0+offset, 1+offset, 2+offset ); |
1305 | RectangleGeometry.pushIndices( 2, 3, 0 ); | 1306 | RectangleGeometry.pushIndices( 2+offset, 3+offset, 0+offset ); |
1306 | } | 1307 | } |
1307 | 1308 | ||
1308 | RectangleGeometry.buildPrimitive = function() | 1309 | RectangleGeometry.buildPrimitive = function() |
1309 | { | 1310 | { |
1310 | var nVertices = this.vertices.length; | 1311 | var nVertices = this.vertices.length/3; |
1311 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); | 1312 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); |
1312 | } | 1313 | } |
1313 | 1314 | ||
diff --git a/js/lib/math/matrix.js b/js/lib/math/matrix.js index 77a0966d..3a5a8215 100755 --- a/js/lib/math/matrix.js +++ b/js/lib/math/matrix.js | |||
@@ -67,6 +67,15 @@ Matrix.Rotation = function(angle, axis) { | |||
67 | return mat; | 67 | return mat; |
68 | }; | 68 | }; |
69 | 69 | ||
70 | Matrix.Scale = function( scaleVec ) { | ||
71 | var mat = Matrix.I(4); | ||
72 | mat[ 0] = scaleVec[0]; | ||
73 | mat[ 5] = scaleVec[1]; | ||
74 | mat[10] = scaleVec[2]; | ||
75 | |||
76 | return mat; | ||
77 | }; | ||
78 | |||
70 | Matrix.flatten = function (mat) { | 79 | Matrix.flatten = function (mat) { |
71 | var result = []; | 80 | var result = []; |
72 | if (this.elements.length == 0) { | 81 | if (this.elements.length == 0) { |
diff --git a/js/lib/rdge/materials/cloud-material.js b/js/lib/rdge/materials/cloud-material.js index 126751c6..e2292c7a 100644 --- a/js/lib/rdge/materials/cloud-material.js +++ b/js/lib/rdge/materials/cloud-material.js | |||
@@ -8,6 +8,8 @@ var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialP | |||
8 | var Material = require("js/lib/rdge/materials/material").Material; | 8 | var Material = require("js/lib/rdge/materials/material").Material; |
9 | var GLWorld = require("js/lib/drawing/world").World; | 9 | var GLWorld = require("js/lib/drawing/world").World; |
10 | var Texture = require("js/lib/rdge/texture").Texture; | 10 | var Texture = require("js/lib/rdge/texture").Texture; |
11 | var ElementMediator = require("js/mediators/element-mediator").ElementMediator; | ||
12 | var TagTool = require("js/tools/TagTool").TagTool; | ||
11 | 13 | ||
12 | /////////////////////////////////////////////////////////////////////// | 14 | /////////////////////////////////////////////////////////////////////// |
13 | // Class GLMaterial | 15 | // Class GLMaterial |
@@ -20,7 +22,9 @@ var CloudMaterial = function CloudMaterial() { | |||
20 | this._name = "CloudMaterial"; | 22 | this._name = "CloudMaterial"; |
21 | this._shaderName = "cloud"; | 23 | this._shaderName = "cloud"; |
22 | 24 | ||
23 | this._texMap = 'assets/images/cloud10.png'; | 25 | //this._texMap = 'assets/images/cloud10.png'; |
26 | this._texMap = 'assets/images/us_flag.png'; | ||
27 | //this._texMap = 'assets/images/cubelight.png'; | ||
24 | this._diffuseColor = [0.5, 0.5, 0.5, 0.5]; | 28 | this._diffuseColor = [0.5, 0.5, 0.5, 0.5]; |
25 | 29 | ||
26 | // base size of cloud polygons. Random adjustments made to each quad | 30 | // base size of cloud polygons. Random adjustments made to each quad |
@@ -31,7 +35,7 @@ var CloudMaterial = function CloudMaterial() { | |||
31 | 35 | ||
32 | // parameter initial values | 36 | // parameter initial values |
33 | this._time = 0.0; | 37 | this._time = 0.0; |
34 | this._surfaceAlpha = 1.0; | 38 | this._surfaceAlpha = 0.6; |
35 | this._zmin = 0.1; | 39 | this._zmin = 0.1; |
36 | this._zmax = 10.0; | 40 | this._zmax = 10.0; |
37 | 41 | ||
@@ -111,80 +115,54 @@ var CloudMaterial = function CloudMaterial() { | |||
111 | 115 | ||
112 | // save the world | 116 | // save the world |
113 | if (world) this.setWorld( world ); | 117 | if (world) this.setWorld( world ); |
114 | 118 | var dstWorld = world; | |
115 | // this variable declared above is inherited set to a smaller delta. | ||
116 | // the cloud material runs a little faster | ||
117 | this._dTime = 0.01; | ||
118 | 119 | ||
119 | // create a canvas to render into | 120 | // create a canvas to render into |
120 | var doc = world.getCanvas().ownerDocument; | 121 | var dstCanvas = this.getWorld().getCanvas(); |
122 | var doc = this.getWorld().getCanvas().ownerDocument; | ||
121 | var canvasID = "__canvas__"; | 123 | var canvasID = "__canvas__"; |
122 | //this._srcCanvas = doc.createElement(canvasID); | 124 | //this._srcCanvas = doc.createElement(canvasID); |
123 | this._srcCanvas = NJUtils.makeNJElement("canvas", canvasID, "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true); | 125 | this._srcCanvas = NJUtils.makeNJElement("canvas", canvasID, "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true); |
124 | var dstCanvas = this.getWorld().getCanvas(), | 126 | srcCanvas = this._srcCanvas; |
125 | srcCanvas = this._srcCanvas; | ||
126 | srcCanvas.width = dstCanvas.width; | 127 | srcCanvas.width = dstCanvas.width; |
127 | srcCanvas.height = dstCanvas.height; | 128 | srcCanvas.height = dstCanvas.height; |
128 | 129 | ||
129 | // save the current RDGE context | 130 | ////////////////////////////////////////////////////////////////////////////////// |
130 | var saveContext = g_Engine.getContext(); | 131 | // IS THIS NECESSARY?? |
131 | 132 | //var elementModel = TagTool.makeElement(~~srcCanvas.width, ~~srcCanvas.height, | |
132 | // build a world to do the rendering | 133 | // Matrix.I(4), [0,0,0], srcCanvas); |
133 | this._srcWorld = new GLWorld( this._srcCanvas, true, true ); | 134 | //ElementMediator.addElement(srcCanvas, elementModel.data, true); |
134 | var srcWorld = this._srcWorld; | 135 | ////////////////////////////////////////////////////////////////////////////////// |
135 | this._srcCanvas.__GLWorld = srcWorld; | ||
136 | 136 | ||
137 | // build the geometry | 137 | // build the source. |
138 | var prim = this.buildGeometry( srcWorld, srcCanvas.width, srcCanvas.height ); | 138 | // the source being the world/canvas/geometry of the clouds. |
139 | // the source is used to create a texture map that is then used by | ||
140 | // the destimation. | ||
141 | this.buildSource(); | ||
139 | 142 | ||
140 | // set up the shader | 143 | // set up the shader |
141 | this._shader = new jshader(); | 144 | this._shader = new jshader(); |
142 | this._shader.def = cloudMaterialDef; | 145 | this._shader.def = cloudMapMaterialDef; |
143 | this._shader.init(); | 146 | this._shader.init(); |
144 | 147 | ||
145 | // set up the material node | 148 | // set up the material node |
146 | this._materialNode = createMaterialNode("cloudMaterial" + "_" + world.generateUniqueNodeID()); | 149 | this._materialNode = createMaterialNode("cloudMapMaterial" + "_" + world.generateUniqueNodeID()); |
147 | this._materialNode.setShader(this._shader); | 150 | this._materialNode.setShader(this._shader); |
148 | 151 | ||
149 | // initialize the shader uniforms | 152 | // initialize the time |
150 | this._time = 0; | 153 | this._time = 0; |
151 | if (this._shader && this._shader['default']) { | ||
152 | var t = this._shader['default']; | ||
153 | if (t) | ||
154 | { | ||
155 | t.u_time.set( [this._time] ); | ||
156 | t.u_surfaceAlpha.set( [this._surfaceAlpha] ); | ||
157 | t.u_zmin.set( [this._zmin] ); | ||
158 | t.u_zmax.set( [this._zmax] ); | ||
159 | 154 | ||
160 | var wrap = 'REPEAT', mips = true; | 155 | // create the texture to map the source cloud generation world/canvas to the destination |
161 | var texMapName = this._propValues[this._propNames[0]]; | ||
162 | var tex = srcWorld.renderer.getTextureByName(texMapName, wrap, mips ); | ||
163 | if (tex) | ||
164 | srcWorld.textureToLoad( tex ); | ||
165 | } | ||
166 | } | ||
167 | |||
168 | // add the nodes to the tree | ||
169 | var trNode = createTransformNode("objRootNode_" + this._srcWorld._nodeCounter++); | ||
170 | srcWorld._rootNode.insertAsChild( trNode ); | ||
171 | trNode.attachMeshNode(srcWorld.renderer.id + "_prim_" + srcWorld._nodeCounter++, prim); | ||
172 | trNode.attachMaterial( this._materialNode ); | ||
173 | |||
174 | // create the texture | ||
175 | var wrap = 'REPEAT', mips = true; | 156 | var wrap = 'REPEAT', mips = true; |
176 | this._srcWorld._hasAnimatedMaterials = true; // hack to make the texture think this world is animated | ||
177 | this._glTex = new Texture( world, this._srcCanvas, wrap, mips ); | 157 | this._glTex = new Texture( world, this._srcCanvas, wrap, mips ); |
178 | 158 | ||
179 | // set the shader values in the shader | 159 | // set the shader values in the shader |
180 | this.updateTexture(); |