diff --git a/examples/playa/playaSpawner.js b/examples/playa/playaSpawner.js index 61101a0e62..4982d70f2b 100644 --- a/examples/playa/playaSpawner.js +++ b/examples/playa/playaSpawner.js @@ -41,21 +41,33 @@ orientationOf = function(vector) { var ground, wall; var boxes = []; var dustSystems = []; -var ZERO_VEC = {x: 0, y: 0, z: 0}; +var ZERO_VEC = { + x: 0, + y: 0, + z: 0 +}; Script.include("../libraries/utils.js"); function spawnGround() { var groundModelURL = "https://hifi-public.s3.amazonaws.com/alan/Playa/Ground.fbx"; - var groundPosition = Vec3.sum(MyAvatar.position, {x: 0, y: -2, z: 0}); + var groundPosition = Vec3.sum(MyAvatar.position, { + x: 0, + y: -2, + z: 0 + }); ground = Entities.addEntity({ type: "Model", modelURL: groundModelURL, shapeType: "box", position: groundPosition, - dimensions: {x: 900, y: 0.82, z: 900}, + dimensions: { + x: 900, + y: 0.82, + z: 900 + }, }); - // Script.addEventHandler(ground, "collisionWithEntity", entityCollisionWithGround); + // Script.addEventHandler(ground, "collisionWithEntity", entityCollisionWithGround); } @@ -80,7 +92,7 @@ function spawnGround() { isEmitting: true, polarStart: Math.PI/2, polarFinish: Math.PI/2, - emitOrientation: orientationChange, + emitOrientation: orientationChange, radiusSpread: 0.1, radiusStart: particleRadius, radiusFinish: particleRadius + particleRadius/2, @@ -106,7 +118,11 @@ function spawnBoxes() { var numBoxes = 200; var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(Camera.getOrientation()))); for (var i = 0; i < numBoxes; i++) { - var position = Vec3.sum(center, {x: Math.random() * numBoxes, y: Math.random() * 3, z: Math.random() * numBoxes }) + var position = Vec3.sum(center, { + x: Math.random() * numBoxes, + y: Math.random() * 3, + z: Math.random() * numBoxes + }) var box = Entities.addEntity({ type: "Model", modelURL: boxModelURL, @@ -114,9 +130,21 @@ function spawnBoxes() { shapeType: "box", position: position, collisionsWillMove: true, - dimensions: {x: 1, y: 2, z: 3}, - velocity: {x: 0, y: -.01, z: 0}, - gravity: {x: 0, y: -2.5 - Math.random() * 6, z: 0} + dimensions: { + x: 1, + y: 2, + z: 3 + }, + velocity: { + x: 0, + y: -.01, + z: 0 + }, + gravity: { + x: 0, + y: -2.5 - Math.random() * 6, + z: 0 + } }); boxes.push(box); @@ -129,7 +157,7 @@ spawnBoxes(); function cleanup() { Entities.deleteEntity(ground); - boxes.forEach(function(box){ + boxes.forEach(function(box) { Entities.deleteEntity(box); }); dustSystems.forEach(function(dustEffect) { @@ -137,6 +165,4 @@ function cleanup() { }) } -Script.scriptEnding.connect(cleanup); - - +Script.scriptEnding.connect(cleanup); \ No newline at end of file diff --git a/examples/toybox/bow/arrow.js b/examples/toybox/bow/arrow.js index 7bee4ee883..2994ce15c0 100644 --- a/examples/toybox/bow/arrow.js +++ b/examples/toybox/bow/arrow.js @@ -27,21 +27,29 @@ Arrow.prototype = { stickOnCollision: false, notched: false, - burning: false, + isBurning: false, + fire: null, preload: function(entityID) { this.entityID = entityID; - }, - unload: function() { - + releaseGrab: function() { + if (this.fire !== null) { + this.fire = null; + this.isBurning = false; + Entities.deleteEntity(this.fire); + } }, continueNearGrab: function() { this.currentProperties = Entities.getEntityProperties(this.entityID, "position"); - if (this.isBurning === true) { - updateFirePosition(); + + if (this.isBurning !== true) { + this.searchForFires(); + } else { + this.updateFirePosition(); } + if (this.notched !== true) { this.searchForNotchDetectors(); } @@ -57,7 +65,7 @@ for (i = 0; i < ids.length; i++) { id = ids[i]; properties = Entities.getEntityProperties(id, 'name'); - if (properties.name == "Hifi-NotchDetector") { + if (properties.name === "Hifi-NotchDetector") { print('NEAR THE NOTCH!!!') this.notched = true; this.tellBowArrowIsNotched(this.getBowID(id)); @@ -65,30 +73,40 @@ } }, + searchForFires: function() { + print('SEARCHING FOR FIRES!') if (this.notched === true) { return }; + if (this.isBurning === true) { + return + }; var ids = Entities.findEntities(this.currentProperties.position, FIRE_DETECTOR_SEARCH_RADIUS); var i, properties; for (i = 0; i < ids.length; i++) { id = ids[i]; properties = Entities.getEntityProperties(id, 'name'); - if (properties.name == "Hifi-Arrow-Fire-Source") { - print('NEAR A FIRE SOURCE!!!') - this.burning = true; - this.fire = this.createFireParticleSystem(); + if (properties.name === "Hifi-Arrow-Fire-Source") { + print('NEAR A FIRE SOURCE!!!'); + this.isBurning = true; + this.createFireParticleSystem(); + + } } }, updateFirePosition: function() { + print('updating fire position' + this.fire) Entities.editEntity(this.fire, { position: this.currentProperties.position }) }, createFireParticleSystem: function() { + print('CREATING FIRE PARTICLE SYSTEM') + var myOrientation = Quat.fromPitchYawRollDegrees(-90, 0, 0.0); var animationSettings = JSON.stringify({ @@ -99,13 +117,13 @@ lastFrame: 10000 }); - var fire = Entities.addEntity({ + this.fire = Entities.addEntity({ type: "ParticleEffect", name: "Hifi-Arrow-Fire-Source", animationSettings: animationSettings, textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png", emitRate: 100, - position: this.bowProperties.position, + position: this.currentProperties.position, colorStart: { red: 70, green: 70, @@ -124,7 +142,7 @@ radiusSpread: 0.01, radiusStart: 0.02, radiusEnd: 0.001, - particleRadius: 0.5, + particleRadius: 0.15, radiusFinish: 0.0, emitOrientation: myOrientation, emitSpeed: 0.3, @@ -150,7 +168,6 @@ }, lifespan: 1 }); - return fire }, getBowID: function(notchDetectorID) { var properties = Entities.getEntityProperties(notchDetectorID, "userData"); @@ -192,31 +209,14 @@ arrowID: this.entityID }); + if (this.isBurning === true) { + this.isBurning = false; + this.fire = null; + Entities.deleteEntity(this.fire); + } + }, - // collisionWithEntity: function(me, otherEntity, collision) { - // print('ARROW HAD COLLISION') - // if (this.stickOnCollision === true) { - // print('ARROW SHOULD STICK') - // Vec3.print('penetration = ', collision.penetration); - // Vec3.print('collision contact point = ', collision.contactPoint); - // Entities.editEntity(this.entityID, { - // velocity: { - // x: 0, - // y: 0, - // z: 0 - // }, - // gravity: { - // x: 0, - // y: 0, - // z: 0 - // }, - // collisionsWillMove: false - - // }) - // } - - // } } function deleteEntity(entityID) { diff --git a/examples/toybox/bow/arrowFieldSpawner.js b/examples/toybox/bow/arrowFieldSpawner.js index b08789cf2b..08bb3be283 100644 --- a/examples/toybox/bow/arrowFieldSpawner.js +++ b/examples/toybox/bow/arrowFieldSpawner.js @@ -1,144 +1,106 @@ -// dustSetSpawner.js +// arrowFieldSpawner.js // examples // -// Created by Eric Levin on 9/2/15 +// Created by James B. Pollack @imgntn on 11/16/2015 // Copyright 2015 High Fidelity, Inc. // -// Spawns a set with blocks and a desert-y ground. When blocks (or anything else is thrown), dust particles will kick up at the point the object hits the ground +// Spawns ground, targets, and fire sources. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -/*global print, MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt, pointInExtents, vec3equal, setEntityCustomData, getEntityCustomData */ - - -map = function(value, min1, max1, min2, max2) { - return min2 + (max2 - min2) * ((value - min1) / (max1 - min1)); -} - -orientationOf = function(vector) { - var Y_AXIS = { - x: 0, - y: 1, - z: 0 - }; - var X_AXIS = { - x: 1, - y: 0, - z: 0 - }; - - var theta = 0.0; - - var RAD_TO_DEG = 180.0 / Math.PI; - var direction, yaw, pitch; - direction = Vec3.normalize(vector); - yaw = Quat.angleAxis(Math.atan2(direction.x, direction.z) * RAD_TO_DEG, Y_AXIS); - pitch = Quat.angleAxis(Math.asin(-direction.y) * RAD_TO_DEG, X_AXIS); - return Quat.multiply(yaw, pitch); -} - var ground, wall; var boxes = []; var dustSystems = []; -var ZERO_VEC = {x: 0, y: 0, z: 0}; +var ZERO_VEC = { + x: 0, + y: 0, + z: 0 +}; Script.include("../libraries/utils.js"); +var startPosition = { + x: 0, + y: 0, + z: 0 +} + function spawnGround() { var groundModelURL = "https://hifi-public.s3.amazonaws.com/alan/Playa/Ground.fbx"; - var groundPosition = Vec3.sum(MyAvatar.position, {x: 0, y: -2, z: 0}); + var groundPosition = Vec3.sum(startPosition, { + x: 0, + y: -2, + z: 0 + }); ground = Entities.addEntity({ type: "Model", modelURL: groundModelURL, shapeType: "box", position: groundPosition, - dimensions: {x: 900, y: 0.82, z: 900}, + dimensions: { + x: 900, + y: 0.82, + z: 900 + }, }); - // Script.addEventHandler(ground, "collisionWithEntity", entityCollisionWithGround); } -/*function entityCollisionWithGround(ground, entity, collision) { - var dVelocityMagnitude = Vec3.length(collision.velocityChange); - var position = Entities.getEntityProperties(entity, "position").position; - var particleRadius = map(dVelocityMagnitude, 0.05, 3, 0.5, 2); - var speed = map(dVelocityMagnitude, 0.05, 3, 0.02, 0.09); - var displayTime = 400; - var orientationChange = orientationOf(collision.velocityChange); - var dustEffect = Entities.addEntity({ - type: "ParticleEffect", - name: "Dust-Puff", - position: position, - color: {red: 195, green: 170, blue: 185}, - lifespan: 3, - lifetime: 7,//displayTime/1000 * 2, //So we can fade particle system out gracefully - emitRate: 5, - emitSpeed: speed, - emitAcceleration: ZERO_VEC, - accelerationSpread: ZERO_VEC, - isEmitting: true, - polarStart: Math.PI/2, - polarFinish: Math.PI/2, - emitOrientation: orientationChange, - radiusSpread: 0.1, - radiusStart: particleRadius, - radiusFinish: particleRadius + particleRadius/2, - particleRadius: particleRadius, - alpha: 0.45, - alphaFinish: 0.001, - textures: "https://hifi-public.s3.amazonaws.com/alan/Playa/Particles/Particle-Sprite-Gen.png" - }); - - dustSystems.push(dustEffect); - - Script.setTimeout(function() { - var newRadius = 0.05; - Entities.editEntity(dustEffect, { - alpha: 0.0 - }); - }, displayTime); -}*/ - function spawnBoxes() { - //why does this crash interface - var boxModelURL = "http://hifi-content.s3.amazonaws.com/james/bow_and_arrow/models/hay_bale_rectangle.fbx"; + var boxModelURL = "http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/target.fbx"; + var COLLISION_HULL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/target_collision_hull.obj'; + var TARGET_DIMENSIONS = { + x: 0.12, + y: 0.84, + z: 0.84 + }; var collisionSoundURL = "https://hifi-public.s3.amazonaws.com/sounds/Collisions-otherorganic/ToyWoodBlock.L.wav"; var numBoxes = 200; - var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(Camera.getOrientation()))); for (var i = 0; i < numBoxes; i++) { - var position = Vec3.sum(center, {x: Math.random() * numBoxes, y: Math.random() * 3, z: Math.random() * numBoxes }) + var position = Vec3.sum(startPosition, { + x: Math.random() * numBoxes, + y: Math.random() * 2, + z: Math.random() * numBoxes + }) var box = Entities.addEntity({ type: "Model", modelURL: boxModelURL, collisionSoundURL: collisionSoundURL, - shapeType: "box", + shapeType: "compound", + compoundShapeURL: COLLISION_HULL_URL, position: position, collisionsWillMove: true, - dimensions: {x: 1, y: 2, z: 3}, - velocity: {x: 0, y: -.01, z: 0}, - gravity: {x: 0, y: -2.5 - Math.random() * 6, z: 0} + dimensions: TARGET_DIMENSIONS, + }); + Script.addEventHandler(box, "collisionWithEntity", boxCollision); boxes.push(box); } } +function boxCollision(me, other, collision) { + Entities.editEntity(me, { + gravity: { + x: 0, + y: -9.8, + z: 0 + } + }) +} + spawnGround(); spawnBoxes(); function cleanup() { Entities.deleteEntity(ground); - boxes.forEach(function(box){ + boxes.forEach(function(box) { Entities.deleteEntity(box); }); - dustSystems.forEach(function(dustEffect) { - Entities.deleteEntity(dustEffect); - }) + } -Script.scriptEnding.connect(cleanup); - - +Script.scriptEnding.connect(cleanup); \ No newline at end of file diff --git a/examples/toybox/bow/bow.js b/examples/toybox/bow/bow.js index 676b6cdca7..df71885448 100644 --- a/examples/toybox/bow/bow.js +++ b/examples/toybox/bow/bow.js @@ -84,8 +84,8 @@ var SHOT_SCALE = { min1: 0, max1: 0.6, - min2: 5, - max2: 20 + min2: 3, + max2: 15 } @@ -110,6 +110,7 @@ hasArrowNotched: false, notchDetector: null, arrow: null, + arrowIsBurning:false, stringData: { currentColor: { red: 255, @@ -187,7 +188,7 @@ this.hasArrowNotched = userData.hifiBowKey.hasArrowNotched; this.arrow = userData.hifiBowKey.arrowID; - this.arrowIsBurning = userData.hifiBowKey.isBurning; + this.arrowIsBurning = userData.hifiBowKey.arrowIsBurning; setEntityCustomData('grabbableKey', this.entityID, { turnOffOtherHand: true, diff --git a/examples/toybox/bow/createFireSource.js b/examples/toybox/bow/createFireSources.js similarity index 55% rename from examples/toybox/bow/createFireSource.js rename to examples/toybox/bow/createFireSources.js index 9d974cd04e..1149626614 100644 --- a/examples/toybox/bow/createFireSource.js +++ b/examples/toybox/bow/createFireSources.js @@ -10,7 +10,35 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -function createFireSource() { +var TORCH_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/james/bow_and_arrow/models/torch.fbx'; +var TORCH_DIMENSIONS = { + x: 0.07, + y: 1.6, + z: 0.08 +}; + +var FIRE_VERTICAL_OFFSET = 0.9; + +function createFireSource(position) { + + var torchProperties = { + type: 'Model', + name: 'Hifi-Fire-Torch', + modelURL: TORCH_MODEL_URL, + shapeType: 'box', + collisionsWillMove: false, + ignoreForCollisions: true, + dimensions: TORCH_DIMENSIONS, + position: position + }; + + var torch = Entities.addEntity(torchProperties); + torches.push(torch); + var torchProperties = Entities.getEntityProperties(torch); + + var upVector = Quat.getUp(torchProperties.rotation); + var upOffset = Vec3.multiply(upVector, FIRE_VERTICAL_OFFSET); + var fireTipPosition = Vec3.sum(torchProperties.position, upOffset); var myOrientation = Quat.fromPitchYawRollDegrees(-90, 0, 0.0); @@ -28,7 +56,7 @@ function createFireSource() { animationSettings: animationSettings, textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png", emitRate: 100, - position: this.bowProperties.position, + position: fireTipPosition, colorStart: { red: 70, green: 70, @@ -74,6 +102,39 @@ function createFireSource() { lifespan: 1 }); + fires.push(fire) } -createFireSource(); +var fireSourcePositions = [{ + x: 100, + y: -1, + z: 100 + }, { + x: 100, + y: -1, + z: 102 + }, { + x: 100, + y: -1, + z: 104 + } + +]; + +var fires = []; +var torches = []; + +fireSourcePositions.forEach(function(position) { + createFireSource(position); +}) + +function cleanup() { + while (fires.length > 0) { + Entities.deleteEntity(fires.pop()); + } + while (torches.length > 0) { + Entities.deleteEntity(torches.pop()); + } +} + +Script.scriptEnding.connect(cleanup); \ No newline at end of file