Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(403)

Side by Side Diff: multiple-lights.html

Issue 3358020: o3djs: Multiple simple lights, and a new demo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/o3d/samples/
Patch Set: added var declarations Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | o3d-webgl-samples/multiple-lights.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!--
2 Copyright 2010, Google Inc.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above
12 copyright notice, this list of conditions and the following disclaimer
13 in the documentation and/or other materials provided with the
14 distribution.
15 * Neither the name of Google Inc. nor the names of its
16 contributors may be used to endorse or promote products derived from
17 this software without specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 -->
31
32 <!--
33 O3D Multiple Lights example.
34
35 Shows a simple cube with one light on each corner.
36 -->
37 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
38 "http://www.w3.org/TR/html4/loose.dtd">
39 <html>
40 <head>
41 <meta http-equiv="content-type" content="text/html; charset=UTF-8">
42 <title>
43 Multiple Lights
44 </title>
45 <!-- Include sample javascript library functions-->
46 <script type="text/javascript" src="../o3djs/base.js"></script>
47
48 <!-- Our javascript code -->
49 <script type="text/javascript" id="o3dscript">
50
51 //o3djs.base.o3d = o3d;
52
53 o3djs.require('o3djs.util');
54 o3djs.require('o3djs.math');
55 o3djs.require('o3djs.rendergraph');
56 o3djs.require('o3djs.material');
57 o3djs.require('o3djs.primitives');
58
59 // Events
60 // init() once the page has finished loading.
61 // unload() when the page is unloaded.
62 window.onload = init;
63 window.onunload = unload;
64
65 // global variables
66 var g_o3d;
67 var g_math;
68 var g_client;
69 var g_viewInfo;
70 var g_pack;
71 var g_transform = null;
72 var g_finished = false; // for selenium testing.
73 var g_clock = 0;
74 var g_timeMult = 1;
75
76 /**
77 * Creates the client area.
78 */
79 function init() {
80 o3djs.util.makeClients(initStep2);
81 }
82
83 /**
84 * Initializes O3D and creates one shape.
85 * @param {Array} clientElements Array of o3d object elements.
86 */
87 function initStep2(clientElements) {
88 // Initializes global variables and libraries.
89 var o3dElement = clientElements[0];
90 g_o3d = o3dElement.o3d;
91 g_math = o3djs.math;
92 g_client = o3dElement.client;
93
94 // Creates a pack to manage our resources/assets
95 g_pack = g_client.createPack();
96
97 // Create the render graph for a view.
98 g_viewInfo = o3djs.rendergraph.createBasicView(
99 g_pack,
100 g_client.root,
101 g_client.renderGraphRoot);
102
103 // Set our projection matrix, with a vertical field of view of 45 degrees
104 // a near clipping plane of 0.1 and far clipping plane of 10000.
105 g_viewInfo.drawContext.projection = g_math.matrix4.perspective(
106 g_math.degToRad(45),
107 g_client.width / g_client.height,
108 0.1,
109 10000);
110
111 // Create a material.
112 var material = g_pack.createObject('Material');
113 material.drawList = g_viewInfo.performanceDrawList;
114
115 material.createParam('diffuse', 'ParamFloat4').value = [.5, .5, .5, 1];
116
117 // Create some suitable defaults for the material to save the user having
118 // to know all this stuff right off the bat.
119 material.createParam('emissive', 'ParamFloat4').value = [0, 0, 0, 1];
120 material.createParam('ambient', 'ParamFloat4').value = [0, 0, 0, 0];
121 material.createParam('specular', 'ParamFloat4').value = [1, 1, 1, 1];
122 material.createParam('shininess', 'ParamFloat').value = 10;
123 material.createParam('specularFactor', 'ParamFloat').value = 1;
124 o3djs.material.attachStandardEffect(
125 g_pack,
126 material,
127 g_viewInfo,
128 'blinn',
129 {lights: 8});
130 var materialColorParamList = material.getParam('lightColorList');
131 var colorParamList = g_pack.createObject('ParamArray');
132 var materialLightPositionList = material.getParam('lightWorldPosList');
133 var lightPositionParamList = g_pack.createObject('ParamArray');
134 // Create a cylinder.
135 var shape = o3djs.primitives.createCube(
136 g_pack,
137 material,
138 150);
139
140 g_transform = g_pack.createObject('Transform');
141 // Add the cylinder to the root transform.
142 g_transform.addShape(shape);
143 g_transform.parent = g_client.root;
144
145 var colors = [
146 [0, 0, 0, 1], // null light
147 [1, 0, 0, 1],
148 [0, 0, 1, 1],
149 [0, 1, 0, 1],
150 [1, 1, 1, 1],
151 [0, 1, 1, 1],
152 [1, 1, 0, 1],
153 [1, 0, 1, 1]];
154 var lightDist = 150;
155 for (var i = 0; i < 8; i++) {
156 colorParamList.createParam(i,'ParamFloat4').value = colors[i];
157 var position = [
158 (i&1)?lightDist:-lightDist,
159 (i&2)?lightDist:-lightDist,
160 (i&4)?lightDist:-lightDist
161 ];
162 lightPositionParamList.createParam(i,'ParamFloat3').value = position;
163 }
164 materialLightPositionList.value = lightPositionParamList;
165 materialColorParamList.value = colorParamList;
166 // Setup an onrender callback for animation.
167 g_client.setRenderCallback(onrender);
168
169 g_finished = true; // for selenium testing.
170 }
171
172 /**
173 * Called every frame.
174 * @param {!o3d.RenderEvent} renderEvent Info for rendering.
175 */
176 function onrender(renderEvent) {
177 // Get the number of seconds since the last render.
178 var elapsedTime = renderEvent.elapsedTime;
179 g_clock += elapsedTime * g_timeMult;
180
181 var x = Math.sin(g_clock * 0.3) * 400;
182 var z = Math.cos(g_clock * 0.3) * 400;
183 var y = Math.sin(g_clock * 0.7) * 200 + 100;
184
185 // spin the camera.
186 g_viewInfo.drawContext.view = g_math.matrix4.lookAt(
187 [x, y, z], // eye
188 [0, 0, 0], // target
189 [0, 1, 0]); // up
190 }
191
192 /**
193 * Removes any callbacks so they don't get called after the page has unloaded.
194 */
195 function unload() {
196 if (g_client) {
197 g_client.cleanup();
198 }
199 }
200 </script>
201 </head>
202 <body>
203 <h1>Multiple Lights</h1>
204 <!-- Start of O3D plugin -->
205 <div id="o3d" style="width: 600px; height: 400px;"></div>
206 <!-- End of O3D plugin -->
207 </body>
208 </html>
OLDNEW
« no previous file with comments | « no previous file | o3d-webgl-samples/multiple-lights.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698