1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 function randomCubeScene(numObjects, zwidth) {
6 var worldDescription = {};
7 worldDescription.shapes = [];
8 worldDescription.shapes.push({
15 worldDescription.bodies = [];
16 for ( var i = 0; i < numObjects; i ++ ) {
20 body.position.x = Math.random() * 30 - 15;
21 body.position.y = Math.random() * 50 + 10;
22 body.position.z = Math.random() * zwidth - (zwidth/2);
24 body.rotation.x = ( Math.random() * 360 ) * Math.PI / 180;
25 body.rotation.y = ( Math.random() * 360 ) * Math.PI / 180;
26 body.rotation.z = ( Math.random() * 360 ) * Math.PI / 180;
29 worldDescription.bodies.push(body);
31 return worldDescription;
34 function randomCylinderScene(numObjects, zwidth) {
35 var worldDescription = {};
36 worldDescription.shapes = [];
37 worldDescription.shapes.push({
43 worldDescription.bodies = [];
44 for ( var i = 0; i < numObjects; i ++ ) {
48 body.position.x = Math.random() * 30 - 15;
49 body.position.y = Math.random() * 50 + 10;
50 body.position.z = Math.random() * zwidth - (zwidth/2);
52 body.rotation.x = ( Math.random() * 360 ) * Math.PI / 180;
53 body.rotation.y = ( Math.random() * 360 ) * Math.PI / 180;
54 body.rotation.z = ( Math.random() * 360 ) * Math.PI / 180;
57 worldDescription.bodies.push(body);
59 return worldDescription;
62 function jengaScene(height) {
63 var worldDescription = {};
64 worldDescription.shapes = [];
65 worldDescription.shapes.push({
72 worldDescription.shapes.push({
79 worldDescription.bodies = [];
80 var baseHeight = 0.55;
81 for (var i = 0; i < height; i++) {
82 var y = i * 1.0 + baseHeight;
84 for (var j = 0; j < 5; j++) {
95 body.rotation.x = 0.0;
96 body.rotation.y = 0.0;
97 body.rotation.z = 0.0;
100 worldDescription.bodies.push(body);
103 for (var j = 0; j < 5; j++) {
114 body.rotation.x = 0.0;
115 body.rotation.y = 0.0;
116 body.rotation.z = 0.0;
119 worldDescription.bodies.push(body);
123 return worldDescription;
126 function randomShapeScene(numObjects) {
127 var worldDescription = {};
128 worldDescription.shapes = [];
129 worldDescription.shapes.push({
136 worldDescription.shapes.push({
142 worldDescription.shapes.push({
147 worldDescription.shapes.push({
161 worldDescription.bodies = [];
162 for (var i = 0; i < numObjects; i++) {
164 if (i % numShapes == 0) {
165 body.shape = 'stick';
166 } else if (i % numShapes == 1) {
168 } else if (i % numShapes == 2) {
169 body.shape = 'sphere';
170 } else if (i % numShapes == 3) {
174 body.position.x = Math.random() * 30 - 15;
175 body.position.y = Math.random() * 50 + 1;
176 body.position.z = Math.random() * 10 - 5;
178 body.rotation.x = ( Math.random() * 360 ) * Math.PI / 180;
179 body.rotation.y = ( Math.random() * 360 ) * Math.PI / 180;
180 body.rotation.z = ( Math.random() * 360 ) * Math.PI / 180;
183 worldDescription.bodies.push(body);
185 return worldDescription;
188 function loadJenga10() {
189 loadWorld(jengaScene(10));
192 function loadJenga20() {
193 loadWorld(jengaScene(20));
196 function loadRandomShapes() {
197 loadWorld(randomShapeScene(100));
200 function load250RandomCubes() {
201 loadWorld(randomCubeScene(250, 10));
204 function load500RandomCylinders() {
205 loadWorld(randomCylinderScene(500, 15));
208 function load1000RandomCubes() {
209 loadWorld(randomCubeScene(1000, 20));
212 function load2000RandomCubes() {
213 loadWorld(randomCubeScene(2000, 20));
216 function loadTextScene(evt) {
217 var txt = evt.target.result;
218 if (txt == undefined) {
219 alert('Could not load file.');
222 var sceneDescription;
225 sceneDescription = JSON.parse(txt);
231 loadWorld(sceneDescription);