mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
Moved LocalVoxels class
This commit is contained in:
parent
41931ebd57
commit
b854c450f4
3 changed files with 1 additions and 201 deletions
|
@ -21,11 +21,11 @@
|
|||
#include <VoxelConstants.h>
|
||||
#include <VoxelDetail.h>
|
||||
#include <ParticlesScriptingInterface.h>
|
||||
#include <LocalVoxels.h>
|
||||
|
||||
#include <Sound.h>
|
||||
|
||||
#include "MenuItemProperties.h"
|
||||
#include "LocalVoxels.h"
|
||||
#include "ScriptEngine.h"
|
||||
|
||||
const unsigned int VISUAL_DATA_CALLBACK_USECS = (1.0 / 60.0) * 1000 * 1000;
|
||||
|
|
|
@ -1,124 +0,0 @@
|
|||
//
|
||||
// LocalVoxels.cpp
|
||||
// hifi
|
||||
//
|
||||
// Created by Clément Brisset on 2/24/14.
|
||||
// Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#include "LocalVoxels.h"
|
||||
|
||||
LocalVoxels::LocalVoxels(QString name) :
|
||||
QObject(NULL),
|
||||
_name(name),
|
||||
_tree(new VoxelTree(true))
|
||||
{
|
||||
// Don't allow creation of a local tree pointing to the domain tree.
|
||||
if (_name == DOMAIN_TREE_NAME) {
|
||||
qDebug() << "Please use the \"Voxels\" interface to modify the domain tree.";
|
||||
_name.clear();
|
||||
_tree.clear();
|
||||
}
|
||||
|
||||
LocalVoxelsList::getInstance()->insert(_name, _tree);
|
||||
}
|
||||
|
||||
LocalVoxels::~LocalVoxels() {
|
||||
_tree.clear();
|
||||
LocalVoxelsList::getInstance()->remove(_name);
|
||||
}
|
||||
|
||||
VoxelDetail LocalVoxels::getVoxelAt(float x, float y, float z, float scale) {
|
||||
// setup a VoxelDetail struct with the data
|
||||
VoxelDetail result = {0,0,0,0,0,0,0};
|
||||
|
||||
if (_tree) {
|
||||
_tree->lockForRead();
|
||||
|
||||
VoxelTreeElement* voxel = static_cast<VoxelTreeElement*>(_tree->getOctreeElementAt(x / (float)TREE_SCALE,
|
||||
y / (float)TREE_SCALE,
|
||||
z / (float)TREE_SCALE,
|
||||
scale / (float)TREE_SCALE));
|
||||
_tree->unlock();
|
||||
if (voxel) {
|
||||
// Note: these need to be in voxel space because the VoxelDetail -> js converter will upscale
|
||||
result.x = voxel->getCorner().x;
|
||||
result.y = voxel->getCorner().y;
|
||||
result.z = voxel->getCorner().z;
|
||||
result.s = voxel->getScale();
|
||||
result.red = voxel->getColor()[RED_INDEX];
|
||||
result.green = voxel->getColor()[GREEN_INDEX];
|
||||
result.blue = voxel->getColor()[BLUE_INDEX];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void LocalVoxels::setVoxelNonDestructive(float x, float y, float z, float scale,
|
||||
uchar red, uchar green, uchar blue) {
|
||||
if (_tree ) {
|
||||
if (_tree->tryLockForWrite()) {
|
||||
_tree->createVoxel(x, y, z, scale, red, green, blue, false);
|
||||
_tree->unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LocalVoxels::setVoxel(float x, float y, float z, float scale,
|
||||
uchar red, uchar green, uchar blue) {
|
||||
if (_tree ) {
|
||||
if (_tree->tryLockForWrite()) {
|
||||
_tree->createVoxel(x, y, z, scale, red, green, blue, true);
|
||||
_tree->unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LocalVoxels::eraseVoxel(float x, float y, float z, float scale) {
|
||||
if (_tree ) {
|
||||
if (_tree->tryLockForWrite()) {
|
||||
_tree->deleteVoxelAt(x, y, z, scale);
|
||||
_tree->unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RayToVoxelIntersectionResult LocalVoxels::findRayIntersection(const PickRay& ray) {
|
||||
RayToVoxelIntersectionResult result;
|
||||
if (_tree) {
|
||||
if (_tree->tryLockForRead()) {
|
||||
OctreeElement* element;
|
||||
result.intersects = _tree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face);
|
||||
if (result.intersects) {
|
||||
VoxelTreeElement* voxel = (VoxelTreeElement*)element;
|
||||
result.voxel.x = voxel->getCorner().x;
|
||||
result.voxel.y = voxel->getCorner().y;
|
||||
result.voxel.z = voxel->getCorner().z;
|
||||
result.voxel.s = voxel->getScale();
|
||||
result.voxel.red = voxel->getColor()[0];
|
||||
result.voxel.green = voxel->getColor()[1];
|
||||
result.voxel.blue = voxel->getColor()[2];
|
||||
result.intersection = ray.origin + (ray.direction * result.distance);
|
||||
}
|
||||
_tree->unlock();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
glm::vec3 LocalVoxels::getFaceVector(const QString& face) {
|
||||
if (face == "MIN_X_FACE") {
|
||||
return glm::vec3(-1, 0, 0);
|
||||
} else if (face == "MAX_X_FACE") {
|
||||
return glm::vec3(1, 0, 0);
|
||||
} else if (face == "MIN_Y_FACE") {
|
||||
return glm::vec3(0, -1, 0);
|
||||
} else if (face == "MAX_Y_FACE") {
|
||||
return glm::vec3(0, 1, 0);
|
||||
} else if (face == "MIN_Z_FACE") {
|
||||
return glm::vec3(0, 0, -1);
|
||||
} else if (face == "MAX_Z_FACE") {
|
||||
return glm::vec3(0, 0, 1);
|
||||
}
|
||||
return glm::vec3(0, 0, 0); //error case
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
//
|
||||
// LocalVoxels.h
|
||||
// hifi
|
||||
//
|
||||
// Created by Clément Brisset on 2/24/14.
|
||||
// Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __hifi__LocalVoxels__
|
||||
#define __hifi__LocalVoxels__
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <RegisteredMetaTypes.h>
|
||||
|
||||
#include "VoxelTree.h"
|
||||
#include "LocalVoxelsList.h"
|
||||
|
||||
|
||||
/// object allowing JS scripters to use their own local trees
|
||||
class LocalVoxels : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
LocalVoxels(QString name);
|
||||
~LocalVoxels();
|
||||
|
||||
/// checks the local voxel tree for a voxel at the specified location and scale
|
||||
/// \param x the x-coordinate of the voxel (in meter units)
|
||||
/// \param y the y-coordinate of the voxel (in meter units)
|
||||
/// \param z the z-coordinate of the voxel (in meter units)
|
||||
/// \param scale the scale of the voxel (in meter units)
|
||||
Q_INVOKABLE VoxelDetail getVoxelAt(float x, float y, float z, float scale);
|
||||
|
||||
/// creates a non destructive voxel in the local tree
|
||||
/// \param x the x-coordinate of the voxel (in meter units)
|
||||
/// \param y the y-coordinate of the voxel (in meter units)
|
||||
/// \param z the z-coordinate of the voxel (in meter units)
|
||||
/// \param scale the scale of the voxel (in meter units)
|
||||
/// \param red the R value for RGB color of voxel
|
||||
/// \param green the G value for RGB color of voxel
|
||||
/// \param blue the B value for RGB color of voxel
|
||||
Q_INVOKABLE void setVoxelNonDestructive(float x, float y, float z, float scale, uchar red, uchar green, uchar blue);
|
||||
|
||||
/// creates a voxel in the local tree
|
||||
/// \param x the x-coordinate of the voxel (in meter units)
|
||||
/// \param y the y-coordinate of the voxel (in meter units)
|
||||
/// \param z the z-coordinate of the voxel (in meter units)
|
||||
/// \param scale the scale of the voxel (in meter units)
|
||||
/// \param red the R value for RGB color of voxel
|
||||
/// \param green the G value for RGB color of voxel
|
||||
/// \param blue the B value for RGB color of voxel
|
||||
Q_INVOKABLE void setVoxel(float x, float y, float z, float scale, uchar red, uchar green, uchar blue);
|
||||
|
||||
/// erase the voxel and its children at the given coordinate
|
||||
/// \param x the x-coordinate of the voxel (in meter units)
|
||||
/// \param y the y-coordinate of the voxel (in meter units)
|
||||
/// \param z the z-coordinate of the voxel (in meter units)
|
||||
/// \param scale the scale of the voxel (in meter units)
|
||||
Q_INVOKABLE void eraseVoxel(float x, float y, float z, float scale);
|
||||
|
||||
/// If the scripting context has visible voxels, this will determine a ray intersection
|
||||
Q_INVOKABLE RayToVoxelIntersectionResult findRayIntersection(const PickRay& ray);
|
||||
|
||||
/// returns a voxel space axis aligned vector for the face, useful in doing voxel math
|
||||
Q_INVOKABLE glm::vec3 getFaceVector(const QString& face);
|
||||
|
||||
private:
|
||||
QString _name;
|
||||
StrongVoxelTreePointer _tree;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* defined(__hifi__LocalVoxels__) */
|
Loading…
Reference in a new issue