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
34void MetavoxelSystem::init() {34void MetavoxelSystem::init() {
35 MetavoxelClientManager::init();35 MetavoxelClientManager::init();
36 DefaultMetavoxelRendererImplementation::init();36 DefaultMetavoxelRendererImplementation::init();
37
37 _pointBufferAttribute = AttributeRegistry::getInstance()->registerAttribute(new BufferDataAttribute("pointBuffer"));38 _pointBufferAttribute = AttributeRegistry::getInstance()->registerAttribute(new BufferDataAttribute("pointBuffer"));
38 _heightfieldBufferAttribute = AttributeRegistry::getInstance()->registerAttribute(
39 new BufferDataAttribute("heightfieldBuffer"));
40 39
40 _heightfieldBufferAttribute = AttributeRegistry::getInstance()->registerAttribute(
41 new BufferDataAttribute("heightfieldBuffer"));
41 _heightfieldBufferAttribute->setLODThresholdMultiplier(42 _heightfieldBufferAttribute->setLODThresholdMultiplier(
42 AttributeRegistry::getInstance()->getHeightfieldAttribute()->getLODThresholdMultiplier());43 AttributeRegistry::getInstance()->getHeightfieldAttribute()->getLODThresholdMultiplier());
44
45 _voxelBufferAttribute = AttributeRegistry::getInstance()->registerAttribute(
46 new BufferDataAttribute("voxelBuffer"));
47 _voxelBufferAttribute->setLODThresholdMultiplier(
48 AttributeRegistry::getInstance()->getVoxelColorAttribute()->getLODThresholdMultiplier());
43}49}
44 50
45MetavoxelLOD MetavoxelSystem::getLOD() {51MetavoxelLOD MetavoxelSystem::getLOD() {
@@ -972,6 +978,16 @@ void HeightfieldPreview::render(const glm::vec3& translation, float scale) const · 926 unmodified lines
972 glEnable(GL_BLEND);978 glEnable(GL_BLEND);
973}979}
974 980
981VoxelBuffer::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
988void VoxelBuffer::render(bool cursor) {
989}
990
975BufferDataAttribute::BufferDataAttribute(const QString& name) :991BufferDataAttribute::BufferDataAttribute(const QString& name) :
976 InlineAttribute<BufferDataPointer>(name) {992 InlineAttribute<BufferDataPointer>(name) {
977}993}
@@ -1213,6 +1229,8 @@ HeightfieldFetchVisitor::HeightfieldFetchVisitor(const MetavoxelLOD& lod, const · 235 unmodified lines
1213 _intersections(intersections) {1229 _intersections(intersections) {
1214}1230}
1215 1231
1232const int EIGHT_BIT_MAXIMUM = 255;
1233
1216int HeightfieldFetchVisitor::visit(MetavoxelInfo& info) {1234int HeightfieldFetchVisitor::visit(MetavoxelInfo& info) {
1217 Box bounds = info.getBounds();1235 Box bounds = info.getBounds();
1218 const Box& heightBounds = _buffer->getHeightBounds();1236 const Box& heightBounds = _buffer->getHeightBounds();
@@ -1263,7 +1281,6 @@ int HeightfieldFetchVisitor::visit(MetavoxelInfo& info) { · 44 unmodified lines
1263 shift++;1281 shift++;
1264 size *= 2.0f;1282 size *= 2.0f;
1265 }1283 }
1266 const int EIGHT_BIT_MAXIMUM = 255;
1267 int subtract = (_buffer->getTranslation().y - info.minimum.y) * EIGHT_BIT_MAXIMUM / _buffer->getScale();1284 int subtract = (_buffer->getTranslation().y - info.minimum.y) * EIGHT_BIT_MAXIMUM / _buffer->getScale();
1268 for (int y = 0; y < destHeight; y++, dest += heightSize, srcY += srcAdvance) {1285 for (int y = 0; y < destHeight; y++, dest += heightSize, srcY += srcAdvance) {
1269 const uchar* src = (const uchar*)srcHeight.constData() + (int)srcY * srcSize;1286 const uchar* src = (const uchar*)srcHeight.constData() + (int)srcY * srcSize;
@@ -1479,6 +1496,71 @@ int HeightfieldUpdateVisitor::visit(MetavoxelInfo& info) { · 209 unmodified lines
1479 return STOP_RECURSION;1496 return STOP_RECURSION;
1480}1497}
1481 1498
1499class VoxelAugmentVisitor : public MetavoxelVisitor {
1500public:
1501
1502 VoxelAugmentVisitor(const MetavoxelLOD& lod);
1503
1504 virtual int visit(MetavoxelInfo& info);
1505};
1506
1507VoxelAugmentVisitor::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
1513int 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
1482void DefaultMetavoxelRendererImplementation::augment(MetavoxelData& data, const MetavoxelData& previous,1564void DefaultMetavoxelRendererImplementation::augment(MetavoxelData& data, const MetavoxelData& previous,
1483 MetavoxelInfo& info, const MetavoxelLOD& lod) {1565 MetavoxelInfo& info, const MetavoxelLOD& lod) {
1484 // copy the previous buffers1566 // copy the previous buffers
@@ -1509,6 +1591,9 @@ void DefaultMetavoxelRendererImplementation::augment(MetavoxelData& data, const · 24 unmodified lines
1509 HeightfieldUpdateVisitor heightfieldUpdateVisitor(lod, heightfieldRegionVisitor.regions,1591 HeightfieldUpdateVisitor heightfieldUpdateVisitor(lod, heightfieldRegionVisitor.regions,
1510 heightfieldRegionVisitor.regionBounds);1592 heightfieldRegionVisitor.regionBounds);
1511 data.guide(heightfieldUpdateVisitor);1593 data.guide(heightfieldUpdateVisitor);
1594
1595 VoxelAugmentVisitor voxelAugmentVisitor(lod);
1596 data.guideToDifferent(expandedPrevious, voxelAugmentVisitor);
1512}1597}
1513 1598
1514class SpannerSimulateVisitor : public SpannerVisitor {1599class SpannerSimulateVisitor : public SpannerVisitor {