Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 5 files). Show all
Unified · Split
| @@ -550,10 +550,47 @@ void MetavoxelSystem::setVoxelMaterial(const SharedObjectPointer& spanner, const · 549 unmodified lines | ||
| 550 | 550 | applyMaterialEdit(edit, true); |
| 551 | 551 | } |
| 552 | 552 | |
| 553 | −class SpannerCursorRenderVisitor : public SpannerVisitor { | |
| 553 | +class SpannerRenderVisitor : public SpannerVisitor { | |
| 554 | +public: | |
| 555 | + | |
| 556 | + SpannerRenderVisitor(const MetavoxelLOD& lod); | |
| 557 | + | |
| 558 | + virtual int visit(MetavoxelInfo& info); | |
| 559 | + virtual bool visit(Spanner* spanner); | |
| 560 | + | |
| 561 | +protected: | |
| 562 | + | |
| 563 | + int _containmentDepth; | |
| 564 | +}; | |
| 565 | + | |
| 566 | +SpannerRenderVisitor::SpannerRenderVisitor(const MetavoxelLOD& lod) : | |
| 567 | + SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute(), | |
| 568 | + QVector<AttributePointer>(), QVector<AttributePointer>(), lod, | |
| 569 | + encodeOrder(Application::getInstance()->getDisplayViewFrustum()->getDirection())), | |
| 570 | + _containmentDepth(INT_MAX) { | |
| 571 | +} | |
| 572 | + | |
| 573 | +int SpannerRenderVisitor::visit(MetavoxelInfo& info) { | |
| 574 | + if (_containmentDepth >= _depth) { | |
| 575 | + Frustum::IntersectionType intersection = Application::getInstance()->getMetavoxels()->getFrustum().getIntersectionType( | |
| 576 | + info.getBounds()); | |
| 577 | + if (intersection == Frustum::NO_INTERSECTION) { | |
| 578 | + return STOP_RECURSION; | |
| 579 | + } | |
| 580 | + _containmentDepth = (intersection == Frustum::CONTAINS_INTERSECTION) ? _depth : INT_MAX; | |
| 581 | + } | |
| 582 | + return SpannerVisitor::visit(info); | |
| 583 | +} | |
| 584 | + | |
| 585 | +bool SpannerRenderVisitor::visit(Spanner* spanner) { | |
| 586 | + spanner->getRenderer()->render(_lod, _containmentDepth <= _depth); | |
| 587 | + return true; | |
| 588 | +} | |
| 589 | + | |
| 590 | +class SpannerCursorRenderVisitor : public SpannerRenderVisitor { | |
| 554 | 591 | public: |
| 555 | 592 | |
| 556 | − SpannerCursorRenderVisitor(const Box& bounds); | |
| 593 | + SpannerCursorRenderVisitor(const MetavoxelLOD& lod, const Box& bounds); | |
| 557 | 594 | |
| 558 | 595 | virtual bool visit(Spanner* spanner); |
| 559 | 596 | |
| @@ -564,20 +601,20 @@ private: · 4 unmodified lines | ||
| 564 | 601 | Box _bounds; |
| 565 | 602 | }; |
| 566 | 603 | |
| 567 | −SpannerCursorRenderVisitor::SpannerCursorRenderVisitor(const Box& bounds) : | |
| 568 | − SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute()), | |
| 604 | +SpannerCursorRenderVisitor::SpannerCursorRenderVisitor(const MetavoxelLOD& lod, const Box& bounds) : | |
| 605 | + SpannerRenderVisitor(lod), | |
| 569 | 606 | _bounds(bounds) { |
| 570 | 607 | } |
| 571 | 608 | |
| 572 | 609 | bool SpannerCursorRenderVisitor::visit(Spanner* spanner) { |
| 573 | 610 | if (spanner->isHeightfield()) { |
| 574 | − spanner->getRenderer()->render(true); | |
| 611 | + spanner->getRenderer()->render(_lod, _containmentDepth <= _depth, true); | |
| 575 | 612 | } |
| 576 | 613 | return true; |
| 577 | 614 | } |
| 578 | 615 | |
| 579 | 616 | int SpannerCursorRenderVisitor::visit(MetavoxelInfo& info) { |
| 580 | − return info.getBounds().intersects(_bounds) ? SpannerVisitor::visit(info) : STOP_RECURSION; | |
| 617 | + return info.getBounds().intersects(_bounds) ? SpannerRenderVisitor::visit(info) : STOP_RECURSION; | |
| 581 | 618 | } |
| 582 | 619 | |
| 583 | 620 | void MetavoxelSystem::renderHeightfieldCursor(const glm::vec3& position, float radius) { |
| @@ -604,7 +641,7 @@ void MetavoxelSystem::renderHeightfieldCursor(const glm::vec3& position, float r · 20 unmodified lines | ||
| 604 | 641 | glActiveTexture(GL_TEXTURE0); |
| 605 | 642 | |
| 606 | 643 | glm::vec3 extents(radius, radius, radius); |
| 607 | − SpannerCursorRenderVisitor visitor(Box(position - extents, position + extents)); | |
| 644 | + SpannerCursorRenderVisitor visitor(getLOD(), Box(position - extents, position + extents)); | |
| 608 | 645 | guide(visitor); |
| 609 | 646 | |
| 610 | 647 | _heightfieldCursorProgram.release(); |
| @@ -678,7 +715,7 @@ void MetavoxelSystem::renderVoxelCursor(const glm::vec3& position, float radius) · 67 unmodified lines | ||
| 678 | 715 | |
| 679 | 716 | _heightfieldCursorProgram.bind(); |
| 680 | 717 | |
| 681 | − SpannerCursorRenderVisitor spannerVisitor(bounds); | |
| 718 | + SpannerCursorRenderVisitor spannerVisitor(getLOD(), bounds); | |
| 682 | 719 | guide(spannerVisitor); |
| 683 | 720 | |
| 684 | 721 | _heightfieldCursorProgram.release(); |
| @@ -1880,43 +1917,6 @@ void DefaultMetavoxelRendererImplementation::simulate(MetavoxelData& data, float · 1195 unmodified lines | ||
| 1880 | 1917 | data.guide(spannerSimulateVisitor); |
| 1881 | 1918 | } |
| 1882 | 1919 | |
| 1883 | −class SpannerRenderVisitor : public SpannerVisitor { | |
| 1884 | −public: | |
| 1885 | − | |
| 1886 | − SpannerRenderVisitor(const MetavoxelLOD& lod); | |
| 1887 | − | |
| 1888 | − virtual int visit(MetavoxelInfo& info); | |
| 1889 | − virtual bool visit(Spanner* spanner); | |
| 1890 | − | |
| 1891 | −private: | |
| 1892 | − | |
| 1893 | − int _containmentDepth; | |
| 1894 | −}; | |
| 1895 | − | |
| 1896 | −SpannerRenderVisitor::SpannerRenderVisitor(const MetavoxelLOD& lod) : | |
| 1897 | − SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute(), | |
| 1898 | − QVector<AttributePointer>(), QVector<AttributePointer>(), lod, | |
| 1899 | − encodeOrder(Application::getInstance()->getDisplayViewFrustum()->getDirection())), | |
| 1900 | − _containmentDepth(INT_MAX) { | |
| 1901 | −} | |
| 1902 | − | |
| 1903 | −int SpannerRenderVisitor::visit(MetavoxelInfo& info) { | |
| 1904 | − if (_containmentDepth >= _depth) { | |
| 1905 | − Frustum::IntersectionType intersection = Application::getInstance()->getMetavoxels()->getFrustum().getIntersectionType( | |
| 1906 | − info.getBounds()); | |
| 1907 | − if (intersection == Frustum::NO_INTERSECTION) { | |
| 1908 | − return STOP_RECURSION; | |
| 1909 | − } | |
| 1910 | − _containmentDepth = (intersection == Frustum::CONTAINS_INTERSECTION) ? _depth : INT_MAX; | |
| 1911 | − } | |
| 1912 | − return SpannerVisitor::visit(info); | |
| 1913 | −} | |
| 1914 | − | |
| 1915 | −bool SpannerRenderVisitor::visit(Spanner* spanner) { | |
| 1916 | − spanner->getRenderer()->render(); | |
| 1917 | − return true; | |
| 1918 | −} | |
| 1919 | − | |
| 1920 | 1920 | class BufferRenderVisitor : public MetavoxelVisitor { |
| 1921 | 1921 | public: |
| 1922 | 1922 | |
| @@ -1970,7 +1970,7 @@ SphereRenderer::SphereRenderer() { · 47 unmodified lines | ||
| 1970 | 1970 | } |
| 1971 | 1971 | |
| 1972 | 1972 | |
| 1973 | −void SphereRenderer::render(bool cursor) { | |
| 1973 | +void SphereRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor) { | |
| 1974 | 1974 | Sphere* sphere = static_cast<Sphere*>(_spanner); |
| 1975 | 1975 | const QColor& color = sphere->getColor(); |
| 1976 | 1976 | glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF()); |
| @@ -1990,7 +1990,7 @@ void SphereRenderer::render(bool cursor) { · 13 unmodified lines | ||
| 1990 | 1990 | CuboidRenderer::CuboidRenderer() { |
| 1991 | 1991 | } |
| 1992 | 1992 | |
| 1993 | −void CuboidRenderer::render(bool cursor) { | |
| 1993 | +void CuboidRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor) { | |
| 1994 | 1994 | Cuboid* cuboid = static_cast<Cuboid*>(_spanner); |
| 1995 | 1995 | const QColor& color = cuboid->getColor(); |
| 1996 | 1996 | glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF()); |
| @@ -2041,7 +2041,7 @@ void StaticModelRenderer::simulate(float deltaTime) { · 44 unmodified lines | ||
| 2041 | 2041 | _model->simulate(deltaTime); |
| 2042 | 2042 | } |
| 2043 | 2043 | |
| 2044 | −void StaticModelRenderer::render(bool cursor) { | |
| 2044 | +void StaticModelRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor) { | |
| 2045 | 2045 | _model->render(); |
| 2046 | 2046 | } |
| 2047 | 2047 | |
| @@ -2083,10 +2083,9 @@ void HeightfieldRenderer::init(Spanner* spanner) { · 35 unmodified lines | ||
| 2083 | 2083 | updateRoot(); |
| 2084 | 2084 | } |
| 2085 | 2085 | |
| 2086 | −void HeightfieldRenderer::render(bool cursor) { | |
| 2086 | +void HeightfieldRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor) { | |
| 2087 | 2087 | Heightfield* heightfield = static_cast<Heightfield*>(_spanner); |
| 2088 | − _root->render(heightfield->getTranslation(), heightfield->getRotation(), glm::vec3(heightfield->getScale(), | |
| 2089 | − heightfield->getScale() * heightfield->getAspectY(), heightfield->getScale() * heightfield->getAspectZ()), cursor); | |
| 2088 | + _root->render(heightfield, heightfield->transformLOD(lod), glm::vec2(), 1.0f, contained, cursor); | |
| 2090 | 2089 | } |
| 2091 | 2090 | |
| 2092 | 2091 | void HeightfieldRenderer::updateRoot() { |
| @@ -2117,15 +2116,28 @@ HeightfieldRendererNode::~HeightfieldRendererNode() { · 24 unmodified lines | ||
| 2117 | 2116 | const int X_MAXIMUM_FLAG = 1; |
| 2118 | 2117 | const int Y_MAXIMUM_FLAG = 2; |
| 2119 | 2118 | |
| 2120 | −void HeightfieldRendererNode::render(const glm::vec3& translation, const glm::quat& rotation, | |
| 2121 | − const glm::vec3& scale, bool cursor) { | |
| 2122 | − if (!isLeaf()) { | |
| 2123 | − glm::vec3 nextScale(scale.x * 0.5f, scale.y, scale.z * 0.5f); | |
| 2124 | − glm::vec3 xOffset = rotation * glm::vec3(nextScale.x, 0.0f, 0.0f); | |
| 2125 | − glm::vec3 zOffset = rotation * glm::vec3(0.0f, 0.0f, nextScale.z); | |
| 2119 | +void HeightfieldRendererNode::render(Heightfield* heightfield, const MetavoxelLOD& lod, | |
| 2120 | + const glm::vec2& minimum, float size, bool contained, bool cursor) { | |
| 2121 | + const glm::quat& rotation = heightfield->getRotation(); | |
| 2122 | + glm::vec3 scale(heightfield->getScale() * size, heightfield->getScale() * heightfield->getAspectY(), | |
| 2123 | + heightfield->getScale() * heightfield->getAspectZ() * size); | |
| 2124 | + glm::vec3 translation = heightfield->getTranslation() + rotation * glm::vec3(minimum.x * heightfield->getScale(), | |
| 2125 | + 0.0f, minimum.y * heightfield->getScale() * heightfield->getAspectZ()); | |
| 2126 | + if (!contained) { | |
| 2127 | + Frustum::IntersectionType type = Application::getInstance()->getMetavoxels()->getFrustum().getIntersectionType( | |
| 2128 | + glm::translate(translation) * glm::mat4_cast(rotation) * Box(glm::vec3(), scale)); | |
| 2129 | + if (type == Frustum::NO_INTERSECTION) { | |
| 2130 | + return; | |
| 2131 | + } | |
| 2132 | + if (type == Frustum::CONTAINS_INTERSECTION) { | |
| 2133 | + contained = true; | |
| 2134 | + } | |
| 2135 | + } | |
| 2136 | + if (!isLeaf() && lod.shouldSubdivide(minimum, size)) { | |
| 2137 | + float nextSize = size * 0.5f; | |
| 2126 | 2138 | for (int i = 0; i < CHILD_COUNT; i++) { |
| 2127 | − _children[i]->render(translation + (i & X_MAXIMUM_FLAG ? xOffset : glm::vec3()) + | |
| 2128 | − (i & Y_MAXIMUM_FLAG ? zOffset : glm::vec3()), rotation, nextScale, cursor); | |
| 2139 | + _children[i]->render(heightfield, lod, minimum + glm::vec2(i & X_MAXIMUM_FLAG ? nextSize : 0.0f, | |
| 2140 | + i & Y_MAXIMUM_FLAG ? nextSize : 0.0f), nextSize, contained, cursor); | |
| 2129 | 2141 | } |
| 2130 | 2142 | return; |
| 2131 | 2143 | } |