aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/plasma-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/plasma-material.js')
-rw-r--r--js/lib/rdge/materials/plasma-material.js57
1 files changed, 31 insertions, 26 deletions
diff --git a/js/lib/rdge/materials/plasma-material.js b/js/lib/rdge/materials/plasma-material.js
index d52f4b88..02172a6b 100644
--- a/js/lib/rdge/materials/plasma-material.js
+++ b/js/lib/rdge/materials/plasma-material.js
@@ -17,8 +17,6 @@ var PlasmaMaterial = function PlasmaMaterial() {
17 this._dTime = 0.01; 17 this._dTime = 0.01;
18 this._speed = 1.0; 18 this._speed = 1.0;
19 19
20 this._color = [1,0,0,1];
21
22 20
23 /////////////////////////////////////////////////////////////////////// 21 ///////////////////////////////////////////////////////////////////////
24 // Property Accessors 22 // Property Accessors
@@ -30,20 +28,12 @@ var PlasmaMaterial = function PlasmaMaterial() {
30 /////////////////////////////////////////////////////////////////////// 28 ///////////////////////////////////////////////////////////////////////
31 // Material Property Accessors 29 // Material Property Accessors
32 /////////////////////////////////////////////////////////////////////// 30 ///////////////////////////////////////////////////////////////////////
33 this._propNames = ["color"]; 31
34 this._propLabels = ["Color"]; 32 this.setProperty = function( prop, value )
35 this._propTypes = ["color"]; 33 {
36 this._propValues = []; 34 // plasma has no properties
37
38 this._propValues[ this._propNames[0] ] = this._color;
39
40 this.setProperty = function( prop, value ) {
41 // make sure we have legitimate imput
42 if (this.validateProperty( prop, value )) {
43 this._color = value.slice(0);
44 this._shader['default'][prop].set(value);
45 }
46 }; 35 };
36
47 /////////////////////////////////////////////////////////////////////// 37 ///////////////////////////////////////////////////////////////////////
48 38
49 /////////////////////////////////////////////////////////////////////// 39 ///////////////////////////////////////////////////////////////////////
@@ -54,7 +44,10 @@ var PlasmaMaterial = function PlasmaMaterial() {
54 return new PlasmaMaterial(); 44 return new PlasmaMaterial();
55 }; 45 };
56 46
57 this.init = function() { 47 this.init = function( world)
48 {
49 this.setWorld( world );
50
58 // set up the shader 51 // set up the shader
59 this._shader = new RDGE.jshader(); 52 this._shader = new RDGE.jshader();
60 this._shader.def = plasmaShaderDef; 53 this._shader.def = plasmaShaderDef;
@@ -62,23 +55,36 @@ var PlasmaMaterial = function PlasmaMaterial() {
62 55
63 // set the default value 56 // set the default value
64 this._time = 0; 57 this._time = 0;
65 this._shader['default'].u_time = this._time; 58 this._shader['default'].u_time.set( [this._time] );
66 this.setProperty( "color", [this._time, 0, 0, 1] );
67 59
68 // set up the material node 60 // set up the material node
69 this._materialNode = RDGE.createMaterialNode("plasmaMaterial"); 61 this._materialNode = RDGE.createMaterialNode("plasmaMaterial" + "_" + world.generateUniqueNodeID());
70 this._materialNode.setShader(this._shader); 62 this._materialNode.setShader(this._shader);
71 }; 63 };
72 64
73 this.update = function( time ) { 65 this.update = function( time ) {
74 this._shader['default'].u_time = this._time; 66 this._shader['default'].u_time.set( [this._time] );
75 var color = this.getProperty( "color" );
76 color[0] = this._time;
77 this.setProperty( "color", color );
78 //console.log( "update color to: " + color );
79 this._time += this._dTime; 67 this._time += this._dTime;
80 } 68 };
69
70 this.exportJSON = function()
71 {
72 var jObj =
73 {
74 'material' : this.getShaderName(),
75 'name' : this.getName(),
76 'speed' : this._speed,
77 'dTime' : this._dTime
78 };
79
80 return jObj;
81 };
81 82
83 this.importJSON = function( jObj )
84 {
85 this._speed = jObj.speed;
86 this._dTime = jObj.dTime;
87 };
82}; 88};
83 89
84/////////////////////////////////////////////////////////////////////////////////////// 90///////////////////////////////////////////////////////////////////////////////////////
@@ -109,7 +115,6 @@ var plasmaShaderDef =
109 'params' : 115 'params' :
110 { 116 {
111 'u_time' : { 'type' : 'float' }, 117 'u_time' : { 'type' : 'float' },
112 'color' : { 'type' : 'vec4' }
113 }, 118 },
114 119
115 // render states 120 // render states