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. 4 5 function verifyWorldDescription(description) { 6 var shapes = description['shapes']; 7 var bodies = description['bodies']; 8 //var constraints = description['constraints']; 9 10 var i; 11 var r; 12 for (i = 0; i < shapes.length; i++) { 13 r = verifyShapeDescription(shapes[i]); 14 if (r == false) { 15 return false; 16 } 17 } 18 19 for (i = 0; i < bodies.length; i++) { 20 r = verifyBodyDescription(bodies[i], shapes); 21 if (r == false) { 22 return false; 23 } 24 } 25 26 return true; 27 } 28 29 function verifyShapeExists(name, shapes) { 30 var i; 31 for (i = 0; i < shapes.length; i++) { 32 if (shapes[i].name == name) { 33 return true; 34 } 35 } 36 return false; 37 } 38 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.'); 46 return false; 47 } 48 if (mass == undefined) { 49 console.log('Body needs a mass.'); 50 return false; 51 } 52 if (friction == undefined) { 53 console.log('Body needs a friction.'); 54 return false; 55 } 56 if (transform == undefined) { 57 console.log('Body needs a transform.'); 58 return false; 59 } 60 if (transform[0] == undefined) { 61 console.log('Body needs a transform array.'); 62 return false; 63 } 64 return verifyShapeExists(shapeName, shapes); 65 } 66 67 function verifyShapeDescription(shape) { 68 if (shape['name'] == undefined) { 69 console.log('Shape needs a name.'); 70 return false; 71 } 72 73 var type = shape['type']; 74 75 if (type != "cube" && 76 type != "sphere" && 77 type != "cylinder" && 78 type != "convex") { 79 console.log('Shape type - ' + type + ' not supported.'); 80 return false; 81 } 82 83 if (type == "cube") { 84 return verifyCubeDescription(shape); 85 } 86 87 if (type == "sphere") { 88 return verifySphereDescription(shape); 89 } 90 91 if (type == "cylinder") { 92 return verifyCylinderDescription(shape); 93 } 94 95 if (type == "convex") { 96 return verifyConvexDescription(shape); 97 } 98 99 return false; 100 } 101 102 function verifyCubeDescription(shape) { 103 if (shape['wx'] == undefined) { 104 return false; 105 } 106 if (shape['wy'] == undefined) { 107 return false; 108 } 109 if (shape['wz'] == undefined) { 110 return false; 111 } 112 return true; 113 } 114 115 function verifySphereDescription(shape) { 116 if (shape['radius'] == undefined) { 117 return false; 118 } 119 return true; 120 } 121 122 function verifyCylinderDescription(shape) { 123 if (shape['radius'] == undefined) { 124 return false; 125 } 126 if (shape['height'] == undefined) { 127 return false; 128 } 129 return true; 130 } 131 132 function verifyConvexDescription(shape) { 133 if (shape['points'] == undefined) { 134 return false; 135 } 136 if (shape['points'][0] == undefined) { 137 return false; 138 } 139 return true; 140 } 141