mirror of
https://github.com/overte-org/overte.git
synced 2025-04-22 16:13:28 +02:00
add findClosestParticle() to JS interface
This commit is contained in:
parent
1c5e32fcb1
commit
90c841ff01
4 changed files with 37 additions and 0 deletions
|
@ -77,6 +77,14 @@ function moveParticle() {
|
|||
print("newProperties.position.x = " + newProperties.position.x);
|
||||
|
||||
Particles.editParticle(particleID, newProperties);
|
||||
|
||||
// also check to see if we can "find" particles...
|
||||
var searchAt = { x: 0, y: 0, z: 0};
|
||||
var searchRadius = 2;
|
||||
var foundParticle = Particles.findClosestParticle(searchAt, searchRadius);
|
||||
if (foundParticle.isKnownID) {
|
||||
print("found particle:" + foundParticle.id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -4224,6 +4224,7 @@ void Application::loadScript() {
|
|||
// we can use the same ones from the application.
|
||||
scriptEngine->getVoxelsScriptingInterface()->setPacketSender(&_voxelEditSender);
|
||||
scriptEngine->getParticlesScriptingInterface()->setPacketSender(&_particleEditSender);
|
||||
scriptEngine->getParticlesScriptingInterface()->setParticleTree(_particles.getTree());
|
||||
|
||||
QThread* workerThread = new QThread(this);
|
||||
|
||||
|
|
|
@ -7,7 +7,13 @@
|
|||
//
|
||||
|
||||
#include "ParticlesScriptingInterface.h"
|
||||
#include "ParticleTree.h"
|
||||
|
||||
ParticlesScriptingInterface::ParticlesScriptingInterface() :
|
||||
_nextCreatorTokenID(0),
|
||||
_particleTree(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ParticlesScriptingInterface::queueParticleMessage(PACKET_TYPE packetType,
|
||||
|
@ -73,3 +79,18 @@ void ParticlesScriptingInterface::deleteParticle(ParticleID particleID) {
|
|||
//qDebug() << "ParticlesScriptingInterface::deleteParticle(), queueParticleMessage......";
|
||||
queueParticleMessage(PACKET_TYPE_PARTICLE_ADD_OR_EDIT, particleID, properties);
|
||||
}
|
||||
|
||||
ParticleID ParticlesScriptingInterface::findClosestParticle(const glm::vec3& center, float radius) const {
|
||||
ParticleID result(UNKNOWN_PARTICLE_ID, UNKNOWN_TOKEN, false);
|
||||
if (_particleTree) {
|
||||
const Particle* closestParticle = _particleTree->findClosestParticle(center/(float)TREE_SCALE,
|
||||
radius/(float)TREE_SCALE);
|
||||
|
||||
if (closestParticle) {
|
||||
result.id = closestParticle->getID();
|
||||
result.isKnownID = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,19 +19,26 @@
|
|||
class ParticlesScriptingInterface : public OctreeScriptingInterface {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ParticlesScriptingInterface();
|
||||
|
||||
ParticleEditPacketSender* getParticlePacketSender() const { return (ParticleEditPacketSender*)getPacketSender(); }
|
||||
virtual NODE_TYPE getServerNodeType() const { return NODE_TYPE_PARTICLE_SERVER; }
|
||||
virtual OctreeEditPacketSender* createPacketSender() { return new ParticleEditPacketSender(); }
|
||||
|
||||
void setParticleTree(ParticleTree* particleTree) { _particleTree = particleTree; }
|
||||
ParticleTree* getParticleTree(ParticleTree*) { return _particleTree; }
|
||||
|
||||
public slots:
|
||||
ParticleID addParticle(const ParticleProperties& properties);
|
||||
void editParticle(ParticleID particleID, const ParticleProperties& properties);
|
||||
void deleteParticle(ParticleID particleID);
|
||||
ParticleID findClosestParticle(const glm::vec3& center, float radius) const;
|
||||
|
||||
private:
|
||||
void queueParticleMessage(PACKET_TYPE packetType, ParticleID particleID, const ParticleProperties& properties);
|
||||
|
||||
uint32_t _nextCreatorTokenID;
|
||||
ParticleTree* _particleTree;
|
||||
};
|
||||
|
||||
#endif /* defined(__hifi__ParticlesScriptingInterface__) */
|
||||
|
|
Loading…
Reference in a new issue