Skip to content

Commit 039531d

Browse files
osscharalja
authored andcommitted
Automatic recalculation of scene-bbox on scene update and near/far clip optimization for perspective camera.
* GlViewerRCore.js: - Add this.scene_bbox, add flag recalc_bbox to request_render() - Call camera.optimizNearFar(scene_bbox) for perspective camera - ApplyTemporaryRCoreExtensions() -- that is not used at this point * EveScene.js - Add comment about better handling of scene / viewer bounding boxes. - In Scene::endChanges() call render via request_render and request bbox recalc.
1 parent c08692c commit 039531d

File tree

2 files changed

+65
-10
lines changed

2 files changed

+65
-10
lines changed

ui5/eve7/lib/EveScene.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,15 @@ sap.ui.define(['rootui5/eve7/lib/EveManager'], function(EveManager) {
201201
this.update3DObjectsVisibility(p.childs, true);
202202
this.need_visibility_update = false;
203203
}
204-
this.glctrl.viewer.render();
205204

205+
// To improve when bbox info is streamed.
206+
// Recalc scene bbox -- and update viewer total bbox, from scene boxes.
207+
// 1. recalc-scene-bbox from known element bboxes (streamed)
208+
// [ this could really be done on the server ]
209+
// 2. tell viewer to recalc-total-bbox ONLY from scene bboxes.
210+
211+
// For now just refresh the gl-viewer.
212+
this.glctrl.viewer.request_render(true);
206213
}
207214
}
208215

ui5/eve7/lib/GlViewerRCore.js

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ sap.ui.define([
8787
return canvasDOM;
8888
};
8989

90+
pthis.ApplyTemporaryRCoreExtensions();
91+
9092
pthis.bootstrap();
9193
});
9294
} else {
@@ -203,6 +205,7 @@ sap.ui.define([
203205
this.renderer.clearColor = "#00000000";
204206
this.scene = new RC.Scene();
205207
this.overlay_scene = new RC.Scene();
208+
this.scene_bbox = new RC.Box3();
206209

207210
this.lights = new RC.Group;
208211
this.lights.name = "Light container";
@@ -470,18 +473,23 @@ sap.ui.define([
470473
this.resetRenderer();
471474
}
472475

473-
resetRenderer()
476+
recalcSceneBBox()
474477
{
475-
let sbbox = new RC.Box3();
476-
sbbox.setFromObject( this.scene );
477-
if (sbbox.isEmpty())
478+
this.scene_bbox.setFromObject( this.scene );
479+
if (this.scene_bbox.isEmpty())
478480
{
479-
console.error("GlViewerRenderCore.resetRenderer scene bbox empty", sbbox);
481+
console.error("GlViewerRenderCore.resetRenderer scene bbox empty", this.scene_bbox);
480482
const ext = 100;
481-
sbbox.expandByPoint(new RC.Vector3(-ext,-ext,-ext));
482-
sbbox.expandByPoint(new RC.Vector3( ext, ext, ext));
483+
this.scene_bbox.expandByPoint(new RC.Vector3(-ext,-ext,-ext));
484+
this.scene_bbox.expandByPoint(new RC.Vector3( ext, ext, ext));
483485
}
486+
}
487+
488+
resetRenderer()
489+
{
490+
this.recalcSceneBBox();
484491

492+
let sbbox = this.scene_bbox;
485493
let posV = new RC.Vector3; posV.subVectors(sbbox.max, this.rot_center);
486494
let negV = new RC.Vector3; negV.subVectors(sbbox.min, this.rot_center);
487495

@@ -540,6 +548,19 @@ sap.ui.define([
540548
this.controls.update();
541549
}
542550

551+
setupCamera()
552+
{
553+
// To be used with JS debugger to edit the values as needed.
554+
555+
let pos = new RC.Vector3;
556+
let lookat = new RC.Vector3;
557+
let fov = 30; // in degrees
558+
559+
console.log("A good place to set the breakpoint and edit the values");
560+
561+
// Call the controller stuff, hope it's not all local, otherwise we need to edit it there.
562+
// Sigh, should really have it (and RedeQuTor) in ROOT.
563+
}
543564

544565
updateViewerAttributes()
545566
{
@@ -641,20 +662,28 @@ sap.ui.define([
641662

642663
//==============================================================================
643664

644-
request_render()
665+
request_render(recalc_sbbox=false)
645666
{
646667
// console.log("REQUEST RENDER");
647668

669+
this.render_requested_recalc_sbbox ||= recalc_sbbox;
648670
if (this.render_requested) return;
649671
setTimeout(this.render.bind(this), 0);
650672
this.render_requested = true;
651673
}
652674

653675
render()
654676
{
655-
// console.log("RENDER", this.scene, this.camera, this.canvas, this.renderer);
677+
console.log("RENDER", this.scene, this.camera, this.canvas, this.renderer);
656678

657679
this.render_requested = false;
680+
if (this.render_requested_recalc_sbbox) {
681+
this.recalcSceneBBox();
682+
this.render_requested_recalc_sbbox = false;
683+
}
684+
if (this.camera.isPerspectiveCamera) {
685+
this.camera.optimizeNearFar(this.scene_bbox);
686+
}
658687

659688
if (this.canvas.width <= 0 || this.canvas.height <= 0) return;
660689

@@ -1220,6 +1249,25 @@ sap.ui.define([
12201249
</html>`);
12211250
win.document.close();
12221251
}
1252+
1253+
//==============================================================================
1254+
// Temporary RCore additions (to avoid updating of RCore.tgz)
1255+
//==============================================================================
1256+
1257+
ApplyTemporaryRCoreExtensions() {
1258+
console.log("GlViewerRCore.ApplyTemporaryRCoreExtensions()");
1259+
1260+
// E.g.:
1261+
// if (RC.PerspectiveCamera.prototype.optimizeNearFar === undefined) {
1262+
// RC.PerspectiveCamera.prototype.optimizeNearFar = function(scene_bbox) {
1263+
// this.matrixWorldInverse.getInverse(this.matrixWorld);
1264+
// // .....
1265+
// };
1266+
// }
1267+
}
1268+
1269+
//==============================================================================
1270+
12231271
} // class GlViewerRCore
12241272

12251273
return GlViewerRCore;

0 commit comments

Comments
 (0)