History

Merge pull request #3602 from ZappoMan/frustumCullModelParts

More Model::render() improvements

AndrewMeadows committed 12 years ago

Commit e75d2a12 parents 866b3d4 ffb7bcf11 files · +153 −88Browse files

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

Unified · Split

interface/src/Menu.cpp+49−2
@@ -122,7 +122,8 @@ Menu::Menu() : · 121 unmodified lines
122122 _hasLoginDialogDisplayed(false),
123123 _snapshotsLocation(),
124124 _scriptsLocation(),
125− _walletPrivateKey()
125+ _walletPrivateKey(),
126+ _shouldRenderTableNeedsRebuilding(true)
126127 {
127128 Application *appInstance = Application::getInstance();
128129
@@ -419,10 +420,12 @@ Menu::Menu() : · 290 unmodified lines
419420 addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::RenderFocusIndicator, 0, false);
420421
421422 QMenu* modelDebugMenu = developerMenu->addMenu("Models");
422− addCheckableActionToQMenuAndActionHash(modelDebugMenu, MenuOption::DontCullMeshParts, 0, false);
423423 addCheckableActionToQMenuAndActionHash(modelDebugMenu, MenuOption::DisplayModelBounds, 0, false);
424424 addCheckableActionToQMenuAndActionHash(modelDebugMenu, MenuOption::DisplayModelElementProxy, 0, false);
425425 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);
426429
427430 QMenu* voxelOptionsMenu = developerMenu->addMenu("Voxels");
428431 addCheckableActionToQMenuAndActionHash(voxelOptionsMenu, MenuOption::VoxelTextures);
@@ -1547,6 +1550,7 @@ void Menu::autoAdjustLOD(float currentFPS) { · 1118 unmodified lines
15471550 && _voxelSizeScale > ADJUST_LOD_MIN_SIZE_SCALE) {
15481551
15491552 _voxelSizeScale *= ADJUST_LOD_DOWN_BY;
1553+
15501554 if (_voxelSizeScale < ADJUST_LOD_MIN_SIZE_SCALE) {
15511555 _voxelSizeScale = ADJUST_LOD_MIN_SIZE_SCALE;
15521556 }
@@ -1569,6 +1573,7 @@ void Menu::autoAdjustLOD(float currentFPS) { · 16 unmodified lines
15691573 }
15701574
15711575 if (changed) {
1576+ _shouldRenderTableNeedsRebuilding = true;
15721577 if (_lodToolsDialog) {
15731578 _lodToolsDialog->reloadSliders();
15741579 }
@@ -1583,14 +1588,56 @@ void Menu::resetLODAdjust() { · 8 unmodified lines
15831588
15841589 void Menu::setVoxelSizeScale(float sizeScale) {
15851590 _voxelSizeScale = sizeScale;
1591+ _shouldRenderTableNeedsRebuilding = true;
15861592 bumpSettings();
15871593 }
15881594
15891595 void Menu::setBoundaryLevelAdjust(int boundaryLevelAdjust) {
15901596 _boundaryLevelAdjust = boundaryLevelAdjust;
1597+ _shouldRenderTableNeedsRebuilding = true;
15911598 bumpSettings();
15921599 }
15931600
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+
15941641 void Menu::lodTools() {
15951642 if (!_lodToolsDialog) {
15961643 _lodToolsDialog = new LodToolsDialog(Application::getInstance()->getGLWidget());