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 verifyWorldDescription(description
) {
6 var shapes
= description
['shapes'];
7 var bodies
= description
['bodies'];
8 //var constraints = description['constraints'];
12 for (i
= 0; i
< shapes
.length
; i
++) {
13 r
= verifyShapeDescription(shapes
[i
]);
19 for (i
= 0; i
< bodies
.length
; i
++) {
20 r
= verifyBodyDescription(bodies
[i
], shapes
);
29 function verifyShapeExists(name
, shapes
) {
31 for (i
= 0; i
< shapes
.length
; i
++) {
32 if (shapes
[i
].name
== name
) {
39 function verifyBodyDescription(body
, shapes
) {
40 var shapeName
= body
['shape'];
41 var mass
= body
['mass'];
42 var friction
= body
['friction'];
43 var transform
= body
['transform'];
44 if (shapeName
== undefined) {
45 console
.log('Body needs a shapename.');
48 if (mass
== undefined) {
49 console
.log('Body needs a mass.');
52 if (friction
== undefined) {
53 console
.log('Body needs a friction.');
56 if (transform
== undefined) {
57 console
.log('Body needs a transform.');
60 if (transform
[0] == undefined) {
61 console
.log('Body needs a transform array.');
64 return verifyShapeExists(shapeName
, shapes
);
67 function verifyShapeDescription(shape
) {
68 if (shape
['name'] == undefined) {
69 console
.log('Shape needs a name.');
73 var type
= shape
['type'];
79 console
.log('Shape type - ' + type
+ ' not supported.');
84 return verifyCubeDescription(shape
);
87 if (type
== "sphere") {
88 return verifySphereDescription(shape
);
91 if (type
== "cylinder") {
92 return verifyCylinderDescription(shape
);
95 if (type
== "convex") {
96 return verifyConvexDescription(shape
);
102 function verifyCubeDescription(shape
) {
103 if (shape
['wx'] == undefined) {
106 if (shape
['wy'] == undefined) {
109 if (shape
['wz'] == undefined) {
115 function verifySphereDescription(shape
) {
116 if (shape
['radius'] == undefined) {
122 function verifyCylinderDescription(shape
) {
123 if (shape
['radius'] == undefined) {
126 if (shape
['height'] == undefined) {
132 function verifyConvexDescription(shape
) {
133 if (shape
['points'] == undefined) {
136 if (shape
['points'][0] == undefined) {