mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 14:03:17 +02:00
Add block building toolset, first version
This commit is contained in:
parent
bf0cde060c
commit
005cd2ba53
1 changed files with 114 additions and 0 deletions
114
examples/blocks.js
Normal file
114
examples/blocks.js
Normal file
|
@ -0,0 +1,114 @@
|
|||
//
|
||||
// Blocks.js
|
||||
//
|
||||
// Created by Philip Rosedale on January 26, 2015
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Create a bunch of building blocks and drop them onto a playing surface in front of you.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
var FLOOR_SIZE = 5.0;
|
||||
var FLOOR_THICKNESS = 0.10;
|
||||
var EDGE_THICKESS = 0.25;
|
||||
var SCALE = 0.25;
|
||||
|
||||
var GRAVITY = -1.0;
|
||||
var LIFETIME = 6000;
|
||||
var DAMPING = 0.50;
|
||||
|
||||
var blockTypes = [];
|
||||
blockTypes.push({ x: 1, y: 1, z: 1, red: 255, green: 0, blue: 0 });
|
||||
blockTypes.push({ x: 1, y: 1, z: 2, red: 0, green: 255, blue: 0 });
|
||||
blockTypes.push({ x: 1, y: 2, z: 5, red: 0, green: 0, blue: 255 });
|
||||
blockTypes.push({ x: 1, y: 2, z: 2, red: 255, green: 255, blue: 0 });
|
||||
|
||||
|
||||
var center = Vec3.sum(MyAvatar.position, Vec3.multiply(FLOOR_SIZE * 2.0, Quat.getFront(Camera.getOrientation())));
|
||||
|
||||
var floor = Entities.addEntity(
|
||||
{ type: "Box",
|
||||
position: Vec3.subtract(center, { x: 0, y: SCALE / 2.0, z: 0 }),
|
||||
dimensions: { x: FLOOR_SIZE, y: FLOOR_THICKNESS, z: FLOOR_SIZE },
|
||||
color: { red: 128, green: 128, blue: 128 },
|
||||
gravity: { x: 0, y: 0, z: 0 },
|
||||
ignoreCollisions: false,
|
||||
locked: true,
|
||||
lifetime: LIFETIME });
|
||||
|
||||
var edge1 = Entities.addEntity(
|
||||
{ type: "Box",
|
||||
position: Vec3.sum(center, { x: FLOOR_SIZE / 2.0, y: FLOOR_THICKNESS / 2.0, z: 0 }),
|
||||
dimensions: { x: EDGE_THICKESS, y: EDGE_THICKESS, z: FLOOR_SIZE },
|
||||
color: { red: 128, green: 128, blue: 128 },
|
||||
gravity: { x: 0, y: 0, z: 0 },
|
||||
ignoreCollisions: false,
|
||||
visible: true,
|
||||
lifetime: LIFETIME });
|
||||
|
||||
var edge2 = Entities.addEntity(
|
||||
{ type: "Box",
|
||||
position: Vec3.sum(center, { x: -FLOOR_SIZE / 2.0, y: FLOOR_THICKNESS / 2.0, z: 0 }),
|
||||
dimensions: { x: EDGE_THICKESS, y: EDGE_THICKESS, z: FLOOR_SIZE },
|
||||
color: { red: 128, green: 128, blue: 128 },
|
||||
gravity: { x: 0, y: 0, z: 0 },
|
||||
ignoreCollisions: false,
|
||||
visible: true,
|
||||
lifetime: LIFETIME });
|
||||
|
||||
var edge3 = Entities.addEntity(
|
||||
{ type: "Box",
|
||||
position: Vec3.sum(center, { x: 0, y: FLOOR_THICKNESS / 2.0, z: -FLOOR_SIZE / 2.0 }),
|
||||
dimensions: { x: FLOOR_SIZE, y: EDGE_THICKESS, z: EDGE_THICKESS },
|
||||
color: { red: 128, green: 128, blue: 128 },
|
||||
gravity: { x: 0, y: 0, z: 0 },
|
||||
ignoreCollisions: false,
|
||||
visible: true,
|
||||
lifetime: LIFETIME });
|
||||
|
||||
var edge4 = Entities.addEntity(
|
||||
{ type: "Box",
|
||||
position: Vec3.sum(center, { x: 0, y: FLOOR_THICKNESS / 2.0, z: FLOOR_SIZE / 2.0 }),
|
||||
dimensions: { x: FLOOR_SIZE, y: EDGE_THICKESS, z: EDGE_THICKESS },
|
||||
color: { red: 128, green: 128, blue: 128 },
|
||||
gravity: { x: 0, y: 0, z: 0 },
|
||||
ignoreCollisions: false,
|
||||
visible: true,
|
||||
lifetime: LIFETIME });
|
||||
|
||||
var NUM_BLOCKS = 20;
|
||||
var DROP_HEIGHT = FLOOR_SIZE / 3;
|
||||
|
||||
blocks = [];
|
||||
|
||||
for (var i = 0; i < NUM_BLOCKS; i++) {
|
||||
var which = Math.floor(Math.random() * blockTypes.length);
|
||||
var type = blockTypes[which];
|
||||
blocks.push(Entities.addEntity(
|
||||
{ type: "Box",
|
||||
position: { x: center.x + (Math.random() - 0.5) * (FLOOR_SIZE * 0.75),
|
||||
y: center.y + DROP_HEIGHT,
|
||||
z: center.z + (Math.random() - 0.5) * (FLOOR_SIZE * 0.75) },
|
||||
dimensions: { x: type.x * SCALE, y: type.y * SCALE, z: type.z * SCALE },
|
||||
color: { red: type.red, green: type.green, blue: type.blue },
|
||||
gravity: { x: 0, y: GRAVITY, z: 0 },
|
||||
ignoreCollisions: false,
|
||||
damping: DAMPING,
|
||||
lifetime: LIFETIME,
|
||||
collisionsWillMove: true }));
|
||||
}
|
||||
|
||||
function scriptEnding() {
|
||||
Entities.deleteEntity(edge1);
|
||||
Entities.deleteEntity(edge2);
|
||||
Entities.deleteEntity(edge3);
|
||||
Entities.deleteEntity(edge4);
|
||||
Entities.deleteEntity(floor);
|
||||
|
||||
for (var i = 0; i < NUM_BLOCKS; i++) {
|
||||
Entities.deleteEntity(blocks[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Script.scriptEnding.connect(scriptEnding);
|
Loading…
Reference in a new issue