From c0a1164b5e84098e005f076de5eddd0e60387286 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Tue, 20 Mar 2012 14:21:29 -0700 Subject: Fixing the selection issues Signed-off-by: Valerio Virgillito --- js/lib/NJUtils.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'js/lib') diff --git a/js/lib/NJUtils.js b/js/lib/NJUtils.js index 4f1082f9..904aa41e 100755 --- a/js/lib/NJUtils.js +++ b/js/lib/NJUtils.js @@ -96,15 +96,45 @@ exports.NJUtils = Object.create(Object.prototype, { value: function(el, selection, controller, isShape) { var p3d = Montage.create(Properties3D).init(el); var shapeProps = null; + var pi = controller + "Pi"; + if(isShape) { shapeProps = Montage.create(ShapeModel); } + if(el.controller) { + + var componentInfo = Montage.getInfoForObject(el.controller); + var componentName = componentInfo.objectName.toLowerCase(); + + controller = "component"; + isShape = false; + + switch(componentName) { + case "feedreader": + selection = "Feed Reader"; + pi = "FeedReaderPi"; + break; + case "map": + selection = "Map"; + pi = "MapPi"; + break; + case "youtubechannel": + selection = "Youtube Channel"; + pi = "YoutubeChannelPi"; + break; + case "picasacarousel": + selection = "Picasa Carousel"; + pi = "PicasaCarouselPi"; + break; + } + } + el.elementModel = Montage.create(ElementModel, { type: { value: el.nodeName}, selection: { value: selection}, controller: { value: ControllerFactory.getController(controller)}, - pi: { value: controller + "Pi"}, + pi: { value: pi}, props3D: { value: p3d}, shapeModel: { value: shapeProps} }); -- cgit v1.2.3 From fdeed8051c3af538d28ca3bc599121cea483c22c Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Thu, 22 Mar 2012 15:47:56 -0700 Subject: Squashed commit of the following GL integration Signed-off-by: Valerio Virgillito --- js/lib/drawing/world.js | 147 +++++++++++ js/lib/geom/circle.js | 54 +++- js/lib/geom/geom-obj.js | 154 ++++++++--- js/lib/geom/line.js | 44 +++- js/lib/geom/rectangle.js | 63 ++++- js/lib/rdge/materials/bump-metal-material.js | 40 +++ js/lib/rdge/materials/cloud-material.js | 300 ++++++++++++++++++++++ js/lib/rdge/materials/flat-material.js | 21 ++ js/lib/rdge/materials/julia-material.js | 6 +- js/lib/rdge/materials/linear-gradient-material.js | 53 ++++ js/lib/rdge/materials/mandel-material.js | 6 +- js/lib/rdge/materials/plasma-material.js | 18 ++ js/lib/rdge/materials/pulse-material.js | 44 +++- js/lib/rdge/materials/radial-blur-material.js | 57 +++- js/lib/rdge/materials/radial-gradient-material.js | 54 +++- js/lib/rdge/materials/taper-material.js | 27 ++ js/lib/rdge/materials/twist-vert-material.js | 28 ++ js/lib/rdge/materials/uber-material.js | 180 ++++++++++++- js/lib/rdge/materials/water-material.js | 103 ++++++++ 19 files changed, 1310 insertions(+), 89 deletions(-) create mode 100644 js/lib/rdge/materials/cloud-material.js (limited to 'js/lib') diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index 049145ce..07a2c3ae 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js @@ -363,6 +363,7 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) { if (this._useWebGL) { rdgeStarted = true; this._canvas.rdgeid = this._canvas.getAttribute( "data-RDGE-id" ); + g_Engine.unregisterCanvas( this._canvas ) g_Engine.registerCanvas(this._canvas, this); RDGEStart( this._canvas ); this._canvas.task.stop() @@ -729,6 +730,72 @@ World.prototype.getShapeFromPoint = function( offsetX, offsetY ) { } }; +World.prototype.exportJSON = function() +{ + // world properties + var worldObj = + { + 'version' : 1.1, + 'id' : this.getCanvas().getAttribute( "data-RDGE-id" ), + 'fov' : this._fov, + 'zNear' : this._zNear, + 'zFar' : this._zFar, + 'viewDist' : this._viewDist, + 'webGL' : this._useWebGL + }; + + // RDGE scenegraph + if (this._useWebGL) + worldObj.scenedata = this.myScene.exportJSON(); + + // object data + var strArray = []; + this.exportObjectsJSON( this._geomRoot, worldObj ); + + // You would think that the RDGE export function + // would not be destructive of the data. You would be wrong... + // We need to rebuild everything + if (this._useWebGL) + { + var root = this._rootNode; + root.children = new Array(); + if (worldObj.children && (worldObj.children.length === 1)) + { + this.init(); + this._geomRoot = undefined; + this.importObjectsJSON( worldObj.children[0] ); + } + } + + // convert the object to a string + var jStr = JSON.stringify( worldObj ); + + // prepend some version information to the string. + // this string is also used to differentiate between JSON + // and pre-JSON versions of fileIO. + // the ending ';' in the version string is necessary + jStr = "v1.0;" + jStr; + + return jStr; +} + +World.prototype.exportObjectsJSON = function( obj, parentObj ) +{ + if (!obj) return; + + var jObj = obj.exportJSON(); + if (!parentObj.children) parentObj.children = []; + parentObj.children.push( jObj ); + + if (obj.getChild()) { + this.exportObjectsJSON( obj.getChild (), jObj ); + } + + if (obj.getNext()) + this.exportObjectsJSON( obj.getNext(), parentObj ); +} + +/* World.prototype.export = function() { var exportStr = "GLWorld 1.0\n"; @@ -791,6 +858,7 @@ World.prototype.exportObjects = function( obj ) { return rtnStr; }; +*/ World.prototype.findTransformNodeByMaterial = function( materialNode, trNode ) { //if (trNode == null) trNode = this._ctrNode; @@ -810,6 +878,85 @@ World.prototype.findTransformNodeByMaterial = function( materialNode, trNode ) return rtnNode; }; +World.prototype.importJSON = function( jObj ) +{ + if (jObj.webGL) + { + // start RDGE + rdgeStarted = true; + var id = this._canvas.getAttribute( "data-RDGE-id" ); + this._canvas.rdgeid = id; + g_Engine.registerCanvas(this._canvas, this); + RDGEStart( this._canvas ); + this._canvas.task.stop() + } + + // import the objects + // there should be exactly one child of the parent object + if (jObj.children && (jObj.children.length === 1)) + this.importObjectsJSON( jObj.children[0] ); + else + throw new Error ("unrecoverable canvas import error - inconsistent root object: " + jObj.children ); + + if (!this._useWebGL) + { + // render using canvas 2D + this.render(); + } + else + this.restartRenderLoop(); +} + +World.prototype.importObjectsJSON = function( jObj, parentGeomObj ) +{ + // read the next object + var gObj = this.importObjectJSON( jObj, parentGeomObj ); + + // determine if we have children + if (jObj.children) + { + var nKids = ojObjbj.chilodren.length; + for (var i=0; i */ var MaterialsModel = require("js/models/materials-model").MaterialsModel; -var FlatMaterial = require("js/lib/rdge/materials/flat-material").FlatMaterial; -var LinearGradientMaterial = require("js/lib/rdge/materials/linear-gradient-material").LinearGradientMaterial; -var RadialGradientMaterial = require("js/lib/rdge/materials/radial-gradient-material").RadialGradientMaterial; -var BumpMetalMaterial = require("js/lib/rdge/materials/bump-metal-material").BumpMetalMaterial; -var UberMaterial = require("js/lib/rdge/materials/uber-material").UberMaterial; -var RadialBlurMaterial = require("js/lib/rdge/materials/radial-blur-material").RadialBlurMaterial; -var PlasmaMaterial = require("js/lib/rdge/materials/plasma-material").PlasmaMaterial; -var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; -var TunnelMaterial = require("js/lib/rdge/materials/tunnel-material").TunnelMaterial; -var ReliefTunnelMaterial = require("js/lib/rdge/materials/relief-tunnel-material").ReliefTunnelMaterial; -var SquareTunnelMaterial = require("js/lib/rdge/materials/square-tunnel-material").SquareTunnelMaterial; -var FlyMaterial = require("js/lib/rdge/materials/fly-material").FlyMaterial; -var WaterMaterial = require("js/lib/rdge/materials/water-material").WaterMaterial; -var ZInvertMaterial = require("js/lib/rdge/materials/z-invert-material").ZInvertMaterial; -var DeformMaterial = require("js/lib/rdge/materials/deform-material").DeformMaterial; -var StarMaterial = require("js/lib/rdge/materials/star-material").StarMaterial; -var TwistMaterial = require("js/lib/rdge/materials/twist-material").TwistMaterial; -var JuliaMaterial = require("js/lib/rdge/materials/julia-material").JuliaMaterial; -var KeleidoscopeMaterial = require("js/lib/rdge/materials/keleidoscope-material").KeleidoscopeMaterial; -var MandelMaterial = require("js/lib/rdge/materials/mandel-material").MandelMaterial; /////////////////////////////////////////////////////////////////////// // Class GLGeomObj @@ -265,6 +245,96 @@ var GeomObj = function GLGeomObj() { return fillMaterial; }; + this.exportMaterialsJSON = function() + { + var jObj; + if (this._materialArray && this._materialNodeArray) + { + var nMats = this._materialArray.length; + if (nMats > 0) + { + var arr = []; + + for (var i=0; i + This file contains proprietary software owned by Motorola Mobility, Inc.
+ No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+ (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. + */ + +var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; +var Material = require("js/lib/rdge/materials/material").Material; +/////////////////////////////////////////////////////////////////////// +// Class GLMaterial +// RDGE representation of a material. +/////////////////////////////////////////////////////////////////////// +var CloudMaterial = function CloudMaterial() { + /////////////////////////////////////////////////////////////////////// + // Instance variables + /////////////////////////////////////////////////////////////////////// + this._name = "CloudMaterial"; + this._shaderName = "cloud"; + + this._texMap = 'assets/images/cloud2.jpg'; + this._diffuseColor = [0.5, 0.5, 0.5, 0.5]; + + this._time = 0.0; + this._dTime = 0.01; + + /////////////////////////////////////////////////////////////////////// + // Property Accessors + /////////////////////////////////////////////////////////////////////// + this.getName = function() { return this._name; }; + this.getShaderName = function() { return this._shaderName; }; + + this.getTextureMap = function() { return this._propValues[this._propNames[0]] ? this._propValues[this._propNames[0]].slice() : null }; + this.setTextureMap = function(m) { this._propValues[this._propNames[0]] = m ? m.slice(0) : null; this.updateTexture(); }; + + this.setDiffuseColor = function(c) { this._propValues[this._propNames[1]] = c.slice(0); this.updateColor(); }; + this.getDiffuseColor = function() { return this._propValues[this._propNames[1]] ? this._propValues[this._propNames[1]].slice() : null; }; + + this.isAnimated = function() { return true; }; + + /////////////////////////////////////////////////////////////////////// + // Material Property Accessors + /////////////////////////////////////////////////////////////////////// + this._propNames = ["texmap", "diffusecolor"]; + this._propLabels = ["Texture map", "Diffuse Color"]; + this._propTypes = ["file", "color"]; + this._propValues = []; + + this._propValues[ this._propNames[0] ] = this._texMap.slice(0); + this._propValues[ this._propNames[1] ] = this._diffuseColor.slice(); + + this.setProperty = function( prop, value ) + { + if (prop === 'color') prop = 'diffusecolor'; + + // make sure we have legitimate imput + var ok = this.validateProperty( prop, value ); + if (!ok) { + console.log( "invalid property in Radial Gradient Material:" + prop + " : " + value ); + } + + switch (prop) + { + case "texmap": + this.setTextureMap(value); + break; + + case "diffusecolor": + this.setDiffuseColor( value ); + break; + + case "color": + break; + } + }; + /////////////////////////////////////////////////////////////////////// + + + /////////////////////////////////////////////////////////////////////// + // Methods + /////////////////////////////////////////////////////////////////////// + // duplcate method requirde + this.dup = function( world ) + { + // save the world + if (world) this.setWorld( world ); + + // allocate a new uber material + var newMat = new CloudMaterial(); + + // copy over the current values; + var propNames = [], propValues = [], propTypes = [], propLabels = []; + this.getAllProperties( propNames, propValues, propTypes, propLabels); + var n = propNames.length; + for (var i=0; i 200.0) this._time = 0.0; + } + } + }; + + // JSON export + this.exportJSON = function() + { + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName(), + 'texture' : this._propValues[this._propNames[0]] + }; + + return jObj; + }; + + this.importJSON = function( jObj ) + { + if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); + this.setName( jObj.name ); + + try { + this._propValues[this._propNames[0]] = jObj.texture; + } + catch (e) + { + throw new Error( "could not import material: " + jObj ); + } + } + + + this.export = function() { + // every material needs the base type and instance name + var exportStr = "material: " + this.getShaderName() + "\n"; + exportStr += "name: " + this.getName() + "\n"; + + var world = this.getWorld(); + if (!world) + throw new Error( "no world in material.export, " + this.getName() ); + + var texMapName = this._propValues[this._propNames[0]]; + exportStr += "texture: " +texMapName + "\n"; + + // every material needs to terminate like this + exportStr += "endMaterial\n"; + + return exportStr; + }; + + this.import = function( importStr ) { + var pu = new MaterialParser( importStr ); + var material = pu.nextValue( "material: " ); + if (material != this.getShaderName()) throw new Error( "ill-formed material" ); + this.setName( pu.nextValue( "name: ") ); + + var rtnStr; + try { + this._propValues[this._propNames[0]] = pu.nextValue( "texture: " ); + + var endKey = "endMaterial\n"; + var index = importStr.indexOf( endKey ); + index += endKey.length; + rtnStr = importStr.substr( index ); + } + catch (e) + { + throw new Error( "could not import material: " + importStr ); + } + + return rtnStr; + } +}; + +/////////////////////////////////////////////////////////////////////////////////////// +// RDGE shader + +// shader spec (can also be loaded from a .JSON file, or constructed at runtime) +var cloudMaterialDef = +{'shaders': + { + 'defaultVShader':"assets/shaders/Cloud.vert.glsl", + 'defaultFShader':"assets/shaders/Cloud.frag.glsl" + }, + 'techniques': + { + 'default': + [ + { + 'vshader' : 'defaultVShader', + 'fshader' : 'defaultFShader', + // attributes + 'attributes' : + { + 'vert' : { 'type' : 'vec3' }, + 'normal' : { 'type' : 'vec3' }, + 'texcoord' : { 'type' : 'vec2' } + }, + // parameters + 'params' : + { + 'u_tex0': { 'type' : 'tex2d' }, + 'u_time' : { 'type' : 'float' }, + 'u_DiffuseColor' : { 'type' : 'vec4' } + }, + + // render states + 'states' : + { + 'depthEnable' : true, + 'offset':[1.0, 0.1] + } + } + ] + } +}; + + + + +CloudMaterial.prototype = new Material(); + +if (typeof exports === "object") { + exports.CloudMaterial = CloudMaterial; +} + diff --git a/js/lib/rdge/materials/flat-material.js b/js/lib/rdge/materials/flat-material.js index fff0e68e..5030cc88 100755 --- a/js/lib/rdge/materials/flat-material.js +++ b/js/lib/rdge/materials/flat-material.js @@ -112,6 +112,27 @@ var FlatMaterial = function FlatMaterial() { return rtnStr; }; + this.exportJSON = function() + { + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName(), + 'color' : this._propValues["color"] + }; + + return jObj; + } + + this.importJSON = function( jObj ) + { + if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); + this.setName( jObj.name ); + + var color = jObj.color; + this.setProperty( "color", color); + } + this.update = function( time ) { }; diff --git a/js/lib/rdge/materials/julia-material.js b/js/lib/rdge/materials/julia-material.js index 976dfad3..a85bd6f7 100644 --- a/js/lib/rdge/materials/julia-material.js +++ b/js/lib/rdge/materials/julia-material.js @@ -21,11 +21,7 @@ var JuliaMaterial = function JuliaMaterial() { /////////////////////////////////////////////////////////////////////// // Properties /////////////////////////////////////////////////////////////////////// - // no properties - this._propNames = []; - this._propLabels = []; - this._propTypes = []; - this._propValues = []; + // properties inherited from PulseMaterial /////////////////////////////////////////////////////////////////////// // Methods diff --git a/js/lib/rdge/materials/linear-gradient-material.js b/js/lib/rdge/materials/linear-gradient-material.js index 8e05e23d..0db6fc90 100755 --- a/js/lib/rdge/materials/linear-gradient-material.js +++ b/js/lib/rdge/materials/linear-gradient-material.js @@ -249,6 +249,59 @@ var LinearGradientMaterial = function LinearGradientMaterial() { } }; + this.exportJSON = function() + { + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName(), + 'color1' : this.getColor1(), + 'color2' : this.getColor2(), + 'color3' : this.getColor3(), + 'color4' : this.getColor4(), + 'colorStop1' : this.getColorStop1(), + 'colorStop2' : this.getColorStop2(), + 'colorStop3' : this.getColorStop3(), + 'colorStop4' : this.getColorStop4(), + 'angle' : this.getAngle() + }; + + return jObj; + }; + + this.importJSON = function( jObj ) + { + if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); + this.setName( jObj.name ); + + try + { + var color1 = jObj.color1, + color2 = jObj.color2, + color3 = jObj.color3, + color4 = jObj.color4, + colorStop1 = jObj.colorStop1, + colorStop2 = jObj.colorStop2, + colorStop3 = jObj.colorStop3, + colorStop4 = jObj.colorStop4, + angle = jObj.angle; + + this.setProperty( "color1", color1 ); + this.setProperty( "color2", color2 ); + this.setProperty( "color3", color3 ); + this.setProperty( "color4", color4 ); + this.setProperty( "colorStop1", colorStop1 ); + this.setProperty( "colorStop2", colorStop2 ); + this.setProperty( "colorStop3", colorStop3 ); + this.setProperty( "colorStop4", colorStop4 ); + this.setProperty( "angle", angle ); + } + catch (e) + { + throw new Error( "could not import material: " + importStr ); + } + }; + this.export = function() { // every material needs the base type and instance name var exportStr = "material: " + this.getShaderName() + "\n"; diff --git a/js/lib/rdge/materials/mandel-material.js b/js/lib/rdge/materials/mandel-material.js index d9f00383..e7b105e1 100644 --- a/js/lib/rdge/materials/mandel-material.js +++ b/js/lib/rdge/materials/mandel-material.js @@ -21,11 +21,7 @@ var MandelMaterial = function MandelMaterial() { /////////////////////////////////////////////////////////////////////// // Properties /////////////////////////////////////////////////////////////////////// - // no properties - this._propNames = []; - this._propLabels = []; - this._propTypes = []; - this._propValues = []; + // properties inherited from PulseMaterial /////////////////////////////////////////////////////////////////////// // Material Property Accessors diff --git a/js/lib/rdge/materials/plasma-material.js b/js/lib/rdge/materials/plasma-material.js index 86b1a93c..b04d8451 100644 --- a/js/lib/rdge/materials/plasma-material.js +++ b/js/lib/rdge/materials/plasma-material.js @@ -67,6 +67,24 @@ var PlasmaMaterial = function PlasmaMaterial() { this._time += this._dTime; } + this.exportJSON = function() + { + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName(), + 'speed' : this._speed, + 'dTime' : this._dTime + } + + return jObj; + } + + this.importJSON = function( jObj ) + { + this._speed = jObj.speed; + this._dTime = jObj.dTime; + } }; /////////////////////////////////////////////////////////////////////////////////////// diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js index 81db36c6..2075d1ff 100644 --- a/js/lib/rdge/materials/pulse-material.js +++ b/js/lib/rdge/materials/pulse-material.js @@ -125,18 +125,6 @@ var PulseMaterial = function PulseMaterial() { var texMapName = this._propValues[this._propNames[0]]; var wrap = 'REPEAT', mips = true; var tex = this.loadTexture( texMapName, wrap, mips ); - - /* - var glTex = new GLTexture( this.getWorld() ); - var prevWorld = this.findPreviousWorld(); - if (prevWorld) - { - var srcCanvas = prevWorld.getCanvas(); - tex = glTex.loadFromCanvas( srcCanvas ); - } - else - tex = glTex.loadFromFile( texMapName, wrap, mips ); - */ if (tex) { technique.u_tex0.set( tex ); @@ -174,6 +162,38 @@ var PulseMaterial = function PulseMaterial() { } }; + // JSON export + this.exportJSON = function() + { + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName(), + 'texture' : this._propValues[this._propNames[0]], + 'dTime' : this._dTime + }; + + return jObj; + }; + + this.importJSON = function( jObj ) + { + if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); + this.setName( jObj.name ); + + try { + this._propValues[this._propNames[0]] = jObj.texture; + this._texMap = jObj.texture; + if (jObj.dTime) + this._dTime = jObj.dTime; + } + catch (e) + { + throw new Error( "could not import material: " + jObj ); + } + } + + this.export = function() { // every material needs the base type and instance name var exportStr = "material: " + this.getShaderName() + "\n"; diff --git a/js/lib/rdge/materials/radial-blur-material.js b/js/lib/rdge/materials/radial-blur-material.js index 46cdda74..f4a4baa2 100644 --- a/js/lib/rdge/materials/radial-blur-material.js +++ b/js/lib/rdge/materials/radial-blur-material.js @@ -157,6 +157,38 @@ var RadialBlurMaterial = function RadialBlurMaterial() { } }; + this.exportJSON = function() + { + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName(), + 'color' : this._propValues["color"], + 'texture' : this._propValues[this._propNames[0]] + }; + + return jObj; + }; + + this.importJSON = function( jObj ) + { + if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); + this.setName( jObj.name ); + + var rtnStr; + try + { + this._propValues[this._propNames[0]] = jObj.texture; + this.updateTexture(); + } + catch (e) + { + throw new Error( "could not import material: " + importStr ); + } + + return rtnStr; + } + this.export = function() { // every material needs the base type and instance name var exportStr = "material: " + this.getShaderName() + "\n"; @@ -242,10 +274,31 @@ var radialBlurMaterialDef = } }; + +var RaidersMaterial = function RaidersMaterial() +{ + // initialize the inherited members + this.inheritedFrom = RadialBlurMaterial; + this.inheritedFrom(); + + this._name = "RaidersMaterial"; + this._shaderName = "radialBlur"; + + this._texMap = 'assets/images/raiders.png'; + this._propValues[ this._propNames[0] ] = this._texMap.slice(0); +} + +RaidersMaterial.prototype = new Material(); + +if (typeof exports === "object") +{ + exports.RaidersMaterial = RaidersMaterial; +} + + RadialBlurMaterial.prototype = new Material(); -if (typeof exports === "object") { +if (typeof exports === "object") exports.RadialBlurMaterial = RadialBlurMaterial; -} diff --git a/js/lib/rdge/materials/radial-gradient-material.js b/js/lib/rdge/materials/radial-gradient-material.js index d19b44b7..87e20ad4 100755 --- a/js/lib/rdge/materials/radial-gradient-material.js +++ b/js/lib/rdge/materials/radial-gradient-material.js @@ -158,7 +158,8 @@ var RadialGradientMaterial = function RadialGradientMaterial() { this._propValues[ this._propNames[6] ] = this._colorStop3; this._propValues[ this._propNames[7] ] = this._colorStop4; - this.setProperty = function( prop, value ) { + this.setProperty = function( prop, value ) + { if (prop === "color") prop = "color1"; // make sure we have legitimate imput @@ -236,6 +237,57 @@ var RadialGradientMaterial = function RadialGradientMaterial() { } }; + this.exportJSON = function() + { + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName(), + + 'color1' : this.getColor1(), + 'color2' : this.getColor2(), + 'color3' : this.getColor3(), + 'color4' : this.getColor4(), + 'colorStop1' : this.getColorStop1(), + 'colorStop2' : this.getColorStop2(), + 'colorStop3' : this.getColorStop3(), + 'colorStop4' : this.getColorStop4() + }; + + return jObj; + }; + + this.importJSON = function( jObj ) + { + if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); + this.setName( jObj.name ); + + try + { + var color1 = jObj.color1, + color2 = jObj.color2, + color3 = jObj.color3, + color4 = jObj.color4, + colorStop1 = jObj.colorStop1, + colorStop2 = jObj.colorStop2, + colorStop3 = jObj.colorStop3, + colorStop4 = jObj.colorStop4; + + this.setProperty( "color1", color1 ); + this.setProperty( "color2", color2 ); + this.setProperty( "color3", color3 ); + this.setProperty( "color4", color4 ); + this.setProperty( "colorStop1", colorStop1 ); + this.setProperty( "colorStop2", colorStop2 ); + this.setProperty( "colorStop3", colorStop3 ); + this.setProperty( "colorStop4", colorStop4 ); + } + catch (e) + { + throw new Error( "could not import material: " + importStr ); + } + }; + this.export = function() { // every material needs the base type and instance name var exportStr = "material: " + this.getShaderName() + "\n"; diff --git a/js/lib/rdge/materials/taper-material.js b/js/lib/rdge/materials/taper-material.js index 03a7ba9c..15b7b2b0 100644 --- a/js/lib/rdge/materials/taper-material.js +++ b/js/lib/rdge/materials/taper-material.js @@ -96,6 +96,33 @@ function TaperMaterial() } } /////////////////////////////////////////////////////////////////////// + this.exportJSON = function() + { + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName(), + 'color' : this._propValues["color"] + }; + + return jObj; + } + + this.importJSON = function( jObj ) + { + if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); + this.setName( jObj.name ); + + try + { + var color = jObj.color; + this.setProperty( "color", color); + } + catch (e) + { + throw new Error( "could not import material: " + jObj ); + } + } this.export = function() { diff --git a/js/lib/rdge/materials/twist-vert-material.js b/js/lib/rdge/materials/twist-vert-material.js index 05172a1b..2d2cdcc5 100644 --- a/js/lib/rdge/materials/twist-vert-material.js +++ b/js/lib/rdge/materials/twist-vert-material.js @@ -102,6 +102,34 @@ function TwistVertMaterial() } /////////////////////////////////////////////////////////////////////// + this.exportJSON = function() + { + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName(), + 'color' : this._propValues["color"] + }; + + return jObj; + } + + this.importJSON = function( jObj ) + { + if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); + this.setName( jObj.name ); + + try + { + var color = jObj.color; + this.setProperty( "color", color); + } + catch (e) + { + throw new Error( "could not import material: " + importStr ); + } + } + this.export = function() { // this function should be overridden by subclasses diff --git a/js/lib/rdge/materials/uber-material.js b/js/lib/rdge/materials/uber-material.js index 91f43754..c1d1913c 100755 --- a/js/lib/rdge/materials/uber-material.js +++ b/js/lib/rdge/materials/uber-material.js @@ -483,6 +483,182 @@ var UberMaterial = function UberMaterial() { this.rebuildShader(); } + this.importJSON = function( jObj ) + { + if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); + this.setName( jObj.name ); + + if (jObj.materialProps) + { + var ambientColor = jObj.materialProps.ambientColor; this.setProperty( "ambientColor", ambientColor ); + var diffuseColor = jObj.materialProps.diffuseColor; this.setProperty( "diffuseColor", diffuseColor ); + var specularColor = jObj.materialProps.specularColor; this.setProperty( "specularColor", specularColor ); + var specularPower = jObj.materialProps.specularPower; this.setProperty( "specularPower", specularPower ); + } + + var lightArray = jObj.lights; + if (lightArray) + { + this._lights = []; + for (var i=0; i 0) + { + this._ubershaderCaps.lighting = + { + 'light0' : this._lights[0], + 'light1' : this._lights[1], + 'light2' : this._lights[2], + 'light3' : this._lights[3] + } + } + } + + var diffuseMap = jObj['diffuseMap']; + if(diffuseMap) + this.setProperty( "diffuseMap", diffuseMap ); + + var normalMap = jObj['normalMap']; + if(normalMap) + this.setProperty( "normalMap", normalMap ); + + var specularMap = jObj['specularMap']; + if(specularMap) + this.setProperty( "specularMap", specularMap ); + + var environmentMap = jObj['environmentMap']; + if(environmentMap) + { + this.setProperty( "environmentMap", environmentMap ); + this.setProperty( "environmentAmount", jObj['environmentAmount'] ); + } + + this.rebuildShader(); + } + + this.exportJSON = function() + { + // every material needs the base type and instance name + var caps = this._ubershaderCaps; + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName() + }; + + // export the material properties + if (typeof caps.material != 'undefined') + { + jObj.materialProps = + { + 'ambientColor' : this._ambientColor, + 'diffuseColor' : this._diffuseColor, + 'specularColor' : this._specularColor, + 'specularPower' : this._specularPower + }; + + } + + if (typeof caps.lighting != 'undefined') + { + var lightArray = []; + for (var i=0; i 0) + jObj.lights = lightArray; + } + + if(typeof caps.diffuseMap != 'undefined') + jObj['diffuseMap'] = caps.diffuseMap.texture; + + if(typeof caps.normalMap != 'undefined') + jObj['normalMap'] = caps.normalMap.texture; + + if(typeof caps.specularMap != 'undefined') + jObj['specularMap'] = caps.specularMap.texture; + + if(typeof caps.environmentMap != 'undefined') + { + jObj['environmentMap'] = caps.environmentMap.texture; + jObj['environmentAmount'] = caps.environmentMap.envReflection; + } + + return jObj; + } + + this.export = function() { // every material needs the base type and instance name @@ -539,10 +715,6 @@ var UberMaterial = function UberMaterial() { } } -// this._diffuseMapOb = { 'texture' : 'assets/images/rocky-diffuse.jpg', 'wrap' : 'REPEAT' }; -// this._normalMapOb = { 'texture' : 'assets/images/rocky-normal.jpg', 'wrap' : 'REPEAT' }; -// this._specularMapOb = { 'texture' : 'assets/images/rocky-spec.jpg', 'wrap' : 'REPEAT' }; -// this._environmentMapOb = { 'texture' : 'assets/images/silver.png', 'wrap' : 'CLAMP', 'envReflection' : this._environmentAmount }; var world = this.getWorld(); if (!world) throw new Error( "no world in material.export, " + this.getName() ); diff --git a/js/lib/rdge/materials/water-material.js b/js/lib/rdge/materials/water-material.js index cac5a249..b7413f55 100644 --- a/js/lib/rdge/materials/water-material.js +++ b/js/lib/rdge/materials/water-material.js @@ -18,6 +18,7 @@ var WaterMaterial = function WaterMaterial() { this._shaderName = "water"; this._texMap = 'assets/images/rocky-normal.jpg'; + //this._texMap = 'assets/images/powderblue.png'; this._time = 0.0; this._dTime = 0.01; @@ -27,6 +28,7 @@ var WaterMaterial = function WaterMaterial() { /////////////////////////////////////////////////////////////////////// // all defined in parent PulseMaterial.js // load the local default value + this._propValues = []; this._propValues[ this._propNames[0] ] = this._texMap.slice(0); /////////////////////////////////////////////////////////////////////// @@ -115,6 +117,107 @@ var waterMaterialDef = } }; +var ParisMaterial = function ParisMaterial() +{ + // initialize the inherited members + this.inheritedFrom = WaterMaterial; + this.inheritedFrom(); + + this._name = "ParisMaterial"; + this._shaderName = "paris"; + + this._texMap = 'assets/images/paris.png'; + this._propValues[ this._propNames[0] ] = this._texMap.slice(0); + + this._diffuseColor = [0.5, 0.5, 0.5, 0.5]; + this._propValues[ this._propNames[1] ] = this._diffuseColor.slice(); + + // duplcate method requirde + this.dup = function( world ) { + // allocate a new uber material + var newMat = new ParisMaterial(); + + // copy over the current values; + var propNames = [], propValues = [], propTypes = [], propLabels = []; + this.getAllProperties( propNames, propValues, propTypes, propLabels); + var n = propNames.length; + for (var i=0; i --- js/lib/drawing/world.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'js/lib') diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index 07a2c3ae..b87c6272 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js @@ -117,6 +117,8 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) { this.getRenderer = function() { return this.renderer; }; + // Flag to play/pause animation at authortime + this._previewAnimation = true; //////////////////////////////////////////////////////////////////////////////////// // RDGE // local variables @@ -475,6 +477,10 @@ World.prototype.restartRenderLoop = function() { if (this._allMapsLoaded) { //console.log( "starting task" ); this._canvas.task.start(); + if(!this._previewAnimation) { + //render only once if authortime animation is turned off + this._canvas.task.stop(); + } } else { //console.log( "stopping task" ); this._canvas.task.stop(); -- cgit v1.2.3 From 2946d01666ff81f913bd06d1ac1381ed42b4a010 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Fri, 23 Mar 2012 13:37:31 -0700 Subject: Check for a authortime animation setting in the draw routine for WebGL. Signed-off-by: Nivesh Rajbhandari --- js/lib/drawing/world.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'js/lib') diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index b87c6272..fb787256 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js @@ -238,7 +238,7 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) { if (this._canvas.task) { this._firstRender = false; - if (!this.hasAnimatedMaterials()) { + if (!this.hasAnimatedMaterials() || !this._previewAnimation) { this._canvas.task.stop(); //this._renderCount = 10; } @@ -477,10 +477,6 @@ World.prototype.restartRenderLoop = function() { if (this._allMapsLoaded) { //console.log( "starting task" ); this._canvas.task.start(); - if(!this._previewAnimation) { - //render only once if authortime animation is turned off - this._canvas.task.stop(); - } } else { //console.log( "stopping task" ); this._canvas.task.stop(); -- cgit v1.2.3 From 86770d0dba6b137e651cbf5c8d240856be65857c Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 23 Mar 2012 14:59:51 -0700 Subject: Fixed a problem switching from 3D to 2D and back to 3D. --- js/lib/drawing/world.js | 2 ++ js/lib/geom/geom-obj.js | 2 +- js/lib/geom/rectangle.js | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) (limited to 'js/lib') diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index b87c6272..73273adc 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js @@ -736,6 +736,8 @@ World.prototype.getShapeFromPoint = function( offsetX, offsetY ) { } }; + + World.prototype.exportJSON = function() { // world properties diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index dbef4859..a87bdbf5 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js @@ -248,7 +248,7 @@ var GeomObj = function GLGeomObj() { this.exportMaterialsJSON = function() { var jObj; - if (this._materialArray && this._materialNodeArray) + if (this._materialArray && this._materialNodeArray && this.getWorld().isWebGL()) { var nMats = this._materialArray.length; if (nMats > 0) diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index 38e428bd..e511d5f4 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js @@ -187,7 +187,8 @@ var Rectangle = function GLRectangle() { /////////////////////////////////////////////////////////////////////// // Methods /////////////////////////////////////////////////////////////////////// - this.export = function() { + /* + this.export = function() { var rtnStr = "type: " + this.geomType() + "\n"; ///////////////////////////////////////////////////////////////////////// @@ -243,6 +244,7 @@ var Rectangle = function GLRectangle() { return rtnStr; }; + */ // JSON export this.exportJSON = function() -- cgit v1.2.3 From a806c422905adf0fa5c244d751535c615ec5d8c7 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Sat, 24 Mar 2012 13:57:23 -0700 Subject: Check for a authortime animation setting in the draw routine for WebGL. Signed-off-by: Nivesh Rajbhandari --- js/lib/drawing/world.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/lib') diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index fd833e4b..781695b6 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js @@ -238,7 +238,7 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) { if (this._canvas.task) { this._firstRender = false; - if (!this.hasAnimatedMaterials() || !this._previewAnimation) { + if (!this.hasAnimatedMaterials() || !this._previewAnimation) { this._canvas.task.stop(); //this._renderCount = 10; } -- cgit v1.2.3