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/taper-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/taper-material.js')
-rw-r--r-- | js/lib/rdge/materials/taper-material.js | 110 |
1 files changed, 66 insertions, 44 deletions
diff --git a/js/lib/rdge/materials/taper-material.js b/js/lib/rdge/materials/taper-material.js index 2dc3e120..73e344d5 100644 --- a/js/lib/rdge/materials/taper-material.js +++ b/js/lib/rdge/materials/taper-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 |
@@ -38,7 +39,7 @@ var Texture = require("js/lib/rdge/texture").Texture; | |||
38 | var TaperMaterial = function TaperMaterial() | 39 | var TaperMaterial = function TaperMaterial() |
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 | /////////////////////////////////////////////////////////////////////// |
@@ -55,13 +56,15 @@ var TaperMaterial = function TaperMaterial() | |||
55 | this.getShaderName = function () { return this._shaderName; }; | 56 | this.getShaderName = function () { return this._shaderName; }; |
56 | 57 | ||
57 | this.isAnimated = function () { return true; }; | 58 | this.isAnimated = function () { return true; }; |
58 | this.getShaderDef = function() { return taperShaderDef; }; | 59 | this.getShaderDef = function() { return taperShaderDef; }; |
59 | this.getTechniqueName = function() { return 'colorMe' }; | 60 | this.getTechniqueName = function() { return 'colorMe' }; |
60 | 61 | ||
61 | this.hasVertexDeformation = function () { return this._hasVertexDeformation; }; | 62 | this.hasVertexDeformation = function () { return this._hasVertexDeformation; }; |
62 | this._hasVertexDeformation = true; | 63 | this._hasVertexDeformation = true; |
63 | this._vertexDeformationTolerance = 0.02; // should be a property | 64 | this._vertexDeformationTolerance = 0.02; // should be a property |
64 | 65 | ||
66 | this.getVertexDeformationTolerance = function() { return this._propValues[this._propNames[7]]; }; | ||
67 | |||
65 | /////////////////////////////////////////////////////////////////////// | 68 | /////////////////////////////////////////////////////////////////////// |
66 | // Methods | 69 | // Methods |
67 | /////////////////////////////////////////////////////////////////////// | 70 | /////////////////////////////////////////////////////////////////////// |
@@ -76,7 +79,7 @@ var TaperMaterial = function TaperMaterial() | |||
76 | // set up the material node | 79 | // set up the material node |
77 | this._materialNode = RDGE.createMaterialNode("taperMaterial" + "_" + world.generateUniqueNodeID()); | 80 | this._materialNode = RDGE.createMaterialNode("taperMaterial" + "_" + world.generateUniqueNodeID()); |
78 | this._materialNode.setShader(this._shader); | 81 | this._materialNode.setShader(this._shader); |
79 | 82 | ||
80 | this._time = 0; | 83 | this._time = 0; |
81 | if (this._shader && this._shader['default']) { | 84 | if (this._shader && this._shader['default']) { |
82 | this._shader['default'].u_time.set([this._time]); | 85 | this._shader['default'].u_time.set([this._time]); |
@@ -86,13 +89,30 @@ var TaperMaterial = function TaperMaterial() | |||
86 | this.setShaderValues(); | 89 | this.setShaderValues(); |
87 | }; | 90 | }; |
88 | 91 | ||
92 | this.resetToDefault = function() | ||
93 | { | ||
94 | this._propValues[this._propNames[0]] = 0.25; | ||
95 | this._propValues[this._propNames[1]] = 0.50; | ||
96 | this._propValues[this._propNames[2]] = 0.75; | ||
97 | this._propValues[this._propNames[3]] = -1; | ||
98 | this._propValues[this._propNames[4]] = 1; | ||
99 | this._propValues[this._propNames[5]] = 0.0; | ||
100 | this._propValues[this._propNames[6]] = 0.9; | ||
101 | this._propValues[this._propNames[7]] = this._vertexDeformationTolerance; | ||
102 | this._propValues[this._propNames[8]] = 1.0; | ||
103 | |||
104 | var nProps = this._propNames.length; | ||
105 | for (var i=0; i<nProps; i++) | ||
106 | this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] ); | ||
107 | }; | ||
108 | |||
89 | 109 | ||
90 | /////////////////////////////////////////////////////////////////////// | 110 | /////////////////////////////////////////////////////////////////////// |
91 | // Material Property Accessors | 111 | // Material Property Accessors |
92 | /////////////////////////////////////////////////////////////////////// | 112 | /////////////////////////////////////////////////////////////////////// |
93 | this._propNames = [ "u_limit1", "u_limit2", "u_limit3", "u_minVal", "u_maxVal", "u_center", "u_taperAmount", "u_speed" ]; | 113 | this._propNames = [ "u_limit1", "u_limit2", "u_limit3", "u_minVal", "u_maxVal", "u_center", "u_taperAmount", "facettol", "u_speed" ]; |
94 | this._propLabels = [ "Minimum Parameter Value", "Center Paramater Value", "Maximum Parameter Value", "Minimum Data Bounds", "Maximum Data Bounds", "Center", "Taper Amount", "Speed" ]; | 114 | this._propLabels = [ "Minimum Parameter Value", "Center Paramater Value", "Maximum Parameter Value", "Minimum Data Bounds", "Maximum Data Bounds", "Center", "Taper Amount", "Faceting Tolerance", "Speed" ]; |
95 | this._propTypes = [ "float", "float", "float", "float", "float", "float", "float", "float" ]; | 115 | this._propTypes = [ "float", "float", "float", "float", "float", "float", "float", "float", "float" ]; |
96 | this._propValues = []; | 116 | this._propValues = []; |
97 | 117 | ||
98 | // initialize the property values | 118 | // initialize the property values |
@@ -103,7 +123,8 @@ var TaperMaterial = function TaperMaterial() | |||
103 | this._propValues[this._propNames[4]] = 1; | 123 | this._propValues[this._propNames[4]] = 1; |
104 | this._propValues[this._propNames[5]] = 0.0; | 124 | this._propValues[this._propNames[5]] = 0.0; |
105 | this._propValues[this._propNames[6]] = 0.9; | 125 | this._propValues[this._propNames[6]] = 0.9; |
106 | this._propValues[this._propNames[7]] = 1.0; | 126 | this._propValues[this._propNames[7]] = this._vertexDeformationTolerance; |
127 | this._propValues[this._propNames[8]] = 1.0; | ||
107 | 128 | ||
108 | this.update = function (time) { | 129 | this.update = function (time) { |
109 | var speed = this._propValues["u_speed"]; | 130 | var speed = this._propValues["u_speed"]; |
@@ -117,7 +138,7 @@ var TaperMaterial = function TaperMaterial() | |||
117 | } | 138 | } |
118 | 139 | ||
119 | var t1 = this._propValues["u_limit1"] - this._deltaTime, | 140 | var t1 = this._propValues["u_limit1"] - this._deltaTime, |
120 | t2 = this._propValues["u_limit2"] - this._deltaTime; | 141 | t2 = this._propValues["u_limit2"] - this._deltaTime; |
121 | 142 | ||
122 | 143 | ||
123 | this._shader.colorMe["u_limit1"].set([t1]); | 144 | this._shader.colorMe["u_limit1"].set([t1]); |
@@ -138,31 +159,32 @@ taperShaderDef = { | |||
138 | }, | 159 | }, |
139 | 'techniques': { // rendering control | 160 | 'techniques': { // rendering control |
140 | 'colorMe': [ // simple color pass | 161 | 'colorMe': [ // simple color pass |
141 | { | 162 | { |
142 | 'vshader': 'defaultVShader', | 163 | 'vshader': 'defaultVShader', |
143 | 'fshader': 'defaultFShader', | 164 | 'fshader': 'defaultFShader', |
144 | 165 | ||
145 | // attributes | 166 | // attributes |
146 | 'attributes': | 167 | 'attributes': |
147 | { | 168 | { |
148 | 'vert': { 'type': 'vec3' }, | 169 | 'vert': { 'type': 'vec3' }, |
149 | 'normal': { 'type': 'vec3' }, | 170 | 'normal': { 'type': 'vec3' }, |
150 | 'texcoord': { 'type': 'vec2' } | 171 | 'texcoord': { 'type': 'vec2' } |
151 | }, | 172 | }, |
152 | // attributes | 173 | // attributes |
153 | 'params': | 174 | 'params': |
154 | { | 175 | { |
155 | 'u_limit1': { 'type': 'float' }, | 176 | 'u_limit1': { 'type': 'float' }, |
156 | 'u_limit2': { 'type': 'float' }, | 177 | 'u_limit2': { 'type': 'float' }, |
157 | 'u_limit3': { 'type': 'float' }, | 178 | 'u_limit3': { 'type': 'float' }, |
158 | 'u_minVal': { 'type': 'float' }, | 179 | 'u_minVal': { 'type': 'float' }, |
159 | 'u_maxVal': { 'type': 'float' }, | 180 | 'u_maxVal': { 'type': 'float' }, |
160 | 'u_center': { 'type': 'float' }, | 181 | 'u_center': { 'type': 'float' }, |
161 | 'u_taperAmount': { 'type': 'float' }, | 182 | 'u_taperAmount': { 'type': 'float' }, |
162 | 'u_speed': { 'type': 'float' } | 183 | 'facettol': { 'type': 'float' }, |
163 | } | 184 | 'u_speed': { 'type': 'float' } |
185 | } | ||
164 | } | 186 | } |
165 | ] | 187 | ] |
166 | } | 188 | } |
167 | }; | 189 | }; |
168 | 190 | ||