Skip to content

Commit

Permalink
Culling tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
xeolabs committed Oct 17, 2023
1 parent 00b797f commit 70eaba4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
15 changes: 13 additions & 2 deletions examples/performance/lodCulling_HolterTower.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,20 @@ <h3>Resources</h3>
//------------------------------------------------------------------------------
// Configure level-of-detail culling
//------------------------------------------------------------------------------

viewer.scene.lod.enabled = true;
viewer.scene.lod.targetFPS = 50; // Set an excessive FPS target to force LoD
viewer.scene.lod.neverCullTypes = [
"IfcWall",
"IfcSlab",
"IfcFloor",
"IfcRoof",
"IfcSpace",
"IfcBeam",
"IfcStair",
"IfcPlate",
"IfcSite"
];

new NavCubePlugin(viewer, {
canvasId: "myNavCubeCanvas",
Expand Down Expand Up @@ -115,7 +126,7 @@ <h3>Resources</h3>
}
});

sceneModel.on("loaded", ()=>{
sceneModel.on("loaded", () => {
viewer.cameraFlight.jumpTo(sceneModel);
});

Expand Down
14 changes: 14 additions & 0 deletions src/viewer/scene/lod/LOD.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export class LOD extends Component {

this._scene = scene;
this._lodLevels = [2000, 600, 150, 80, 20];
this._neverCullTypes = [];
this._neverCullTypesMap = {};
this._lodManagers = {};
this._lodManagerList = [];

Expand Down Expand Up @@ -143,6 +145,10 @@ export class LOD extends Component {
value = [];
}
this._neverCullTypes = value;
this._neverCullTypesMap = {};
for (let i = 0, len = this._neverCullTypes.length; i < len; i++) {
this._neverCullTypesMap[this._neverCullTypes[i]] = true;
}
// this.glRedraw();
}

Expand All @@ -156,6 +162,14 @@ export class LOD extends Component {
get neverCullTypes() {
return this._neverCullTypes;
}

/**
* @private
* @returns {*|{}}
*/
get neverCullTypesMap() {
return this._neverCullTypesMap;
}

/**
* Called within SceneModel constructors
Expand Down
4 changes: 2 additions & 2 deletions src/viewer/scene/lod/LODCullingManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ export class LODCullingManager {
let lodState = this.lodState;
let retVal = false;
if (currentFPS < lodState.targetFps) {
if (++lodState.consecutiveFramesWithoutTargetFps > 5) {
if (++lodState.consecutiveFramesWithoutTargetFps > 2) {
lodState.consecutiveFramesWithoutTargetFps = 0;
retVal = this._increaseLODLevelIndex();
}
} else if (currentFPS > (lodState.targetFps + 4)) {
if (++lodState.consecutiveFramesWithTargetFps > 5) {
if (++lodState.consecutiveFramesWithTargetFps > 2) {
lodState.consecutiveFramesWithTargetFps = 0;
retVal = this._decreaseLODLevelIndex();
}
Expand Down
23 changes: 6 additions & 17 deletions src/viewer/scene/lod/LODState.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@ import {math} from "../math/math.js";
* @private
*/


const neverCullTypes = {
"IfcWall": true,
"IfcSlab": true,
"IfcFloor": true,
"IfcRoof": true,
"IfcSpace": true,
"IfcBeam": true,
"IfcStair": true,
"IfcPlate":true
}

export class LODState {

/**
Expand Down Expand Up @@ -101,6 +89,7 @@ export class LODState {
if (entityList.length === 0) {
return;
}
const neverCullTypesMap = sceneModel.scene.lod.neverCullTypesMap;
const metaScene = sceneModel.scene.viewer.metaScene;
const entitiesInLOD = {};
const primCountInLOD = {};
Expand All @@ -110,15 +99,15 @@ export class LODState {
for (let i = 0, len = entityList.length; i < len; i++) {
const entity = entityList[i];
const metaObject = metaScene.metaObjects[entity.id];
if (metaObject && neverCullTypes[metaObject.type]) {
if (metaObject && neverCullTypesMap[metaObject.type]) {
continue;
}
const entityComplexity = entity.numPrimitives;
const entitySize = math.getAABB3Diag(entity.aabb);
const isCullable = ((minComplexity <= entityComplexity) && (entitySize <= maxSize));
if (!isCullable) {
continue;
}
// const isCullable = ((minComplexity <= entityComplexity) && (entitySize <= maxSize));
// if (!isCullable) {
// continue;
// }
let lodLevel = 0, len;
for (lodLevel = 0, len = this.primLODLevels.length; lodLevel < len; lodLevel++) {
if (entity.numPrimitives >= this.primLODLevels [lodLevel]) {
Expand Down

0 comments on commit 70eaba4

Please sign in to comment.