Mercurial > hg > Members > e105711
annotate webGL/src/J3DI.js @ 0:9285dae61395 draft
1st commit,just play sounds.
author | e105711 <yomitan.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 25 Apr 2012 23:45:59 +0900 |
parents | |
children | 55702e139f69 |
rev | line source |
---|---|
0
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 /* |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 * Copyright (C) 2009 Apple Inc. All Rights Reserved. |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 * |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 * Redistribution and use in source and binary forms, with or without |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 * modification, are permitted provided that the following conditions |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 * are met: |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 * 1. Redistributions of source code must retain the above copyright |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 * notice, this list of conditions and the following disclaimer. |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 * 2. Redistributions in binary form must reproduce the above copyright |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 * notice, this list of conditions and the following disclaimer in the |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 * documentation and/or other materials provided with the distribution. |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 * |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 */ |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 // initWebGL |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 // Initialize the Canvas element with the passed name as a WebGL object and return the |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 // WebGLRenderingContext. |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 // Load shaders with the passed names and create a program with them. Return this program |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 // in the 'program' property of the returned context. |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 // For each string in the passed attribs array, bind an attrib with that name at that index. |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 // Once the attribs are bound, link the program and then use it. |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 // Set the clear color to the passed array (4 values) and set the clear depth to the passed value. |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 // Enable depth testing and blending with a blend func of (SRC_ALPHA, ONE_MINUS_SRC_ALPHA) |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 // A console function is added to the context: console(string). This can be replaced |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 // by the caller. By default, it maps to the window.console() function on WebKit and to |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 // an empty function on other browsers. |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 function initWebGL(canvasName, vshader, fshader, attribs, clearColor, clearDepth) |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 var canvas = document.getElementById(canvasName); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 var gl = canvas.getContext("experimental-webgl"); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 if (!gl) { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 alert("No WebGL context found"); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 return null; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
54 // Add a console |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 gl.console = ("console" in window) ? window.console : { log: function() { } }; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 // create our shaders |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58 var vertexShader = loadShader(gl, vshader); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
59 var fragmentShader = loadShader(gl, fshader); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61 if (!vertexShader || !fragmentShader) |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
62 return null; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
63 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
64 // Create the program object |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
65 gl.program = gl.createProgram(); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
66 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
67 if (!gl.program) |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
68 return null; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
69 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70 // Attach our two shaders to the program |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 gl.attachShader (gl.program, vertexShader); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 gl.attachShader (gl.program, fragmentShader); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
74 // Bind attributes |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
75 for (var i = 0; i < attribs.length; ++i) |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76 gl.bindAttribLocation (gl.program, i, attribs[i]); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
78 // Link the program |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
79 gl.linkProgram(gl.program); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
80 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 // Check the link status |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82 var linked = gl.getProgramParameter(gl.program, gl.LINK_STATUS); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
83 if (!linked) { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
84 // something went wrong with the link |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
85 var error = gl.getProgramInfoLog (gl.program); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
86 gl.console.log("Error in program linking:"+error); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
87 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
88 gl.deleteProgram(gl.program); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
89 gl.deleteProgram(fragmentShader); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
90 gl.deleteProgram(vertexShader); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
91 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
92 return null; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
93 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
94 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
95 gl.useProgram(gl.program); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
96 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
97 gl.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
98 gl.clearDepth(clearDepth); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
99 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
100 gl.enable(gl.DEPTH_TEST); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
101 gl.enable(gl.BLEND); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
102 gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
103 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
104 return gl; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
105 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
106 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
107 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
108 // loadShader |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
109 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
110 // 'shaderId' is the id of a <script> element containing the shader source string. |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
111 // Load this shader and return the WebGLShader object corresponding to it. |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
112 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
113 function loadShader(ctx, shaderId) |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
114 { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
115 var shaderScript = document.getElementById(shaderId); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
116 if (!shaderScript) { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
117 ctx.console.log("*** Error: shader script '"+shaderId+"' not found"); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
118 return null; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
119 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
120 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
121 if (shaderScript.type == "x-shader/x-vertex") |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
122 var shaderType = ctx.VERTEX_SHADER; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
123 else if (shaderScript.type == "x-shader/x-fragment") |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
124 var shaderType = ctx.FRAGMENT_SHADER; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
125 else { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
126 ctx.console.log("*** Error: shader script '"+shaderId+"' of undefined type '"+shaderScript.type+"'"); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
127 return null; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
128 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
129 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
130 // Create the shader object |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
131 var shader = ctx.createShader(shaderType); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
132 if (shader == null) { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
133 ctx.console.log("*** Error: unable to create shader '"+shaderId+"'"); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
134 return null; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
135 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
136 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
137 // Load the shader source |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
138 ctx.shaderSource(shader, shaderScript.text); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
139 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
140 // Compile the shader |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
141 ctx.compileShader(shader); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
142 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
143 // Check the compile status |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
144 var compiled = ctx.getShaderParameter(shader, ctx.COMPILE_STATUS); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
145 if (!compiled) { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
146 // Something went wrong during compilation; get the error |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
147 var error = ctx.getShaderInfoLog(shader); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
148 ctx.console.log("*** Error compiling shader '"+shaderId+"':"+error); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
149 ctx.deleteShader(shader); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
150 return null; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
151 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
152 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
153 return shader; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
154 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
155 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
156 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
157 // makeBox |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
158 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
159 // Create a box with vertices, normals and texCoords. Create VBOs for each as well as the index array. |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
160 // Return an object with the following properties: |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
161 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
162 // normalObject WebGLBuffer object for normals |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
163 // texCoordObject WebGLBuffer object for texCoords |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
164 // vertexObject WebGLBuffer object for vertices |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
165 // indexObject WebGLBuffer object for indices |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
166 // numIndices The number of indices in the indexObject |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
167 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
168 function makeBox(ctx) |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
169 { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
170 // box |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
171 // v6----- v5 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
172 // /| /| |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
173 // v1------v0| |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
174 // | | | | |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
175 // | |v7---|-|v4 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
176 // |/ |/ |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
177 // v2------v3 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
178 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
179 // vertex coords array |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
180 var vertices = new Float32Array( |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
181 [ 1, 1, 1, -1, 1, 1, -1,-1, 1, 1,-1, 1, // v0-v1-v2-v3 front |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
182 1, 1, 1, 1,-1, 1, 1,-1,-1, 1, 1,-1, // v0-v3-v4-v5 right |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
183 1, 1, 1, 1, 1,-1, -1, 1,-1, -1, 1, 1, // v0-v5-v6-v1 top |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
184 -1, 1, 1, -1, 1,-1, -1,-1,-1, -1,-1, 1, // v1-v6-v7-v2 left |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
185 -1,-1,-1, 1,-1,-1, 1,-1, 1, -1,-1, 1, // v7-v4-v3-v2 bottom |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
186 1,-1,-1, -1,-1,-1, -1, 1,-1, 1, 1,-1 ] // v4-v7-v6-v5 back |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
187 ); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
188 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
189 // normal array |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
190 var normals = new Float32Array( |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
191 [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, // v0-v1-v2-v3 front |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
192 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, // v0-v3-v4-v5 right |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
193 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, // v0-v5-v6-v1 top |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
194 -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, // v1-v6-v7-v2 left |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
195 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, // v7-v4-v3-v2 bottom |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
196 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1 ] // v4-v7-v6-v5 back |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
197 ); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
198 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
199 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
200 // texCoord array |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
201 var texCoords = new Float32Array( |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
202 [ 1, 1, 0, 1, 0, 0, 1, 0, // v0-v1-v2-v3 front |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
203 0, 1, 0, 0, 1, 0, 1, 1, // v0-v3-v4-v5 right |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
204 1, 0, 1, 1, 0, 1, 0, 0, // v0-v5-v6-v1 top |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
205 1, 1, 0, 1, 0, 0, 1, 0, // v1-v6-v7-v2 left |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
206 0, 0, 1, 0, 1, 1, 0, 1, // v7-v4-v3-v2 bottom |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
207 0, 0, 1, 0, 1, 1, 0, 1 ] // v4-v7-v6-v5 back |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
208 ); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
209 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
210 // index array |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
211 var indices = new Uint8Array( |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
212 [ 0, 1, 2, 0, 2, 3, // front |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
213 4, 5, 6, 4, 6, 7, // right |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
214 8, 9,10, 8,10,11, // top |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
215 12,13,14, 12,14,15, // left |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
216 16,17,18, 16,18,19, // bottom |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
217 20,21,22, 20,22,23 ] // back |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
218 ); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
219 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
220 var retval = { }; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
221 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
222 retval.normalObject = ctx.createBuffer(); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
223 ctx.bindBuffer(ctx.ARRAY_BUFFER, retval.normalObject); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
224 ctx.bufferData(ctx.ARRAY_BUFFER, normals, ctx.STATIC_DRAW); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
225 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
226 retval.texCoordObject = ctx.createBuffer(); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
227 ctx.bindBuffer(ctx.ARRAY_BUFFER, retval.texCoordObject); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
228 ctx.bufferData(ctx.ARRAY_BUFFER, texCoords, ctx.STATIC_DRAW); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
229 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
230 retval.vertexObject = ctx.createBuffer(); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
231 ctx.bindBuffer(ctx.ARRAY_BUFFER, retval.vertexObject); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
232 ctx.bufferData(ctx.ARRAY_BUFFER, vertices, ctx.STATIC_DRAW); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
233 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
234 ctx.bindBuffer(ctx.ARRAY_BUFFER, null); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
235 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
236 retval.indexObject = ctx.createBuffer(); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
237 ctx.bindBuffer(ctx.ELEMENT_ARRAY_BUFFER, retval.indexObject); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
238 ctx.bufferData(ctx.ELEMENT_ARRAY_BUFFER, indices, ctx.STATIC_DRAW); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
239 ctx.bindBuffer(ctx.ELEMENT_ARRAY_BUFFER, null); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
240 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
241 retval.numIndices = indices.length; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
242 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
243 return retval; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
244 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
245 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
246 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
247 // makeSphere |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
248 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
249 // Create a sphere with the passed number of latitude and longitude bands and the passed radius. |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
250 // Sphere has vertices, normals and texCoords. Create VBOs for each as well as the index array. |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
251 // Return an object with the following properties: |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
252 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
253 // normalObject WebGLBuffer object for normals |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
254 // texCoordObject WebGLBuffer object for texCoords |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
255 // vertexObject WebGLBuffer object for vertices |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
256 // indexObject WebGLBuffer object for indices |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
257 // numIndices The number of indices in the indexObject |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
258 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
259 function makeSphere(ctx, radius, lats, longs) |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
260 { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
261 var geometryData = [ ]; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
262 var normalData = [ ]; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
263 var texCoordData = [ ]; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
264 var indexData = [ ]; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
265 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
266 for (var latNumber = 0; latNumber <= lats; ++latNumber) { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
267 for (var longNumber = 0; longNumber <= longs; ++longNumber) { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
268 var theta = latNumber * Math.PI / lats; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
269 var phi = longNumber * 2 * Math.PI / longs; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
270 var sinTheta = Math.sin(theta); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
271 var sinPhi = Math.sin(phi); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
272 var cosTheta = Math.cos(theta); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
273 var cosPhi = Math.cos(phi); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
274 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
275 var x = cosPhi * sinTheta; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
276 var y = cosTheta; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
277 var z = sinPhi * sinTheta; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
278 var u = 1-(longNumber/longs); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
279 var v = latNumber/lats; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
280 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
281 normalData.push(x); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
282 normalData.push(y); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
283 normalData.push(z); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
284 texCoordData.push(u); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
285 texCoordData.push(v); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
286 geometryData.push(radius * x); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
287 geometryData.push(radius * y); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
288 geometryData.push(radius * z); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
289 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
290 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
291 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
292 for (var latNumber = 0; latNumber < lats; ++latNumber) { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
293 for (var longNumber = 0; longNumber < longs; ++longNumber) { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
294 var first = (latNumber * (longs+1)) + longNumber; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
295 var second = first + longs + 1; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
296 indexData.push(first); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
297 indexData.push(second); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
298 indexData.push(first+1); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
299 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
300 indexData.push(second); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
301 indexData.push(second+1); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
302 indexData.push(first+1); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
303 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
304 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
305 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
306 var retval = { }; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
307 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
308 retval.normalObject = ctx.createBuffer(); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
309 ctx.bindBuffer(ctx.ARRAY_BUFFER, retval.normalObject); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
310 ctx.bufferData(ctx.ARRAY_BUFFER, new Float32Array(normalData), ctx.STATIC_DRAW); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
311 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
312 retval.texCoordObject = ctx.createBuffer(); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
313 ctx.bindBuffer(ctx.ARRAY_BUFFER, retval.texCoordObject); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
314 ctx.bufferData(ctx.ARRAY_BUFFER, new Float32Array(texCoordData), ctx.STATIC_DRAW); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
315 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
316 retval.vertexObject = ctx.createBuffer(); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
317 ctx.bindBuffer(ctx.ARRAY_BUFFER, retval.vertexObject); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
318 ctx.bufferData(ctx.ARRAY_BUFFER, new Float32Array(geometryData), ctx.STATIC_DRAW); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
319 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
320 retval.numIndices = indexData.length; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
321 retval.indexObject = ctx.createBuffer(); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
322 ctx.bindBuffer(ctx.ELEMENT_ARRAY_BUFFER, retval.indexObject); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
323 ctx.bufferData(ctx.ELEMENT_ARRAY_BUFFER, new Uint16Array(indexData), ctx.STREAM_DRAW); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
324 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
325 return retval; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
326 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
327 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
328 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
329 // loadObj |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
330 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
331 // Load a .obj file from the passed URL. Return an object with a 'loaded' property set to false. |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
332 // When the object load is complete, the 'loaded' property becomes true and the following |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
333 // properties are set: |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
334 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
335 // normalObject WebGLBuffer object for normals |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
336 // texCoordObject WebGLBuffer object for texCoords |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
337 // vertexObject WebGLBuffer object for vertices |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
338 // indexObject WebGLBuffer object for indices |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
339 // numIndices The number of indices in the indexObject |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
340 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
341 function loadObj(ctx, url) |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
342 { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
343 var obj = { loaded : false }; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
344 obj.ctx = ctx; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
345 var req = new XMLHttpRequest(); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
346 req.obj = obj; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
347 req.onreadystatechange = function () { processLoadObj(req) }; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
348 req.open("GET", url, true); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
349 req.send(null); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
350 return obj; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
351 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
352 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
353 function processLoadObj(req) |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
354 { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
355 req.obj.ctx.console.log("req="+req) |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
356 // only if req shows "complete" |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
357 if (req.readyState == 4) { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
358 doLoadObj(req.obj, req.responseText); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
359 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
360 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
361 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
362 function doLoadObj(obj, text) |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
363 { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
364 vertexArray = [ ]; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
365 normalArray = [ ]; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
366 textureArray = [ ]; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
367 indexArray = [ ]; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
368 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
369 var vertex = [ ]; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
370 var normal = [ ]; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
371 var texture = [ ]; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
372 var facemap = { }; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
373 var index = 0; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
374 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
375 // This is a map which associates a range of indices with a name |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
376 // The name comes from the 'g' tag (of the form "g NAME"). Indices |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
377 // are part of one group until another 'g' tag is seen. If any indices |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
378 // come before a 'g' tag, it is given the group name "_unnamed" |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
379 // 'group' is an object whose property names are the group name and |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
380 // whose value is a 2 element array with [<first index>, <num indices>] |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
381 var groups = { }; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
382 var currentGroup = [-1, 0]; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
383 groups["_unnamed"] = currentGroup; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
384 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
385 var lines = text.split("\n"); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
386 for (var lineIndex in lines) { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
387 var line = lines[lineIndex].replace(/[ \t]+/g, " ").replace(/\s\s*$/, ""); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
388 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
389 // ignore comments |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
390 if (line[0] == "#") |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
391 continue; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
392 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
393 var array = line.split(" "); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
394 if (array[0] == "g") { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
395 // new group |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
396 currentGroup = [indexArray.length, 0]; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
397 groups[array[1]] = currentGroup; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
398 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
399 else if (array[0] == "v") { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
400 // vertex |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
401 vertex.push(parseFloat(array[1])); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
402 vertex.push(parseFloat(array[2])); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
403 vertex.push(parseFloat(array[3])); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
404 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
405 else if (array[0] == "vt") { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
406 // normal |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
407 texture.push(parseFloat(array[1])); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
408 texture.push(parseFloat(array[2])); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
409 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
410 else if (array[0] == "vn") { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
411 // normal |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
412 normal.push(parseFloat(array[1])); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
413 normal.push(parseFloat(array[2])); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
414 normal.push(parseFloat(array[3])); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
415 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
416 else if (array[0] == "f") { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
417 // face |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
418 if (array.length != 4) { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
419 obj.ctx.console.log("*** Error: face '"+line+"' not handled"); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
420 continue; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
421 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
422 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
423 for (var i = 1; i < 4; ++i) { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
424 if (!(array[i] in facemap)) { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
425 // add a new entry to the map and arrays |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
426 var f = array[i].split("/"); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
427 var vtx, nor, tex; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
428 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
429 if (f.length == 1) { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
430 vtx = parseInt(f[0]) - 1; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
431 nor = vtx; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
432 tex = vtx; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
433 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
434 else if (f.length = 3) { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
435 vtx = parseInt(f[0]) - 1; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
436 tex = parseInt(f[1]) - 1; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
437 nor = parseInt(f[2]) - 1; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
438 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
439 else { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
440 obj.ctx.console.log("*** Error: did not understand face '"+array[i]+"'"); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
441 return null; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
442 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
443 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
444 // do the vertices |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
445 var x = 0; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
446 var y = 0; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
447 var z = 0; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
448 if (vtx * 3 + 2 < vertex.length) { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
449 x = vertex[vtx*3]; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
450 y = vertex[vtx*3+1]; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
451 z = vertex[vtx*3+2]; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
452 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
453 vertexArray.push(x); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
454 vertexArray.push(y); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
455 vertexArray.push(z); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
456 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
457 // do the textures |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
458 x = 0; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
459 y = 0; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
460 if (tex * 2 + 1 < texture.length) { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
461 x = texture[tex*2]; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
462 y = texture[tex*2+1]; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
463 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
464 textureArray.push(x); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
465 textureArray.push(y); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
466 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
467 // do the normals |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
468 x = 0; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
469 y = 0; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
470 z = 1; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
471 if (nor * 3 + 2 < normal.length) { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
472 x = normal[nor*3]; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
473 y = normal[nor*3+1]; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
474 z = normal[nor*3+2]; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
475 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
476 normalArray.push(x); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
477 normalArray.push(y); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
478 normalArray.push(z); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
479 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
480 facemap[array[i]] = index++; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
481 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
482 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
483 indexArray.push(facemap[array[i]]); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
484 currentGroup[1]++; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
485 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
486 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
487 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
488 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
489 // set the VBOs |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
490 obj.normalObject = obj.ctx.createBuffer(); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
491 obj.ctx.bindBuffer(obj.ctx.ARRAY_BUFFER, obj.normalObject); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
492 obj.ctx.bufferData(obj.ctx.ARRAY_BUFFER, new Float32Array(normalArray), obj.ctx.STATIC_DRAW); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
493 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
494 obj.texCoordObject = obj.ctx.createBuffer(); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
495 obj.ctx.bindBuffer(obj.ctx.ARRAY_BUFFER, obj.texCoordObject); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
496 obj.ctx.bufferData(obj.ctx.ARRAY_BUFFER, new Float32Array(textureArray), obj.ctx.STATIC_DRAW); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
497 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
498 obj.vertexObject = obj.ctx.createBuffer(); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
499 obj.ctx.bindBuffer(obj.ctx.ARRAY_BUFFER, obj.vertexObject); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
500 obj.ctx.bufferData(obj.ctx.ARRAY_BUFFER, new Float32Array(vertexArray), obj.ctx.STATIC_DRAW); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
501 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
502 obj.numIndices = indexArray.length; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
503 obj.indexObject = obj.ctx.createBuffer(); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
504 obj.ctx.bindBuffer(obj.ctx.ELEMENT_ARRAY_BUFFER, obj.indexObject); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
505 obj.ctx.bufferData(obj.ctx.ELEMENT_ARRAY_BUFFER, new Uint16Array(indexArray), obj.ctx.STREAM_DRAW); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
506 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
507 obj.groups = groups; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
508 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
509 obj.loaded = true; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
510 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
511 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
512 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
513 // loadImageTexture |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
514 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
515 // Load the image at the passed url, place it in a new WebGLTexture object and return the WebGLTexture. |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
516 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
517 function loadImageTexture(ctx, url) |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
518 { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
519 var texture = ctx.createTexture(); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
520 texture.image = new Image(); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
521 texture.image.onload = function() { doLoadImageTexture(ctx, texture.image, texture) } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
522 texture.image.src = url; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
523 return texture; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
524 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
525 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
526 function doLoadImageTexture(ctx, image, texture) |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
527 { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
528 ctx.bindTexture(ctx.TEXTURE_2D, texture); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
529 ctx.texImage2D( |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
530 ctx.TEXTURE_2D, 0, ctx.RGBA, ctx.RGBA, ctx.UNSIGNED_BYTE, image); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
531 ctx.texParameteri(ctx.TEXTURE_2D, ctx.TEXTURE_MAG_FILTER, ctx.LINEAR); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
532 ctx.texParameteri(ctx.TEXTURE_2D, ctx.TEXTURE_MIN_FILTER, ctx.LINEAR); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
533 ctx.texParameteri(ctx.TEXTURE_2D, ctx.TEXTURE_WRAP_S, ctx.CLAMP_TO_EDGE); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
534 ctx.texParameteri(ctx.TEXTURE_2D, ctx.TEXTURE_WRAP_T, ctx.CLAMP_TO_EDGE); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
535 //ctx.generateMipmap(ctx.TEXTURE_2D) |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
536 ctx.bindTexture(ctx.TEXTURE_2D, null); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
537 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
538 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
539 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
540 // Framerate object |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
541 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
542 // This object keeps track of framerate and displays it as the innerHTML text of the |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
543 // HTML element with the passed id. Once created you call snapshot at the end |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
544 // of every rendering cycle. Every 500ms the framerate is updated in the HTML element. |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
545 // |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
546 Framerate = function(id) |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
547 { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
548 this.numFramerates = 10; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
549 this.framerateUpdateInterval = 500; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
550 this.id = id; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
551 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
552 this.renderTime = -1; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
553 this.framerates = [ ]; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
554 self = this; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
555 var fr = function() { self.updateFramerate() } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
556 setInterval(fr, this.framerateUpdateInterval); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
557 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
558 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
559 Framerate.prototype.updateFramerate = function() |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
560 { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
561 var tot = 0; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
562 for (var i = 0; i < this.framerates.length; ++i) |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
563 tot += this.framerates[i]; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
564 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
565 var framerate = tot / this.framerates.length; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
566 framerate = Math.round(framerate); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
567 document.getElementById(this.id).innerHTML = "Framerate:"+framerate+"fps"; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
568 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
569 |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
570 Framerate.prototype.snapshot = function() |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
571 { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
572 if (this.renderTime < 0) |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
573 this.renderTime = new Date().getTime(); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
574 else { |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
575 var newTime = new Date().getTime(); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
576 var t = newTime - this.renderTime; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
577 var framerate = 1000/t; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
578 this.framerates.push(framerate); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
579 while (this.framerates.length > this.numFramerates) |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
580 this.framerates.shift(); |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
581 this.renderTime = newTime; |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
582 } |
9285dae61395
1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
583 } |