From b127b6a9e887874b0cfa253c9dcb447a2e91f7d4 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 17 Dec 2015 08:55:57 -0800 Subject: [PATCH] separating out rave stick --- examples/flowArts/flowArtsHutSpawner.js | 5 + examples/flowArts/lightSaber/LightSaber.js | 38 ++++++ .../lightSaber/lightSaberEntityScript.js | 121 ++++++++++++++++++ 3 files changed, 164 insertions(+) create mode 100644 examples/flowArts/lightSaber/LightSaber.js create mode 100644 examples/flowArts/lightSaber/lightSaberEntityScript.js diff --git a/examples/flowArts/flowArtsHutSpawner.js b/examples/flowArts/flowArtsHutSpawner.js index b9d89859df..920fcc90ea 100644 --- a/examples/flowArts/flowArtsHutSpawner.js +++ b/examples/flowArts/flowArtsHutSpawner.js @@ -16,6 +16,9 @@ Script.include("../../libraries/utils.js"); Script.include("lightBall/LightBall.js"); Script.include("raveStick/RaveStick.js"); +Script.include("lightSaber/LightSaber.js"); + + var basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(1, Quat.getFront(Camera.getOrientation()))); basePosition.y = MyAvatar.position.y + 1; @@ -24,6 +27,7 @@ basePosition.y = MyAvatar.position.y + 1; var lightBall = new LightBall(basePosition); var raveStick = new RaveStick(Vec3.sum(basePosition, {x: 1, y: 0.5, z: 1})); var raveStick2 = new RaveStick(Vec3.sum(basePosition, {x: 2, y: 0.5, z: 1})); +var lightSaber = new LightSaber(Vec3.sum(basePosition, {x: 3, y: 0.5, z: 1})); var modelURL = "file:///C:/Users/Eric/Desktop/RaveRoom.fbx?v1" + Math.random(); @@ -75,6 +79,7 @@ function cleanup() { lightBall.cleanup(); raveStick.cleanup(); raveStick2.cleanup(); + lightSaber.cleanup(); } Script.scriptEnding.connect(cleanup); \ No newline at end of file diff --git a/examples/flowArts/lightSaber/LightSaber.js b/examples/flowArts/lightSaber/LightSaber.js new file mode 100644 index 0000000000..12ac3f3b60 --- /dev/null +++ b/examples/flowArts/lightSaber/LightSaber.js @@ -0,0 +1,38 @@ +Script.include("../../libraries/utils.js"); +var modelURL = "file:///C:/Users/Eric/Desktop/lightSaber.fbx?v1" + Math.random(); +var scriptURL = Script.resolvePath("lightSaberEntityScript.js"); +LightSaber = function(spawnPosition) { + + var stick = Entities.addEntity({ + type: "Model", + modelURL: modelURL, + position: spawnPosition, + shapeType: 'box', + script: scriptURL, + dimensions: { + x: 0.06, + y: 0.06, + z: 0.31 + }, + userData: JSON.stringify({ + grabbableKey: { + spatialKey: { + relativePosition: { + x: 0, + y: 0, + z: -0.1 + }, + relativeRotation: Quat.fromPitchYawRollDegrees(90, 90, 0) + }, + invertSolidWhileHeld: true + } + }) + }); + + + function cleanup() { + Entities.deleteEntity(stick); + } + + this.cleanup = cleanup; +} \ No newline at end of file diff --git a/examples/flowArts/lightSaber/lightSaberEntityScript.js b/examples/flowArts/lightSaber/lightSaberEntityScript.js new file mode 100644 index 0000000000..5ff3c65afd --- /dev/null +++ b/examples/flowArts/lightSaber/lightSaberEntityScript.js @@ -0,0 +1,121 @@ +// lightSaberEntityScript.js +// +// Script Type: Entity +// Created by Eric Levin on 12/16/15. +// Copyright 2015 High Fidelity, Inc. +// +// This entity script creates a lightsaber. +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +(function() { + Script.include("../../libraries/utils.js"); + var _this; + // this is the "constructor" for the entity as a JS object we don't do much here + var LightSaber = function() { + _this = this; + this.colorPalette = [{ + red: 0, + green: 200, + blue: 40 + }, { + red: 200, + green: 10, + blue: 40 + }]; + }; + + LightSaber.prototype = { + isGrabbed: false, + + startNearGrab: function() { + // this.createBeam(); + this.createBeam(); + }, + + continueNearGrab: function() { + + }, + + releaseGrab: function() { + + }, + + preload: function(entityID) { + this.entityID = entityID; + }, + + unload: function() { + Entities.deleteEntity(this.beam); + // Entities.deleteEntity(this.beamTrail); + }, + + createBeam: function() { + + var props = Entities.getEntityProperties(this.entityID, ["position", "rotation"]); + var forwardVec = Quat.getFront(Quat.multiply(props.rotation, Quat.fromPitchYawRollDegrees(-90, 0, 0))); + forwardVec = Vec3.normalize(forwardVec); + var forwardQuat = orientationOf(forwardVec); + var position = Vec3.sum(props.position, Vec3.multiply(Quat.getFront(props.rotation), 0.1)); + position.z += 0.1; + position.x += -0.035; + var color = this.colorPalette[randInt(0, this.colorPalette.length)]; + var props = { + type: "ParticleEffect", + position: position, + parentID: this.entityID, + isEmitting: true, + "name": "ParticlesTest Emitter", + "colorStart": color, + color: { + red: 200, + green: 200, + blue: 255 + }, + "colorFinish": color, + "maxParticles": 100000, + "lifespan": 2, + "emitRate": 1000, + emitOrientation: forwardQuat, + "emitSpeed": .4, + "speedSpread": 0.0, + // "emitDimensions": { + // "x": .1, + // "y": .1, + // "z": .1 + // }, + "polarStart": 0, + "polarFinish": .0, + "azimuthStart": .1, + "azimuthFinish": .01, + "emitAcceleration": { + "x": 0, + "y": 0, + "z": 0 + }, + "accelerationSpread": { + "x": .00, + "y": .00, + "z": .00 + }, + "radiusStart": 0.03, + radiusFinish: 0.025, + "alpha": 0.7, + "alphaSpread": .1, + "alphaStart": 0.5, + "alphaFinish": 0.5, + // "textures": "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png", + "textures": "file:///C:/Users/Eric/Desktop/beamParticle.png?v1" + Math.random(), + emitterShouldTrail: false + } + this.beam = Entities.addEntity(props); + + // props.emitterShouldTrail = true; + // this.beamTrail = Entities.addEntity(props); + + } + }; + // entity scripts always need to return a newly constructed object of our type + return new LightSaber(); +}); \ No newline at end of file