Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 5 files). Show all
Unified · Split
| @@ -137,15 +137,13 @@ void MetavoxelSystem::render() { · 136 unmodified lines | ||
| 137 | 137 | emit rendering(); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | −void MetavoxelSystem::updateHermiteDisplay() { | |
| 141 | − if (Menu::getInstance()->isOptionChecked(MenuOption::DisplayHermiteData)) { | |
| 142 | − foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { | |
| 143 | − if (node->getType() == NodeType::MetavoxelServer) { | |
| 144 | − QMutexLocker locker(&node->getMutex()); | |
| 145 | − MetavoxelSystemClient* client = static_cast<MetavoxelSystemClient*>(node->getLinkedData()); | |
| 146 | − if (client) { | |
| 147 | − QMetaObject::invokeMethod(client, "refreshVoxelData"); | |
| 148 | − } | |
| 140 | +void MetavoxelSystem::refreshVoxelData() { | |
| 141 | + foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { | |
| 142 | + if (node->getType() == NodeType::MetavoxelServer) { | |
| 143 | + QMutexLocker locker(&node->getMutex()); | |
| 144 | + MetavoxelSystemClient* client = static_cast<MetavoxelSystemClient*>(node->getLinkedData()); | |
| 145 | + if (client) { | |
| 146 | + QMetaObject::invokeMethod(client, "refreshVoxelData"); | |
| 149 | 147 | } |
| 150 | 148 | } |
| 151 | 149 | } |
| @@ -642,8 +640,47 @@ void PointBuffer::render(bool cursor) { · 490 unmodified lines | ||
| 642 | 640 | _buffer.release(); |
| 643 | 641 | } |
| 644 | 642 | |
| 645 | −VoxelPointBuffer::VoxelPointBuffer(const BufferPointVector& points) : | |
| 646 | − PointBuffer(points) { | |
| 643 | +VoxelPointBuffer::VoxelPointBuffer(const BufferPointVector& points, const QVector<glm::vec3>& hermite) : | |
| 644 | + PointBuffer(points), | |
| 645 | + _hermite(hermite), | |
| 646 | + _hermiteCount(hermite.size()) { | |
| 647 | +} | |
| 648 | + | |
| 649 | +static void renderHermiteData(QVector<glm::vec3>& hermite, int hermiteCount, QOpenGLBuffer& hermiteBuffer) { | |
| 650 | + if (hermiteCount > 0 && Menu::getInstance()->isOptionChecked(MenuOption::DisplayHermiteData)) { | |
| 651 | + if (!hermiteBuffer.isCreated()) { | |
| 652 | + hermiteBuffer.create(); | |
| 653 | + hermiteBuffer.bind(); | |
| 654 | + hermiteBuffer.allocate(hermite.constData(), hermite.size() * sizeof(glm::vec3)); | |
| 655 | + hermite.clear(); | |
| 656 | + | |
| 657 | + } else { | |
| 658 | + hermiteBuffer.bind(); | |
| 659 | + } | |
| 660 | + | |
| 661 | + glDisableClientState(GL_COLOR_ARRAY); | |
| 662 | + glDisableClientState(GL_NORMAL_ARRAY); | |
| 663 | + | |
| 664 | + glVertexPointer(3, GL_FLOAT, 0, 0); | |
| 665 | + | |
| 666 | + Application::getInstance()->getDeferredLightingEffect()->getSimpleProgram().bind(); | |
| 667 | + | |
| 668 | + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | |
| 669 | + glNormal3f(0.0f, 1.0f, 0.0f); | |
| 670 | + | |
| 671 | + glLineWidth(2.0f); | |
| 672 | + | |
| 673 | + glDrawArrays(GL_LINES, 0, hermiteCount); | |
| 674 | + | |
| 675 | + glLineWidth(1.0f); | |
| 676 | + | |
| 677 | + DefaultMetavoxelRendererImplementation::getBaseVoxelProgram().bind(); | |
| 678 | + | |
| 679 | + glEnableClientState(GL_COLOR_ARRAY); | |
| 680 | + glEnableClientState(GL_NORMAL_ARRAY); | |
| 681 | + | |
| 682 | + hermiteBuffer.release(); | |
| 683 | + } | |
| 647 | 684 | } |
| 648 | 685 | |
| 649 | 686 | void VoxelPointBuffer::render(bool cursor) { |
| @@ -656,6 +693,8 @@ void VoxelPointBuffer::render(bool cursor) { · 6 unmodified lines | ||
| 656 | 693 | glDisable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB); |
| 657 | 694 | |
| 658 | 695 | DefaultMetavoxelRendererImplementation::getBaseVoxelProgram().bind(); |
| 696 | + | |
| 697 | + renderHermiteData(_hermite, _hermiteCount, _hermiteBuffer); | |
| 659 | 698 | } |
| 660 | 699 | |
| 661 | 700 | const int HeightfieldBuffer::HEIGHT_BORDER = 1; |
| @@ -1136,40 +1175,7 @@ void VoxelBuffer::render(bool cursor) { · 474 unmodified lines | ||
| 1136 | 1175 | _vertexBuffer.release(); |
| 1137 | 1176 | _indexBuffer.release(); |
| 1138 | 1177 | |
| 1139 | − if (_hermiteCount > 0 && Menu::getInstance()->isOptionChecked(MenuOption::DisplayHermiteData)) { | |
| 1140 | − if (!_hermiteBuffer.isCreated()) { | |
| 1141 | − _hermiteBuffer.create(); | |
| 1142 | − _hermiteBuffer.bind(); | |
| 1143 | − _hermiteBuffer.allocate(_hermite.constData(), _hermite.size() * sizeof(glm::vec3)); | |
| 1144 | − _hermite.clear(); | |
| 1145 | − | |
| 1146 | − } else { | |
| 1147 | − _hermiteBuffer.bind(); | |
| 1148 | − } | |
| 1149 | − | |
| 1150 | − glDisableClientState(GL_COLOR_ARRAY); | |
| 1151 | − glDisableClientState(GL_NORMAL_ARRAY); | |
| 1152 | − | |
| 1153 | − glVertexPointer(3, GL_FLOAT, 0, 0); | |
| 1154 | − | |
| 1155 | − Application::getInstance()->getDeferredLightingEffect()->getSimpleProgram().bind(); | |
| 1156 | − | |
| 1157 | − glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | |
| 1158 | − glNormal3f(0.0f, 1.0f, 0.0f); | |
| 1159 | − | |
| 1160 | − glLineWidth(2.0f); | |
| 1161 | − | |
| 1162 | − glDrawArrays(GL_LINES, 0, _hermiteCount); | |
| 1163 | − | |
| 1164 | − glLineWidth(1.0f); | |
| 1165 | − | |
| 1166 | − DefaultMetavoxelRendererImplementation::getBaseVoxelProgram().bind(); | |
| 1167 | − | |
| 1168 | − glEnableClientState(GL_COLOR_ARRAY); | |
| 1169 | − glEnableClientState(GL_NORMAL_ARRAY); | |
| 1170 | − | |
| 1171 | − _hermiteBuffer.release(); | |
| 1172 | − } | |
| 1178 | + renderHermiteData(_hermite, _hermiteCount, _hermiteBuffer); | |
| 1173 | 1179 | } |
| 1174 | 1180 | |
| 1175 | 1181 | BufferDataAttribute::BufferDataAttribute(const QString& name) : |
| @@ -1638,11 +1644,14 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 462 unmodified lines | ||
| 1638 | 1644 | if (!info.isLeaf) { |
| 1639 | 1645 | return DEFAULT_ORDER; |
| 1640 | 1646 | } |
| 1647 | + const int EDGES_PER_CUBE = 12; | |
| 1648 | + | |
| 1641 | 1649 | BufferData* buffer = NULL; |
| 1642 | 1650 | VoxelColorDataPointer color = info.inputValues.at(0).getInlineValue<VoxelColorDataPointer>(); |
| 1643 | 1651 | VoxelMaterialDataPointer material = info.inputValues.at(1).getInlineValue<VoxelMaterialDataPointer>(); |
| 1644 | 1652 | VoxelHermiteDataPointer hermite = info.inputValues.at(2).getInlineValue<VoxelHermiteDataPointer>(); |
| 1645 | − if (color && hermite && material) { | |
| 1653 | + | |
| 1654 | + if (color && hermite && (material || !Menu::getInstance()->isOptionChecked(MenuOption::LowerDetailAsPoints))) { | |
| 1646 | 1655 | QVector<VoxelPoint> vertices; |
| 1647 | 1656 | QVector<int> indices; |
| 1648 | 1657 | QVector<glm::vec3> hermiteSegments; |
| @@ -1677,7 +1686,6 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 28 unmodified lines | ||
| 1677 | 1686 | QVector<AxisIndex> planeIndices(expanded * expanded); |
| 1678 | 1687 | QVector<AxisIndex> lastPlaneIndices(expanded * expanded); |
| 1679 | 1688 | |
| 1680 | − const int EDGES_PER_CUBE = 12; | |
| 1681 | 1689 | EdgeCrossing crossings[EDGES_PER_CUBE]; |
| 1682 | 1690 | |
| 1683 | 1691 | float highest = size - 1.0f; |
| @@ -2182,6 +2190,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 498 unmodified lines | ||
| 2182 | 2190 | |
| 2183 | 2191 | } else if (color && hermite) { |
| 2184 | 2192 | BufferPointVector points; |
| 2193 | + QVector<glm::vec3> hermiteSegments; | |
| 2185 | 2194 | |
| 2186 | 2195 | const QVector<QRgb>& colorContents = color->getContents(); |
| 2187 | 2196 | const QVector<QRgb>& hermiteContents = hermite->getContents(); |
| @@ -2201,6 +2210,9 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 13 unmodified lines | ||
| 2201 | 2210 | const QRgb* hermiteData = hermiteContents.constData(); |
| 2202 | 2211 | int hermiteStride = hermite->getSize() * VoxelHermiteData::EDGE_COUNT; |
| 2203 | 2212 | int hermiteArea = hermiteStride * hermite->getSize(); |
| 2213 | + bool displayHermite = Menu::getInstance()->isOptionChecked(MenuOption::DisplayHermiteData); | |
| 2214 | + | |
| 2215 | + EdgeCrossing crossings[EDGES_PER_CUBE]; | |
| 2204 | 2216 | |
| 2205 | 2217 | for (int z = 0; z < limit; z++) { |
| 2206 | 2218 | const QRgb* colorY = colorZ; |
| @@ -2218,80 +2230,90 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 11 unmodified lines | ||
| 2218 | 2230 | } |
| 2219 | 2231 | const QRgb* hermiteBase = hermiteData + z * hermiteArea + y * hermiteStride + |
| 2220 | 2232 | x * VoxelHermiteData::EDGE_COUNT; |
| 2221 | − glm::vec3 normal; | |
| 2222 | − glm::vec3 position; | |
| 2223 | 2233 | int crossingCount = 0; |
| 2224 | 2234 | if (a0 != a1) { |
| 2225 | 2235 | QRgb hermite = hermiteBase[0]; |
| 2226 | − position += glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 0.0f); | |
| 2227 | − normal += unpackNormal(hermite); | |
| 2228 | − crossingCount++; | |
| 2236 | + EdgeCrossing& crossing = crossings[crossingCount++]; | |
| 2237 | + crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 0.0f); | |
| 2238 | + crossing.normal = unpackNormal(hermite); | |
| 2229 | 2239 | } |
| 2230 | 2240 | if (a0 != a2) { |
| 2231 | 2241 | QRgb hermite = hermiteBase[1]; |
| 2232 | − position += glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f); | |
| 2233 | − normal += unpackNormal(hermite); | |
| 2234 | − crossingCount++; | |
| 2242 | + EdgeCrossing& crossing = crossings[crossingCount++]; | |
| 2243 | + crossing.point = glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f); | |
| 2244 | + crossing.normal = unpackNormal(hermite); | |
| 2235 | 2245 | } |
| 2236 | 2246 | if (a0 != a4) { |
| 2237 | 2247 | QRgb hermite = hermiteBase[2]; |
| 2238 | − position += glm::vec3(0.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL); | |
| 2239 | − normal += unpackNormal(hermite); | |
| 2240 | − crossingCount++; | |
| 2248 | + EdgeCrossing& crossing = crossings[crossingCount++]; | |
| 2249 | + crossing.point = glm::vec3(0.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL); | |
| 2250 | + crossing.normal = unpackNormal(hermite); | |
| 2241 | 2251 | } |
| 2242 | 2252 | if (a1 != a3) { |
| 2243 | 2253 | QRgb hermite = hermiteBase[VoxelHermiteData::EDGE_COUNT + 1]; |
| 2244 | − position += glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f); | |
| 2245 | − normal += unpackNormal(hermite); | |
| 2246 | − crossingCount++; | |
| 2254 | + EdgeCrossing& crossing = crossings[crossingCount++]; | |
| 2255 | + crossing.point = glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f); | |
| 2256 | + crossing.normal = unpackNormal(hermite); | |
| 2247 | 2257 | } |
| 2248 | 2258 | if (a1 != a5) { |
| 2249 | 2259 | QRgb hermite = hermiteBase[VoxelHermiteData::EDGE_COUNT + 2]; |
| 2250 | − position += glm::vec3(1.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL); | |
| 2251 | − normal += unpackNormal(hermite); | |
| 2252 | − crossingCount++; | |
| 2260 | + EdgeCrossing& crossing = crossings[crossingCount++]; | |
| 2261 | + crossing.point = glm::vec3(1.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL); | |
| 2262 | + crossing.normal = unpackNormal(hermite); | |
| 2253 | 2263 | } |
| 2254 | 2264 | if (a2 != a3) { |
| 2255 | 2265 | QRgb hermite = hermiteBase[hermiteStride]; |
| 2256 | − position += glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 0.0f); | |
| 2257 | − normal += unpackNormal(hermite); | |
| 2258 | − crossingCount++; | |
| 2266 | + EdgeCrossing& crossing = crossings[crossingCount++]; | |
| 2267 | + crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 0.0f); | |
| 2268 | + crossing.normal = unpackNormal(hermite); | |
| 2259 | 2269 | } |
| 2260 | 2270 | if (a2 != a6) { |
| 2261 | 2271 | QRgb hermite = hermiteBase[hermiteStride + 2]; |
| 2262 | − position += glm::vec3(0.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL); | |
| 2263 | − normal += unpackNormal(hermite); | |
| 2264 | − crossingCount++; | |
| 2272 | + EdgeCrossing& crossing = crossings[crossingCount++]; | |
| 2273 | + crossing.point = glm::vec3(0.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL); | |
| 2274 | + crossing.normal = unpackNormal(hermite); | |
| 2265 | 2275 | } |
| 2266 | 2276 | if (a3 != a7) { |
| 2267 | 2277 | QRgb hermite = hermiteBase[hermiteStride + VoxelHermiteData::EDGE_COUNT + 2]; |
| 2268 | − position += glm::vec3(1.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL); | |
| 2269 | − normal += unpackNormal(hermite); | |
| 2270 | − crossingCount++; | |
| 2278 | + EdgeCrossing& crossing = crossings[crossingCount++]; | |
| 2279 | + crossing.point = glm::vec3(1.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL); | |
| 2280 | + crossing.normal = unpackNormal(hermite); | |
| 2271 | 2281 | } |
| 2272 | 2282 | if (a4 != a5) { |
| 2273 | 2283 | QRgb hermite = hermiteBase[hermiteArea]; |
| 2274 | − position += glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 1.0f); | |
| 2275 | − normal += unpackNormal(hermite); | |
| 2276 | − crossingCount++; | |
| 2284 | + EdgeCrossing& crossing = crossings[crossingCount++]; | |
| 2285 | + crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 1.0f); | |
| 2286 | + crossing.normal = unpackNormal(hermite); | |
| 2277 | 2287 | } |
| 2278 | 2288 | if (a4 != a6) { |
| 2279 | 2289 | QRgb hermite = hermiteBase[hermiteArea + 1]; |
| 2280 | − position += glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f); | |
| 2281 | − normal += unpackNormal(hermite); | |
| 2282 | − crossingCount++; | |
| 2290 | + EdgeCrossing& crossing = crossings[crossingCount++]; | |
| 2291 | + crossing.point = glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f); | |
| 2292 | + crossing.normal = unpackNormal(hermite); | |
| 2283 | 2293 | } |
| 2284 | 2294 | if (a5 != a7) { |
| 2285 | 2295 | QRgb hermite = hermiteBase[hermiteArea + VoxelHermiteData::EDGE_COUNT + 1]; |
| 2286 | − position += glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f); | |
| 2287 | − normal += unpackNormal(hermite); | |
| 2288 | − crossingCount++; | |
| 2296 | + EdgeCrossing& crossing = crossings[crossingCount++]; | |
| 2297 | + crossing.point = glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f); | |
| 2298 | + crossing.normal = unpackNormal(hermite); | |
| 2289 | 2299 | } |
| 2290 | 2300 | if (a6 != a7) { |
| 2291 | 2301 | QRgb hermite = hermiteBase[hermiteArea + hermiteStride]; |
| 2292 | − position += glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 1.0f); | |
| 2293 | − normal += unpackNormal(hermite); | |
| 2294 | − crossingCount++; | |
| 2302 | + EdgeCrossing& crossing = crossings[crossingCount++]; | |
| 2303 | + crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 1.0f); | |
| 2304 | + crossing.normal = unpackNormal(hermite); | |
| 2305 | + } | |
| 2306 | + glm::vec3 normal; | |
| 2307 | + glm::vec3 position; | |
| 2308 | + for (int i = 0; i < crossingCount; i++) { | |
| 2309 | + const EdgeCrossing& crossing = crossings[i]; | |
| 2310 | + position += crossing.point; | |
| 2311 | + normal += crossing.normal; | |
| 2312 | + if (displayHermite) { | |
| 2313 | + glm::vec3 base = glm::vec3(minimum) + (glm::vec3(x, y, z) + crossing.point) * step; | |
| 2314 | + hermiteSegments.append(base); | |
| 2315 | + hermiteSegments.append(base + crossing.normal * step); | |
| 2316 | + } | |
| 2295 | 2317 | } |
| 2296 | 2318 | normal = safeNormalize(normal); |
| 2297 | 2319 | BufferPoint point = { minimum + (glm::vec4(x, y, z, 1.0f) + |
| @@ -2309,7 +2331,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 11 unmodified lines | ||
| 2309 | 2331 | } |
| 2310 | 2332 | colorZ += area; |
| 2311 | 2333 | } |
| 2312 | − buffer = new VoxelPointBuffer(points); | |
| 2334 | + buffer = new VoxelPointBuffer(points, hermiteSegments); | |
| 2313 | 2335 | } |
| 2314 | 2336 | BufferDataPointer pointer(buffer); |
| 2315 | 2337 | info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(pointer)); |