mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:44:02 +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);
|
||||
// And compute how far the current position is from the center of the volume
|
||||
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 (fDistToCenter <= radius) {
|
||||
// Our new voxel value
|
||||
uVoxelValue = toValue;
|
||||
_volData->setVoxelAt(x, y, z, toValue);
|
||||
}
|
||||
|
||||
// Wrte the voxel value into the volume
|
||||
_volData->setVoxelAt(x, y, z, uVoxelValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
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) {
|
||||
// glm::vec3 centerVoxelCoords = worldToVoxelCoordinates(centerWorldCoords);
|
||||
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);
|
||||
}
|
||||
|
||||
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() {
|
||||
if (!_volData) {
|
||||
// this will cause the allocation of _volData
|
||||
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
|
||||
PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> polyVoxMesh;
|
||||
|
||||
//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
|
||||
(_volData, _volData->getEnclosingRegion(), &polyVoxMesh);
|
||||
// PolyVox::MarchingCubesSurfaceExtractor<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);
|
||||
|
||||
//Execute the surface extractor.
|
||||
surfaceExtractor.execute();
|
||||
|
||||
|
||||
// convert PolyVox mesh to a Sam mesh
|
||||
model::Mesh* mesh = new model::Mesh();
|
||||
model::MeshPointer meshPtr(mesh);
|
||||
|
|
|
@ -47,13 +47,11 @@ public:
|
|||
glm::mat4 voxelToWorldMatrix() const;
|
||||
glm::mat4 worldToVoxelMatrix() const;
|
||||
|
||||
void setSphere(glm::vec3 center, float radius, uint8_t toValue);
|
||||
void createSphere(glm::vec3 centerWorldCoords, float radiusWorldCoords);
|
||||
void eraseSphere(glm::vec3 centerWorldCoords, float radiusWorldCoords);
|
||||
// coords are in voxel-volume space
|
||||
virtual void setSphereInVolume(glm::vec3 center, float radius, uint8_t toValue);
|
||||
|
||||
void setSphereInVolume(glm::vec3 center, float radius, uint8_t toValue);
|
||||
void createSphereInVolume(glm::vec3 center, float radius);
|
||||
void eraseSphereInVolume(glm::vec3 center, float radius);
|
||||
// coords are in world-space
|
||||
virtual void setSphere(glm::vec3 center, float radius, uint8_t toValue);
|
||||
|
||||
private:
|
||||
void compressVolumeData();
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "ModelEntityItem.h"
|
||||
#include "ZoneEntityItem.h"
|
||||
#include "EntitiesLogging.h"
|
||||
#include "PolyVoxEntityItem.h"
|
||||
|
||||
|
||||
EntityScriptingInterface::EntityScriptingInterface() :
|
||||
|
@ -380,3 +381,19 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra
|
|||
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 bool getSendPhysicsUpdates() const;
|
||||
|
||||
Q_INVOKABLE bool setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) const;
|
||||
|
||||
Q_INVOKABLE void dumpTree() const;
|
||||
|
||||
signals:
|
||||
|
|
|
@ -70,6 +70,12 @@ class PolyVoxEntityItem : public EntityItem {
|
|||
static const glm::vec3 DEFAULT_VOXEL_VOLUME_SIZE;
|
||||
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:
|
||||
rgbColor _color;
|
||||
glm::vec3 _voxelVolumeSize; // this is always 3 bytes
|
||||
|
|
Loading…
Reference in a new issue