more Particles to Entities migration

This commit is contained in:
ZappoMan 2014-10-16 20:52:38 -07:00
parent fc507850be
commit ce638dd14d
2 changed files with 38 additions and 34 deletions

View file

@ -1,5 +1,5 @@
// //
// collidingParticles.js // collidingEntities.js
// examples // examples
// //
// Created by Brad Hefta-Gaub on 12/31/13. // Created by Brad Hefta-Gaub on 12/31/13.

View file

@ -1,11 +1,11 @@
// //
// findParticleExample.js // findEntityExample.js
// examples // examples
// //
// Created by Brad Hefta-Gaub on 1/24/14. // Created by Brad Hefta-Gaub on 1/24/14.
// Copyright 2014 High Fidelity, Inc. // Copyright 2014 High Fidelity, Inc.
// //
// This is an example script that demonstrates "finding" particles // This is an example script that demonstrates "finding" entities
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
@ -13,21 +13,23 @@
var iteration = 0; var iteration = 0;
var particleA = Particles.addParticle( var entityA = Entities.addEntity(
{ {
type: "Sphere",
position: { x: 2, y: 0, z: 2 }, position: { x: 2, y: 0, z: 2 },
velocity: { x: 0, y: 0, z: 0 }, velocity: { x: 0, y: 0, z: 0 },
gravity: { x: 0, y: 0, z: 0 }, gravity: { x: 0, y: 0, z: 0 },
radius : 0.1, dimensions: { x: 0.1, y: 0.1, z: 0.1 },
color: { red: 0, green: 255, blue: 0 } color: { red: 0, green: 255, blue: 0 }
}); });
var particleB = Particles.addParticle( var entityB = Entities.addEntity(
{ {
type: "Sphere",
position: { x: 5, y: 0, z: 5 }, position: { x: 5, y: 0, z: 5 },
velocity: { x: 0, y: 0, z: 0 }, velocity: { x: 0, y: 0, z: 0 },
gravity: { x: 0, y: 0, z: 0 }, gravity: { x: 0, y: 0, z: 0 },
radius : 0.1, dimensions: { x: 0.1, y: 0.1, z: 0.1 },
color: { red: 0, green: 255, blue: 255 } color: { red: 0, green: 255, blue: 255 }
}); });
@ -36,14 +38,14 @@ var moveSearch = { x: 0.1, y: 0, z: 0.1};
var searchRadius = 1; var searchRadius = 1;
var searchRadiusChange = 0; var searchRadiusChange = 0;
print("particleA.creatorTokenID = " + particleA.creatorTokenID); print("entityA.creatorTokenID = " + entityA.creatorTokenID);
print("particleB.creatorTokenID = " + particleB.creatorTokenID); print("entityB.creatorTokenID = " + entityB.creatorTokenID);
function scriptEnding() { function scriptEnding() {
print("calling Particles.deleteParticle()"); print("calling Entities.deleteEntity()");
Particles.deleteParticle(particleA); Entities.deleteEntity(entityA);
Particles.deleteParticle(particleB); Entities.deleteEntity(entityB);
} }
function printProperties(properties) { function printProperties(properties) {
@ -63,7 +65,7 @@ function printProperties(properties) {
} }
} }
function findParticles(deltaTime) { function findEntities(deltaTime) {
// run for a while, then clean up // run for a while, then clean up
// stop it... // stop it...
@ -76,35 +78,37 @@ function findParticles(deltaTime) {
print("iteration =" + iteration); print("iteration =" + iteration);
iteration++; iteration++;
// Check to see if we've been notified of the actual identity of the particles we created // Check to see if we've been notified of the actual identity of the entities we created
if (!particleA.isKnownID) { if (!entityA.isKnownID) {
var identifyA = Particles.identifyParticle(particleA); var identifyA = Entities.identifyEntity(entityA);
if (identifyA.isKnownID) { if (identifyA.isKnownID) {
particleA = identifyA; entityA = identifyA;
print(">>>> identified particleA.id = " + particleA.id); print(">>>> identified entityA.id = " + entityA.id);
} }
} }
if (!particleB.isKnownID) { if (!entityB.isKnownID) {
var identifyB = Particles.identifyParticle(particleB); var identifyB = Entities.identifyEntity(entityB);
if (identifyB.isKnownID) { if (identifyB.isKnownID) {
particleB = identifyB; entityB = identifyB;
print(">>>> identified particleB.id = " + particleB.id); print(">>>> identified entityB.id = " + entityB.id);
} }
} }
// also check to see if we can "find" particles... // also check to see if we can "find" entities...
print("searching for particles at:" + searchAt.x + ", " + searchAt.y + ", " + searchAt.z + " radius:" + searchRadius); print("searching for entities at:" + searchAt.x + ", " + searchAt.y + ", " + searchAt.z + " radius:" + searchRadius);
var foundParticles = Particles.findParticles(searchAt, searchRadius); var foundEntities = Entities.findEntities(searchAt, searchRadius);
print("found this many particles: "+ foundParticles.length); print("found this many entities: "+ foundEntities.length);
for (var i = 0; i < foundParticles.length; i++) { for (var i = 0; i < foundEntities.length; i++) {
print(" particle[" + i + "].id:" + foundParticles[i].id); print(" foundEntities[" + i + "].id:" + foundEntities[i].id);
if (foundParticles[i].id == particleA.id) { if (foundEntities[i].id == entityA.id) {
print(">>>> found particleA!!"); print(">>>> found entityA!!");
var propertiesA = Particles.getParticleProperties(particleA); var propertiesA = Entities.getEntityProperties(entityA);
printProperties(propertiesA); printProperties(propertiesA);
} }
if (foundParticles[i].id == particleB.id) { if (foundEntities[i].id == entityB.id) {
print(">>>> found particleB!!"); print(">>>> found entityB!!");
var propertiesB = Entities.getEntityProperties(entityB);
printProperties(propertiesB);
} }
} }
// move search // move search
@ -125,7 +129,7 @@ function findParticles(deltaTime) {
// register the call back so it fires before each data send // register the call back so it fires before each data send
Script.update.connect(findParticles); Script.update.connect(findEntities);
// register our scriptEnding callback // register our scriptEnding callback
Script.scriptEnding.connect(scriptEnding); Script.scriptEnding.connect(scriptEnding);