mirror of
https://github.com/lubosz/overte.git
synced 2025-04-16 15:30:11 +02:00
Merge branch 'master' of https://github.com/highfidelity/hifi into modelRayPick
This commit is contained in:
commit
0647211fb8
22 changed files with 1993 additions and 572 deletions
|
@ -311,7 +311,7 @@ MetavoxelPersister::MetavoxelPersister(MetavoxelServer* server) :
|
|||
const char* SAVE_FILE = "/resources/metavoxels.dat";
|
||||
|
||||
const int FILE_MAGIC = 0xDADAFACE;
|
||||
const int FILE_VERSION = 1;
|
||||
const int FILE_VERSION = 2;
|
||||
|
||||
void MetavoxelPersister::load() {
|
||||
QString path = QCoreApplication::applicationDirPath() + SAVE_FILE;
|
||||
|
|
|
@ -461,6 +461,34 @@ void MetavoxelSystem::render() {
|
|||
_voxelBaseBatches.clear();
|
||||
}
|
||||
|
||||
if (!_hermiteBatches.isEmpty() && Menu::getInstance()->isOptionChecked(MenuOption::DisplayHermiteData)) {
|
||||
Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, true);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
glNormal3f(0.0f, 1.0f, 0.0f);
|
||||
|
||||
Application::getInstance()->getDeferredLightingEffect()->bindSimpleProgram();
|
||||
|
||||
foreach (const HermiteBatch& batch, _hermiteBatches) {
|
||||
batch.vertexBuffer->bind();
|
||||
|
||||
glVertexPointer(3, GL_FLOAT, 0, 0);
|
||||
|
||||
glDrawArrays(GL_LINES, 0, batch.vertexCount);
|
||||
|
||||
batch.vertexBuffer->release();
|
||||
}
|
||||
|
||||
Application::getInstance()->getDeferredLightingEffect()->releaseSimpleProgram();
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, false);
|
||||
}
|
||||
_hermiteBatches.clear();
|
||||
|
||||
// give external parties a chance to join in
|
||||
emit rendering();
|
||||
}
|
||||
|
@ -550,10 +578,53 @@ void MetavoxelSystem::setVoxelMaterial(const SharedObjectPointer& spanner, const
|
|||
applyMaterialEdit(edit, true);
|
||||
}
|
||||
|
||||
class SpannerCursorRenderVisitor : public SpannerVisitor {
|
||||
void MetavoxelSystem::deleteTextures(int heightTextureID, int colorTextureID, int materialTextureID) const {
|
||||
glDeleteTextures(1, (const GLuint*)&heightTextureID);
|
||||
glDeleteTextures(1, (const GLuint*)&colorTextureID);
|
||||
glDeleteTextures(1, (const GLuint*)&materialTextureID);
|
||||
}
|
||||
|
||||
class SpannerRenderVisitor : public SpannerVisitor {
|
||||
public:
|
||||
|
||||
SpannerCursorRenderVisitor(const Box& bounds);
|
||||
SpannerRenderVisitor(const MetavoxelLOD& lod);
|
||||
|
||||
virtual int visit(MetavoxelInfo& info);
|
||||
virtual bool visit(Spanner* spanner);
|
||||
|
||||
protected:
|
||||
|
||||
int _containmentDepth;
|
||||
};
|
||||
|
||||
SpannerRenderVisitor::SpannerRenderVisitor(const MetavoxelLOD& lod) :
|
||||
SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute(),
|
||||
QVector<AttributePointer>(), QVector<AttributePointer>(), lod,
|
||||
encodeOrder(Application::getInstance()->getViewFrustum()->getDirection())),
|
||||
_containmentDepth(INT_MAX) {
|
||||
}
|
||||
|
||||
int SpannerRenderVisitor::visit(MetavoxelInfo& info) {
|
||||
if (_containmentDepth >= _depth) {
|
||||
Frustum::IntersectionType intersection = Application::getInstance()->getMetavoxels()->getFrustum().getIntersectionType(
|
||||
info.getBounds());
|
||||
if (intersection == Frustum::NO_INTERSECTION) {
|
||||
return STOP_RECURSION;
|
||||
}
|
||||
_containmentDepth = (intersection == Frustum::CONTAINS_INTERSECTION) ? _depth : INT_MAX;
|
||||
}
|
||||
return SpannerVisitor::visit(info);
|
||||
}
|
||||
|
||||
bool SpannerRenderVisitor::visit(Spanner* spanner) {
|
||||
spanner->getRenderer()->render(_lod, _containmentDepth <= _depth);
|
||||
return true;
|
||||
}
|
||||
|
||||
class SpannerCursorRenderVisitor : public SpannerRenderVisitor {
|
||||
public:
|
||||
|
||||
SpannerCursorRenderVisitor(const MetavoxelLOD& lod, const Box& bounds);
|
||||
|
||||
virtual bool visit(Spanner* spanner);
|
||||
|
||||
|
@ -564,20 +635,20 @@ private:
|
|||
Box _bounds;
|
||||
};
|
||||
|
||||
SpannerCursorRenderVisitor::SpannerCursorRenderVisitor(const Box& bounds) :
|
||||
SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute()),
|
||||
SpannerCursorRenderVisitor::SpannerCursorRenderVisitor(const MetavoxelLOD& lod, const Box& bounds) :
|
||||
SpannerRenderVisitor(lod),
|
||||
_bounds(bounds) {
|
||||
}
|
||||
|
||||
bool SpannerCursorRenderVisitor::visit(Spanner* spanner) {
|
||||
if (spanner->isHeightfield()) {
|
||||
spanner->getRenderer()->render(true);
|
||||
spanner->getRenderer()->render(_lod, _containmentDepth <= _depth, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int SpannerCursorRenderVisitor::visit(MetavoxelInfo& info) {
|
||||
return info.getBounds().intersects(_bounds) ? SpannerVisitor::visit(info) : STOP_RECURSION;
|
||||
return info.getBounds().intersects(_bounds) ? SpannerRenderVisitor::visit(info) : STOP_RECURSION;
|
||||
}
|
||||
|
||||
void MetavoxelSystem::renderHeightfieldCursor(const glm::vec3& position, float radius) {
|
||||
|
@ -604,7 +675,7 @@ void MetavoxelSystem::renderHeightfieldCursor(const glm::vec3& position, float r
|
|||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
glm::vec3 extents(radius, radius, radius);
|
||||
SpannerCursorRenderVisitor visitor(Box(position - extents, position + extents));
|
||||
SpannerCursorRenderVisitor visitor(getLOD(), Box(position - extents, position + extents));
|
||||
guide(visitor);
|
||||
|
||||
_heightfieldCursorProgram.release();
|
||||
|
@ -678,7 +749,7 @@ void MetavoxelSystem::renderVoxelCursor(const glm::vec3& position, float radius)
|
|||
|
||||
_heightfieldCursorProgram.bind();
|
||||
|
||||
SpannerCursorRenderVisitor spannerVisitor(bounds);
|
||||
SpannerCursorRenderVisitor spannerVisitor(getLOD(), bounds);
|
||||
guide(spannerVisitor);
|
||||
|
||||
_heightfieldCursorProgram.release();
|
||||
|
@ -1192,31 +1263,18 @@ void VoxelBuffer::render(bool cursor) {
|
|||
}
|
||||
}
|
||||
|
||||
if (_hermiteCount > 0 && Menu::getInstance()->isOptionChecked(MenuOption::DisplayHermiteData)) {
|
||||
if (_hermiteCount > 0) {
|
||||
if (!_hermiteBuffer.isCreated()) {
|
||||
_hermiteBuffer.create();
|
||||
_hermiteBuffer.bind();
|
||||
_hermiteBuffer.allocate(_hermite.constData(), _hermite.size() * sizeof(glm::vec3));
|
||||
_hermiteBuffer.allocate(_hermite.constData(), _hermite.size() * sizeof(glm::vec3));
|
||||
_hermiteBuffer.release();
|
||||
_hermite.clear();
|
||||
|
||||
} else {
|
||||
_hermiteBuffer.bind();
|
||||
}
|
||||
|
||||
glVertexPointer(3, GL_FLOAT, 0, 0);
|
||||
|
||||
Application::getInstance()->getDeferredLightingEffect()->getSimpleProgram().bind();
|
||||
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
glNormal3f(0.0f, 1.0f, 0.0f);
|
||||
|
||||
glLineWidth(1.0f);
|
||||
|
||||
glDrawArrays(GL_LINES, 0, _hermiteCount);
|
||||
|
||||
Application::getInstance()->getDeferredLightingEffect()->getSimpleProgram().release();
|
||||
|
||||
_hermiteBuffer.release();
|
||||
HermiteBatch hermiteBatch;
|
||||
hermiteBatch.vertexBuffer = &_hermiteBuffer;
|
||||
hermiteBatch.vertexCount = _hermiteCount;
|
||||
Application::getInstance()->getMetavoxels()->addHermiteBatch(hermiteBatch);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1880,43 +1938,6 @@ void DefaultMetavoxelRendererImplementation::simulate(MetavoxelData& data, float
|
|||
data.guide(spannerSimulateVisitor);
|
||||
}
|
||||
|
||||
class SpannerRenderVisitor : public SpannerVisitor {
|
||||
public:
|
||||
|
||||
SpannerRenderVisitor(const MetavoxelLOD& lod);
|
||||
|
||||
virtual int visit(MetavoxelInfo& info);
|
||||
virtual bool visit(Spanner* spanner);
|
||||
|
||||
private:
|
||||
|
||||
int _containmentDepth;
|
||||
};
|
||||
|
||||
SpannerRenderVisitor::SpannerRenderVisitor(const MetavoxelLOD& lod) :
|
||||
SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute(),
|
||||
QVector<AttributePointer>(), QVector<AttributePointer>(), lod,
|
||||
encodeOrder(Application::getInstance()->getViewFrustum()->getDirection())),
|
||||
_containmentDepth(INT_MAX) {
|
||||
}
|
||||
|
||||
int SpannerRenderVisitor::visit(MetavoxelInfo& info) {
|
||||
if (_containmentDepth >= _depth) {
|
||||
Frustum::IntersectionType intersection = Application::getInstance()->getMetavoxels()->getFrustum().getIntersectionType(
|
||||
info.getBounds());
|
||||
if (intersection == Frustum::NO_INTERSECTION) {
|
||||
return STOP_RECURSION;
|
||||
}
|
||||
_containmentDepth = (intersection == Frustum::CONTAINS_INTERSECTION) ? _depth : INT_MAX;
|
||||
}
|
||||
return SpannerVisitor::visit(info);
|
||||
}
|
||||
|
||||
bool SpannerRenderVisitor::visit(Spanner* spanner) {
|
||||
spanner->getRenderer()->render();
|
||||
return true;
|
||||
}
|
||||
|
||||
class BufferRenderVisitor : public MetavoxelVisitor {
|
||||
public:
|
||||
|
||||
|
@ -1970,7 +1991,7 @@ SphereRenderer::SphereRenderer() {
|
|||
}
|
||||
|
||||
|
||||
void SphereRenderer::render(bool cursor) {
|
||||
void SphereRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor) {
|
||||
Sphere* sphere = static_cast<Sphere*>(_spanner);
|
||||
const QColor& color = sphere->getColor();
|
||||
glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF());
|
||||
|
@ -1990,7 +2011,7 @@ void SphereRenderer::render(bool cursor) {
|
|||
CuboidRenderer::CuboidRenderer() {
|
||||
}
|
||||
|
||||
void CuboidRenderer::render(bool cursor) {
|
||||
void CuboidRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor) {
|
||||
Cuboid* cuboid = static_cast<Cuboid*>(_spanner);
|
||||
const QColor& color = cuboid->getColor();
|
||||
glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF());
|
||||
|
@ -2041,7 +2062,7 @@ void StaticModelRenderer::simulate(float deltaTime) {
|
|||
_model->simulate(deltaTime);
|
||||
}
|
||||
|
||||
void StaticModelRenderer::render(bool cursor) {
|
||||
void StaticModelRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor) {
|
||||
_model->render();
|
||||
}
|
||||
|
||||
|
@ -2073,57 +2094,66 @@ void StaticModelRenderer::applyURL(const QUrl& url) {
|
|||
}
|
||||
|
||||
HeightfieldRenderer::HeightfieldRenderer() {
|
||||
glGenTextures(1, &_heightTextureID);
|
||||
glBindTexture(GL_TEXTURE_2D, _heightTextureID);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
glGenTextures(1, &_colorTextureID);
|
||||
glBindTexture(GL_TEXTURE_2D, _colorTextureID);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
glGenTextures(1, &_materialTextureID);
|
||||
glBindTexture(GL_TEXTURE_2D, _materialTextureID);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
HeightfieldRenderer::~HeightfieldRenderer() {
|
||||
glDeleteTextures(1, &_heightTextureID);
|
||||
glDeleteTextures(1, &_colorTextureID);
|
||||
glDeleteTextures(1, &_materialTextureID);
|
||||
}
|
||||
const int X_MAXIMUM_FLAG = 1;
|
||||
const int Y_MAXIMUM_FLAG = 2;
|
||||
|
||||
void HeightfieldRenderer::init(Spanner* spanner) {
|
||||
SpannerRenderer::init(spanner);
|
||||
|
||||
Heightfield* heightfield = static_cast<Heightfield*>(spanner);
|
||||
applyHeight(heightfield->getHeight());
|
||||
applyColor(heightfield->getColor());
|
||||
applyMaterial(heightfield->getMaterial());
|
||||
|
||||
connect(heightfield, &Heightfield::heightChanged, this, &HeightfieldRenderer::applyHeight);
|
||||
connect(heightfield, &Heightfield::colorChanged, this, &HeightfieldRenderer::applyColor);
|
||||
connect(heightfield, &Heightfield::materialChanged, this, &HeightfieldRenderer::applyMaterial);
|
||||
}
|
||||
|
||||
void HeightfieldRenderer::render(bool cursor) {
|
||||
// create the buffer objects lazily
|
||||
Heightfield* heightfield = static_cast<Heightfield*>(_spanner);
|
||||
if (!heightfield->getHeight()) {
|
||||
static void renderNode(const HeightfieldNodePointer& node, Heightfield* heightfield, const MetavoxelLOD& lod,
|
||||
const glm::vec2& minimum, float size, bool contained, bool cursor) {
|
||||
const glm::quat& rotation = heightfield->getRotation();
|
||||
glm::vec3 scale(heightfield->getScale() * size, heightfield->getScale() * heightfield->getAspectY(),
|
||||
heightfield->getScale() * heightfield->getAspectZ() * size);
|
||||
glm::vec3 translation = heightfield->getTranslation() + rotation * glm::vec3(minimum.x * heightfield->getScale(),
|
||||
0.0f, minimum.y * heightfield->getScale() * heightfield->getAspectZ());
|
||||
if (!contained) {
|
||||
Frustum::IntersectionType type = Application::getInstance()->getMetavoxels()->getFrustum().getIntersectionType(
|
||||
glm::translate(translation) * glm::mat4_cast(rotation) * Box(glm::vec3(), scale));
|
||||
if (type == Frustum::NO_INTERSECTION) {
|
||||
return;
|
||||
}
|
||||
if (type == Frustum::CONTAINS_INTERSECTION) {
|
||||
contained = true;
|
||||
}
|
||||
}
|
||||
if (!node->isLeaf() && lod.shouldSubdivide(minimum, size)) {
|
||||
float nextSize = size * 0.5f;
|
||||
for (int i = 0; i < HeightfieldNode::CHILD_COUNT; i++) {
|
||||
renderNode(node->getChild(i), heightfield, lod, minimum + glm::vec2(i & X_MAXIMUM_FLAG ? nextSize : 0.0f,
|
||||
i & Y_MAXIMUM_FLAG ? nextSize : 0.0f), nextSize, contained, cursor);
|
||||
}
|
||||
return;
|
||||
}
|
||||
int width = heightfield->getHeight()->getWidth();
|
||||
int height = heightfield->getHeight()->getContents().size() / width;
|
||||
|
||||
HeightfieldNodeRenderer* renderer = static_cast<HeightfieldNodeRenderer*>(node->getRenderer());
|
||||
if (!renderer) {
|
||||
node->setRenderer(renderer = new HeightfieldNodeRenderer());
|
||||
}
|
||||
renderer->render(node, translation, rotation, scale, cursor);
|
||||
}
|
||||
|
||||
void HeightfieldRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor) {
|
||||
Heightfield* heightfield = static_cast<Heightfield*>(_spanner);
|
||||
renderNode(heightfield->getRoot(), heightfield, heightfield->transformLOD(lod), glm::vec2(), 1.0f, contained, cursor);
|
||||
}
|
||||
|
||||
HeightfieldNodeRenderer::HeightfieldNodeRenderer() :
|
||||
_heightTextureID(0),
|
||||
_colorTextureID(0),
|
||||
_materialTextureID(0) {
|
||||
}
|
||||
|
||||
HeightfieldNodeRenderer::~HeightfieldNodeRenderer() {
|
||||
QMetaObject::invokeMethod(Application::getInstance()->getMetavoxels(), "deleteTextures", Q_ARG(int, _heightTextureID),
|
||||
Q_ARG(int, _colorTextureID), Q_ARG(int, _materialTextureID));
|
||||
}
|
||||
|
||||
void HeightfieldNodeRenderer::render(const HeightfieldNodePointer& node, const glm::vec3& translation,
|
||||
const glm::quat& rotation, const glm::vec3& scale, bool cursor) {
|
||||
if (!node->getHeight()) {
|
||||
return;
|
||||
}
|
||||
int width = node->getHeight()->getWidth();
|
||||
int height = node->getHeight()->getContents().size() / width;
|
||||
int innerWidth = width - 2 * HeightfieldHeight::HEIGHT_BORDER;
|
||||
int innerHeight = height - 2 * HeightfieldHeight::HEIGHT_BORDER;
|
||||
int vertexCount = width * height;
|
||||
|
@ -2180,17 +2210,71 @@ void HeightfieldRenderer::render(bool cursor) {
|
|||
bufferPair.second.allocate(indices.constData(), indexCount * sizeof(int));
|
||||
bufferPair.second.release();
|
||||
}
|
||||
if (_heightTextureID == 0) {
|
||||
glGenTextures(1, &_heightTextureID);
|
||||
glBindTexture(GL_TEXTURE_2D, _heightTextureID);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
const QVector<quint16>& heightContents = node->getHeight()->getContents();
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R16, width, height, 0,
|
||||
GL_RED, GL_UNSIGNED_SHORT, heightContents.constData());
|
||||
|
||||
glGenTextures(1, &_colorTextureID);
|
||||
glBindTexture(GL_TEXTURE_2D, _colorTextureID);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
if (node->getColor()) {
|
||||
const QByteArray& contents = node->getColor()->getContents();
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, node->getColor()->getWidth(),
|
||||
contents.size() / (node->getColor()->getWidth() * DataBlock::COLOR_BYTES),
|
||||
0, GL_RGB, GL_UNSIGNED_BYTE, contents.constData());
|
||||
|
||||
} else {
|
||||
const quint8 WHITE_COLOR[] = { 255, 255, 255 };
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, WHITE_COLOR);
|
||||
}
|
||||
|
||||
glGenTextures(1, &_materialTextureID);
|
||||
glBindTexture(GL_TEXTURE_2D, _materialTextureID);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
if (node->getMaterial()) {
|
||||
const QByteArray& contents = node->getMaterial()->getContents();
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, node->getMaterial()->getWidth(),
|
||||
contents.size() / node->getMaterial()->getWidth(),
|
||||
0, GL_RED, GL_UNSIGNED_BYTE, contents.constData());
|
||||
|
||||
const QVector<SharedObjectPointer>& materials = node->getMaterial()->getMaterials();
|
||||
_networkTextures.resize(materials.size());
|
||||
for (int i = 0; i < materials.size(); i++) {
|
||||
const SharedObjectPointer& material = materials.at(i);
|
||||
if (material) {
|
||||
_networkTextures[i] = Application::getInstance()->getTextureCache()->getTexture(
|
||||
static_cast<MaterialObject*>(material.data())->getDiffuse(), SPLAT_TEXTURE);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const quint8 ZERO_VALUE = 0;
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, 1, 1, 0, GL_RED, GL_UNSIGNED_BYTE, &ZERO_VALUE);
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
float xScale = heightfield->getScale(), zScale = xScale * heightfield->getAspectZ();
|
||||
if (cursor) {
|
||||
bufferPair.first.bind();
|
||||
bufferPair.second.bind();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(heightfield->getTranslation().x, heightfield->getTranslation().y, heightfield->getTranslation().z);
|
||||
glm::vec3 axis = glm::axis(heightfield->getRotation());
|
||||
glRotatef(glm::degrees(glm::angle(heightfield->getRotation())), axis.x, axis.y, axis.z);
|
||||
glScalef(xScale, xScale * heightfield->getAspectY(), zScale);
|
||||
glTranslatef(translation.x, translation.y, translation.z);
|
||||
glm::vec3 axis = glm::axis(rotation);
|
||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||
glScalef(scale.x, scale.y, scale.z);
|
||||
|
||||
HeightfieldPoint* point = 0;
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(HeightfieldPoint), &point->vertex);
|
||||
|
@ -2208,13 +2292,12 @@ void HeightfieldRenderer::render(bool cursor) {
|
|||
bufferPair.second.release();
|
||||
return;
|
||||
}
|
||||
|
||||
HeightfieldBaseLayerBatch baseBatch;
|
||||
baseBatch.vertexBuffer = &bufferPair.first;
|
||||
baseBatch.indexBuffer = &bufferPair.second;
|
||||
baseBatch.translation = heightfield->getTranslation();
|
||||
baseBatch.rotation = heightfield->getRotation();
|
||||
baseBatch.scale = glm::vec3(xScale, xScale * heightfield->getAspectY(), zScale);
|
||||
baseBatch.translation = translation;
|
||||
baseBatch.rotation = rotation;
|
||||
baseBatch.scale = scale;
|
||||
baseBatch.vertexCount = vertexCount;
|
||||
baseBatch.indexCount = indexCount;
|
||||
baseBatch.heightTextureID = _heightTextureID;
|
||||
|
@ -2223,13 +2306,13 @@ void HeightfieldRenderer::render(bool cursor) {
|
|||
baseBatch.colorScale = glm::vec2((float)width / innerWidth, (float)height / innerHeight);
|
||||
Application::getInstance()->getMetavoxels()->addHeightfieldBaseBatch(baseBatch);
|
||||
|
||||
if (heightfield->getMaterial() && !_networkTextures.isEmpty()) {
|
||||
if (!_networkTextures.isEmpty()) {
|
||||
HeightfieldSplatBatch splatBatch;
|
||||
splatBatch.vertexBuffer = &bufferPair.first;
|
||||
splatBatch.indexBuffer = &bufferPair.second;
|
||||
splatBatch.translation = heightfield->getTranslation();
|
||||
splatBatch.rotation = heightfield->getRotation();
|
||||
splatBatch.scale = glm::vec3(xScale, xScale * heightfield->getAspectY(), zScale);
|
||||
splatBatch.translation = translation;
|
||||
splatBatch.rotation = rotation;
|
||||
splatBatch.scale = scale;
|
||||
splatBatch.vertexCount = vertexCount;
|
||||
splatBatch.indexCount = indexCount;
|
||||
splatBatch.heightTextureID = _heightTextureID;
|
||||
|
@ -2237,10 +2320,10 @@ void HeightfieldRenderer::render(bool cursor) {
|
|||
splatBatch.materialTextureID = _materialTextureID;
|
||||
splatBatch.textureScale = glm::vec2((float)width / innerWidth, (float)height / innerHeight);
|
||||
splatBatch.splatTextureOffset = glm::vec2(
|
||||
glm::dot(heightfield->getTranslation(), heightfield->getRotation() * glm::vec3(1.0f, 0.0f, 0.0f)) / xScale,
|
||||
glm::dot(heightfield->getTranslation(), heightfield->getRotation() * glm::vec3(0.0f, 0.0f, 1.0f)) / zScale);
|
||||
glm::dot(translation, rotation * glm::vec3(1.0f, 0.0f, 0.0f)) / scale.x,
|
||||
glm::dot(translation, rotation * glm::vec3(0.0f, 0.0f, 1.0f)) / scale.z);
|
||||
|
||||
const QVector<SharedObjectPointer>& materials = heightfield->getMaterial()->getMaterials();
|
||||
const QVector<SharedObjectPointer>& materials = node->getMaterial()->getMaterials();
|
||||
for (int i = 0; i < materials.size(); i += SPLAT_COUNT) {
|
||||
for (int j = 0; j < SPLAT_COUNT; j++) {
|
||||
int index = i + j;
|
||||
|
@ -2248,8 +2331,8 @@ void HeightfieldRenderer::render(bool cursor) {
|
|||
const NetworkTexturePointer& texture = _networkTextures.at(index);
|
||||
if (texture) {
|
||||
MaterialObject* material = static_cast<MaterialObject*>(materials.at(index).data());
|
||||
splatBatch.splatTextureScalesS[j] = xScale / material->getScaleS();
|
||||
splatBatch.splatTextureScalesT[j] = zScale / material->getScaleT();
|
||||
splatBatch.splatTextureScalesS[j] = scale.x / material->getScaleS();
|
||||
splatBatch.splatTextureScalesT[j] = scale.z / material->getScaleT();
|
||||
splatBatch.splatTextureIDs[j] = texture->getID();
|
||||
|
||||
} else {
|
||||
|
@ -2265,62 +2348,5 @@ void HeightfieldRenderer::render(bool cursor) {
|
|||
}
|
||||
}
|
||||
|
||||
void HeightfieldRenderer::applyHeight(const HeightfieldHeightPointer& height) {
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glBindTexture(GL_TEXTURE_2D, _heightTextureID);
|
||||
if (height) {
|
||||
const QVector<quint16>& contents = height->getContents();
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R16, height->getWidth(), contents.size() / height->getWidth(), 0,
|
||||
GL_RED, GL_UNSIGNED_SHORT, contents.constData());
|
||||
|
||||
} else {
|
||||
const quint16 ZERO_VALUE = 0;
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R16, 1, 1, 0, GL_RED, GL_UNSIGNED_SHORT, &ZERO_VALUE);
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
void HeightfieldRenderer::applyColor(const HeightfieldColorPointer& color) {
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glBindTexture(GL_TEXTURE_2D, _colorTextureID);
|
||||
if (color) {
|
||||
const QByteArray& contents = color->getContents();
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, color->getWidth(),
|
||||
contents.size() / (color->getWidth() * DataBlock::COLOR_BYTES), 0, GL_RGB, GL_UNSIGNED_BYTE, contents.constData());
|
||||
|
||||
} else {
|
||||
const quint8 WHITE_COLOR[] = { 255, 255, 255 };
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, WHITE_COLOR);
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
void HeightfieldRenderer::applyMaterial(const HeightfieldMaterialPointer& material) {
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glBindTexture(GL_TEXTURE_2D, _materialTextureID);
|
||||
if (material) {
|
||||
const QByteArray& contents = material->getContents();
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, material->getWidth(), contents.size() / material->getWidth(), 0,
|
||||
GL_RED, GL_UNSIGNED_BYTE, contents.constData());
|
||||
|
||||
const QVector<SharedObjectPointer>& materials = material->getMaterials();
|
||||
_networkTextures.resize(materials.size());
|
||||
for (int i = 0; i < materials.size(); i++) {
|
||||
const SharedObjectPointer& material = materials.at(i);
|
||||
if (material) {
|
||||
_networkTextures[i] = Application::getInstance()->getTextureCache()->getTexture(
|
||||
static_cast<MaterialObject*>(material.data())->getDiffuse(), SPLAT_TEXTURE);
|
||||
} else {
|
||||
_networkTextures[i].clear();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const quint8 ZERO_VALUE = 0;
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, 1, 1, 0, GL_RED, GL_UNSIGNED_BYTE, &ZERO_VALUE);
|
||||
_networkTextures.clear();
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
QHash<HeightfieldRenderer::IntPair, HeightfieldRenderer::BufferPair> HeightfieldRenderer::_bufferPairs;
|
||||
QHash<HeightfieldNodeRenderer::IntPair, HeightfieldNodeRenderer::BufferPair> HeightfieldNodeRenderer::_bufferPairs;
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
class HeightfieldBaseLayerBatch;
|
||||
class HeightfieldSplatBatch;
|
||||
class HermiteBatch;
|
||||
class Model;
|
||||
class VoxelBatch;
|
||||
class VoxelSplatBatch;
|
||||
|
@ -88,6 +89,10 @@ public:
|
|||
void addVoxelBaseBatch(const VoxelBatch& batch) { _voxelBaseBatches.append(batch); }
|
||||
void addVoxelSplatBatch(const VoxelSplatBatch& batch) { _voxelSplatBatches.append(batch); }
|
||||
|
||||
void addHermiteBatch(const HermiteBatch& batch) { _hermiteBatches.append(batch); }
|
||||
|
||||
Q_INVOKABLE void deleteTextures(int heightTextureID, int colorTextureID, int materialTextureID) const;
|
||||
|
||||
signals:
|
||||
|
||||
void rendering();
|
||||
|
@ -120,6 +125,7 @@ private:
|
|||
QVector<HeightfieldSplatBatch> _heightfieldSplatBatches;
|
||||
QVector<VoxelBatch> _voxelBaseBatches;
|
||||
QVector<VoxelSplatBatch> _voxelSplatBatches;
|
||||
QVector<HermiteBatch> _hermiteBatches;
|
||||
|
||||
ProgramObject _baseHeightfieldProgram;
|
||||
int _baseHeightScaleLocation;
|
||||
|
@ -211,6 +217,13 @@ public:
|
|||
int materialIndex;
|
||||
};
|
||||
|
||||
/// A batch containing Hermite data for debugging.
|
||||
class HermiteBatch {
|
||||
public:
|
||||
QOpenGLBuffer* vertexBuffer;
|
||||
int vertexCount;
|
||||
};
|
||||
|
||||
/// Generic abstract base class for objects that handle a signal.
|
||||
class SignalHandler : public QObject {
|
||||
Q_OBJECT
|
||||
|
@ -380,7 +393,7 @@ public:
|
|||
|
||||
Q_INVOKABLE SphereRenderer();
|
||||
|
||||
virtual void render(bool cursor = false);
|
||||
virtual void render(const MetavoxelLOD& lod = MetavoxelLOD(), bool contained = false, bool cursor = false);
|
||||
};
|
||||
|
||||
/// Renders cuboids.
|
||||
|
@ -391,7 +404,7 @@ public:
|
|||
|
||||
Q_INVOKABLE CuboidRenderer();
|
||||
|
||||
virtual void render(bool cursor = false);
|
||||
virtual void render(const MetavoxelLOD& lod = MetavoxelLOD(), bool contained = false, bool cursor = false);
|
||||
};
|
||||
|
||||
/// Renders static models.
|
||||
|
@ -404,7 +417,7 @@ public:
|
|||
|
||||
virtual void init(Spanner* spanner);
|
||||
virtual void simulate(float deltaTime);
|
||||
virtual void render(bool cursor = false);
|
||||
virtual void render(const MetavoxelLOD& lod = MetavoxelLOD(), bool contained = false, bool cursor = false);
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance) const;
|
||||
|
||||
private slots:
|
||||
|
@ -426,26 +439,29 @@ class HeightfieldRenderer : public SpannerRenderer {
|
|||
public:
|
||||
|
||||
Q_INVOKABLE HeightfieldRenderer();
|
||||
virtual ~HeightfieldRenderer();
|
||||
|
||||
virtual void init(Spanner* spanner);
|
||||
virtual void render(bool cursor = false);
|
||||
|
||||
private slots:
|
||||
|
||||
void applyHeight(const HeightfieldHeightPointer& height);
|
||||
void applyColor(const HeightfieldColorPointer& color);
|
||||
void applyMaterial(const HeightfieldMaterialPointer& material);
|
||||
virtual void render(const MetavoxelLOD& lod = MetavoxelLOD(), bool contained = false, bool cursor = false);
|
||||
};
|
||||
|
||||
/// Renders a single quadtree node.
|
||||
class HeightfieldNodeRenderer : public AbstractHeightfieldNodeRenderer {
|
||||
public:
|
||||
|
||||
HeightfieldNodeRenderer();
|
||||
virtual ~HeightfieldNodeRenderer();
|
||||
|
||||
void render(const HeightfieldNodePointer& node, const glm::vec3& translation,
|
||||
const glm::quat& rotation, const glm::vec3& scale, bool cursor);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
GLuint _heightTextureID;
|
||||
GLuint _colorTextureID;
|
||||
GLuint _materialTextureID;
|
||||
QVector<NetworkTexturePointer> _networkTextures;
|
||||
|
||||
typedef QPair<int, int> IntPair;
|
||||
typedef QPair<QOpenGLBuffer, QOpenGLBuffer> BufferPair;
|
||||
typedef QPair<int, int> IntPair;
|
||||
typedef QPair<QOpenGLBuffer, QOpenGLBuffer> BufferPair;
|
||||
static QHash<IntPair, BufferPair> _bufferPairs;
|
||||
};
|
||||
|
||||
|
|
|
@ -68,10 +68,7 @@ void AvatarManager::updateOtherAvatars(float deltaTime) {
|
|||
PerformanceWarning warn(showWarnings, "Application::updateAvatars()");
|
||||
|
||||
PerformanceTimer perfTimer("otherAvatars");
|
||||
Application* applicationInstance = Application::getInstance();
|
||||
glm::vec3 mouseOrigin = applicationInstance->getMouseRayOrigin();
|
||||
glm::vec3 mouseDirection = applicationInstance->getMouseRayDirection();
|
||||
|
||||
|
||||
// simulate avatars
|
||||
AvatarHash::iterator avatarIterator = _avatarHash.begin();
|
||||
while (avatarIterator != _avatarHash.end()) {
|
||||
|
|
|
@ -445,7 +445,6 @@ void GLBackend::updateTransform() {
|
|||
_transform._lastMode = GL_PROJECTION;
|
||||
}
|
||||
CHECK_GL_ERROR();*/
|
||||
_transform._invalidProj;
|
||||
}
|
||||
|
||||
if (_transform._invalidModel || _transform._invalidView) {
|
||||
|
|
|
@ -829,28 +829,44 @@ void GeometryReader::run() {
|
|||
return;
|
||||
}
|
||||
try {
|
||||
std::string urlname = _url.path().toLower().toStdString();
|
||||
FBXGeometry fbxgeo;
|
||||
if (_url.path().toLower().endsWith(".svo")) {
|
||||
fbxgeo = readSVO(_reply->readAll());
|
||||
} else {
|
||||
bool grabLightmaps = true;
|
||||
float lightmapLevel = 1.0f;
|
||||
// HACK: For monday 12/01/2014 we need to kill lighmaps loading in starchamber...
|
||||
if (_url.path().toLower().endsWith("loungev4_11-18.fbx")) {
|
||||
grabLightmaps = false;
|
||||
} else if (_url.path().toLower().endsWith("apt8_reboot.fbx")) {
|
||||
lightmapLevel = 4.0f;
|
||||
} else if (_url.path().toLower().endsWith("palaceoforinthilian4.fbx")) {
|
||||
lightmapLevel = 3.5f;
|
||||
}
|
||||
fbxgeo = readFBX(_reply->readAll(), _mapping, grabLightmaps, lightmapLevel);
|
||||
if (!_reply) {
|
||||
throw QString("Reply is NULL ?!");
|
||||
}
|
||||
QMetaObject::invokeMethod(geometry.data(), "setGeometry", Q_ARG(const FBXGeometry&, fbxgeo));
|
||||
std::string urlname = _url.path().toLower().toStdString();
|
||||
bool urlValid = true;
|
||||
urlValid &= !urlname.empty();
|
||||
urlValid &= !_url.path().isEmpty();
|
||||
urlValid &= _url.path().toLower().endsWith(".fbx")
|
||||
|| _url.path().toLower().endsWith(".svo");
|
||||
|
||||
if (urlValid) {
|
||||
// Let's read the binaries from the network
|
||||
QByteArray fileBinary = _reply->readAll();
|
||||
if (fileBinary.isEmpty() || fileBinary.isNull()) {
|
||||
throw QString("Read File binary is empty?!");
|
||||
}
|
||||
|
||||
FBXGeometry fbxgeo;
|
||||
if (_url.path().toLower().endsWith(".svo")) {
|
||||
fbxgeo = readSVO(fileBinary);
|
||||
} else if (_url.path().toLower().endsWith(".fbx")) {
|
||||
bool grabLightmaps = true;
|
||||
float lightmapLevel = 1.0f;
|
||||
// HACK: For monday 12/01/2014 we need to kill lighmaps loading in starchamber...
|
||||
if (_url.path().toLower().endsWith("loungev4_11-18.fbx")) {
|
||||
grabLightmaps = false;
|
||||
} else if (_url.path().toLower().endsWith("apt8_reboot.fbx")) {
|
||||
lightmapLevel = 4.0f;
|
||||
} else if (_url.path().toLower().endsWith("palaceoforinthilian4.fbx")) {
|
||||
lightmapLevel = 3.5f;
|
||||
}
|
||||
fbxgeo = readFBX(fileBinary, _mapping, grabLightmaps, lightmapLevel);
|
||||
}
|
||||
QMetaObject::invokeMethod(geometry.data(), "setGeometry", Q_ARG(const FBXGeometry&, fbxgeo));
|
||||
} else {
|
||||
throw QString("url is invalid");
|
||||
}
|
||||
|
||||
// _url.path().toLower().endsWith(".svo") ? readSVO(_reply->readAll()) : readFBX(_reply->readAll(), _mapping)));
|
||||
|
||||
} catch (const QString& error) {
|
||||
qDebug() << "Error reading " << _url << ": " << error;
|
||||
QMetaObject::invokeMethod(geometry.data(), "finishedLoading", Q_ARG(bool, false));
|
||||
|
|
|
@ -182,13 +182,6 @@ QVariant MetavoxelEditor::getValue() const {
|
|||
return editor ? editor->metaObject()->userProperty().read(editor) : QVariant();
|
||||
}
|
||||
|
||||
void MetavoxelEditor::detachValue() {
|
||||
SharedObjectEditor* editor = qobject_cast<SharedObjectEditor*>(_valueArea->widget());
|
||||
if (editor) {
|
||||
editor->detachObject();
|
||||
}
|
||||
}
|
||||
|
||||
bool MetavoxelEditor::eventFilter(QObject* watched, QEvent* event) {
|
||||
// pass along to the active tool
|
||||
MetavoxelTool* tool = getActiveTool();
|
||||
|
@ -616,7 +609,7 @@ PlaceSpannerTool::PlaceSpannerTool(MetavoxelEditor* editor, const QString& name,
|
|||
}
|
||||
|
||||
void PlaceSpannerTool::simulate(float deltaTime) {
|
||||
Spanner* spanner = static_cast<Spanner*>(getSpanner(true).data());
|
||||
Spanner* spanner = static_cast<Spanner*>(getSpanner().data());
|
||||
Transformable* transformable = qobject_cast<Transformable*>(spanner);
|
||||
if (transformable && _followMouse->isChecked() && !Application::getInstance()->isMouseHidden()) {
|
||||
// find the intersection of the mouse ray with the grid and place the transformable there
|
||||
|
@ -634,7 +627,7 @@ void PlaceSpannerTool::simulate(float deltaTime) {
|
|||
|
||||
void PlaceSpannerTool::renderPreview() {
|
||||
Spanner* spanner = static_cast<Spanner*>(getSpanner().data());
|
||||
spanner->getRenderer()->render();
|
||||
spanner->getRenderer()->render(Application::getInstance()->getMetavoxels()->getLOD());
|
||||
}
|
||||
|
||||
bool PlaceSpannerTool::appliesTo(const AttributePointer& attribute) const {
|
||||
|
@ -649,10 +642,7 @@ bool PlaceSpannerTool::eventFilter(QObject* watched, QEvent* event) {
|
|||
return false;
|
||||
}
|
||||
|
||||
SharedObjectPointer PlaceSpannerTool::getSpanner(bool detach) {
|
||||
if (detach) {
|
||||
_editor->detachValue();
|
||||
}
|
||||
SharedObjectPointer PlaceSpannerTool::getSpanner() {
|
||||
return _editor->getValue().value<SharedObjectPointer>();
|
||||
}
|
||||
|
||||
|
@ -663,7 +653,7 @@ QColor PlaceSpannerTool::getColor() {
|
|||
void PlaceSpannerTool::place() {
|
||||
AttributePointer attribute = AttributeRegistry::getInstance()->getAttribute(_editor->getSelectedAttribute());
|
||||
if (attribute) {
|
||||
applyEdit(attribute, getSpanner());
|
||||
applyEdit(attribute, getSpanner()->clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -732,11 +722,11 @@ HeightfieldTool::HeightfieldTool(MetavoxelEditor* editor, const QString& name) :
|
|||
layout()->addWidget(widget);
|
||||
|
||||
_form->addRow("Translation:", _translation = new Vec3Editor(widget));
|
||||
_form->addRow("Scale:", _scale = new QDoubleSpinBox());
|
||||
_scale->setMinimum(-FLT_MAX);
|
||||
_scale->setMaximum(FLT_MAX);
|
||||
_scale->setPrefix("2^");
|
||||
_scale->setValue(2.0);
|
||||
_form->addRow("Spacing:", _spacing = new QDoubleSpinBox());
|
||||
_spacing->setMaximum(FLT_MAX);
|
||||
_spacing->setDecimals(3);
|
||||
_spacing->setSingleStep(0.001);
|
||||
_spacing->setValue(1.0);
|
||||
|
||||
QPushButton* applyButton = new QPushButton("Apply");
|
||||
layout()->addWidget(applyButton);
|
||||
|
@ -747,28 +737,20 @@ bool HeightfieldTool::appliesTo(const AttributePointer& attribute) const {
|
|||
return attribute->inherits("SpannerSetAttribute");
|
||||
}
|
||||
|
||||
void HeightfieldTool::render() {
|
||||
float scale = pow(2.0, _scale->value());
|
||||
_translation->setSingleStep(scale);
|
||||
glm::vec3 quantizedTranslation = scale * glm::floor(_translation->getValue() / scale);
|
||||
_translation->setValue(quantizedTranslation);
|
||||
}
|
||||
|
||||
ImportHeightfieldTool::ImportHeightfieldTool(MetavoxelEditor* editor) :
|
||||
HeightfieldTool(editor, "Import Heightfield"),
|
||||
_spanner(new Heightfield()) {
|
||||
|
||||
_form->addRow("Height Scale:", _heightScale = new QDoubleSpinBox());
|
||||
const double MAX_OFFSET_SCALE = 100000.0;
|
||||
_heightScale->setMaximum(MAX_OFFSET_SCALE);
|
||||
_heightScale->setMaximum(FLT_MAX);
|
||||
_heightScale->setSingleStep(0.01);
|
||||
_heightScale->setValue(8.0);
|
||||
_heightScale->setValue(16.0);
|
||||
connect(_heightScale, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this,
|
||||
&ImportHeightfieldTool::updateSpanner);
|
||||
|
||||
_form->addRow("Height Offset:", _heightOffset = new QDoubleSpinBox());
|
||||
_heightOffset->setMinimum(-MAX_OFFSET_SCALE);
|
||||
_heightOffset->setMaximum(MAX_OFFSET_SCALE);
|
||||
_heightOffset->setMinimum(-FLT_MAX);
|
||||
_heightOffset->setMaximum(FLT_MAX);
|
||||
_heightOffset->setSingleStep(0.01);
|
||||
connect(_heightOffset, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this,
|
||||
&ImportHeightfieldTool::updateSpanner);
|
||||
|
@ -780,7 +762,7 @@ ImportHeightfieldTool::ImportHeightfieldTool(MetavoxelEditor* editor) :
|
|||
connect(_color, &HeightfieldColorEditor::colorChanged, this, &ImportHeightfieldTool::updateSpanner);
|
||||
|
||||
connect(_translation, &Vec3Editor::valueChanged, this, &ImportHeightfieldTool::updateSpanner);
|
||||
connect(_scale, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this,
|
||||
connect(_spacing, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this,
|
||||
&ImportHeightfieldTool::updateSpanner);
|
||||
}
|
||||
|
||||
|
@ -789,77 +771,16 @@ void ImportHeightfieldTool::simulate(float deltaTime) {
|
|||
}
|
||||
|
||||
void ImportHeightfieldTool::renderPreview() {
|
||||
static_cast<Heightfield*>(_spanner.data())->getRenderer()->render();
|
||||
static_cast<Heightfield*>(_spanner.data())->getRenderer()->render(Application::getInstance()->getMetavoxels()->getLOD());
|
||||
}
|
||||
|
||||
const int HEIGHTFIELD_BLOCK_SIZE = 256;
|
||||
|
||||
void ImportHeightfieldTool::apply() {
|
||||
AttributePointer attribute = AttributeRegistry::getInstance()->getAttribute(_editor->getSelectedAttribute());
|
||||
if (!(_height->getHeight() && attribute)) {
|
||||
return;
|
||||
}
|
||||
int width = _height->getHeight()->getWidth();
|
||||
const QVector<quint16>& contents = _height->getHeight()->getContents();
|
||||
int height = contents.size() / width;
|
||||
int innerWidth = width - HeightfieldHeight::HEIGHT_EXTENSION;
|
||||
int innerHeight = height - HeightfieldHeight::HEIGHT_EXTENSION;
|
||||
float scale = pow(2.0, _scale->value());
|
||||
|
||||
for (int i = 0; i < innerHeight; i += HEIGHTFIELD_BLOCK_SIZE) {
|
||||
for (int j = 0; j < innerWidth; j += HEIGHTFIELD_BLOCK_SIZE) {
|
||||
Heightfield* heightfield = new Heightfield();
|
||||
|
||||
int extendedHeightSize = HEIGHTFIELD_BLOCK_SIZE + HeightfieldHeight::HEIGHT_EXTENSION;
|
||||
QVector<quint16> heightContents(extendedHeightSize * extendedHeightSize);
|
||||
quint16* dest = heightContents.data();
|
||||
const quint16* src = contents.constData() + i * width + j;
|
||||
int copyWidth = qMin(width - j, extendedHeightSize);
|
||||
int copyHeight = qMin(height - i, extendedHeightSize);
|
||||
for (int z = 0; z < copyHeight; z++, src += width, dest += extendedHeightSize) {
|
||||
memcpy(dest, src, copyWidth * sizeof(quint16));
|
||||
}
|
||||
heightfield->setHeight(HeightfieldHeightPointer(new HeightfieldHeight(extendedHeightSize, heightContents)));
|
||||
|
||||
int materialWidth = HEIGHTFIELD_BLOCK_SIZE + HeightfieldData::SHARED_EDGE;
|
||||
int materialHeight = materialWidth;
|
||||
if (_color->getColor()) {
|
||||
int colorWidth = _color->getColor()->getWidth();
|
||||
const QByteArray& contents = _color->getColor()->getContents();
|
||||
int colorHeight = contents.size() / (colorWidth * DataBlock::COLOR_BYTES);
|
||||
int innerColorWidth = colorWidth - HeightfieldData::SHARED_EDGE;
|
||||
int innerColorHeight = colorHeight - HeightfieldData::SHARED_EDGE;
|
||||
materialWidth = HEIGHTFIELD_BLOCK_SIZE * innerColorWidth / innerWidth + HeightfieldData::SHARED_EDGE;
|
||||
materialHeight = HEIGHTFIELD_BLOCK_SIZE * innerColorHeight / innerHeight + HeightfieldData::SHARED_EDGE;
|
||||
QByteArray colorContents(materialWidth * materialHeight * DataBlock::COLOR_BYTES, 0);
|
||||
int colorI = i * (materialWidth - HeightfieldData::SHARED_EDGE) / HEIGHTFIELD_BLOCK_SIZE;
|
||||
int colorJ = j * (materialHeight - HeightfieldData::SHARED_EDGE) / HEIGHTFIELD_BLOCK_SIZE;
|
||||
char* dest = colorContents.data();
|
||||
const char* src = contents.constData() + (colorI * colorWidth + colorJ) * DataBlock::COLOR_BYTES;
|
||||
int copyWidth = qMin(colorWidth - colorJ, materialWidth);
|
||||
int copyHeight = qMin(colorHeight - colorI, materialHeight);
|
||||
for (int z = 0; z < copyHeight; z++, src += colorWidth * DataBlock::COLOR_BYTES,
|
||||
dest += materialWidth * DataBlock::COLOR_BYTES) {
|
||||
memcpy(dest, src, copyWidth * DataBlock::COLOR_BYTES);
|
||||
}
|
||||
heightfield->setColor(HeightfieldColorPointer(new HeightfieldColor(materialWidth, colorContents)));
|
||||
|
||||
} else {
|
||||
heightfield->setColor(HeightfieldColorPointer(new HeightfieldColor(materialWidth,
|
||||
QByteArray(materialWidth * materialHeight * DataBlock::COLOR_BYTES, 0xFF))));
|
||||
}
|
||||
heightfield->setMaterial(HeightfieldMaterialPointer(new HeightfieldMaterial(materialWidth,
|
||||
QByteArray(materialWidth * materialHeight, 0), QVector<SharedObjectPointer>())));
|
||||
|
||||
heightfield->setScale(scale);
|
||||
heightfield->setAspectY(_heightScale->value() / scale);
|
||||
heightfield->setTranslation(_translation->getValue() + glm::vec3((j / HEIGHTFIELD_BLOCK_SIZE) * scale,
|
||||
_heightOffset->value(), (i / HEIGHTFIELD_BLOCK_SIZE) * scale));
|
||||
|
||||
MetavoxelEditMessage message = { QVariant::fromValue(InsertSpannerEdit(attribute, heightfield)) };
|
||||
Application::getInstance()->getMetavoxels()->applyEdit(message, true);
|
||||
}
|
||||
}
|
||||
MetavoxelEditMessage message = { QVariant::fromValue(InsertSpannerEdit(attribute, _spanner->clone())) };
|
||||
Application::getInstance()->getMetavoxels()->applyEdit(message, true);
|
||||
}
|
||||
|
||||
void ImportHeightfieldTool::updateSpanner() {
|
||||
|
@ -867,15 +788,14 @@ void ImportHeightfieldTool::updateSpanner() {
|
|||
heightfield->setHeight(_height->getHeight());
|
||||
heightfield->setColor(_color->getColor());
|
||||
|
||||
float scale = pow(2.0, _scale->value());
|
||||
float scale = 1.0f;
|
||||
float aspectZ = 1.0f;
|
||||
if (_height->getHeight()) {
|
||||
int width = _height->getHeight()->getWidth();
|
||||
int innerWidth = width - HeightfieldHeight::HEIGHT_EXTENSION;
|
||||
int innerHeight = _height->getHeight()->getContents().size() / width - HeightfieldHeight::HEIGHT_EXTENSION;
|
||||
float widthBlocks = glm::ceil((float)innerWidth / HEIGHTFIELD_BLOCK_SIZE);
|
||||
scale *= widthBlocks;
|
||||
aspectZ = glm::ceil((float)innerHeight / HEIGHTFIELD_BLOCK_SIZE) / widthBlocks;
|
||||
scale = innerWidth * _spacing->value();
|
||||
aspectZ = (float)innerHeight / innerWidth;
|
||||
}
|
||||
heightfield->setScale(scale);
|
||||
heightfield->setAspectY(_heightScale->value() / scale);
|
||||
|
@ -970,7 +890,8 @@ MaterialControl::MaterialControl(QWidget* widget, QFormLayout* form, bool cleara
|
|||
SharedObjectPointer MaterialControl::getMaterial() {
|
||||
SharedObjectPointer material = _materialEditor->getObject();
|
||||
if (static_cast<MaterialObject*>(material.data())->getDiffuse().isValid()) {
|
||||
_materialEditor->detachObject();
|
||||
material = material->clone();
|
||||
|
||||
} else {
|
||||
material = SharedObjectPointer();
|
||||
}
|
||||
|
@ -1087,10 +1008,7 @@ bool VoxelMaterialSpannerTool::appliesTo(const AttributePointer& attribute) cons
|
|||
return attribute->inherits("VoxelColorAttribute");
|
||||
}
|
||||
|
||||
SharedObjectPointer VoxelMaterialSpannerTool::getSpanner(bool detach) {
|
||||
if (detach) {
|
||||
_spannerEditor->detachObject();
|
||||
}
|
||||
SharedObjectPointer VoxelMaterialSpannerTool::getSpanner() {
|
||||
return _spannerEditor->getObject();
|
||||
}
|
||||
|
||||
|
@ -1099,7 +1017,7 @@ QColor VoxelMaterialSpannerTool::getColor() {
|
|||
}
|
||||
|
||||
void VoxelMaterialSpannerTool::applyEdit(const AttributePointer& attribute, const SharedObjectPointer& spanner) {
|
||||
_spannerEditor->detachObject();
|
||||
static_cast<Spanner*>(spanner.data())->setWillBeVoxelized(true);
|
||||
MetavoxelEditMessage message = { QVariant::fromValue(VoxelMaterialSpannerEdit(spanner,
|
||||
_materialControl->getMaterial(), _materialControl->getColor())) };
|
||||
Application::getInstance()->getMetavoxels()->applyEdit(message, true);
|
||||
|
|
|
@ -46,7 +46,6 @@ public:
|
|||
glm::quat getGridRotation() const;
|
||||
|
||||
QVariant getValue() const;
|
||||
void detachValue();
|
||||
|
||||
virtual bool eventFilter(QObject* watched, QEvent* event);
|
||||
|
||||
|
@ -197,7 +196,7 @@ public:
|
|||
protected:
|
||||
|
||||
virtual QColor getColor();
|
||||
virtual SharedObjectPointer getSpanner(bool detach = false);
|
||||
virtual SharedObjectPointer getSpanner();
|
||||
virtual void applyEdit(const AttributePointer& attribute, const SharedObjectPointer& spanner) = 0;
|
||||
|
||||
protected slots:
|
||||
|
@ -260,8 +259,6 @@ public:
|
|||
|
||||
virtual bool appliesTo(const AttributePointer& attribute) const;
|
||||
|
||||
virtual void render();
|
||||
|
||||
protected slots:
|
||||
|
||||
virtual void apply() = 0;
|
||||
|
@ -270,7 +267,7 @@ protected:
|
|||
|
||||
QFormLayout* _form;
|
||||
Vec3Editor* _translation;
|
||||
QDoubleSpinBox* _scale;
|
||||
QDoubleSpinBox* _spacing;
|
||||
};
|
||||
|
||||
/// Allows importing a heightfield.
|
||||
|
@ -425,7 +422,7 @@ public:
|
|||
|
||||
protected:
|
||||
|
||||
virtual SharedObjectPointer getSpanner(bool detach = false);
|
||||
virtual SharedObjectPointer getSpanner();
|
||||
virtual QColor getColor();
|
||||
virtual void applyEdit(const AttributePointer& attribute, const SharedObjectPointer& spanner);
|
||||
|
||||
|
|
|
@ -1046,6 +1046,7 @@ FBXBlendshape extractBlendshape(const FBXNode& object) {
|
|||
return blendshape;
|
||||
}
|
||||
|
||||
|
||||
void setTangents(FBXMesh& mesh, int firstIndex, int secondIndex) {
|
||||
const glm::vec3& normal = mesh.normals.at(firstIndex);
|
||||
glm::vec3 bitangent = glm::cross(normal, mesh.vertices.at(secondIndex) - mesh.vertices.at(firstIndex));
|
||||
|
@ -1194,6 +1195,44 @@ int matchTextureUVSetToAttributeChannel(const std::string& texUVSetName, const Q
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
FBXLight extractLight(const FBXNode& object) {
|
||||
FBXLight light;
|
||||
|
||||
foreach (const FBXNode& subobject, object.children) {
|
||||
std::string childname = QString(subobject.name).toStdString();
|
||||
if (subobject.name == "Properties70") {
|
||||
foreach (const FBXNode& property, subobject.children) {
|
||||
int valIndex = 4;
|
||||
std::string propName = QString(property.name).toStdString();
|
||||
if (property.name == "P") {
|
||||
std::string propname = property.properties.at(0).toString().toStdString();
|
||||
if (propname == "Intensity") {
|
||||
light.intensity = 0.01f * property.properties.at(valIndex).value<double>();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ( subobject.name == "GeometryVersion"
|
||||
|| subobject.name == "TypeFlags") {
|
||||
}
|
||||
}
|
||||
#if defined(DEBUG_FBXREADER)
|
||||
|
||||
std::string type = object.properties.at(0).toString().toStdString();
|
||||
type = object.properties.at(1).toString().toStdString();
|
||||
type = object.properties.at(2).toString().toStdString();
|
||||
|
||||
foreach (const QVariant& prop, object.properties) {
|
||||
std::string proptype = prop.typeName();
|
||||
std::string propval = prop.toString().toStdString();
|
||||
if (proptype == "Properties70") {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return light;
|
||||
}
|
||||
|
||||
FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping, bool loadLightmaps, float lightmapLevel) {
|
||||
QHash<QString, ExtractedMesh> meshes;
|
||||
QHash<QString, QString> modelIDsToNames;
|
||||
|
@ -1222,6 +1261,8 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping,
|
|||
QHash<QString, QString> yComponents;
|
||||
QHash<QString, QString> zComponents;
|
||||
|
||||
std::map<std::string, FBXLight> lights;
|
||||
|
||||
QVariantHash joints = mapping.value("joint").toHash();
|
||||
QString jointEyeLeftName = processID(getString(joints.value("jointEyeLeft", "jointEyeLeft")));
|
||||
QString jointEyeRightName = processID(getString(joints.value("jointEyeRight", "jointEyeRight")));
|
||||
|
@ -1276,6 +1317,8 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping,
|
|||
#endif
|
||||
FBXGeometry geometry;
|
||||
float unitScaleFactor = 1.0f;
|
||||
glm::vec3 ambientColor;
|
||||
QString hifiGlobalNodeID;
|
||||
foreach (const FBXNode& child, node.children) {
|
||||
|
||||
if (child.name == "FBXHeaderExtension") {
|
||||
|
@ -1302,10 +1345,16 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping,
|
|||
} else if (child.name == "GlobalSettings") {
|
||||
foreach (const FBXNode& object, child.children) {
|
||||
if (object.name == "Properties70") {
|
||||
QString propertyName = "P";
|
||||
int index = 4;
|
||||
foreach (const FBXNode& subobject, object.children) {
|
||||
if (subobject.name == "P" && subobject.properties.size() >= 5 &&
|
||||
subobject.properties.at(0) == "UnitScaleFactor") {
|
||||
unitScaleFactor = subobject.properties.at(4).toFloat();
|
||||
if (subobject.name == propertyName) {
|
||||
std::string subpropName = subobject.properties.at(0).toString().toStdString();
|
||||
if (subpropName == "UnitScaleFactor") {
|
||||
unitScaleFactor = subobject.properties.at(index).toFloat();
|
||||
} else if (subpropName == "AmbientColor") {
|
||||
ambientColor = getVec3(subobject.properties, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1324,6 +1373,11 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping,
|
|||
QString id = getID(object.properties);
|
||||
modelIDsToNames.insert(id, name);
|
||||
|
||||
std::string modelname = name.toLower().toStdString();
|
||||
if (modelname.find("hifi") == 0) {
|
||||
hifiGlobalNodeID = id;
|
||||
}
|
||||
|
||||
if (name == jointEyeLeftName || name == "EyeL" || name == "joint_Leye") {
|
||||
jointEyeLeftID = getID(object.properties);
|
||||
|
||||
|
@ -1354,6 +1408,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping,
|
|||
} else if (name == "RightToe" || name == "joint_R_toe" || name == "RightToe_End") {
|
||||
jointRightToeID = getID(object.properties);
|
||||
}
|
||||
|
||||
int humanIKJointIndex = humanIKJointNames.indexOf(name);
|
||||
if (humanIKJointIndex != -1) {
|
||||
humanIKJointIDs[humanIKJointIndex] = getID(object.properties);
|
||||
|
@ -1450,6 +1505,25 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping,
|
|||
extractBlendshape(subobject) };
|
||||
blendshapes.append(blendshape);
|
||||
}
|
||||
#if defined(DEBUG_FBXREADER)
|
||||
else if (subobject.name == "TypeFlags") {
|
||||
std::string attributetype = subobject.properties.at(0).toString().toStdString();
|
||||
if (!attributetype.empty()) {
|
||||
if (attributetype == "Light") {
|
||||
std::string lightprop;
|
||||
foreach (const QVariant& vprop, subobject.properties) {
|
||||
lightprop = vprop.toString().toStdString();
|
||||
}
|
||||
|
||||
FBXLight light = extractLight(object);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
std::string whatisthat = subobject.name;
|
||||
if (whatisthat == "WTF") {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// add the blendshapes included in the model, if any
|
||||
|
@ -1477,7 +1551,6 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping,
|
|||
|
||||
} else if (object.name == "Texture") {
|
||||
TextureParam tex;
|
||||
bool texparam = false;
|
||||
foreach (const FBXNode& subobject, object.children) {
|
||||
if (subobject.name == "RelativeFilename") {
|
||||
// trim off any path information
|
||||
|
@ -1625,11 +1698,28 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping,
|
|||
materials.insert(material.id, material);
|
||||
|
||||
} else if (object.name == "NodeAttribute") {
|
||||
#if defined(DEBUG_FBXREADER)
|
||||
std::vector<std::string> properties;
|
||||
foreach(const QVariant& v, object.properties) {
|
||||
properties.push_back(v.toString().toStdString());
|
||||
}
|
||||
#endif
|
||||
std::string attribID = getID(object.properties).toStdString();
|
||||
std::string attributetype;
|
||||
foreach (const FBXNode& subobject, object.children) {
|
||||
if (subobject.name == "TypeFlags") {
|
||||
typeFlags.insert(getID(object.properties), subobject.properties.at(0).toString());
|
||||
attributetype = subobject.properties.at(0).toString().toStdString();
|
||||
}
|
||||
}
|
||||
|
||||
if (!attributetype.empty()) {
|
||||
if (attributetype == "Light") {
|
||||
FBXLight light = extractLight(object);
|
||||
lights[attribID] = light;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (object.name == "Deformer") {
|
||||
if (object.properties.last() == "Cluster") {
|
||||
Cluster cluster;
|
||||
|
@ -1667,7 +1757,20 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping,
|
|||
}
|
||||
}
|
||||
animationCurves.insert(getID(object.properties), curve);
|
||||
|
||||
}
|
||||
#if defined(DEBUG_FBXREADER)
|
||||
else {
|
||||
std::string objectname = object.name.data();
|
||||
if ( objectname == "Pose"
|
||||
|| objectname == "AnimationStack"
|
||||
|| objectname == "AnimationLayer"
|
||||
|| objectname == "AnimationCurveNode") {
|
||||
} else {
|
||||
unknown++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} else if (child.name == "Connections") {
|
||||
foreach (const FBXNode& connection, child.children) {
|
||||
|
@ -1676,6 +1779,15 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping,
|
|||
QString childID = getID(connection.properties, 1);
|
||||
QString parentID = getID(connection.properties, 2);
|
||||
ooChildToParent.insert(childID, parentID);
|
||||
if (!hifiGlobalNodeID.isEmpty() && (parentID == hifiGlobalNodeID)) {
|
||||
std::map< std::string, FBXLight >::iterator lit = lights.find(childID.toStdString());
|
||||
if (lit != lights.end()) {
|
||||
lightmapLevel = (*lit).second.intensity;
|
||||
if (lightmapLevel <= 0.0f) {
|
||||
loadLightmaps = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (connection.properties.at(0) == "OP") {
|
||||
int counter = 0;
|
||||
|
@ -1719,6 +1831,33 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping,
|
|||
}
|
||||
}
|
||||
}
|
||||
#if defined(DEBUG_FBXREADER)
|
||||
else {
|
||||
std::string objectname = child.name.data();
|
||||
if ( objectname == "Pose"
|
||||
|| objectname == "CreationTime"
|
||||
|| objectname == "FileId"
|
||||
|| objectname == "Creator"
|
||||
|| objectname == "Documents"
|
||||
|| objectname == "References"
|
||||
|| objectname == "Definitions"
|
||||
|| objectname == "Takes"
|
||||
|| objectname == "AnimationStack"
|
||||
|| objectname == "AnimationLayer"
|
||||
|| objectname == "AnimationCurveNode") {
|
||||
} else {
|
||||
unknown++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// TODO: check if is code is needed
|
||||
if (!lights.empty()) {
|
||||
if (hifiGlobalNodeID.isEmpty()) {
|
||||
std::map< std::string, FBXLight >::iterator l = lights.begin();
|
||||
lightmapLevel = (*l).second.intensity;
|
||||
}
|
||||
}
|
||||
|
||||
// assign the blendshapes to their corresponding meshes
|
||||
|
@ -1957,7 +2096,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping,
|
|||
emissiveParams.y = lightmapLevel;
|
||||
QString emissiveTextureID = emissiveTextures.value(childID);
|
||||
QString ambientTextureID = ambientTextures.value(childID);
|
||||
if (!emissiveTextureID.isNull() || !ambientTextureID.isNull()) {
|
||||
if (loadLightmaps && (!emissiveTextureID.isNull() || !ambientTextureID.isNull())) {
|
||||
|
||||
if (!emissiveTextureID.isNull()) {
|
||||
emissiveTexture = getTexture(emissiveTextureID, textureNames, textureFilenames, textureContent, textureParams);
|
||||
|
|
|
@ -165,6 +165,22 @@ public:
|
|||
QVector<glm::quat> rotations;
|
||||
};
|
||||
|
||||
/// A light in an FBX document.
|
||||
class FBXLight {
|
||||
public:
|
||||
QString name;
|
||||
Transform transform;
|
||||
float intensity;
|
||||
glm::vec3 color;
|
||||
|
||||
FBXLight() :
|
||||
name(),
|
||||
transform(),
|
||||
intensity(1.0f),
|
||||
color(1.0f)
|
||||
{}
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(FBXAnimationFrame)
|
||||
Q_DECLARE_METATYPE(QVector<FBXAnimationFrame>)
|
||||
|
||||
|
|
|
@ -1274,25 +1274,37 @@ void SpannerSetAttribute::writeMetavoxelRoot(const MetavoxelNode& root, Metavoxe
|
|||
|
||||
void SpannerSetAttribute::readMetavoxelDelta(MetavoxelData& data,
|
||||
const MetavoxelNode& reference, MetavoxelStreamState& state) {
|
||||
forever {
|
||||
SharedObjectPointer object;
|
||||
state.base.stream >> object;
|
||||
if (!object) {
|
||||
break;
|
||||
readMetavoxelSubdivision(data, state);
|
||||
}
|
||||
|
||||
static void writeDeltaSubdivision(SharedObjectSet& oldSet, SharedObjectSet& newSet, Bitstream& stream) {
|
||||
for (SharedObjectSet::iterator newIt = newSet.begin(); newIt != newSet.end(); ) {
|
||||
SharedObjectSet::iterator oldIt = oldSet.find(*newIt);
|
||||
if (oldIt == oldSet.end()) {
|
||||
stream << *newIt; // added
|
||||
newIt = newSet.erase(newIt);
|
||||
|
||||
} else {
|
||||
oldSet.erase(oldIt);
|
||||
newIt++;
|
||||
}
|
||||
data.toggle(state.base.attribute, object);
|
||||
}
|
||||
// even if the root is empty, it should still exist
|
||||
if (!data.getRoot(state.base.attribute)) {
|
||||
data.createRoot(state.base.attribute);
|
||||
foreach (const SharedObjectPointer& object, oldSet) {
|
||||
stream << object; // removed
|
||||
}
|
||||
stream << SharedObjectPointer();
|
||||
foreach (const SharedObjectPointer& object, newSet) {
|
||||
object->maybeWriteSubdivision(stream);
|
||||
}
|
||||
stream << SharedObjectPointer();
|
||||
}
|
||||
|
||||
void SpannerSetAttribute::writeMetavoxelDelta(const MetavoxelNode& root,
|
||||
const MetavoxelNode& reference, MetavoxelStreamState& state) {
|
||||
state.base.visit = Spanner::getAndIncrementNextVisit();
|
||||
root.writeSpannerDelta(reference, state);
|
||||
state.base.stream << SharedObjectPointer();
|
||||
SharedObjectSet oldSet, newSet;
|
||||
reference.getSpanners(this, state.minimum, state.size, state.base.referenceLOD, oldSet);
|
||||
root.getSpanners(this, state.minimum, state.size, state.base.lod, newSet);
|
||||
writeDeltaSubdivision(oldSet, newSet, state.base.stream);
|
||||
}
|
||||
|
||||
void SpannerSetAttribute::readMetavoxelSubdivision(MetavoxelData& data, MetavoxelStreamState& state) {
|
||||
|
@ -1302,14 +1314,31 @@ void SpannerSetAttribute::readMetavoxelSubdivision(MetavoxelData& data, Metavoxe
|
|||
if (!object) {
|
||||
break;
|
||||
}
|
||||
data.insert(state.base.attribute, object);
|
||||
data.toggle(state.base.attribute, object);
|
||||
}
|
||||
forever {
|
||||
SharedObjectPointer object;
|
||||
state.base.stream >> object;
|
||||
if (!object) {
|
||||
break;
|
||||
}
|
||||
SharedObjectPointer newObject = object->readSubdivision(state.base.stream);
|
||||
if (newObject != object) {
|
||||
data.replace(state.base.attribute, object, newObject);
|
||||
state.base.stream.addSubdividedObject(newObject);
|
||||
}
|
||||
}
|
||||
// even if the root is empty, it should still exist
|
||||
if (!data.getRoot(state.base.attribute)) {
|
||||
data.createRoot(state.base.attribute);
|
||||
}
|
||||
}
|
||||
|
||||
void SpannerSetAttribute::writeMetavoxelSubdivision(const MetavoxelNode& root, MetavoxelStreamState& state) {
|
||||
state.base.visit = Spanner::getAndIncrementNextVisit();
|
||||
root.writeSpannerSubdivision(state);
|
||||
state.base.stream << SharedObjectPointer();
|
||||
SharedObjectSet oldSet, newSet;
|
||||
root.getSpanners(this, state.minimum, state.size, state.base.referenceLOD, oldSet);
|
||||
root.getSpanners(this, state.minimum, state.size, state.base.lod, newSet);
|
||||
writeDeltaSubdivision(oldSet, newSet, state.base.stream);
|
||||
}
|
||||
|
||||
bool SpannerSetAttribute::metavoxelRootsEqual(const MetavoxelNode& firstRoot, const MetavoxelNode& secondRoot,
|
||||
|
|
|
@ -151,6 +151,7 @@ Bitstream::Bitstream(QDataStream& underlying, MetadataType metadataType, Generic
|
|||
_position(0),
|
||||
_metadataType(metadataType),
|
||||
_genericsMode(genericsMode),
|
||||
_context(NULL),
|
||||
_objectStreamerStreamer(*this),
|
||||
_typeStreamerStreamer(*this),
|
||||
_attributeStreamer(*this),
|
||||
|
@ -266,7 +267,9 @@ Bitstream::ReadMappings Bitstream::getAndResetReadMappings() {
|
|||
_typeStreamerStreamer.getAndResetTransientValues(),
|
||||
_attributeStreamer.getAndResetTransientValues(),
|
||||
_scriptStringStreamer.getAndResetTransientValues(),
|
||||
_sharedObjectStreamer.getAndResetTransientValues() };
|
||||
_sharedObjectStreamer.getAndResetTransientValues(),
|
||||
_subdividedObjects };
|
||||
_subdividedObjects.clear();
|
||||
return mappings;
|
||||
}
|
||||
|
||||
|
@ -290,6 +293,16 @@ void Bitstream::persistReadMappings(const ReadMappings& mappings) {
|
|||
reference = it.value();
|
||||
_weakSharedObjectHash.remove(it.value()->getRemoteID());
|
||||
}
|
||||
foreach (const SharedObjectPointer& object, mappings.subdividedObjects) {
|
||||
QPointer<SharedObject>& reference = _sharedObjectReferences[object->getRemoteOriginID()];
|
||||
if (reference && reference != object) {
|
||||
int id = _sharedObjectStreamer.removePersistentValue(reference.data());
|
||||
if (id != 0) {
|
||||
_sharedObjectStreamer.insertPersistentValue(id, object);
|
||||
}
|
||||
}
|
||||
reference = object;
|
||||
}
|
||||
}
|
||||
|
||||
void Bitstream::persistAndResetReadMappings() {
|
||||
|
@ -1155,6 +1168,16 @@ Bitstream& Bitstream::operator<(const ObjectStreamer* streamer) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
static MappedObjectStreamer* createMappedObjectStreamer(const QMetaObject* metaObject,
|
||||
const QVector<StreamerPropertyPair>& properties) {
|
||||
for (const QMetaObject* super = metaObject; super; super = super->superClass()) {
|
||||
if (super == &SharedObject::staticMetaObject) {
|
||||
return new SharedObjectStreamer(metaObject, properties);
|
||||
}
|
||||
}
|
||||
return new MappedObjectStreamer(metaObject, properties);
|
||||
}
|
||||
|
||||
Bitstream& Bitstream::operator>(ObjectStreamerPointer& streamer) {
|
||||
QByteArray className;
|
||||
*this >> className;
|
||||
|
@ -1230,7 +1253,7 @@ Bitstream& Bitstream::operator>(ObjectStreamerPointer& streamer) {
|
|||
} else if (metaObject) {
|
||||
const QVector<StreamerPropertyPair>& localProperties = streamer->getProperties();
|
||||
if (localProperties.size() != properties.size()) {
|
||||
streamer = ObjectStreamerPointer(new MappedObjectStreamer(metaObject, properties));
|
||||
streamer = ObjectStreamerPointer(createMappedObjectStreamer(metaObject, properties));
|
||||
return *this;
|
||||
}
|
||||
for (int i = 0; i < localProperties.size(); i++) {
|
||||
|
@ -1238,13 +1261,13 @@ Bitstream& Bitstream::operator>(ObjectStreamerPointer& streamer) {
|
|||
const StreamerPropertyPair& localProperty = localProperties.at(i);
|
||||
if (property.first != localProperty.first ||
|
||||
property.second.propertyIndex() != localProperty.second.propertyIndex()) {
|
||||
streamer = ObjectStreamerPointer(new MappedObjectStreamer(metaObject, properties));
|
||||
streamer = ObjectStreamerPointer(createMappedObjectStreamer(metaObject, properties));
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
streamer = ObjectStreamerPointer(new MappedObjectStreamer(metaObject, properties));
|
||||
streamer = ObjectStreamerPointer(createMappedObjectStreamer(metaObject, properties));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -1670,7 +1693,7 @@ QHash<const QMetaObject*, const ObjectStreamer*> Bitstream::createObjectStreamer
|
|||
properties.append(StreamerPropertyPair(streamer->getSelf(), property));
|
||||
}
|
||||
}
|
||||
ObjectStreamerPointer streamer = ObjectStreamerPointer(new MappedObjectStreamer(metaObject, properties));
|
||||
ObjectStreamerPointer streamer = ObjectStreamerPointer(createMappedObjectStreamer(metaObject, properties));
|
||||
streamer->_self = streamer;
|
||||
objectStreamers.insert(metaObject, streamer.data());
|
||||
}
|
||||
|
@ -2121,7 +2144,7 @@ JSONReader::JSONReader(const QJsonDocument& document, Bitstream::GenericsMode ge
|
|||
if (matches) {
|
||||
_objectStreamers.insert(name, baseStreamer->getSelf());
|
||||
} else {
|
||||
_objectStreamers.insert(name, ObjectStreamerPointer(new MappedObjectStreamer(metaObject, properties)));
|
||||
_objectStreamers.insert(name, ObjectStreamerPointer(createMappedObjectStreamer(metaObject, properties)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2436,6 +2459,32 @@ QObject* MappedObjectStreamer::readRawDelta(Bitstream& in, const QObject* refere
|
|||
return object;
|
||||
}
|
||||
|
||||
SharedObjectStreamer::SharedObjectStreamer(const QMetaObject* metaObject, const QVector<StreamerPropertyPair>& properties) :
|
||||
MappedObjectStreamer(metaObject, properties) {
|
||||
}
|
||||
|
||||
void SharedObjectStreamer::write(Bitstream& out, const QObject* object) const {
|
||||
MappedObjectStreamer::write(out, object);
|
||||
static_cast<const SharedObject*>(object)->writeExtra(out);
|
||||
}
|
||||
|
||||
void SharedObjectStreamer::writeRawDelta(Bitstream& out, const QObject* object, const QObject* reference) const {
|
||||
MappedObjectStreamer::writeRawDelta(out, object, reference);
|
||||
static_cast<const SharedObject*>(object)->writeExtraDelta(out, static_cast<const SharedObject*>(reference));
|
||||
}
|
||||
|
||||
QObject* SharedObjectStreamer::read(Bitstream& in, QObject* object) const {
|
||||
QObject* result = MappedObjectStreamer::read(in, object);
|
||||
static_cast<SharedObject*>(result)->readExtra(in);
|
||||
return result;
|
||||
}
|
||||
|
||||
QObject* SharedObjectStreamer::readRawDelta(Bitstream& in, const QObject* reference, QObject* object) const {
|
||||
QObject* result = MappedObjectStreamer::readRawDelta(in, reference, object);
|
||||
static_cast<SharedObject*>(result)->readExtraDelta(in, static_cast<const SharedObject*>(reference));
|
||||
return result;
|
||||
}
|
||||
|
||||
GenericObjectStreamer::GenericObjectStreamer(const QByteArray& name, const QVector<StreamerNamePair>& properties,
|
||||
const QByteArray& hash) :
|
||||
ObjectStreamer(&GenericSharedObject::staticMetaObject),
|
||||
|
|
|
@ -99,10 +99,12 @@ public:
|
|||
|
||||
int takePersistentID(P value) { return _persistentIDs.take(value); }
|
||||
|
||||
void removePersistentValue(V value) { int id = _valueIDs.take(value); _persistentValues.remove(id); }
|
||||
int removePersistentValue(V value) { int id = _valueIDs.take(value); _persistentValues.remove(id); return id; }
|
||||
|
||||
V takePersistentValue(int id) { V value = _persistentValues.take(id); _valueIDs.remove(value); return value; }
|
||||
|
||||
void insertPersistentValue(int id, V value) { _valueIDs.insert(value, id); _persistentValues.insert(id, value); }
|
||||
|
||||
void copyPersistentMappings(const RepeatedValueStreamer& other);
|
||||
void clearPersistentMappings();
|
||||
|
||||
|
@ -289,6 +291,7 @@ public:
|
|||
QHash<int, AttributePointer> attributeValues;
|
||||
QHash<int, QScriptString> scriptStringValues;
|
||||
QHash<int, SharedObjectPointer> sharedObjectValues;
|
||||
QVector<SharedObjectPointer> subdividedObjects;
|
||||
};
|
||||
|
||||
/// Performs all of the various lazily initializations (of object streamers, etc.) If multiple threads need to use
|
||||
|
@ -342,6 +345,12 @@ public:
|
|||
/// Returns a reference to the underlying data stream.
|
||||
QDataStream& getUnderlying() { return _underlying; }
|
||||
|
||||
/// Sets the context pointer.
|
||||
void setContext(void* context) { _context = context; }
|
||||
|
||||
/// Returns the context pointer.
|
||||
void* getContext() const { return _context; }
|
||||
|
||||
/// Substitutes the supplied metaobject for the given class name's default mapping. This is mostly useful for testing the
|
||||
/// process of mapping between different types, but may in the future be used for permanently renaming classes.
|
||||
void addMetaObjectSubstitution(const QByteArray& className, const QMetaObject* metaObject);
|
||||
|
@ -368,6 +377,9 @@ public:
|
|||
/// Resets to the initial state.
|
||||
void reset();
|
||||
|
||||
/// Adds a subdivided object, which will be added to the read mappings and used as a reference if persisted.
|
||||
void addSubdividedObject(const SharedObjectPointer& object) { _subdividedObjects.append(object); }
|
||||
|
||||
/// Returns the set of transient mappings gathered during writing and resets them.
|
||||
WriteMappings getAndResetWriteMappings();
|
||||
|
||||
|
@ -562,12 +574,16 @@ private:
|
|||
MetadataType _metadataType;
|
||||
GenericsMode _genericsMode;
|
||||
|
||||
void* _context;
|
||||
|
||||
RepeatedValueStreamer<const ObjectStreamer*, const ObjectStreamer*, ObjectStreamerPointer> _objectStreamerStreamer;
|
||||
RepeatedValueStreamer<const TypeStreamer*, const TypeStreamer*, TypeStreamerPointer> _typeStreamerStreamer;
|
||||
RepeatedValueStreamer<AttributePointer> _attributeStreamer;
|
||||
RepeatedValueStreamer<QScriptString> _scriptStringStreamer;
|
||||
RepeatedValueStreamer<SharedObjectPointer, SharedObject*> _sharedObjectStreamer;
|
||||
|
||||
QVector<SharedObjectPointer> _subdividedObjects;
|
||||
|
||||
WeakSharedObjectHash _sharedObjectReferences;
|
||||
|
||||
WeakSharedObjectHash _weakSharedObjectHash;
|
||||
|
@ -1125,6 +1141,18 @@ private:
|
|||
QVector<StreamerPropertyPair> _properties;
|
||||
};
|
||||
|
||||
/// A streamer that maps to a local shared object class. Shared objects can write extra, non-property data.
|
||||
class SharedObjectStreamer : public MappedObjectStreamer {
|
||||
public:
|
||||
|
||||
SharedObjectStreamer(const QMetaObject* metaObject, const QVector<StreamerPropertyPair>& properties);
|
||||
|
||||
virtual void write(Bitstream& out, const QObject* object) const;
|
||||
virtual void writeRawDelta(Bitstream& out, const QObject* object, const QObject* reference) const;
|
||||
virtual QObject* read(Bitstream& in, QObject* object = NULL) const;
|
||||
virtual QObject* readRawDelta(Bitstream& in, const QObject* reference, QObject* object = NULL) const;
|
||||
};
|
||||
|
||||
typedef QPair<TypeStreamerPointer, QByteArray> StreamerNamePair;
|
||||
|
||||
/// A streamer for generic objects.
|
||||
|
|
|
@ -239,39 +239,44 @@ void DatagramSequencer::receivedDatagram(const QByteArray& datagram) {
|
|||
_sendRecords.erase(_sendRecords.begin(), it + 1);
|
||||
}
|
||||
|
||||
// alert external parties so that they can read the middle
|
||||
emit readyToRead(_inputStream);
|
||||
|
||||
// read and dispatch the high-priority messages
|
||||
int highPriorityMessageCount;
|
||||
_inputStream >> highPriorityMessageCount;
|
||||
int newHighPriorityMessages = highPriorityMessageCount - _receivedHighPriorityMessages;
|
||||
for (int i = 0; i < highPriorityMessageCount; i++) {
|
||||
QVariant data;
|
||||
_inputStream >> data;
|
||||
if (i >= _receivedHighPriorityMessages) {
|
||||
emit receivedHighPriorityMessage(data);
|
||||
try {
|
||||
// alert external parties so that they can read the middle
|
||||
emit readyToRead(_inputStream);
|
||||
|
||||
// read and dispatch the high-priority messages
|
||||
int highPriorityMessageCount;
|
||||
_inputStream >> highPriorityMessageCount;
|
||||
int newHighPriorityMessages = highPriorityMessageCount - _receivedHighPriorityMessages;
|
||||
for (int i = 0; i < highPriorityMessageCount; i++) {
|
||||
QVariant data;
|
||||
_inputStream >> data;
|
||||
if (i >= _receivedHighPriorityMessages) {
|
||||
emit receivedHighPriorityMessage(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
_receivedHighPriorityMessages = highPriorityMessageCount;
|
||||
_receivedHighPriorityMessages = highPriorityMessageCount;
|
||||
|
||||
// read the reliable data, if any
|
||||
quint32 reliableChannels;
|
||||
_incomingPacketStream >> reliableChannels;
|
||||
for (quint32 i = 0; i < reliableChannels; i++) {
|
||||
quint32 channelIndex;
|
||||
_incomingPacketStream >> channelIndex;
|
||||
getReliableInputChannel(channelIndex)->readData(_incomingPacketStream);
|
||||
}
|
||||
|
||||
// record the receipt
|
||||
ReceiveRecord record = { _incomingPacketNumber, _inputStream.getAndResetReadMappings(), newHighPriorityMessages };
|
||||
_receiveRecords.append(record);
|
||||
|
||||
emit receiveRecorded();
|
||||
|
||||
// read the reliable data, if any
|
||||
quint32 reliableChannels;
|
||||
_incomingPacketStream >> reliableChannels;
|
||||
for (quint32 i = 0; i < reliableChannels; i++) {
|
||||
quint32 channelIndex;
|
||||
_incomingPacketStream >> channelIndex;
|
||||
getReliableInputChannel(channelIndex)->readData(_incomingPacketStream);
|
||||
} catch (const BitstreamException& e) {
|
||||
qWarning() << "Error reading datagram:" << e.getDescription();
|
||||
}
|
||||
|
||||
_incomingPacketStream.device()->seek(0);
|
||||
_inputStream.reset();
|
||||
|
||||
// record the receipt
|
||||
ReceiveRecord record = { _incomingPacketNumber, _inputStream.getAndResetReadMappings(), newHighPriorityMessages };
|
||||
_receiveRecords.append(record);
|
||||
|
||||
emit receiveRecorded();
|
||||
_inputStream.reset();
|
||||
}
|
||||
|
||||
void DatagramSequencer::sendClearSharedObjectMessage(int id) {
|
||||
|
|
|
@ -56,6 +56,34 @@ bool MetavoxelLOD::becameSubdividedOrCollapsed(const glm::vec3& minimum, float s
|
|||
return true;
|
||||
}
|
||||
|
||||
bool MetavoxelLOD::shouldSubdivide(const glm::vec2& minimum, float size, float multiplier) const {
|
||||
return size >= glm::distance(glm::vec2(position), minimum + glm::vec2(size, size) * 0.5f) * threshold * multiplier;
|
||||
}
|
||||
|
||||
bool MetavoxelLOD::becameSubdivided(const glm::vec2& minimum, float size,
|
||||
const MetavoxelLOD& reference, float multiplier) const {
|
||||
if (position == reference.position && threshold >= reference.threshold) {
|
||||
return false; // first off, nothing becomes subdivided if it doesn't change
|
||||
}
|
||||
if (!shouldSubdivide(minimum, size, multiplier)) {
|
||||
return false; // this one must be subdivided
|
||||
}
|
||||
// TODO: find some way of culling subtrees that can't possibly contain subdivided nodes
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MetavoxelLOD::becameSubdividedOrCollapsed(const glm::vec2& minimum, float size,
|
||||
const MetavoxelLOD& reference, float multiplier) const {
|
||||
if (position == reference.position && threshold == reference.threshold) {
|
||||
return false; // first off, nothing becomes subdivided or collapsed if it doesn't change
|
||||
}
|
||||
if (!(shouldSubdivide(minimum, size, multiplier) || reference.shouldSubdivide(minimum, size, multiplier))) {
|
||||
return false; // this one or the reference must be subdivided
|
||||
}
|
||||
// TODO: find some way of culling subtrees that can't possibly contain subdivided or collapsed nodes
|
||||
return true;
|
||||
}
|
||||
|
||||
MetavoxelData::MetavoxelData() : _size(1.0f) {
|
||||
}
|
||||
|
||||
|
@ -577,7 +605,9 @@ void MetavoxelData::read(Bitstream& in, const MetavoxelLOD& lod) {
|
|||
}
|
||||
MetavoxelStreamBase base = { attribute, in, lod, lod };
|
||||
MetavoxelStreamState state = { base, getMinimum(), _size };
|
||||
in.setContext(&base);
|
||||
attribute->readMetavoxelRoot(*this, state);
|
||||
in.setContext(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -587,7 +617,9 @@ void MetavoxelData::write(Bitstream& out, const MetavoxelLOD& lod) const {
|
|||
out << it.key();
|
||||
MetavoxelStreamBase base = { it.key(), out, lod, lod };
|
||||
MetavoxelStreamState state = { base, getMinimum(), _size };
|
||||
out.setContext(&base);
|
||||
it.key()->writeMetavoxelRoot(*it.value(), state);
|
||||
out.setContext(NULL);
|
||||
}
|
||||
out << AttributePointer();
|
||||
}
|
||||
|
@ -622,6 +654,7 @@ void MetavoxelData::readDelta(const MetavoxelData& reference, const MetavoxelLOD
|
|||
MetavoxelStreamBase base = { attribute, in, lod, referenceLOD };
|
||||
MetavoxelStreamState state = { base, minimum, _size };
|
||||
MetavoxelNode* oldRoot = _roots.value(attribute);
|
||||
in.setContext(&base);
|
||||
if (oldRoot) {
|
||||
bool changed;
|
||||
in >> changed;
|
||||
|
@ -637,6 +670,7 @@ void MetavoxelData::readDelta(const MetavoxelData& reference, const MetavoxelLOD
|
|||
} else {
|
||||
attribute->readMetavoxelRoot(*this, state);
|
||||
}
|
||||
in.setContext(NULL);
|
||||
}
|
||||
|
||||
forever {
|
||||
|
@ -657,7 +691,9 @@ void MetavoxelData::readDelta(const MetavoxelData& reference, const MetavoxelLOD
|
|||
it != remainingRoots.constEnd(); it++) {
|
||||
MetavoxelStreamBase base = { it.key(), in, lod, referenceLOD };
|
||||
MetavoxelStreamState state = { base, minimum, _size };
|
||||
in.setContext(&base);
|
||||
it.key()->readMetavoxelSubdivision(*this, state);
|
||||
in.setContext(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -693,6 +729,7 @@ void MetavoxelData::writeDelta(const MetavoxelData& reference, const MetavoxelLO
|
|||
MetavoxelNode* referenceRoot = expandedReference->_roots.value(it.key());
|
||||
MetavoxelStreamBase base = { it.key(), out, lod, referenceLOD };
|
||||
MetavoxelStreamState state = { base, minimum, _size };
|
||||
out.setContext(&base);
|
||||
if (it.value() != referenceRoot || becameSubdivided) {
|
||||
out << it.key();
|
||||
if (referenceRoot) {
|
||||
|
@ -707,6 +744,7 @@ void MetavoxelData::writeDelta(const MetavoxelData& reference, const MetavoxelLO
|
|||
it.key()->writeMetavoxelRoot(*it.value(), state);
|
||||
}
|
||||
}
|
||||
out.setContext(NULL);
|
||||
}
|
||||
out << AttributePointer();
|
||||
|
||||
|
|
|
@ -53,6 +53,17 @@ public:
|
|||
/// enabled or disabled as compared to the reference.
|
||||
bool becameSubdividedOrCollapsed(const glm::vec3& minimum, float size,
|
||||
const MetavoxelLOD& reference, float multiplier = 1.0f) const;
|
||||
|
||||
/// Checks whether, according to this LOD, we should subdivide the described region.
|
||||
bool shouldSubdivide(const glm::vec2& minimum, float size, float multiplier = 1.0f) const;
|
||||
|
||||
/// Checks whether the node or any of the nodes underneath it have had subdivision enabled as compared to the reference.
|
||||
bool becameSubdivided(const glm::vec2& minimum, float size, const MetavoxelLOD& reference, float multiplier = 1.0f) const;
|
||||
|
||||
/// Checks whether the node or any of the nodes underneath it have had subdivision
|
||||
/// enabled or disabled as compared to the reference.
|
||||
bool becameSubdividedOrCollapsed(const glm::vec2& minimum, float size,
|
||||
const MetavoxelLOD& reference, float multiplier = 1.0f) const;
|
||||
};
|
||||
|
||||
DECLARE_STREAMABLE_METATYPE(MetavoxelLOD)
|
||||
|
|
|
@ -123,11 +123,9 @@ RemoveSpannerEdit::RemoveSpannerEdit(const AttributePointer& attribute, int id)
|
|||
|
||||
void RemoveSpannerEdit::apply(MetavoxelData& data, const WeakSharedObjectHash& objects) const {
|
||||
SharedObject* object = objects.value(id);
|
||||
if (!object) {
|
||||
qDebug() << "Missing object to remove" << id;
|
||||
return;
|
||||
if (object) {
|
||||
data.remove(attribute, object);
|
||||
}
|
||||
data.remove(attribute, object);
|
||||
}
|
||||
|
||||
ClearSpannersEdit::ClearSpannersEdit(const AttributePointer& attribute) :
|
||||
|
|
|
@ -131,6 +131,30 @@ void SharedObject::dump(QDebug debug) const {
|
|||
}
|
||||
}
|
||||
|
||||
void SharedObject::writeExtra(Bitstream& out) const {
|
||||
// nothing by default
|
||||
}
|
||||
|
||||
void SharedObject::readExtra(Bitstream& in) {
|
||||
// nothing by default
|
||||
}
|
||||
|
||||
void SharedObject::writeExtraDelta(Bitstream& out, const SharedObject* reference) const {
|
||||
// nothing by default
|
||||
}
|
||||
|
||||
void SharedObject::readExtraDelta(Bitstream& in, const SharedObject* reference) {
|
||||
// nothing by default
|
||||
}
|
||||
|
||||
void SharedObject::maybeWriteSubdivision(Bitstream& out) {
|
||||
// nothing by default
|
||||
}
|
||||
|
||||
SharedObject* SharedObject::readSubdivision(Bitstream& in) {
|
||||
return this;
|
||||
}
|
||||
|
||||
QAtomicInt SharedObject::_nextID(1);
|
||||
WeakSharedObjectHash SharedObject::_weakHash;
|
||||
QReadWriteLock SharedObject::_weakHashLock;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
class QComboBox;
|
||||
|
||||
class Bitstream;
|
||||
class SharedObject;
|
||||
|
||||
typedef QHash<int, QPointer<SharedObject> > WeakSharedObjectHash;
|
||||
|
@ -76,9 +77,29 @@ public:
|
|||
/// this is an instance of a superclass of the other object's class) rather than simply returning false.
|
||||
virtual bool equals(const SharedObject* other, bool sharedAncestry = false) const;
|
||||
|
||||
// Dumps the contents of this object to the debug output.
|
||||
/// Dumps the contents of this object to the debug output.
|
||||
virtual void dump(QDebug debug = QDebug(QtDebugMsg)) const;
|
||||
|
||||
/// Writes the non-property contents of this object to the specified stream.
|
||||
virtual void writeExtra(Bitstream& out) const;
|
||||
|
||||
/// Reads the non-property contents of this object from the specified stream.
|
||||
virtual void readExtra(Bitstream& in);
|
||||
|
||||
/// Writes the delta-encoded non-property contents of this object to the specified stream.
|
||||
virtual void writeExtraDelta(Bitstream& out, const SharedObject* reference) const;
|
||||
|
||||
/// Reads the delta-encoded non-property contents of this object from the specified stream.
|
||||
virtual void readExtraDelta(Bitstream& in, const SharedObject* reference);
|
||||
|
||||
/// Writes the subdivision of the contents of this object (preceeded by a
|
||||
/// reference to the object itself) to the specified stream if necessary.
|
||||
virtual void maybeWriteSubdivision(Bitstream& out);
|
||||
|
||||
/// Reads the subdivision of this object from the specified stream.
|
||||
/// \return the modified object, or this if no modification was performed
|
||||
virtual SharedObject* readSubdivision(Bitstream& in);
|
||||
|
||||
private:
|
||||
|
||||
int _id;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -17,9 +17,12 @@
|
|||
#include "AttributeRegistry.h"
|
||||
#include "MetavoxelUtil.h"
|
||||
|
||||
class AbstractHeightfieldNodeRenderer;
|
||||
class Heightfield;
|
||||
class HeightfieldColor;
|
||||
class HeightfieldHeight;
|
||||
class HeightfieldMaterial;
|
||||
class HeightfieldNode;
|
||||
class SpannerRenderer;
|
||||
|
||||
/// An object that spans multiple octree cells.
|
||||
|
@ -28,6 +31,7 @@ class Spanner : public SharedObject {
|
|||
Q_PROPERTY(Box bounds MEMBER _bounds WRITE setBounds NOTIFY boundsChanged DESIGNABLE false)
|
||||
Q_PROPERTY(float placementGranularity MEMBER _placementGranularity DESIGNABLE false)
|
||||
Q_PROPERTY(float voxelizationGranularity MEMBER _voxelizationGranularity DESIGNABLE false)
|
||||
Q_PROPERTY(bool willBeVoxelized MEMBER _willBeVoxelized DESIGNABLE false)
|
||||
|
||||
public:
|
||||
|
||||
|
@ -48,6 +52,9 @@ public:
|
|||
void setMerged(bool merged) { _merged = merged; }
|
||||
bool isMerged() const { return _merged; }
|
||||
|
||||
void setWillBeVoxelized(bool willBeVoxelized) { _willBeVoxelized = willBeVoxelized; }
|
||||
bool getWillBeVoxelized() const { return _willBeVoxelized; }
|
||||
|
||||
/// Checks whether we've visited this object on the current traversal. If we have, returns false.
|
||||
/// If we haven't, sets the last visit identifier and returns true.
|
||||
bool testAndSetVisited(int visit);
|
||||
|
@ -117,6 +124,7 @@ private:
|
|||
float _placementGranularity;
|
||||
float _voxelizationGranularity;
|
||||
bool _merged;
|
||||
bool _willBeVoxelized;
|
||||
QHash<QThread*, int> _lastVisits; ///< last visit identifiers for each thread
|
||||
QMutex _lastVisitsMutex;
|
||||
|
||||
|
@ -133,7 +141,7 @@ public:
|
|||
|
||||
virtual void init(Spanner* spanner);
|
||||
virtual void simulate(float deltaTime);
|
||||
virtual void render(bool cursor = false);
|
||||
virtual void render(const MetavoxelLOD& lod = MetavoxelLOD(), bool contained = false, bool cursor = false);
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance) const;
|
||||
|
||||
protected:
|
||||
|
@ -458,14 +466,129 @@ Bitstream& operator>>(Bitstream& in, HeightfieldMaterialPointer& value);
|
|||
template<> void Bitstream::writeRawDelta(const HeightfieldMaterialPointer& value, const HeightfieldMaterialPointer& reference);
|
||||
template<> void Bitstream::readRawDelta(HeightfieldMaterialPointer& value, const HeightfieldMaterialPointer& reference);
|
||||
|
||||
typedef QExplicitlySharedDataPointer<HeightfieldNode> HeightfieldNodePointer;
|
||||
|
||||
/// Holds the base state used in streaming heightfield data.
|
||||
class HeightfieldStreamBase {
|
||||
public:
|
||||
Bitstream& stream;
|
||||
const MetavoxelLOD& lod;
|
||||
const MetavoxelLOD& referenceLOD;
|
||||
};
|
||||
|
||||
/// Holds the state used in streaming a heightfield node.
|
||||
class HeightfieldStreamState {
|
||||
public:
|
||||
HeightfieldStreamBase& base;
|
||||
glm::vec2 minimum;
|
||||
float size;
|
||||
|
||||
bool shouldSubdivide() const;
|
||||
bool shouldSubdivideReference() const;
|
||||
bool becameSubdivided() const;
|
||||
bool becameSubdividedOrCollapsed() const;
|
||||
|
||||
void setMinimum(const glm::vec2& lastMinimum, int index);
|
||||
};
|
||||
|
||||
/// A node in a heightfield quadtree.
|
||||
class HeightfieldNode : public QSharedData {
|
||||
public:
|
||||
|
||||
static const int CHILD_COUNT = 4;
|
||||
|
||||
HeightfieldNode(const HeightfieldHeightPointer& height = HeightfieldHeightPointer(),
|
||||
const HeightfieldColorPointer& color = HeightfieldColorPointer(),
|
||||
const HeightfieldMaterialPointer& material = HeightfieldMaterialPointer());
|
||||
|
||||
HeightfieldNode(const HeightfieldNode& other);
|
||||
|
||||
~HeightfieldNode();
|
||||
|
||||
void setContents(const HeightfieldHeightPointer& height, const HeightfieldColorPointer& color,
|
||||
const HeightfieldMaterialPointer& material);
|
||||
|
||||
void setHeight(const HeightfieldHeightPointer& height) { _height = height; }
|
||||
const HeightfieldHeightPointer& getHeight() const { return _height; }
|
||||
|
||||
void setColor(const HeightfieldColorPointer& color) { _color = color; }
|
||||
const HeightfieldColorPointer& getColor() const { return _color; }
|
||||
|
||||
void setMaterial(const HeightfieldMaterialPointer& material) { _material = material; }
|
||||
const HeightfieldMaterialPointer& getMaterial() const { return _material; }
|
||||
|
||||
void setRenderer(AbstractHeightfieldNodeRenderer* renderer) { _renderer = renderer; }
|
||||
AbstractHeightfieldNodeRenderer* getRenderer() const { return _renderer; }
|
||||
|
||||
bool isLeaf() const;
|
||||
|
||||
void setChild(int index, const HeightfieldNodePointer& child) { _children[index] = child; }
|
||||
const HeightfieldNodePointer& getChild(int index) const { return _children[index]; }
|
||||
|
||||
float getHeight(const glm::vec3& location) const;
|
||||
|
||||
bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance) const;
|
||||
|
||||
HeightfieldNode* paintMaterial(const glm::vec3& position, const glm::vec3& radius, const SharedObjectPointer& material,
|
||||
const QColor& color);
|
||||
|
||||
void getRangeAfterHeightPaint(const glm::vec3& position, const glm::vec3& radius,
|
||||
float height, int& minimum, int& maximum) const;
|
||||
|
||||
HeightfieldNode* paintHeight(const glm::vec3& position, const glm::vec3& radius, float height,
|
||||
float normalizeScale, float normalizeOffset);
|
||||
|
||||
HeightfieldNode* clearAndFetchHeight(const glm::vec3& translation, const glm::quat& rotation, const glm::vec3& scale,
|
||||
const Box& bounds, SharedObjectPointer& heightfield);
|
||||
|
||||
void read(HeightfieldStreamState& state);
|
||||
void write(HeightfieldStreamState& state) const;
|
||||
|
||||
void readDelta(const HeightfieldNodePointer& reference, HeightfieldStreamState& state);
|
||||
void writeDelta(const HeightfieldNodePointer& reference, HeightfieldStreamState& state) const;
|
||||
|
||||
HeightfieldNode* readSubdivision(HeightfieldStreamState& state);
|
||||
void writeSubdivision(HeightfieldStreamState& state) const;
|
||||
|
||||
void readSubdivided(HeightfieldStreamState& state, const HeightfieldStreamState& ancestorState,
|
||||
const HeightfieldNode* ancestor);
|
||||
void writeSubdivided(HeightfieldStreamState& state, const HeightfieldStreamState& ancestorState,
|
||||
const HeightfieldNode* ancestor) const;
|
||||
|
||||
private:
|
||||
|
||||
void clearChildren();
|
||||
void mergeChildren(bool height = true, bool colorMaterial = true);
|
||||
|
||||
QRgb getColorAt(const glm::vec3& location) const;
|
||||
int getMaterialAt(const glm::vec3& location) const;
|
||||
|
||||
HeightfieldHeightPointer _height;
|
||||
HeightfieldColorPointer _color;
|
||||
HeightfieldMaterialPointer _material;
|
||||
|
||||
HeightfieldNodePointer _children[CHILD_COUNT];
|
||||
|
||||
AbstractHeightfieldNodeRenderer* _renderer;
|
||||
};
|
||||
|
||||
/// Base class for heightfield node rendering.
|
||||
class AbstractHeightfieldNodeRenderer {
|
||||
public:
|
||||
|
||||
virtual ~AbstractHeightfieldNodeRenderer();
|
||||
};
|
||||
|
||||
/// A heightfield represented as a spanner.
|
||||
class Heightfield : public Transformable {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(float aspectY MEMBER _aspectY WRITE setAspectY NOTIFY aspectYChanged)
|
||||
Q_PROPERTY(float aspectZ MEMBER _aspectZ WRITE setAspectZ NOTIFY aspectZChanged)
|
||||
Q_PROPERTY(HeightfieldHeightPointer height MEMBER _height WRITE setHeight NOTIFY heightChanged)
|
||||
Q_PROPERTY(HeightfieldColorPointer color MEMBER _color WRITE setColor NOTIFY colorChanged)
|
||||
Q_PROPERTY(HeightfieldMaterialPointer material MEMBER _material WRITE setMaterial NOTIFY materialChanged DESIGNABLE false)
|
||||
Q_PROPERTY(HeightfieldHeightPointer height MEMBER _height WRITE setHeight NOTIFY heightChanged STORED false)
|
||||
Q_PROPERTY(HeightfieldColorPointer color MEMBER _color WRITE setColor NOTIFY colorChanged STORED false)
|
||||
Q_PROPERTY(HeightfieldMaterialPointer material MEMBER _material WRITE setMaterial NOTIFY materialChanged STORED false
|
||||
DESIGNABLE false)
|
||||
Q_PROPERTY(HeightfieldNodePointer root MEMBER _root WRITE setRoot NOTIFY rootChanged STORED false DESIGNABLE false)
|
||||
|
||||
public:
|
||||
|
||||
|
@ -486,6 +609,13 @@ public:
|
|||
void setMaterial(const HeightfieldMaterialPointer& material);
|
||||
const HeightfieldMaterialPointer& getMaterial() const { return _material; }
|
||||
|
||||
void setRoot(const HeightfieldNodePointer& root);
|
||||
const HeightfieldNodePointer& getRoot() const { return _root; }
|
||||
|
||||
MetavoxelLOD transformLOD(const MetavoxelLOD& lod) const;
|
||||
|
||||
virtual SharedObject* clone(bool withID = false, SharedObject* target = NULL) const;
|
||||
|
||||
virtual bool isHeightfield() const;
|
||||
|
||||
virtual float getHeight(const glm::vec3& location) const;
|
||||
|
@ -508,6 +638,13 @@ public:
|
|||
virtual bool contains(const glm::vec3& point);
|
||||
virtual bool intersects(const glm::vec3& start, const glm::vec3& end, float& distance, glm::vec3& normal);
|
||||
|
||||
virtual void writeExtra(Bitstream& out) const;
|
||||
virtual void readExtra(Bitstream& in);
|
||||
virtual void writeExtraDelta(Bitstream& out, const SharedObject* reference) const;
|
||||
virtual void readExtraDelta(Bitstream& in, const SharedObject* reference);
|
||||
virtual void maybeWriteSubdivision(Bitstream& out);
|
||||
virtual SharedObject* readSubdivision(Bitstream& in);
|
||||
|
||||
signals:
|
||||
|
||||
void aspectYChanged(float aspectY);
|
||||
|
@ -515,6 +652,7 @@ signals:
|
|||
void heightChanged(const HeightfieldHeightPointer& height);
|
||||
void colorChanged(const HeightfieldColorPointer& color);
|
||||
void materialChanged(const HeightfieldMaterialPointer& material);
|
||||
void rootChanged(const HeightfieldNodePointer& root);
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -523,14 +661,18 @@ protected:
|
|||
private slots:
|
||||
|
||||
void updateBounds();
|
||||
void updateRoot();
|
||||
|
||||
private:
|
||||
|
||||
float _aspectY;
|
||||
float _aspectZ;
|
||||
|
||||
HeightfieldHeightPointer _height;
|
||||
HeightfieldColorPointer _color;
|
||||
HeightfieldMaterialPointer _material;
|
||||
|
||||
HeightfieldNodePointer _root;
|
||||
};
|
||||
|
||||
#endif // hifi_Spanner_h
|
||||
|
|
|
@ -81,7 +81,7 @@ PacketVersion versionForPacketType(PacketType type) {
|
|||
case PacketTypeAudioStreamStats:
|
||||
return 1;
|
||||
case PacketTypeMetavoxelData:
|
||||
return 9;
|
||||
return 10;
|
||||
case PacketTypeVoxelData:
|
||||
return VERSION_VOXELS_HAS_FILE_BREAKS;
|
||||
default:
|
||||
|
|
Loading…
Reference in a new issue