diff options
author | John Mayhew | 2012-07-09 17:28:24 -0700 |
---|---|---|
committer | John Mayhew | 2012-07-09 17:28:24 -0700 |
commit | 770bcb52422742ff741a88a75ecefbeb90bc9247 (patch) | |
tree | 64cb3e09a8daeb340261dd7f3869c73f7b90b643 /js/lib/rdge/materials/twist-vert-material.js | |
parent | 8c5ecaf90062f9e030386f338bdc19fd62b826c8 (diff) | |
parent | 2b2b5fbb4b6a786daa4e9d4ee9eba9ac78924842 (diff) | |
download | ninja-770bcb52422742ff741a88a75ecefbeb90bc9247.tar.gz |
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal
Conflicts:
manifest.json
Diffstat (limited to 'js/lib/rdge/materials/twist-vert-material.js')
-rw-r--r-- | js/lib/rdge/materials/twist-vert-material.js | 323 |
1 files changed, 169 insertions, 154 deletions
diff --git a/js/lib/rdge/materials/twist-vert-material.js b/js/lib/rdge/materials/twist-vert-material.js index 6b71593f..57ef23ea 100644 --- a/js/lib/rdge/materials/twist-vert-material.js +++ b/js/lib/rdge/materials/twist-vert-material.js | |||
@@ -1,24 +1,25 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility LLC. |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | ||
5 | 4 | ||
6 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
8 | 7 | ||
9 | - Redistributions of source code must retain the above copyright notice, | 8 | * Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. | 9 | this list of conditions and the following disclaimer. |
11 | - Redistributions in binary form must reproduce the above copyright | 10 | |
12 | notice, this list of conditions and the following disclaimer in the | 11 | * Redistributions in binary form must reproduce the above copyright notice, |
13 | documentation and/or other materials provided with the distribution. | 12 | this list of conditions and the following disclaimer in the documentation |
14 | - Neither the name of Motorola Mobility nor the names of its contributors | 13 | and/or other materials provided with the distribution. |
15 | may be used to endorse or promote products derived from this software | 14 | |
16 | without specific prior written permission. | 15 | * Neither the name of Motorola Mobility LLC nor the names of its |
16 | contributors may be used to endorse or promote products derived from this | ||
17 | software without specific prior written permission. | ||
17 | 18 | ||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
@@ -37,159 +38,173 @@ var Texture = require("js/lib/rdge/texture").Texture; | |||
37 | /////////////////////////////////////////////////////////////////////// | 38 | /////////////////////////////////////////////////////////////////////// |
38 | var TwistVertMaterial = function TwistVertMaterial() | 39 | var TwistVertMaterial = function TwistVertMaterial() |
39 | { | 40 | { |
40 | // initialize the inherited members | 41 | // initialize the inherited members |
41 | this.inheritedFrom = Material; | 42 | this.inheritedFrom = Material; |
42 | this.inheritedFrom(); | 43 | this.inheritedFrom(); |
43 | 44 | ||
44 | /////////////////////////////////////////////////////////////////////// | 45 | /////////////////////////////////////////////////////////////////////// |
45 | // Instance variables | 46 | // Instance variables |
46 | /////////////////////////////////////////////////////////////////////// | 47 | /////////////////////////////////////////////////////////////////////// |
47 | this._name = "Twist Vertex"; | 48 | this._name = "Twist Vertex"; |
48 | this._shaderName = "twistVert"; | 49 | this._shaderName = "twistVert"; |
49 | 50 | ||
50 | this._tex0 = 'assets/images/rocky-normal.jpg'; | 51 | this._tex0 = 'assets/images/rocky-normal.jpg'; |
51 | this._tex1 = 'assets/images/metal.png'; | 52 | this._tex1 = 'assets/images/metal.png'; |
52 | 53 | ||
53 | this._angle = 0.0; | 54 | this._angle = 0.0; |
54 | this._deltaTime = 0.01; | 55 | this._deltaTime = 0.01; |
55 | this._speed = 1.0; | 56 | this._speed = 1.0; |
56 | 57 | ||
57 | /////////////////////////////////////////////////////////////////////// | 58 | /////////////////////////////////////////////////////////////////////// |
58 | // Property Accessors | 59 | // Property Accessors |
59 | /////////////////////////////////////////////////////////////////////// | 60 | /////////////////////////////////////////////////////////////////////// |
60 | this.getShaderName = function () { return this._shaderName; }; | 61 | this.getShaderName = function () { return this._shaderName; }; |
61 | this.isAnimated = function () { return true; }; | 62 | this.isAnimated = function () { return true; }; |
62 | this.getShaderDef = function() { return twistVertShaderDef; }; | 63 | this.getShaderDef = function() { return twistVertShaderDef; }; |
63 | this.getTechniqueName = function() { return 'twistMe' }; | 64 | this.getTechniqueName = function() { return 'twistMe' }; |
64 | 65 | ||
65 | this.hasVertexDeformation = function () { return this._hasVertexDeformation; }; | 66 | this.hasVertexDeformation = function () { return this._hasVertexDeformation; }; |
66 | this._hasVertexDeformation = true; | 67 | this._hasVertexDeformation = true; |
67 | this._vertexDeformationTolerance = 0.02; // should be a property | 68 | this._vertexDeformationTolerance = 0.02; // should be a property |
68 | 69 | ||
69 | /////////////////////////////////////////////////////////////////////// | 70 | /////////////////////////////////////////////////////////////////////// |
70 | // Material Property Accessors | 71 | // Material Property Accessors |
71 | /////////////////////////////////////////////////////////////////////// | 72 | /////////////////////////////////////////////////////////////////////// |
72 | this._propNames = [ "u_limit1", "u_limit2", "u_twistAmount", "speed", "u_tex0", "u_tex1"]; | 73 | this._propNames = [ "u_limit1", "u_limit2", "u_twistAmount", "speed", "u_tex0", "u_tex1"]; |
73 | this._propLabels = [ "Start Parameter", "End Paramater", "Twist Amount", "Speed", "Front facing texture map", "Back facing texture map"]; | 74 | this._propLabels = [ "Start Parameter", "End Paramater", "Twist Amount", "Speed", "Front facing texture map", "Back facing texture map"]; |
74 | this._propTypes = [ "float", "float", "angle", "float", "file", "file"]; | 75 | this._propTypes = [ "float", "float", "angle", "float", "file", "file"]; |
75 | this._propValues = []; | 76 | this._propValues = []; |
76 | 77 | ||
77 | // initialize the property values | 78 | // initialize the property values |
78 | this._propValues[this._propNames[0]] = 0.0; | 79 | this._propValues[this._propNames[0]] = 0.0; |
79 | this._propValues[this._propNames[1]] = 1.0; | 80 | this._propValues[this._propNames[1]] = 1.0; |
80 | this._propValues[this._propNames[2]] = 2.0 * Math.PI; | 81 | this._propValues[this._propNames[2]] = 2.0 * Math.PI; |
81 | this._propValues[this._propNames[3]] = this._speed; | 82 | this._propValues[this._propNames[3]] = this._speed; |
82 | this._propValues[this._propNames[4]] = this._tex0.slice(); | 83 | this._propValues[this._propNames[4]] = this._tex0.slice(); |
83 | this._propValues[this._propNames[5]] = this._tex1.slice(); | 84 | this._propValues[this._propNames[5]] = this._tex1.slice(); |
84 | /////////////////////////////////////////////////////////////////////// | 85 | /////////////////////////////////////////////////////////////////////// |
85 | 86 | ||
86 | /////////////////////////////////////////////////////////////////////// | 87 | /////////////////////////////////////////////////////////////////////// |
87 | // Methods | 88 | // Methods |
88 | /////////////////////////////////////////////////////////////////////// | 89 | /////////////////////////////////////////////////////////////////////// |
89 | 90 | ||
90 | this.init = function (world) | 91 | this.init = function (world) |
91 | { | 92 | { |
92 | this.setWorld(world); | 93 | this.setWorld(world); |
93 | 94 | ||
94 | // set up the shader | 95 | // set up the shader |
95 | this._shader = new RDGE.jshader(); | 96 | this._shader = new RDGE.jshader(); |
96 | this._shader.def = twistVertShaderDef; | 97 | this._shader.def = twistVertShaderDef; |
97 | this._shader.init(); | 98 | this._shader.init(); |
98 | 99 | ||
99 | // set up the material node | 100 | // set up the material node |
100 | this._materialNode = RDGE.createMaterialNode("twistVertMaterial" + "_" + world.generateUniqueNodeID()); | 101 | this._materialNode = RDGE.createMaterialNode("twistVertMaterial" + "_" + world.generateUniqueNodeID()); |
101 | this._materialNode.setShader(this._shader); | 102 | this._materialNode.setShader(this._shader); |
102 | 103 | ||
103 | 104 | ||
104 | // initialize the twist vert properties | 105 | // initialize the twist vert properties |
105 | this.setShaderValues(); | 106 | this.setShaderValues(); |
106 | }; | 107 | }; |
107 | 108 | ||
108 | this.update = function (time) | 109 | this.resetToDefault = function() |
109 | { | 110 | { |
110 | if (this._shader && this._shader.twistMe) | 111 | this._propValues[this._propNames[0]] = 0.0; |
111 | { | 112 | this._propValues[this._propNames[1]] = 1.0; |
112 | var technique = this._shader.twistMe; | 113 | this._propValues[this._propNames[2]] = 2.0 * Math.PI; |
113 | 114 | this._propValues[this._propNames[3]] = this._speed; | |
114 | var angle = this._angle; | 115 | this._propValues[this._propNames[4]] = this._tex0.slice(); |
115 | angle += this._deltaTime * this._propValues["speed"]; | 116 | this._propValues[this._propNames[5]] = this._tex1.slice(); |
116 | if (angle > this._propValues["u_twistAmount"]) | 117 | |
117 | { | 118 | var nProps = this._propNames.length; |
118 | angle = this._propValues["u_twistAmount"]; | 119 | for (var i=0; i<nProps; i++) |
119 | this._deltaTime = -this._deltaTime; | 120 | this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] ); |
120 | } | 121 | }; |
121 | else if (angle < 0.0) | 122 | |
122 | { | 123 | this.update = function (time) |
123 | angle = 0; | 124 | { |
124 | this._deltaTime = -this._deltaTime; | 125 | if (this._shader && this._shader.twistMe) |
125 | } | 126 | { |
126 | this._angle = angle; | 127 | var technique = this._shader.twistMe; |
127 | this._shader.twistMe["u_twistAmount"].set([angle]); | 128 | |
128 | 129 | var angle = this._angle; | |
129 | var tex; | 130 | angle += this._deltaTime * this._propValues["speed"]; |
130 | var glTex = this._glTextures["u_tex0"]; | 131 | if (angle > this._propValues["u_twistAmount"]) |
131 | if (glTex) | 132 | { |
132 | { | 133 | angle = this._propValues["u_twistAmount"]; |
133 | //if (glTex.isAnimated()) | 134 | this._deltaTime = -this._deltaTime; |
134 | glTex.render(); | 135 | } |
135 | tex = glTex.getTexture(); | 136 | else if (angle < 0.0) |
136 | if (tex) | 137 | { |