From 1b7592f81c9b47c2b42d78efe385cd979d54d3ca Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 11 Apr 2012 06:24:05 -0700 Subject: Cloud material --- js/lib/rdge/materials/cloud-material.js | 12 +++++++----- js/lib/rdge/texture.js | 20 +++++++++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) (limited to 'js/lib/rdge') diff --git a/js/lib/rdge/materials/cloud-material.js b/js/lib/rdge/materials/cloud-material.js index 198f7cfa..c1dabce8 100644 --- a/js/lib/rdge/materials/cloud-material.js +++ b/js/lib/rdge/materials/cloud-material.js @@ -20,7 +20,7 @@ var CloudMaterial = function CloudMaterial() { this._name = "CloudMaterial"; this._shaderName = "cloud"; - this._texMap = 'assets/images/cloud2.jpg'; + this._texMap = 'assets/images/cloud10.png'; this._diffuseColor = [0.5, 0.5, 0.5, 0.5]; // base size of cloud polygons. Random adjustments made to each quad @@ -106,7 +106,8 @@ var CloudMaterial = function CloudMaterial() { this.init = function( world ) { - var GLWorld = require("js/lib/drawing/world").World; + var GLWorld = require("js/lib/drawing/world").World, + NJUtils = require("js/lib/NJUtils").NJUtils; // save the world if (world) this.setWorld( world ); @@ -118,7 +119,8 @@ var CloudMaterial = function CloudMaterial() { // create a canvas to render into var doc = world.getCanvas().ownerDocument; var canvasID = "__canvas__"; - this._srcCanvas = doc.createElement(canvasID); + //this._srcCanvas = doc.createElement(canvasID); + this._srcCanvas = NJUtils.makeNJElement("canvas", canvasID, "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true); // build a world to do the rendering this._srcWorld = new GLWorld( this._srcCanvas, true ); @@ -157,7 +159,7 @@ var CloudMaterial = function CloudMaterial() { // create the texture var wrap = 'REPEAT', mips = true; - this._glTex = new Texture( dstWorld, canvasID, wrap, mips ); + this._glTex = new Texture( world, this._srcCanvas, wrap, mips ); // set the shader values in the shader this.updateTexture(); @@ -213,7 +215,7 @@ var CloudMaterial = function CloudMaterial() { RectangleGeometry.init(); var verts = [], - norms = [ [0,0,1], [0,0,1], [0,0,1], [0,0,1] ], + normals = [ [0,0,1], [0,0,1], [0,0,1], [0,0,1] ], uvs = [ [0,0], [1,0], [1,1], [0,1] ]; for ( i = 0; i < 2; i++ ) diff --git a/js/lib/rdge/texture.js b/js/lib/rdge/texture.js index 94147852..345effd6 100644 --- a/js/lib/rdge/texture.js +++ b/js/lib/rdge/texture.js @@ -19,8 +19,16 @@ function Texture( dstWorld, texMapName, wrap, mips ) /////////////////////////////////////////////////////////////////////// this._texture; + // the canvas generating the texture map (if there is one) + this._srcCanvas; + this._srcWorld; + // texture attributes - this._texMapName = texMapName.slice(); + if (typeof texMapName === "string") + this._texMapName = texMapName.slice(); + else + this._srcCanvas = texMapName; + // set default values for wrap and mips if (wrap === undefined) @@ -30,10 +38,6 @@ function Texture( dstWorld, texMapName, wrap, mips ) this._wrap = wrap; this._mips = mips; - // the canvas generating the texture map (if there is one) - this._srcCanvas; - this._srcWorld; - // cache whether or not the source is animated this._isAnimated = false; @@ -65,7 +69,9 @@ function Texture( dstWorld, texMapName, wrap, mips ) // determine if the source is a canvas or an image file var viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils; var root = viewUtils.application.ninja.currentDocument.documentRoot; - var srcCanvas = this.findCanvas( this._texMapName, root ); + var srcCanvas = this._srcCanvas; + if (!srcCanvas) + srcCanvas = this.findCanvas( this._texMapName, root ); if (srcCanvas) { this._srcCanvas = srcCanvas; @@ -169,7 +175,7 @@ function Texture( dstWorld, texMapName, wrap, mips ) // create the canvas and context to render into var doc = srcCanvas.ownerDocument; - this._renderCanvas = doc.createElement("canvas"); + this._renderCanvas = doc.createElement("texture_canvas"); this.render(); -- cgit v1.2.3