mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-10 21:27:22 +02:00
expose setVoxelSphere to js
This commit is contained in:
parent
1ec384ab4d
commit
cdef502e2e
5 changed files with 33 additions and 36 deletions
|
@ -80,29 +80,16 @@ void RenderablePolyVoxEntityItem::setSphereInVolume(glm::vec3 center, float radi
|
||||||
glm::vec3 pos(x, y, z);
|
glm::vec3 pos(x, y, z);
|
||||||
// And compute how far the current position is from the center of the volume
|
// And compute how far the current position is from the center of the volume
|
||||||
float fDistToCenter = glm::distance(pos, center);
|
float fDistToCenter = glm::distance(pos, center);
|
||||||
uint8_t uVoxelValue = _volData->getVoxelAt(x, y, z);
|
|
||||||
// If the current voxel is less than 'radius' units from the center then we make it solid.
|
// If the current voxel is less than 'radius' units from the center then we make it solid.
|
||||||
if (fDistToCenter <= radius) {
|
if (fDistToCenter <= radius) {
|
||||||
// Our new voxel value
|
_volData->setVoxelAt(x, y, z, toValue);
|
||||||
uVoxelValue = toValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrte the voxel value into the volume
|
|
||||||
_volData->setVoxelAt(x, y, z, uVoxelValue);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
compressVolumeData();
|
compressVolumeData();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderablePolyVoxEntityItem::createSphereInVolume(glm::vec3 centerVoxelCoords, float radiusVoxelCoords) {
|
|
||||||
setSphereInVolume(centerVoxelCoords, radiusVoxelCoords, 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderablePolyVoxEntityItem::eraseSphereInVolume(glm::vec3 centerVoxelCoords, float radiusVoxelCoords) {
|
|
||||||
setSphereInVolume(centerVoxelCoords, radiusVoxelCoords, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderablePolyVoxEntityItem::setSphere(glm::vec3 centerWorldCoords, float radiusWorldCoords, uint8_t toValue) {
|
void RenderablePolyVoxEntityItem::setSphere(glm::vec3 centerWorldCoords, float radiusWorldCoords, uint8_t toValue) {
|
||||||
// glm::vec3 centerVoxelCoords = worldToVoxelCoordinates(centerWorldCoords);
|
// glm::vec3 centerVoxelCoords = worldToVoxelCoordinates(centerWorldCoords);
|
||||||
glm::vec4 centerVoxelCoords = worldToVoxelMatrix() * glm::vec4(centerWorldCoords, 1.0f);
|
glm::vec4 centerVoxelCoords = worldToVoxelMatrix() * glm::vec4(centerWorldCoords, 1.0f);
|
||||||
|
@ -112,37 +99,24 @@ void RenderablePolyVoxEntityItem::setSphere(glm::vec3 centerWorldCoords, float r
|
||||||
setSphereInVolume(glm::vec3(centerVoxelCoords), radiusVoxelCoords, toValue);
|
setSphereInVolume(glm::vec3(centerVoxelCoords), radiusVoxelCoords, toValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderablePolyVoxEntityItem::createSphere(glm::vec3 centerWorldCoords, float radiusWorldCoords) {
|
|
||||||
setSphere(centerWorldCoords, radiusWorldCoords, 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderablePolyVoxEntityItem::eraseSphere(glm::vec3 centerWorldCoords, float radiusWorldCoords) {
|
|
||||||
setSphere(centerWorldCoords, radiusWorldCoords, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderablePolyVoxEntityItem::getModel() {
|
void RenderablePolyVoxEntityItem::getModel() {
|
||||||
if (!_volData) {
|
if (!_volData) {
|
||||||
// this will cause the allocation of _volData
|
// this will cause the allocation of _volData
|
||||||
setVoxelVolumeSize(_voxelVolumeSize);
|
setVoxelVolumeSize(_voxelVolumeSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 center = getCenter();
|
|
||||||
createSphere(center, 4);
|
|
||||||
createSphere(center + glm::vec3(6.0f, 0.0f, 0.0f), 2);
|
|
||||||
|
|
||||||
// A mesh object to hold the result of surface extraction
|
// A mesh object to hold the result of surface extraction
|
||||||
PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> polyVoxMesh;
|
PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> polyVoxMesh;
|
||||||
|
|
||||||
//Create a surface extractor. Comment out one of the following two lines to decide which type gets created.
|
//Create a surface extractor. Comment out one of the following two lines to decide which type gets created.
|
||||||
PolyVox::CubicSurfaceExtractorWithNormals<PolyVox::SimpleVolume<uint8_t>> surfaceExtractor
|
// PolyVox::CubicSurfaceExtractorWithNormals<PolyVox::SimpleVolume<uint8_t>> surfaceExtractor
|
||||||
(_volData, _volData->getEnclosingRegion(), &polyVoxMesh);
|
|
||||||
// PolyVox::MarchingCubesSurfaceExtractor<PolyVox::SimpleVolume<uint8_t>> surfaceExtractor
|
|
||||||
// (_volData, _volData->getEnclosingRegion(), &polyVoxMesh);
|
// (_volData, _volData->getEnclosingRegion(), &polyVoxMesh);
|
||||||
|
PolyVox::MarchingCubesSurfaceExtractor<PolyVox::SimpleVolume<uint8_t>> surfaceExtractor
|
||||||
|
(_volData, _volData->getEnclosingRegion(), &polyVoxMesh);
|
||||||
|
|
||||||
//Execute the surface extractor.
|
//Execute the surface extractor.
|
||||||
surfaceExtractor.execute();
|
surfaceExtractor.execute();
|
||||||
|
|
||||||
|
|
||||||
// convert PolyVox mesh to a Sam mesh
|
// convert PolyVox mesh to a Sam mesh
|
||||||
model::Mesh* mesh = new model::Mesh();
|
model::Mesh* mesh = new model::Mesh();
|
||||||
model::MeshPointer meshPtr(mesh);
|
model::MeshPointer meshPtr(mesh);
|
||||||
|
|
|
@ -47,13 +47,11 @@ public:
|
||||||
glm::mat4 voxelToWorldMatrix() const;
|
glm::mat4 voxelToWorldMatrix() const;
|
||||||
glm::mat4 worldToVoxelMatrix() const;
|
glm::mat4 worldToVoxelMatrix() const;
|
||||||
|
|
||||||
void setSphere(glm::vec3 center, float radius, uint8_t toValue);
|
// coords are in voxel-volume space
|
||||||
void createSphere(glm::vec3 centerWorldCoords, float radiusWorldCoords);
|
virtual void setSphereInVolume(glm::vec3 center, float radius, uint8_t toValue);
|
||||||
void eraseSphere(glm::vec3 centerWorldCoords, float radiusWorldCoords);
|
|
||||||
|
|
||||||
void setSphereInVolume(glm::vec3 center, float radius, uint8_t toValue);
|
// coords are in world-space
|
||||||
void createSphereInVolume(glm::vec3 center, float radius);
|
virtual void setSphere(glm::vec3 center, float radius, uint8_t toValue);
|
||||||
void eraseSphereInVolume(glm::vec3 center, float radius);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void compressVolumeData();
|
void compressVolumeData();
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "ModelEntityItem.h"
|
#include "ModelEntityItem.h"
|
||||||
#include "ZoneEntityItem.h"
|
#include "ZoneEntityItem.h"
|
||||||
#include "EntitiesLogging.h"
|
#include "EntitiesLogging.h"
|
||||||
|
#include "PolyVoxEntityItem.h"
|
||||||
|
|
||||||
|
|
||||||
EntityScriptingInterface::EntityScriptingInterface() :
|
EntityScriptingInterface::EntityScriptingInterface() :
|
||||||
|
@ -380,3 +381,19 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra
|
||||||
vec3FromScriptValue(intersection, value.intersection);
|
vec3FromScriptValue(intersection, value.intersection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) const {
|
||||||
|
EntityItem* entity = const_cast<EntityItem*>(_entityTree->findEntityByEntityItemID(entityID));
|
||||||
|
if (!entity) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
EntityTypes::EntityType entityType = entity->getType();
|
||||||
|
if (entityType != EntityTypes::PolyVox) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PolyVoxEntityItem* polyVoxEntity = static_cast<PolyVoxEntityItem*>(entity);
|
||||||
|
polyVoxEntity->setSphere(center, radius, value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -117,6 +117,8 @@ public slots:
|
||||||
Q_INVOKABLE void setSendPhysicsUpdates(bool value);
|
Q_INVOKABLE void setSendPhysicsUpdates(bool value);
|
||||||
Q_INVOKABLE bool getSendPhysicsUpdates() const;
|
Q_INVOKABLE bool getSendPhysicsUpdates() const;
|
||||||
|
|
||||||
|
Q_INVOKABLE bool setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) const;
|
||||||
|
|
||||||
Q_INVOKABLE void dumpTree() const;
|
Q_INVOKABLE void dumpTree() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
|
@ -70,6 +70,12 @@ class PolyVoxEntityItem : public EntityItem {
|
||||||
static const glm::vec3 DEFAULT_VOXEL_VOLUME_SIZE;
|
static const glm::vec3 DEFAULT_VOXEL_VOLUME_SIZE;
|
||||||
static const QByteArray DEFAULT_VOXEL_DATA;
|
static const QByteArray DEFAULT_VOXEL_DATA;
|
||||||
|
|
||||||
|
// coords are in voxel-volume space
|
||||||
|
virtual void setSphereInVolume(glm::vec3 center, float radius, uint8_t toValue) {}
|
||||||
|
|
||||||
|
// coords are in world-space
|
||||||
|
virtual void setSphere(glm::vec3 center, float radius, uint8_t toValue) {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
rgbColor _color;
|
rgbColor _color;
|
||||||
glm::vec3 _voxelVolumeSize; // this is always 3 bytes
|
glm::vec3 _voxelVolumeSize; // this is always 3 bytes
|
||||||
|
|
Loading…
Reference in a new issue