From 1c5e32fcb1df0243ddd91634016c715ad1ec996d Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Tue, 21 Jan 2014 14:08:19 -0800 Subject: [PATCH] add example of new particle edit JS api --- examples/editParticleExample.js | 85 +++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 examples/editParticleExample.js diff --git a/examples/editParticleExample.js b/examples/editParticleExample.js new file mode 100644 index 0000000000..932d9ccbe2 --- /dev/null +++ b/examples/editParticleExample.js @@ -0,0 +1,85 @@ +// +// editParticleExample.js +// hifi +// +// Created by Brad Hefta-Gaub on 12/31/13. +// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. +// +// This is an example script that demonstrates creating and editing a particle +// + +var count = 0; + +var originalProperties = { + position: { x: 1/TREE_SCALE, + y: 0/TREE_SCALE, + z: 1/TREE_SCALE }, + + velocity: { x: 0, + y: 0, + z: 0 }, + + gravity: { x: 0, + y: 0, + z: 0 }, + + + radius : 0.1/TREE_SCALE, + + color: { red: 0, + green: 255, + blue: 0 } + +}; + +var positionDelta = { x: 0.5/TREE_SCALE, y: 0, z: 0 }; + + +var particleID = Particles.addParticle(originalProperties); + +function moveParticle() { + if (count >= 10) { + //Agent.stop(); + + // delete it... + if (count == 10) { + print("calling Particles.deleteParticle()"); + Particles.deleteParticle(particleID); + } + + // stop it... + if (count >= 100) { + print("calling Agent.stop()"); + Agent.stop(); + } + + count++; + return; // break early + } + + print("count =" + count); + count++; + + print("particleID.creatorTokenID = " + particleID.creatorTokenID); + + var newProperties = { + position: { + x: originalProperties.position.x + (count * positionDelta.x), + y: originalProperties.position.y + (count * positionDelta.y), + z: originalProperties.position.z + (count * positionDelta.z) + }, + radius : 0.25/TREE_SCALE, + + }; + + + //print("particleID = " + particleID); + print("newProperties.position.x = " + newProperties.position.x); + + Particles.editParticle(particleID, newProperties); +} + + +// register the call back so it fires before each data send +Agent.willSendVisualDataCallback.connect(moveParticle); +