repairs to MetavoxelSystem after reset to upstream

This commit is contained in:
Stephen Birarda 2014-12-15 11:48:24 -08:00
parent c18c45a401
commit fa8b7020b0

View file

@ -40,12 +40,12 @@ REGISTER_META_OBJECT(StaticModelRenderer)
REGISTER_META_OBJECT(HeightfieldRenderer) REGISTER_META_OBJECT(HeightfieldRenderer)
MetavoxelSystem::NetworkSimulation::NetworkSimulation(float dropRate, float repeatRate, MetavoxelSystem::NetworkSimulation::NetworkSimulation(float dropRate, float repeatRate,
int minimumDelay, int maximumDelay, int bandwidthLimit) : int minimumDelay, int maximumDelay, int bandwidthLimit) :
dropRate(dropRate), dropRate(dropRate),
repeatRate(repeatRate), repeatRate(repeatRate),
minimumDelay(minimumDelay), minimumDelay(minimumDelay),
maximumDelay(maximumDelay), maximumDelay(maximumDelay),
bandwidthLimit(bandwidthLimit) { bandwidthLimit(bandwidthLimit) {
} }
MetavoxelSystem::~MetavoxelSystem() { MetavoxelSystem::~MetavoxelSystem() {
@ -59,14 +59,14 @@ void MetavoxelSystem::init() {
MetavoxelClientManager::init(); MetavoxelClientManager::init();
_voxelBufferAttribute = AttributeRegistry::getInstance()->registerAttribute( _voxelBufferAttribute = AttributeRegistry::getInstance()->registerAttribute(
new BufferDataAttribute("voxelBuffer")); new BufferDataAttribute("voxelBuffer"));
_voxelBufferAttribute->setLODThresholdMultiplier( _voxelBufferAttribute->setLODThresholdMultiplier(
AttributeRegistry::getInstance()->getVoxelColorAttribute()->getLODThresholdMultiplier()); AttributeRegistry::getInstance()->getVoxelColorAttribute()->getLODThresholdMultiplier());
_baseHeightfieldProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + _baseHeightfieldProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() +
"shaders/metavoxel_heightfield_base.vert"); "shaders/metavoxel_heightfield_base.vert");
_baseHeightfieldProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + _baseHeightfieldProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() +
"shaders/metavoxel_heightfield_base.frag"); "shaders/metavoxel_heightfield_base.frag");
_baseHeightfieldProgram.link(); _baseHeightfieldProgram.link();
_baseHeightfieldProgram.bind(); _baseHeightfieldProgram.bind();
@ -79,9 +79,9 @@ void MetavoxelSystem::init() {
loadSplatProgram("heightfield", _splatHeightfieldProgram, _splatHeightfieldLocations); loadSplatProgram("heightfield", _splatHeightfieldProgram, _splatHeightfieldLocations);
_heightfieldCursorProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + _heightfieldCursorProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() +
"shaders/metavoxel_heightfield_cursor.vert"); "shaders/metavoxel_heightfield_cursor.vert");
_heightfieldCursorProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + _heightfieldCursorProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() +
"shaders/metavoxel_cursor.frag"); "shaders/metavoxel_cursor.frag");
_heightfieldCursorProgram.link(); _heightfieldCursorProgram.link();
_heightfieldCursorProgram.bind(); _heightfieldCursorProgram.bind();
@ -89,17 +89,17 @@ void MetavoxelSystem::init() {
_heightfieldCursorProgram.release(); _heightfieldCursorProgram.release();
_baseVoxelProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + _baseVoxelProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() +
"shaders/metavoxel_voxel_base.vert"); "shaders/metavoxel_voxel_base.vert");
_baseVoxelProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + _baseVoxelProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() +
"shaders/metavoxel_voxel_base.frag"); "shaders/metavoxel_voxel_base.frag");
_baseVoxelProgram.link(); _baseVoxelProgram.link();
loadSplatProgram("voxel", _splatVoxelProgram, _splatVoxelLocations); loadSplatProgram("voxel", _splatVoxelProgram, _splatVoxelLocations);
_voxelCursorProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + _voxelCursorProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() +
"shaders/metavoxel_voxel_cursor.vert"); "shaders/metavoxel_voxel_cursor.vert");
_voxelCursorProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + _voxelCursorProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() +
"shaders/metavoxel_cursor.frag"); "shaders/metavoxel_cursor.frag");
_voxelCursorProgram.link(); _voxelCursorProgram.link();
} }
@ -131,9 +131,9 @@ private:
}; };
SimulateVisitor::SimulateVisitor(float deltaTime, const MetavoxelLOD& lod) : SimulateVisitor::SimulateVisitor(float deltaTime, const MetavoxelLOD& lod) :
MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getRendererAttribute(), MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getRendererAttribute(),
QVector<AttributePointer>(), lod), QVector<AttributePointer>(), lod),
_deltaTime(deltaTime) { _deltaTime(deltaTime) {
} }
int SimulateVisitor::visit(MetavoxelInfo& info) { int SimulateVisitor::visit(MetavoxelInfo& info) {
@ -141,7 +141,7 @@ int SimulateVisitor::visit(MetavoxelInfo& info) {
return DEFAULT_ORDER; return DEFAULT_ORDER;
} }
static_cast<MetavoxelRenderer*>(info.inputValues.at(0).getInlineValue< static_cast<MetavoxelRenderer*>(info.inputValues.at(0).getInlineValue<
SharedObjectPointer>().data())->getImplementation()->simulate(*_data, _deltaTime, info, _lod); SharedObjectPointer>().data())->getImplementation()->simulate(*_data, _deltaTime, info, _lod);
return STOP_RECURSION; return STOP_RECURSION;
} }
@ -166,8 +166,8 @@ public:
}; };
RenderVisitor::RenderVisitor(const MetavoxelLOD& lod) : RenderVisitor::RenderVisitor(const MetavoxelLOD& lod) :
MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getRendererAttribute(), MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getRendererAttribute(),
QVector<AttributePointer>(), lod) { QVector<AttributePointer>(), lod) {
} }
int RenderVisitor::visit(MetavoxelInfo& info) { int RenderVisitor::visit(MetavoxelInfo& info) {
@ -175,7 +175,7 @@ int RenderVisitor::visit(MetavoxelInfo& info) {
return DEFAULT_ORDER; return DEFAULT_ORDER;
} }
static_cast<MetavoxelRenderer*>(info.inputValues.at(0).getInlineValue< static_cast<MetavoxelRenderer*>(info.inputValues.at(0).getInlineValue<
SharedObjectPointer>().data())->getImplementation()->render(*_data, info, _lod); SharedObjectPointer>().data())->getImplementation()->render(*_data, info, _lod);
return STOP_RECURSION; return STOP_RECURSION;
} }
@ -195,8 +195,8 @@ void MetavoxelSystem::render() {
// update the frustum // update the frustum
ViewFrustum* viewFrustum = Application::getInstance()->getDisplayViewFrustum(); ViewFrustum* viewFrustum = Application::getInstance()->getDisplayViewFrustum();
_frustum.set(viewFrustum->getFarTopLeft(), viewFrustum->getFarTopRight(), viewFrustum->getFarBottomLeft(), _frustum.set(viewFrustum->getFarTopLeft(), viewFrustum->getFarTopRight(), viewFrustum->getFarBottomLeft(),
viewFrustum->getFarBottomRight(), viewFrustum->getNearTopLeft(), viewFrustum->getNearTopRight(), viewFrustum->getFarBottomRight(), viewFrustum->getNearTopLeft(), viewFrustum->getNearTopRight(),
viewFrustum->getNearBottomLeft(), viewFrustum->getNearBottomRight()); viewFrustum->getNearBottomLeft(), viewFrustum->getNearBottomRight());
RenderVisitor renderVisitor(getLOD()); RenderVisitor renderVisitor(getLOD());
guideToAugmented(renderVisitor, true); guideToAugmented(renderVisitor, true);
@ -283,7 +283,7 @@ void MetavoxelSystem::render() {
glBindTexture(GL_TEXTURE_2D, batch.heightTextureID); glBindTexture(GL_TEXTURE_2D, batch.heightTextureID);
_splatHeightfieldProgram.setUniformValue(_splatHeightfieldLocations.heightScale, _splatHeightfieldProgram.setUniformValue(_splatHeightfieldLocations.heightScale,
batch.heightScale.x, batch.heightScale.y); batch.heightScale.x, batch.heightScale.y);
_splatHeightfieldProgram.setUniform(_splatHeightfieldLocations.textureScale, batch.textureScale); _splatHeightfieldProgram.setUniform(_splatHeightfieldLocations.textureScale, batch.textureScale);
_splatHeightfieldProgram.setUniform(_splatHeightfieldLocations.splatTextureOffset, batch.splatTextureOffset); _splatHeightfieldProgram.setUniform(_splatHeightfieldLocations.splatTextureOffset, batch.splatTextureOffset);
@ -291,17 +291,17 @@ void MetavoxelSystem::render() {
_splatHeightfieldProgram.setUniform(_splatHeightfieldLocations.splatTextureScalesS, batch.splatTextureScalesS); _splatHeightfieldProgram.setUniform(_splatHeightfieldLocations.splatTextureScalesS, batch.splatTextureScalesS);
_splatHeightfieldProgram.setUniform(_splatHeightfieldLocations.splatTextureScalesT, batch.splatTextureScalesT); _splatHeightfieldProgram.setUniform(_splatHeightfieldLocations.splatTextureScalesT, batch.splatTextureScalesT);
_splatHeightfieldProgram.setUniformValue( _splatHeightfieldProgram.setUniformValue(
_splatHeightfieldLocations.textureValueMinima, _splatHeightfieldLocations.textureValueMinima,
(batch.materialIndex + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, (batch.materialIndex + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP,
(batch.materialIndex + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, (batch.materialIndex + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP,
(batch.materialIndex + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, (batch.materialIndex + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP,
(batch.materialIndex + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP); (batch.materialIndex + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP);
_splatHeightfieldProgram.setUniformValue( _splatHeightfieldProgram.setUniformValue(
_splatHeightfieldLocations.textureValueMaxima, _splatHeightfieldLocations.textureValueMaxima,
(batch.materialIndex + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, (batch.materialIndex + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP,
(batch.materialIndex + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, (batch.materialIndex + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP,
(batch.materialIndex + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, (batch.materialIndex + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP,
(batch.materialIndex + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP); (batch.materialIndex + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP);
glActiveTexture(GL_TEXTURE1); glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, batch.materialTextureID); glBindTexture(GL_TEXTURE_2D, batch.materialTextureID);
@ -406,25 +406,25 @@ void MetavoxelSystem::render() {
glNormalPointer(GL_BYTE, sizeof(VoxelPoint), &point->normal); glNormalPointer(GL_BYTE, sizeof(VoxelPoint), &point->normal);
_splatVoxelProgram.setAttributeBuffer(_splatVoxelLocations.materials, _splatVoxelProgram.setAttributeBuffer(_splatVoxelLocations.materials,
GL_UNSIGNED_BYTE, (qint64)&point->materials, SPLAT_COUNT, sizeof(VoxelPoint)); GL_UNSIGNED_BYTE, (qint64)&point->materials, SPLAT_COUNT, sizeof(VoxelPoint));
_splatVoxelProgram.setAttributeBuffer(_splatVoxelLocations.materialWeights, _splatVoxelProgram.setAttributeBuffer(_splatVoxelLocations.materialWeights,
GL_UNSIGNED_BYTE, (qint64)&point->materialWeights, SPLAT_COUNT, sizeof(VoxelPoint)); GL_UNSIGNED_BYTE, (qint64)&point->materialWeights, SPLAT_COUNT, sizeof(VoxelPoint));
const float QUARTER_STEP = 0.25f * EIGHT_BIT_MAXIMUM_RECIPROCAL; const float QUARTER_STEP = 0.25f * EIGHT_BIT_MAXIMUM_RECIPROCAL;
_splatVoxelProgram.setUniform(_splatVoxelLocations.splatTextureScalesS, batch.splatTextureScalesS); _splatVoxelProgram.setUniform(_splatVoxelLocations.splatTextureScalesS, batch.splatTextureScalesS);
_splatVoxelProgram.setUniform(_splatVoxelLocations.splatTextureScalesT, batch.splatTextureScalesT); _splatVoxelProgram.setUniform(_splatVoxelLocations.splatTextureScalesT, batch.splatTextureScalesT);
_splatVoxelProgram.setUniformValue( _splatVoxelProgram.setUniformValue(
_splatVoxelLocations.textureValueMinima, _splatVoxelLocations.textureValueMinima,
(batch.materialIndex + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, (batch.materialIndex + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP,
(batch.materialIndex + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, (batch.materialIndex + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP,
(batch.materialIndex + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, (batch.materialIndex + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP,
(batch.materialIndex + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP); (batch.materialIndex + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP);
_splatVoxelProgram.setUniformValue( _splatVoxelProgram.setUniformValue(
_splatVoxelLocations.textureValueMaxima, _splatVoxelLocations.textureValueMaxima,
(batch.materialIndex + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, (batch.materialIndex + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP,
(batch.materialIndex + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, (batch.materialIndex + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP,
(batch.materialIndex + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, (batch.materialIndex + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP,
(batch.materialIndex + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP); (batch.materialIndex + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP);
for (int i = 0; i < SPLAT_COUNT; i++) { for (int i = 0; i < SPLAT_COUNT; i++) {
glActiveTexture(GL_TEXTURE0 + SPLAT_TEXTURE_UNITS[i]); glActiveTexture(GL_TEXTURE0 + SPLAT_TEXTURE_UNITS[i]);
@ -517,10 +517,10 @@ public:
}; };
RayVoxelIntersectionVisitor::RayVoxelIntersectionVisitor(const glm::vec3& origin, RayVoxelIntersectionVisitor::RayVoxelIntersectionVisitor(const glm::vec3& origin,
const glm::vec3& direction, const MetavoxelLOD& lod) : const glm::vec3& direction, const MetavoxelLOD& lod) :
RayIntersectionVisitor(origin, direction, QVector<AttributePointer>() << RayIntersectionVisitor(origin, direction, QVector<AttributePointer>() <<
Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute(), QVector<AttributePointer>(), lod), Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute(), QVector<AttributePointer>(), lod),
intersectionDistance(FLT_MAX) { intersectionDistance(FLT_MAX) {
} }
int RayVoxelIntersectionVisitor::visit(MetavoxelInfo& info, float distance) { int RayVoxelIntersectionVisitor::visit(MetavoxelInfo& info, float distance) {
@ -528,7 +528,7 @@ int RayVoxelIntersectionVisitor::visit(MetavoxelInfo& info, float distance) {
return _order; return _order;
} }
const VoxelBuffer* buffer = static_cast<VoxelBuffer*>( const VoxelBuffer* buffer = static_cast<VoxelBuffer*>(
info.inputValues.at(0).getInlineValue<BufferDataPointer>().data()); info.inputValues.at(0).getInlineValue<BufferDataPointer>().data());
if (!buffer) { if (!buffer) {
return STOP_RECURSION; return STOP_RECURSION;
} }
@ -702,8 +702,8 @@ private:
}; };
BufferCursorRenderVisitor::BufferCursorRenderVisitor(const AttributePointer& attribute, const Box& bounds) : BufferCursorRenderVisitor::BufferCursorRenderVisitor(const AttributePointer& attribute, const Box& bounds) :
MetavoxelVisitor(QVector<AttributePointer>() << attribute), MetavoxelVisitor(QVector<AttributePointer>() << attribute),
_bounds(bounds) { _bounds(bounds) {
} }
int BufferCursorRenderVisitor::visit(MetavoxelInfo& info) { int BufferCursorRenderVisitor::visit(MetavoxelInfo& info) {
@ -778,8 +778,8 @@ protected:
}; };
MaterialEditApplier::MaterialEditApplier(const MetavoxelEditMessage& message, const QSharedPointer<NetworkTexture> texture) : MaterialEditApplier::MaterialEditApplier(const MetavoxelEditMessage& message, const QSharedPointer<NetworkTexture> texture) :
_message(message), _message(message),
_texture(texture) { _texture(texture) {
} }
void MaterialEditApplier::handle() { void MaterialEditApplier::handle() {
@ -794,11 +794,11 @@ void MetavoxelSystem::applyMaterialEdit(const MetavoxelEditMessage& message, boo
if (material && material->getDiffuse().isValid()) { if (material && material->getDiffuse().isValid()) {
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "applyMaterialEdit", Q_ARG(const MetavoxelEditMessage&, message), QMetaObject::invokeMethod(this, "applyMaterialEdit", Q_ARG(const MetavoxelEditMessage&, message),
Q_ARG(bool, reliable)); Q_ARG(bool, reliable));
return; return;
} }
QSharedPointer<NetworkTexture> texture = Application::getInstance()->getTextureCache()->getTexture( QSharedPointer<NetworkTexture> texture = Application::getInstance()->getTextureCache()->getTexture(
material->getDiffuse(), SPLAT_TEXTURE); material->getDiffuse(), SPLAT_TEXTURE);
if (texture->isLoaded()) { if (texture->isLoaded()) {
MetavoxelEditMessage newMessage = message; MetavoxelEditMessage newMessage = message;
static_cast<MaterialEdit*>(newMessage.edit.data())->averageColor = texture->getAverageColor(); static_cast<MaterialEdit*>(newMessage.edit.data())->averageColor = texture->getAverageColor();
@ -818,7 +818,7 @@ MetavoxelClient* MetavoxelSystem::createClient(const SharedNodePointer& node) {
} }
void MetavoxelSystem::guideToAugmented(MetavoxelVisitor& visitor, bool render) { void MetavoxelSystem::guideToAugmented(MetavoxelVisitor& visitor, bool render) {
NodeList::getInstance()->eachNode([&visitor, &render](const SharedNodePointer& node) { NodeList::getInstance()->eachNode([&visitor, &render](const SharedNodePointer& node){
if (node->getType() == NodeType::MetavoxelServer) { if (node->getType() == NodeType::MetavoxelServer) {
QMutexLocker locker(&node->getMutex()); QMutexLocker locker(&node->getMutex());
MetavoxelSystemClient* client = static_cast<MetavoxelSystemClient*>(node->getLinkedData()); MetavoxelSystemClient* client = static_cast<MetavoxelSystemClient*>(node->getLinkedData());
@ -837,9 +837,9 @@ void MetavoxelSystem::guideToAugmented(MetavoxelVisitor& visitor, bool render) {
void MetavoxelSystem::loadSplatProgram(const char* type, ProgramObject& program, SplatLocations& locations) { void MetavoxelSystem::loadSplatProgram(const char* type, ProgramObject& program, SplatLocations& locations) {
program.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + program.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() +
"shaders/metavoxel_" + type + "_splat.vert"); "shaders/metavoxel_" + type + "_splat.vert");
program.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + program.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() +
"shaders/metavoxel_" + type + "_splat.frag"); "shaders/metavoxel_" + type + "_splat.frag");
program.link(); program.link();
program.bind(); program.bind();
@ -859,8 +859,8 @@ void MetavoxelSystem::loadSplatProgram(const char* type, ProgramObject& program,
} }
Throttle::Throttle() : Throttle::Throttle() :
_limit(INT_MAX), _limit(INT_MAX),
_total(0) { _total(0) {
} }
bool Throttle::shouldThrottle(int bytes) { bool Throttle::shouldThrottle(int bytes) {
@ -881,7 +881,7 @@ bool Throttle::shouldThrottle(int bytes) {
} }
MetavoxelSystemClient::MetavoxelSystemClient(const SharedNodePointer& node, MetavoxelUpdater* updater) : MetavoxelSystemClient::MetavoxelSystemClient(const SharedNodePointer& node, MetavoxelUpdater* updater) :
MetavoxelClient(node, updater) { MetavoxelClient(node, updater) {
} }
void MetavoxelSystemClient::setAugmentedData(const MetavoxelData& data) { void MetavoxelSystemClient::setAugmentedData(const MetavoxelData& data) {
@ -910,8 +910,8 @@ private:
}; };
ReceiveDelayer::ReceiveDelayer(const SharedNodePointer& node, const QByteArray& packet) : ReceiveDelayer::ReceiveDelayer(const SharedNodePointer& node, const QByteArray& packet) :
_node(node), _node(node),
_packet(packet) { _packet(packet) {
} }
void ReceiveDelayer::timerEvent(QTimerEvent* event) { void ReceiveDelayer::timerEvent(QTimerEvent* event) {
@ -963,9 +963,9 @@ private:
}; };
AugmentVisitor::AugmentVisitor(const MetavoxelLOD& lod, const MetavoxelData& previousData) : AugmentVisitor::AugmentVisitor(const MetavoxelLOD& lod, const MetavoxelData& previousData) :
MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getRendererAttribute(), MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getRendererAttribute(),
QVector<AttributePointer>(), lod), QVector<AttributePointer>(), lod),
_previousData(previousData) { _previousData(previousData) {
} }
int AugmentVisitor::visit(MetavoxelInfo& info) { int AugmentVisitor::visit(MetavoxelInfo& info) {
@ -973,7 +973,7 @@ int AugmentVisitor::visit(MetavoxelInfo& info) {
return DEFAULT_ORDER; return DEFAULT_ORDER;
} }
static_cast<MetavoxelRenderer*>(info.inputValues.at(0).getInlineValue< static_cast<MetavoxelRenderer*>(info.inputValues.at(0).getInlineValue<
SharedObjectPointer>().data())->getImplementation()->augment(*_data, _previousData, info, _lod); SharedObjectPointer>().data())->getImplementation()->augment(*_data, _previousData, info, _lod);
return STOP_RECURSION; return STOP_RECURSION;
} }
@ -981,7 +981,7 @@ class Augmenter : public QRunnable {
public: public:
Augmenter(const SharedNodePointer& node, const MetavoxelData& data, Augmenter(const SharedNodePointer& node, const MetavoxelData& data,
const MetavoxelData& previousData, const MetavoxelLOD& lod); const MetavoxelData& previousData, const MetavoxelLOD& lod);
virtual void run(); virtual void run();
@ -994,11 +994,11 @@ private:
}; };
Augmenter::Augmenter(const SharedNodePointer& node, const MetavoxelData& data, Augmenter::Augmenter(const SharedNodePointer& node, const MetavoxelData& data,
const MetavoxelData& previousData, const MetavoxelLOD& lod) : const MetavoxelData& previousData, const MetavoxelLOD& lod) :
_node(node), _node(node),
_data(data), _data(data),
_previousData(previousData), _previousData(previousData),
_lod(lod) { _lod(lod) {
} }
void Augmenter::run() { void Augmenter::run() {
@ -1039,8 +1039,8 @@ private:
}; };
SendDelayer::SendDelayer(const SharedNodePointer& node, const QByteArray& data) : SendDelayer::SendDelayer(const SharedNodePointer& node, const QByteArray& data) :
_node(node), _node(node),
_data(data.constData(), data.size()) { _data(data.constData(), data.size()) {
} }
void SendDelayer::timerEvent(QTimerEvent* event) { void SendDelayer::timerEvent(QTimerEvent* event) {
@ -1083,21 +1083,21 @@ void VoxelPoint::setNormal(const glm::vec3& normal) {
} }
VoxelBuffer::VoxelBuffer(const QVector<VoxelPoint>& vertices, const QVector<int>& indices, const QVector<glm::vec3>& hermite, VoxelBuffer::VoxelBuffer(const QVector<VoxelPoint>& vertices, const QVector<int>& indices, const QVector<glm::vec3>& hermite,
const QMultiHash<VoxelCoord, int>& quadIndices, int size, const QVector<SharedObjectPointer>& materials) : const QMultiHash<VoxelCoord, int>& quadIndices, int size, const QVector<SharedObjectPointer>& materials) :
_vertices(vertices), _vertices(vertices),
_indices(indices), _indices(indices),
_hermite(hermite), _hermite(hermite),
_quadIndices(quadIndices), _quadIndices(quadIndices),
_size(size), _size(size),
_vertexCount(vertices.size()), _vertexCount(vertices.size()),
_indexCount(indices.size()), _indexCount(indices.size()),
_hermiteCount(hermite.size()), _hermiteCount(hermite.size()),
_indexBuffer(QOpenGLBuffer::IndexBuffer), _indexBuffer(QOpenGLBuffer::IndexBuffer),
_materials(materials) { _materials(materials) {
} }
bool VoxelBuffer::findFirstRayIntersection(const glm::vec3& entry, const glm::vec3& origin, bool VoxelBuffer::findFirstRayIntersection(const glm::vec3& entry, const glm::vec3& origin,
const glm::vec3& direction, float& distance) const { const glm::vec3& direction, float& distance) const {
float highest = _size - 1.0f; float highest = _size - 1.0f;
glm::vec3 position = entry * highest; glm::vec3 position = entry * highest;
glm::vec3 floors = glm::floor(position); glm::vec3 floors = glm::floor(position);
@ -1105,14 +1105,14 @@ bool VoxelBuffer::findFirstRayIntersection(const glm::vec3& entry, const glm::ve
int x = qMin((int)floors.x, max), y = qMin((int)floors.y, max), z = qMin((int)floors.z, max); int x = qMin((int)floors.x, max), y = qMin((int)floors.y, max), z = qMin((int)floors.z, max);
forever { forever {
for (QMultiHash<VoxelCoord, int>::const_iterator it = _quadIndices.constFind(qRgb(x + 1, y + 1, z + 1)); for (QMultiHash<VoxelCoord, int>::const_iterator it = _quadIndices.constFind(qRgb(x + 1, y + 1, z + 1));
it != _quadIndices.constEnd(); it++) { it != _quadIndices.constEnd(); it++) {
const int* indices = _indices.constData() + *it; const int* indices = _indices.constData() + *it;
if (findRayTriangleIntersection(origin, direction, _vertices.at(indices[0]).vertex, if (findRayTriangleIntersection(origin, direction, _vertices.at(indices[0]).vertex,
_vertices.at(indices[1]).vertex, _vertices.at(indices[2]).vertex, distance) || _vertices.at(indices[1]).vertex, _vertices.at(indices[2]).vertex, distance) ||
findRayTriangleIntersection(origin, direction, _vertices.at(indices[0]).vertex, findRayTriangleIntersection(origin, direction, _vertices.at(indices[0]).vertex,
_vertices.at(indices[2]).vertex, _vertices.at(indices[3]).vertex, distance)) { _vertices.at(indices[2]).vertex, _vertices.at(indices[3]).vertex, distance)) {
return true; return true;
} }
} }
float xDistance = FLT_MAX, yDistance = FLT_MAX, zDistance = FLT_MAX; float xDistance = FLT_MAX, yDistance = FLT_MAX, zDistance = FLT_MAX;
if (direction.x > 0.0f) { if (direction.x > 0.0f) {
@ -1181,7 +1181,7 @@ void VoxelBuffer::render(bool cursor) {
const SharedObjectPointer material = _materials.at(i); const SharedObjectPointer material = _materials.at(i);
if (material) { if (material) {
_networkTextures[i] = Application::getInstance()->getTextureCache()->getTexture( _networkTextures[i] = Application::getInstance()->getTextureCache()->getTexture(
static_cast<MaterialObject*>(material.data())->getDiffuse(), SPLAT_TEXTURE); static_cast<MaterialObject*>(material.data())->getDiffuse(), SPLAT_TEXTURE);
} }
} }
} }
@ -1256,7 +1256,7 @@ void VoxelBuffer::render(bool cursor) {
} }
BufferDataAttribute::BufferDataAttribute(const QString& name) : BufferDataAttribute::BufferDataAttribute(const QString& name) :
InlineAttribute<BufferDataPointer>(name) { InlineAttribute<BufferDataPointer>(name) {
} }
bool BufferDataAttribute::merge(void*& parent, void* children[], bool postRead) const { bool BufferDataAttribute::merge(void*& parent, void* children[], bool postRead) const {
@ -1285,10 +1285,10 @@ public:
}; };
VoxelAugmentVisitor::VoxelAugmentVisitor(const MetavoxelLOD& lod) : VoxelAugmentVisitor::VoxelAugmentVisitor(const MetavoxelLOD& lod) :
MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getVoxelColorAttribute() << MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getVoxelColorAttribute() <<
AttributeRegistry::getInstance()->getVoxelMaterialAttribute() << AttributeRegistry::getInstance()->getVoxelMaterialAttribute() <<
AttributeRegistry::getInstance()->getVoxelHermiteAttribute(), QVector<AttributePointer>() << AttributeRegistry::getInstance()->getVoxelHermiteAttribute(), QVector<AttributePointer>() <<
Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute(), lod) { Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute(), lod) {
} }
class EdgeCrossing { class EdgeCrossing {
@ -1446,9 +1446,9 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) {
// its properties (color, material, normal) if one is present; as before, boundary edges are excluded // its properties (color, material, normal) if one is present; as before, boundary edges are excluded
int clampedX = qMax(x - 1, 0), clampedY = qMax(y - 1, 0), clampedZ = qMax(z - 1, 0); int clampedX = qMax(x - 1, 0), clampedY = qMax(y - 1, 0), clampedZ = qMax(z - 1, 0);
const QRgb* hermiteBase = hermiteData + clampedZ * hermiteArea + clampedY * hermiteStride + const QRgb* hermiteBase = hermiteData + clampedZ * hermiteArea + clampedY * hermiteStride +
clampedX * VoxelHermiteData::EDGE_COUNT; clampedX * VoxelHermiteData::EDGE_COUNT;
const char* materialBase = materialData ? const char* materialBase = materialData ?
(materialData + clampedZ * area + clampedY * size + clampedX) : NULL; (materialData + clampedZ * area + clampedY * size + clampedX) : NULL;
int crossingCount = 0; int crossingCount = 0;
if (middleX) { if (middleX) {
if (alpha0 != alpha1) { if (alpha0 != alpha1) {
@ -1650,7 +1650,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) {
if (displayHermite) { if (displayHermite) {
glm::vec3 start = info.minimum + (glm::vec3(clampedX, clampedY, clampedZ) + glm::vec3 start = info.minimum + (glm::vec3(clampedX, clampedY, clampedZ) +
crossing.point) * scale; crossing.point) * scale;
hermiteSegments.append(start); hermiteSegments.append(start);
hermiteSegments.append(start + crossing.normal * scale); hermiteSegments.append(start + crossing.normal * scale);
} }
@ -1710,7 +1710,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) {
for (int i = 0; i < MAX_ITERATIONS; i++) { for (int i = 0; i < MAX_ITERATIONS; i++) {
glm::vec3 offDiagonals = glm::abs(glm::vec3(d[1][0], d[2][0], d[2][1])); glm::vec3 offDiagonals = glm::abs(glm::vec3(d[1][0], d[2][0], d[2][1]));
int largestIndex = (offDiagonals[0] > offDiagonals[1]) ? (offDiagonals[0] > offDiagonals[2] ? 0 : 2) : int largestIndex = (offDiagonals[0] > offDiagonals[1]) ? (offDiagonals[0] > offDiagonals[2] ? 0 : 2) :
(offDiagonals[1] > offDiagonals[2] ? 1 : 2); (offDiagonals[1] > offDiagonals[2] ? 1 : 2);
const float DESIRED_PRECISION = 0.00001f; const float DESIRED_PRECISION = 0.00001f;
if (offDiagonals[largestIndex] < DESIRED_PRECISION) { if (offDiagonals[largestIndex] < DESIRED_PRECISION) {
break; break;
@ -1721,7 +1721,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) {
float sii = d[largestI][largestI]; float sii = d[largestI][largestI];
float angle = glm::atan(2.0f * d[largestJ][largestI], sjj - sii) / 2.0f; float angle = glm::atan(2.0f * d[largestJ][largestI], sjj - sii) / 2.0f;
glm::quat rotation = glm::angleAxis(angle, largestIndex == 0 ? glm::vec3(0.0f, 0.0f, -1.0f) : glm::quat rotation = glm::angleAxis(angle, largestIndex == 0 ? glm::vec3(0.0f, 0.0f, -1.0f) :
(largestIndex == 1 ? glm::vec3(0.0f, 1.0f, 0.0f) : glm::vec3(-1.0f, 0.0f, 0.0f))); (largestIndex == 1 ? glm::vec3(0.0f, 1.0f, 0.0f) : glm::vec3(-1.0f, 0.0f, 0.0f)));
combinedRotation = glm::normalize(rotation * combinedRotation); combinedRotation = glm::normalize(rotation * combinedRotation);
glm::mat3 matrix = glm::mat3_cast(combinedRotation); glm::mat3 matrix = glm::mat3_cast(combinedRotation);
d = matrix * ata * glm::transpose(matrix); d = matrix * ata * glm::transpose(matrix);
@ -1774,7 +1774,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) {
const glm::vec3& first = vertices.at(index.indices[0]).vertex; const glm::vec3& first = vertices.at(index.indices[0]).vertex;
glm::vec3 normal = glm::cross(vertices.at(index1.indices[0]).vertex - first, glm::vec3 normal = glm::cross(vertices.at(index1.indices[0]).vertex - first,
vertices.at(index3.indices[0]).vertex - first); vertices.at(index3.indices[0]).vertex - first);
if (alpha0 == 0) { // quad faces negative x if (alpha0 == 0) { // quad faces negative x
indices.append(index3.getClosestIndex(normal = -normal, vertices)); indices.append(index3.getClosestIndex(normal = -normal, vertices));
@ -1800,7 +1800,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) {
const glm::vec3& first = vertices.at(index.indices[0]).vertex; const glm::vec3& first = vertices.at(index.indices[0]).vertex;
glm::vec3 normal = glm::cross(vertices.at(index3.indices[0]).vertex - first, glm::vec3 normal = glm::cross(vertices.at(index3.indices[0]).vertex - first,
vertices.at(index1.indices[0]).vertex - first); vertices.at(index1.indices[0]).vertex - first);
if (alpha0 == 0) { // quad faces negative y if (alpha0 == 0) { // quad faces negative y
indices.append(index1.getClosestIndex(normal = -normal, vertices)); indices.append(index1.getClosestIndex(normal = -normal, vertices));
@ -1826,7 +1826,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) {
const glm::vec3& first = vertices.at(index.indices[0]).vertex; const glm::vec3& first = vertices.at(index.indices[0]).vertex;
glm::vec3 normal = glm::cross(vertices.at(index1.indices[0]).vertex - first, glm::vec3 normal = glm::cross(vertices.at(index1.indices[0]).vertex - first,
vertices.at(index3.indices[0]).vertex - first); vertices.at(index3.indices[0]).vertex - first);
if (alpha0 == 0) { // quad faces negative z if (alpha0 == 0) { // quad faces negative z
indices.append(index3.getClosestIndex(normal = -normal, vertices)); indices.append(index3.getClosestIndex(normal = -normal, vertices));
@ -1861,7 +1861,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) {
} }
} }
buffer = new VoxelBuffer(vertices, indices, hermiteSegments, quadIndices, size, buffer = new VoxelBuffer(vertices, indices, hermiteSegments, quadIndices, size,
material ? material->getMaterials() : QVector<SharedObjectPointer>()); material ? material->getMaterials() : QVector<SharedObjectPointer>());
} }
BufferDataPointer pointer(buffer); BufferDataPointer pointer(buffer);
info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(pointer)); info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(pointer));
@ -1869,14 +1869,14 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) {
} }
void DefaultMetavoxelRendererImplementation::augment(MetavoxelData& data, const MetavoxelData& previous, void DefaultMetavoxelRendererImplementation::augment(MetavoxelData& data, const MetavoxelData& previous,
MetavoxelInfo& info, const MetavoxelLOD& lod) { MetavoxelInfo& info, const MetavoxelLOD& lod) {
// copy the previous buffers // copy the previous buffers
MetavoxelData expandedPrevious = previous; MetavoxelData expandedPrevious = previous;
while (expandedPrevious.getSize() < data.getSize()) { while (expandedPrevious.getSize() < data.getSize()) {
expandedPrevious.expand(); expandedPrevious.expand();
} }
const AttributePointer& voxelBufferAttribute = const AttributePointer& voxelBufferAttribute =
Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute(); Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute();
MetavoxelNode* root = expandedPrevious.getRoot(voxelBufferAttribute); MetavoxelNode* root = expandedPrevious.getRoot(voxelBufferAttribute);
if (root) { if (root) {
data.setRoot(voxelBufferAttribute, root); data.setRoot(voxelBufferAttribute, root);
@ -1899,9 +1899,9 @@ private:
}; };
SpannerSimulateVisitor::SpannerSimulateVisitor(float deltaTime, const MetavoxelLOD& lod) : SpannerSimulateVisitor::SpannerSimulateVisitor(float deltaTime, const MetavoxelLOD& lod) :
SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute(), SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute(),
QVector<AttributePointer>(), QVector<AttributePointer>(), lod), QVector<AttributePointer>(), QVector<AttributePointer>(), lod),
_deltaTime(deltaTime) { _deltaTime(deltaTime) {
} }
bool SpannerSimulateVisitor::visit(Spanner* spanner) { bool SpannerSimulateVisitor::visit(Spanner* spanner) {
@ -1910,7 +1910,7 @@ bool SpannerSimulateVisitor::visit(Spanner* spanner) {
} }
void DefaultMetavoxelRendererImplementation::simulate(MetavoxelData& data, float deltaTime, void DefaultMetavoxelRendererImplementation::simulate(MetavoxelData& data, float deltaTime,
MetavoxelInfo& info, const MetavoxelLOD& lod) { MetavoxelInfo& info, const MetavoxelLOD& lod) {
SpannerSimulateVisitor spannerSimulateVisitor(deltaTime, lod); SpannerSimulateVisitor spannerSimulateVisitor(deltaTime, lod);
data.guide(spannerSimulateVisitor); data.guide(spannerSimulateVisitor);
} }
@ -1929,15 +1929,15 @@ private:
}; };
BufferRenderVisitor::BufferRenderVisitor(const AttributePointer& attribute) : BufferRenderVisitor::BufferRenderVisitor(const AttributePointer& attribute) :
MetavoxelVisitor(QVector<AttributePointer>() << attribute), MetavoxelVisitor(QVector<AttributePointer>() << attribute),
_order(encodeOrder(Application::getInstance()->getDisplayViewFrustum()->getDirection())), _order(encodeOrder(Application::getInstance()->getDisplayViewFrustum()->getDirection())),
_containmentDepth(INT_MAX) { _containmentDepth(INT_MAX) {
} }
int BufferRenderVisitor::visit(MetavoxelInfo& info) { int BufferRenderVisitor::visit(MetavoxelInfo& info) {
if (_containmentDepth >= _depth) { if (_containmentDepth >= _depth) {
Frustum::IntersectionType intersection = Application::getInstance()->getMetavoxels()->getFrustum().getIntersectionType( Frustum::IntersectionType intersection = Application::getInstance()->getMetavoxels()->getFrustum().getIntersectionType(
info.getBounds()); info.getBounds());
if (intersection == Frustum::NO_INTERSECTION) { if (intersection == Frustum::NO_INTERSECTION) {
return STOP_RECURSION; return STOP_RECURSION;
} }
@ -2007,7 +2007,7 @@ void CuboidRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor
} }
StaticModelRenderer::StaticModelRenderer() : StaticModelRenderer::StaticModelRenderer() :
_model(new Model(this)) { _model(new Model(this)) {
} }
void StaticModelRenderer::init(Spanner* spanner) { void StaticModelRenderer::init(Spanner* spanner) {
@ -2035,7 +2035,7 @@ void StaticModelRenderer::simulate(float deltaTime) {
bounds = Box(extents.minimum, extents.maximum); bounds = Box(extents.minimum, extents.maximum);
} }
static_cast<StaticModel*>(_spanner)->setBounds(glm::translate(_model->getTranslation()) * static_cast<StaticModel*>(_spanner)->setBounds(glm::translate(_model->getTranslation()) *
glm::mat4_cast(_model->getRotation()) * glm::scale(_model->getScale()) * bounds); glm::mat4_cast(_model->getRotation()) * glm::scale(_model->getScale()) * bounds);
_model->simulate(deltaTime); _model->simulate(deltaTime);
} }
@ -2331,3 +2331,4 @@ void HeightfieldNodeRenderer::render(const HeightfieldNodePointer& node, const g
} }
QHash<HeightfieldNodeRenderer::IntPair, HeightfieldNodeRenderer::BufferPair> HeightfieldNodeRenderer::_bufferPairs; QHash<HeightfieldNodeRenderer::IntPair, HeightfieldNodeRenderer::BufferPair> HeightfieldNodeRenderer::_bufferPairs;