History

Working on voxel bits.

Andrzej Kapolka committed 12 years ago

Commit 9a4d56b1 parent e8755643 files · +153 −5Browse files

Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 3 files). Show all

Unified · Split

interface/src/MetavoxelSystem.cpp+88−3
@@ -34,12 +34,18 @@ static int bufferPointVectorMetaTypeId = qRegisterMetaType<BufferPointVector>(); · 33 unmodified lines
3434 void MetavoxelSystem::init() {
3535 MetavoxelClientManager::init();
3636 DefaultMetavoxelRendererImplementation::init();
37+
3738 _pointBufferAttribute = AttributeRegistry::getInstance()->registerAttribute(new BufferDataAttribute("pointBuffer"));
38− _heightfieldBufferAttribute = AttributeRegistry::getInstance()->registerAttribute(
39− new BufferDataAttribute("heightfieldBuffer"));
4039
40+ _heightfieldBufferAttribute = AttributeRegistry::getInstance()->registerAttribute(
41+ new BufferDataAttribute("heightfieldBuffer"));
4142 _heightfieldBufferAttribute->setLODThresholdMultiplier(
4243 AttributeRegistry::getInstance()->getHeightfieldAttribute()->getLODThresholdMultiplier());
44+
45+ _voxelBufferAttribute = AttributeRegistry::getInstance()->registerAttribute(
46+ new BufferDataAttribute("voxelBuffer"));
47+ _voxelBufferAttribute->setLODThresholdMultiplier(
48+ AttributeRegistry::getInstance()->getVoxelColorAttribute()->getLODThresholdMultiplier());
4349 }
4450
4551 MetavoxelLOD MetavoxelSystem::getLOD() {
@@ -972,6 +978,16 @@ void HeightfieldPreview::render(const glm::vec3& translation, float scale) const · 926 unmodified lines
972978 glEnable(GL_BLEND);
973979 }
974980
981+VoxelBuffer::VoxelBuffer(const QVector<VoxelVertex>& vertices, const QVector<int>& indices,
982+ const QVector<SharedObjectPointer>& materials) :
983+ _vertices(vertices),
984+ _indices(indices),
985+ _materials(materials) {
986+}
987+
988+void VoxelBuffer::render(bool cursor) {
989+}
990+
975991 BufferDataAttribute::BufferDataAttribute(const QString& name) :
976992 InlineAttribute<BufferDataPointer>(name) {
977993 }
@@ -1213,6 +1229,8 @@ HeightfieldFetchVisitor::HeightfieldFetchVisitor(const MetavoxelLOD& lod, const · 235 unmodified lines
12131229 _intersections(intersections) {
12141230 }
12151231
1232+const int EIGHT_BIT_MAXIMUM = 255;
1233+
12161234 int HeightfieldFetchVisitor::visit(MetavoxelInfo& info) {
12171235 Box bounds = info.getBounds();
12181236 const Box& heightBounds = _buffer->getHeightBounds();
@@ -1263,7 +1281,6 @@ int HeightfieldFetchVisitor::visit(MetavoxelInfo& info) { · 44 unmodified lines
12631281 shift++;
12641282 size *= 2.0f;
12651283 }
1266− const int EIGHT_BIT_MAXIMUM = 255;
12671284 int subtract = (_buffer->getTranslation().y - info.minimum.y) * EIGHT_BIT_MAXIMUM / _buffer->getScale();
12681285 for (int y = 0; y < destHeight; y++, dest += heightSize, srcY += srcAdvance) {
12691286 const uchar* src = (const uchar*)srcHeight.constData() + (int)srcY * srcSize;
@@ -1479,6 +1496,71 @@ int HeightfieldUpdateVisitor::visit(MetavoxelInfo& info) { · 209 unmodified lines
14791496 return STOP_RECURSION;
14801497 }
14811498
1499+class VoxelAugmentVisitor : public MetavoxelVisitor {
1500+public:
1501+
1502+ VoxelAugmentVisitor(const MetavoxelLOD& lod);
1503+
1504+ virtual int visit(MetavoxelInfo& info);
1505+};
1506+
1507+VoxelAugmentVisitor::VoxelAugmentVisitor(const MetavoxelLOD& lod) :
1508+ MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getVoxelColorAttribute() <<
1509+ AttributeRegistry::getInstance()->getVoxelMaterialAttribute(), QVector<AttributePointer>() <<
1510+ Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute(), lod) {
1511+}
1512+
1513+int VoxelAugmentVisitor::visit(MetavoxelInfo& info) {
1514+ if (!info.isLeaf) {
1515+ return DEFAULT_ORDER;
1516+ }
1517+ VoxelBuffer* buffer = NULL;
1518+ VoxelColorDataPointer color = info.inputValues.at(0).getInlineValue<VoxelColorDataPointer>();
1519+ if (color) {
1520+ QVector<VoxelVertex> vertices;
1521+ QVector<int> indices;
1522+
1523+ const QVector<QRgb>& contents = color->getContents();
1524+ int size = color->getSize();
1525+ int area = size * size;
1526+ int highest = size - 1;
1527+ int offset3 = size + 1;
1528+ int offset5 = area + 1;
1529+ int offset6 = area + size;
1530+ int offset7 = area + size + 1;
1531+
1532+ const QRgb* src = contents.constData();
1533+
1534+ const int ALPHA_OFFSET = 24;
1535+ const int MAX_ALPHA_TOTAL = EIGHT_BIT_MAXIMUM * 8;
1536+ for (int z = 0; z < highest; z++) {
1537+ for (int y = 0; y < highest; z++) {
1538+ for (int x = 0; x < highest; x++, src++) {
1539+ int alpha0 = src[0] >> ALPHA_OFFSET;
1540+ int alpha1 = src[1] >> ALPHA_OFFSET;
1541+ int alpha2 = src[size] >> ALPHA_OFFSET;
1542+ int alpha3 = src[offset3] >> ALPHA_OFFSET;
1543+ int alpha4 = src[area] >> ALPHA_OFFSET;
1544+ int alpha5 = src[offset5] >> ALPHA_OFFSET;
1545+ int alpha6 = src[offset6] >> ALPHA_OFFSET;
1546+ int alpha7 = src[offset7] >> ALPHA_OFFSET;
1547+ int alphaTotal = alpha0 + alpha1 + alpha2 + alpha3 + alpha4 + alpha5 + alpha6 + alpha7;
1548+ if (alphaTotal == 0 || alphaTotal == MAX_ALPHA_TOTAL) {
1549+ continue; // no corners set/all corners set
1550+ }
1551+
1552+ }
1553+ src++;
1554+ }
1555+ src += size;
1556+ }
1557+
1558+ buffer = new VoxelBuffer(vertices, indices);
1559+ }
1560+ info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(BufferDataPointer(buffer)));
1561+ return STOP_RECURSION;
1562+}
1563+
14821564 void DefaultMetavoxelRendererImplementation::augment(MetavoxelData& data, const MetavoxelData& previous,
14831565 MetavoxelInfo& info, const MetavoxelLOD& lod) {
14841566 // copy the previous buffers
@@ -1509,6 +1591,9 @@ void DefaultMetavoxelRendererImplementation::augment(MetavoxelData& data, const · 24 unmodified lines
15091591 HeightfieldUpdateVisitor heightfieldUpdateVisitor(lod, heightfieldRegionVisitor.regions,
15101592 heightfieldRegionVisitor.regionBounds);
15111593 data.guide(heightfieldUpdateVisitor);
1594+
1595+ VoxelAugmentVisitor voxelAugmentVisitor(lod);
1596+ data.guideToDifferent(expandedPrevious, voxelAugmentVisitor);
15121597 }
15131598
15141599 class SpannerSimulateVisitor : public SpannerVisitor {