From 3ee111d7572ebaf3786e79bbf58bc8dde25c628b Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Fri, 1 May 2015 09:56:21 -0700 Subject: [PATCH] added script to generate a lot of physical blocks within a specified range --- examples/lotsoBlocks.js | 63 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 examples/lotsoBlocks.js diff --git a/examples/lotsoBlocks.js b/examples/lotsoBlocks.js new file mode 100644 index 0000000000..63ed774d2d --- /dev/null +++ b/examples/lotsoBlocks.js @@ -0,0 +1,63 @@ +var NUM_BLOCKS = 200; +var size; +var SPAWN_RANGE = 10; +var boxes = []; +var basePosition, avatarRot; +var isAssignmentScript = false; +if(isAssignmentScript){ + basePosition = {x: 8000, y: 8000, z: 8000}; +} +else { + avatarRot = Quat.fromPitchYawRollDegrees(0, MyAvatar.bodyYaw, 0.0); + basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(SPAWN_RANGE * 3, Quat.getFront(avatarRot))); +} +basePosition.y -= SPAWN_RANGE; + +var ground = Entities.addEntity({ + type: "Model", + modelURL: "https://hifi-public.s3.amazonaws.com/eric/models/woodFloor.fbx", + dimensions: { + x: 100, + y: 2, + z: 100 + }, + position: basePosition, + shapeType: 'box' +}); + + +basePosition.y += SPAWN_RANGE + 2; +for (var i = 0; i < NUM_BLOCKS; i++) { + size = randFloat(-.2, 0.7); + boxes.push(Entities.addEntity({ + type: 'Box', + dimensions: { + x: size, + y: size, + z: size + }, + position: { + x: basePosition.x + randFloat(-SPAWN_RANGE, SPAWN_RANGE), + y: basePosition.y - randFloat(-SPAWN_RANGE, SPAWN_RANGE), + z: basePosition.z + randFloat(-SPAWN_RANGE, SPAWN_RANGE) + }, + color: {red: Math.random() * 255, green: Math.random() * 255, blue: Math.random() * 255}, + collisionsWillMove: true, + gravity: {x: 0, y: 0, z: 0} + })); +} + + + +function cleanup() { + Entities.deleteEntity(ground); + boxes.forEach(function(box){ + Entities.deleteEntity(box); + }); +} + +Script.scriptEnding.connect(cleanup); + +function randFloat(low, high) { + return low + Math.random() * ( high - low ); +} \ No newline at end of file