More Model::render() improvements
Showing the changes to interface/src/Menu.cpp (1 of 11 files). Show all
Unified · Split
| @@ -122,7 +122,8 @@ Menu::Menu() : · 121 unmodified lines | |||
| 122 | _hasLoginDialogDisplayed(false), | 122 | _hasLoginDialogDisplayed(false), |
| 123 | _snapshotsLocation(), | 123 | _snapshotsLocation(), |
| 124 | _scriptsLocation(), | 124 | _scriptsLocation(), |
| 125 | _walletPrivateKey() | 125 | _walletPrivateKey(), |
| 126 | _shouldRenderTableNeedsRebuilding(true) | ||
| 126 | { | 127 | { |
| 127 | Application *appInstance = Application::getInstance(); | 128 | Application *appInstance = Application::getInstance(); |
| 128 | 129 | ||
| @@ -419,10 +420,12 @@ Menu::Menu() : · 290 unmodified lines | |||
| 419 | addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::RenderFocusIndicator, 0, false); | 420 | addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::RenderFocusIndicator, 0, false); |
| 420 | 421 | ||
| 421 | QMenu* modelDebugMenu = developerMenu->addMenu("Models"); | 422 | QMenu* modelDebugMenu = developerMenu->addMenu("Models"); |
| 422 | addCheckableActionToQMenuAndActionHash(modelDebugMenu, MenuOption::DontCullMeshParts, 0, false); | ||
| 423 | addCheckableActionToQMenuAndActionHash(modelDebugMenu, MenuOption::DisplayModelBounds, 0, false); | 423 | addCheckableActionToQMenuAndActionHash(modelDebugMenu, MenuOption::DisplayModelBounds, 0, false); |
| 424 | addCheckableActionToQMenuAndActionHash(modelDebugMenu, MenuOption::DisplayModelElementProxy, 0, false); | 424 | addCheckableActionToQMenuAndActionHash(modelDebugMenu, MenuOption::DisplayModelElementProxy, 0, false); |
| 425 | addCheckableActionToQMenuAndActionHash(modelDebugMenu, MenuOption::DisplayModelElementChildProxies, 0, false); | 425 | addCheckableActionToQMenuAndActionHash(modelDebugMenu, MenuOption::DisplayModelElementChildProxies, 0, false); |
| 426 | QMenu* modelCullingMenu = modelDebugMenu->addMenu("Culling"); | ||
| 427 | addCheckableActionToQMenuAndActionHash(modelCullingMenu, MenuOption::DontCullOutOfViewMeshParts, 0, false); | ||
| 428 | addCheckableActionToQMenuAndActionHash(modelCullingMenu, MenuOption::DontCullTooSmallMeshParts, 0, false); | ||
| 426 | 429 | ||
| 427 | QMenu* voxelOptionsMenu = developerMenu->addMenu("Voxels"); | 430 | QMenu* voxelOptionsMenu = developerMenu->addMenu("Voxels"); |
| 428 | addCheckableActionToQMenuAndActionHash(voxelOptionsMenu, MenuOption::VoxelTextures); | 431 | addCheckableActionToQMenuAndActionHash(voxelOptionsMenu, MenuOption::VoxelTextures); |
| @@ -1547,6 +1550,7 @@ void Menu::autoAdjustLOD(float currentFPS) { · 1118 unmodified lines | |||
| 1547 | && _voxelSizeScale > ADJUST_LOD_MIN_SIZE_SCALE) { | 1550 | && _voxelSizeScale > ADJUST_LOD_MIN_SIZE_SCALE) { |
| 1548 | 1551 | ||
| 1549 | _voxelSizeScale *= ADJUST_LOD_DOWN_BY; | 1552 | _voxelSizeScale *= ADJUST_LOD_DOWN_BY; |
| 1553 | |||
| 1550 | if (_voxelSizeScale < ADJUST_LOD_MIN_SIZE_SCALE) { | 1554 | if (_voxelSizeScale < ADJUST_LOD_MIN_SIZE_SCALE) { |
| 1551 | _voxelSizeScale = ADJUST_LOD_MIN_SIZE_SCALE; | 1555 | _voxelSizeScale = ADJUST_LOD_MIN_SIZE_SCALE; |
| 1552 | } | 1556 | } |
| @@ -1569,6 +1573,7 @@ void Menu::autoAdjustLOD(float currentFPS) { · 16 unmodified lines | |||
| 1569 | } | 1573 | } |
| 1570 | 1574 | ||
| 1571 | if (changed) { | 1575 | if (changed) { |
| 1576 | _shouldRenderTableNeedsRebuilding = true; | ||
| 1572 | if (_lodToolsDialog) { | 1577 | if (_lodToolsDialog) { |
| 1573 | _lodToolsDialog->reloadSliders(); | 1578 | _lodToolsDialog->reloadSliders(); |
| 1574 | } | 1579 | } |
| @@ -1583,14 +1588,56 @@ void Menu::resetLODAdjust() { · 8 unmodified lines | |||
| 1583 | 1588 | ||
| 1584 | void Menu::setVoxelSizeScale(float sizeScale) { | 1589 | void Menu::setVoxelSizeScale(float sizeScale) { |
| 1585 | _voxelSizeScale = sizeScale; | 1590 | _voxelSizeScale = sizeScale; |
| 1591 | _shouldRenderTableNeedsRebuilding = true; | ||
| 1586 | bumpSettings(); | 1592 | bumpSettings(); |
| 1587 | } | 1593 | } |
| 1588 | 1594 | ||
| 1589 | void Menu::setBoundaryLevelAdjust(int boundaryLevelAdjust) { | 1595 | void Menu::setBoundaryLevelAdjust(int boundaryLevelAdjust) { |
| 1590 | _boundaryLevelAdjust = boundaryLevelAdjust; | 1596 | _boundaryLevelAdjust = boundaryLevelAdjust; |
| 1597 | _shouldRenderTableNeedsRebuilding = true; | ||
| 1591 | bumpSettings(); | 1598 | bumpSettings(); |
| 1592 | } | 1599 | } |
| 1593 | 1600 | ||
| 1601 | // TODO: This is essentially the same logic used to render voxels, but since models are more detailed then voxels | ||
| 1602 | // I've added a voxelToModelRatio that adjusts how much closer to a model you have to be to see it. | ||
| 1603 | bool Menu::shouldRenderMesh(float largestDimension, float distanceToCamera) { | ||
| 1604 | const float voxelToMeshRatio = 4.0f; // must be this many times closer to a mesh than a voxel to see it. | ||
| 1605 | float voxelSizeScale = getVoxelSizeScale(); | ||
| 1606 | int boundaryLevelAdjust = getBoundaryLevelAdjust(); | ||
| 1607 | float maxScale = (float)TREE_SCALE; | ||
| 1608 | float visibleDistanceAtMaxScale = boundaryDistanceForRenderLevel(boundaryLevelAdjust, voxelSizeScale) / voxelToMeshRatio; | ||
| 1609 | |||
| 1610 | if (_shouldRenderTableNeedsRebuilding) { | ||
| 1611 | _shouldRenderTable.clear(); | ||
| 1612 | |||
| 1613 | float SMALLEST_SCALE_IN_TABLE = 0.001f; // 1mm is plenty small | ||
| 1614 | float scale = maxScale; | ||
| 1615 | float visibleDistanceAtScale = visibleDistanceAtMaxScale; | ||
| 1616 | |||
| 1617 | while (scale > SMALLEST_SCALE_IN_TABLE) { | ||
| 1618 | scale /= 2.0f; | ||
| 1619 | visibleDistanceAtScale /= 2.0f; | ||
| 1620 | _shouldRenderTable[scale] = visibleDistanceAtScale; | ||
| 1621 | } | ||
| 1622 | _shouldRenderTableNeedsRebuilding = false; | ||
| 1623 | } | ||
| 1624 | |||
| 1625 | float closestScale = maxScale; | ||
| 1626 | float visibleDistanceAtClosestScale = visibleDistanceAtMaxScale; | ||
| 1627 | QMap<float, float>::const_iterator lowerBound = _shouldRenderTable.lowerBound(largestDimension); | ||
| 1628 | if (lowerBound != _shouldRenderTable.constEnd()) { | ||
| 1629 | closestScale = lowerBound.key(); | ||
| 1630 | visibleDistanceAtClosestScale = lowerBound.value(); | ||
| 1631 | } | ||
| 1632 | |||
| 1633 | if (closestScale < largestDimension) { | ||
| 1634 | visibleDistanceAtClosestScale *= 2.0f; | ||
| 1635 | } | ||
| 1636 | |||
| 1637 | return (distanceToCamera <= visibleDistanceAtClosestScale); | ||
| 1638 | } | ||
| 1639 | |||
| 1640 | |||
| 1594 | void Menu::lodTools() { | 1641 | void Menu::lodTools() { |
| 1595 | if (!_lodToolsDialog) { | 1642 | if (!_lodToolsDialog) { |
| 1596 | _lodToolsDialog = new LodToolsDialog(Application::getInstance()->getGLWidget()); | 1643 | _lodToolsDialog = new LodToolsDialog(Application::getInstance()->getGLWidget()); |