diff options
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/renderUtils.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/renderUtils.js | 793 |
1 files changed, 397 insertions, 396 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/renderUtils.js b/js/helper-classes/RDGE/src/core/script/renderUtils.js index 2d2a5930..60a51d4e 100755 --- a/js/helper-classes/RDGE/src/core/script/renderUtils.js +++ b/js/helper-classes/RDGE/src/core/script/renderUtils.js | |||
@@ -1,396 +1,397 @@ | |||
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. | 4 | |
5 | 5 | Redistribution and use in source and binary forms, with or without | |
6 | Redistribution and use in source and binary forms, with or without | 6 | modification, are permitted provided that the following conditions are met: |
7 | modification, are permitted provided that the following conditions are met: | 7 | |
8 | 8 | * Redistributions of source code must retain the above copyright notice, | |
9 | - Redistributions of source code must retain the above copyright notice, | 9 | this list of conditions and the following disclaimer. |
10 | this list of conditions and the following disclaimer. | 10 | |
11 | - Redistributions in binary form must reproduce the above copyright | 11 | * Redistributions in binary form must reproduce the above copyright notice, |
12 | notice, this list of conditions and the following disclaimer in the | 12 | this list of conditions and the following disclaimer in the documentation |
13 | documentation and/or other materials provided with the distribution. | 13 | and/or other materials provided with the distribution. |
14 | - Neither the name of Motorola Mobility nor the names of its contributors | 14 | |
15 | may be used to endorse or promote products derived from this software | 15 | * Neither the name of Motorola Mobility LLC nor the names of its |
16 | without specific prior written permission. | 16 | contributors may be used to endorse or promote products derived from this |
17 | 17 | software without specific prior written permission. | |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 18 | |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | POSSIBILITY OF SUCH DAMAGE. | 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | </copyright> */ | 29 | POSSIBILITY OF SUCH DAMAGE. |
30 | 30 | </copyright> */ | |
31 | var RDGE = RDGE || {}; | 31 | |
32 | RDGE.renderUtils = RDGE.renderUtils || {}; | 32 | var RDGE = RDGE || {}; |
33 | 33 | RDGE.renderUtils = RDGE.renderUtils || {}; | |
34 | /* | 34 | |
35 | * Creates an indexed box primitive | 35 | /* |
36 | * @return a rdge primitive | 36 | * Creates an indexed box primitive |
37 | */ | 37 | * @return a rdge primitive |
38 | RDGE.renderUtils.createBox = function () { | 38 | */ |
39 | var renderer = RDGE.globals.engine.getContext().renderer; | 39 | RDGE.renderUtils.createBox = function () { |
40 | 40 | var renderer = RDGE.globals.engine.getContext().renderer; | |
41 | var coords = | 41 | |
42 | [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, // front | 42 | var coords = |
43 | 1, 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, // right | 43 | [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, // front |
44 | 1, 1, 1, 1, 1, -1, -1, 1, -1, -1, 1, 1, // top | 44 | 1, 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, // right |
45 | -1, 1, 1, -1, 1, -1, -1, -1, -1, -1, -1, 1, // left | 45 | 1, 1, 1, 1, 1, -1, -1, 1, -1, -1, 1, 1, // top |
46 | -1, -1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, // bottom | 46 | -1, 1, 1, -1, 1, -1, -1, -1, -1, -1, -1, 1, // left |
47 | 1, -1, -1, -1, -1, -1, -1, 1, -1, 1, 1, -1]; // back | 47 | -1, -1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, // bottom |
48 | 48 | 1, -1, -1, -1, -1, -1, -1, 1, -1, 1, 1, -1]; // back | |
49 | var normals = | 49 | |
50 | [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, // front | 50 | var normals = |
51 | 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, // right | 51 | [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, // front |
52 | 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, // top | 52 | 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, // right |
53 | -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, // left | 53 | 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, // top |
54 | 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, // bottom | 54 | -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, // left |
55 | 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1]; // back | 55 | 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, // bottom |
56 | 56 | 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1]; // back | |
57 | var uvs = | 57 | |
58 | [1, 1, 0, 1, 0, 0, 1, 0, // front | 58 | var uvs = |
59 | 0, 1, 0, 0, 1, 0, 1, 1, // right | 59 | [1, 1, 0, 1, 0, 0, 1, 0, // front |
60 | 1, 0, 1, 1, 0, 1, 0, 0, // top | 60 | 0, 1, 0, 0, 1, 0, 1, 1, // right |
61 | 1, 1, 0, 1, 0, 0, 1, 0, // left | 61 | 1, 0, 1, 1, 0, 1, 0, 0, // top |
62 | 0, 0, 1, 0, 1, 1, 0, 1, // bottom | 62 | 1, 1, 0, 1, 0, 0, 1, 0, // left |
63 | 0, 0, 1, 0, 1, 1, 0, 1]; // back | 63 | 0, 0, 1, 0, 1, 1, 0, 1, // bottom |
64 | 64 | 0, 0, 1, 0, 1, 1, 0, 1]; // back | |
65 | var indices = | 65 | |
66 | [0, 1, 2, 0, 2, 3, // front | 66 | var indices = |
67 | 4, 5, 6, 4, 6, 7, // right | 67 | [0, 1, 2, 0, 2, 3, // front |
68 | 8, 9, 10, 8, 10, 11, // top | 68 | 4, 5, 6, 4, 6, 7, // right |
69 | 12, 13, 14, 12, 14, 15, // left | 69 | 8, 9, 10, 8, 10, 11, // top |
70 | 16, 17, 18, 16, 18, 19, // bottom | 70 | 12, 13, 14, 12, 14, 15, // left |
71 | 20, 21, 22, 20, 22, 23]; // back | 71 | 16, 17, 18, 16, 18, 19, // bottom |
72 | 72 | 20, 21, 22, 20, 22, 23]; // back | |
73 | 73 | ||
74 | var prim = new RDGE.rdgePrimitiveDefinition(); | 74 | |
75 | 75 | var prim = new RDGE.rdgePrimitiveDefinition(); | |
76 | prim.vertexDefinition = | 76 | |
77 | { | 77 | prim.vertexDefinition = |
78 | "vert": { 'type': RDGE.rdgeConstants.VS_ELEMENT_POS, 'bufferIndex': 0, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, | 78 | { |
79 | "a_pos": { 'type': RDGE.rdgeConstants.VS_ELEMENT_POS, 'bufferIndex': 0, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, | 79 | "vert": { 'type': RDGE.rdgeConstants.VS_ELEMENT_POS, 'bufferIndex': 0, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, |
80 | 80 | "a_pos": { 'type': RDGE.rdgeConstants.VS_ELEMENT_POS, 'bufferIndex': 0, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, | |
81 | "normal": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex': 1, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, | 81 | |
82 | "a_nrm": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex': 1, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, | 82 | "normal": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex': 1, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, |
83 | 83 | "a_nrm": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex': 1, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, | |
84 | "texcoord": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex': 2, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, | 84 | |
85 | "a_uv": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex': 2, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC } | 85 | "texcoord": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex': 2, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, |
86 | }; | 86 | "a_uv": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex': 2, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC } |
87 | 87 | }; | |
88 | prim.bufferStreams = | 88 | |
89 | [ | 89 | prim.bufferStreams = |
90 | coords, | 90 | [ |
91 | normals, | 91 | coords, |
92 | uvs | 92 | normals, |
93 | ]; | 93 | uvs |
94 | 94 | ]; | |
95 | prim.streamUsage = | 95 | |
96 | [ | 96 | prim.streamUsage = |
97 | RDGE.rdgeConstants.BUFFER_STATIC, | 97 | [ |
98 | RDGE.rdgeConstants.BUFFER_STATIC, | 98 | RDGE.rdgeConstants.BUFFER_STATIC, |
99 | RDGE.rdgeConstants.BUFFER_STATIC | 99 | RDGE.rdgeConstants.BUFFER_STATIC, |
100 | ]; | 100 | RDGE.rdgeConstants.BUFFER_STATIC |
101 | 101 | ]; | |
102 | prim.indexUsage = RDGE.rdgeConstants.BUFFER_STREAM; | 102 | |
103 | prim.indexBuffer = indices; | 103 | prim.indexUsage = RDGE.rdgeConstants.BUFFER_STREAM; |
104 | 104 | prim.indexBuffer = indices; | |
105 | prim.type = RDGE.rdgeConstants.TRIANGLES; | 105 | |
106 | 106 | prim.type = RDGE.rdgeConstants.TRIANGLES; | |
107 | renderer.createPrimitive(prim); | 107 | |
108 | 108 | renderer.createPrimitive(prim); | |
109 | return prim; | 109 | |
110 | }; | 110 | return prim; |
111 | 111 | }; | |
112 | // | 112 | |
113 | // makeSphere | 113 | // |
114 | // | 114 | // makeSphere |
115 | // Create a sphere with the passed number of latitude and longitude bands and the passed radius. | 115 | // |
116 | // Sphere has vertices, normals and texCoords. Create VBOs for each as well as the index array. | 116 | // Create a sphere with the passed number of latitude and longitude bands and the passed radius. |
117 | // Return an object with the following properties: | 117 | // Sphere has vertices, normals and texCoords. Create VBOs for each as well as the index array. |
118 | // | 118 | // Return an object with the following properties: |
119 | // normalObject WebGLBuffer object for normals | 119 | // |
120 | // texCoordObject WebGLBuffer object for texCoords | 120 | // normalObject WebGLBuffer object for normals |
121 | // vertexObject WebGLBuffer object for vertices | 121 | // texCoordObject WebGLBuffer object for texCoords |
122 | // indexObject WebGLBuffer object for indices | 122 | // vertexObject WebGLBuffer object for vertices |
123 | // numIndices The number of indices in the indexObject | 123 | // indexObject WebGLBuffer object for indices |
124 | // | 124 | // numIndices The number of indices in the indexObject |
125 | RDGE.renderUtils.makeSphere = function (ctx, radius, lats, longs) { | 125 | // |
126 | var geometryData = []; | 126 | RDGE.renderUtils.makeSphere = function (ctx, radius, lats, longs) { |
127 | var normalData = []; | 127 | var geometryData = []; |
128 | var texCoordData = []; | 128 | var normalData = []; |
129 | var indexData = []; | 129 | var texCoordData = []; |
130 | 130 | var indexData = []; | |