Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic LOD switching #324

Draft
wants to merge 33 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e4d2f6a
backport [ff-three #3](https://github.com/Smithsonian/ff-three/pull/3…
sdumetz Aug 1, 2024
727d436
add navigation type setting
sdumetz Apr 15, 2024
47969ef
prototype orbit pivot
sdumetz Apr 15, 2024
2829fb3
handle double-click pivot move
sdumetz Apr 15, 2024
c0ae81a
add model matrix to event coordinates to take into account the scene'…
sdumetz Apr 30, 2024
71a1d43
Fix : offset compensation, mesh transform support
sdumetz Apr 30, 2024
d7427ca
proper scene file storage for pivot point. Update schema.
sdumetz Apr 30, 2024
d5c4d66
merge OrbitNavigation and Camera projection property
sdumetz Jun 17, 2024
ab114cd
retain pivot point when saving annotation view
sdumetz Jun 17, 2024
e8f4bf9
fix a bug where if a mesh was the children of another node, the paren…
sdumetz Jul 3, 2024
342ab8f
add internal _projection value to CVOrbitNavigation to force update w…
sdumetz Sep 4, 2024
442f0fb
better zoomExtents with pivot
sdumetz Sep 5, 2024
3ea8e66
cancellable fetch for derivatives
sdumetz Jul 15, 2024
713738c
pre-init textures when loading model
sdumetz Sep 6, 2024
a84f8aa
simplest prototype for central management of derivatives quality
sdumetz Sep 6, 2024
8477a99
very simple quality selection algorithm based on relative size
sdumetz Sep 6, 2024
a44e87e
use renderer's compileAsync to speed up models injection
sdumetz Sep 9, 2024
f6f235f
fix a race condition on derivative load callback. Explain early retur…
sdumetz Sep 9, 2024
2ce2365
fix another race condition where CVModel would try to remove an objec…
sdumetz Sep 9, 2024
525e785
Merge branch 'perf_three_168' into perf_merged
sdumetz Sep 9, 2024
3391835
Merge branch 'perf_init_textures' into perf_merged
sdumetz Sep 9, 2024
8db054e
Merge branch 'perf_compile_async' into perf_merged
sdumetz Sep 9, 2024
7b5795f
Merge branch 'perf_central_quality' into perf_merged
sdumetz Sep 9, 2024
64cf99d
improved derivative quality selection algorithm : use models visible …
sdumetz Sep 9, 2024
41c8dab
totally broken and flickering dynamic performance adjustment
sdumetz Sep 9, 2024
b2741b6
hide spinner outside of initial load
sdumetz Sep 9, 2024
10d6ae9
enable unit tests (empty)
sdumetz Sep 10, 2024
f6a21ed
dump better but still bad dynamic LOD algorithm
sdumetz Sep 10, 2024
6eba93f
[WIP] dump things
sdumetz Sep 19, 2024
2ea5f95
[WIP] dump progress, working moderately well on Lascaux
sdumetz Oct 15, 2024
828564c
Merge branch 'upstream_nav_pivot' into perf_merged
sdumetz Oct 15, 2024
0676208
dblclick on touch devices
sdumetz Oct 17, 2024
bbc8efb
some minor tweaks
sdumetz Oct 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
node_modules/

dist/
test/
files/
services/server/bin/
services/secrets.env
Expand Down
5 changes: 4 additions & 1 deletion libs/ff-scene/source/components/CRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { Mesh } from "three";
import * as constants from "three/src/constants";
import * as constants from "three/src/constants.js";

import Component, { Node, ITypedEvent, types } from "@ff/graph/Component";
import CPulse, { IPulseEvent } from "@ff/graph/components/CPulse";
Expand Down Expand Up @@ -66,6 +66,7 @@ export default class CRenderer extends Component
static readonly outs = {
maxTextureSize: types.Integer("Caps.MaxTextureSize"),
maxCubemapSize: types.Integer("Caps.MaxCubemapSize"),
framerate: types.Integer("Renderer.Framerate"),
};

ins = this.addInputs(CRenderer.ins);
Expand Down Expand Up @@ -221,7 +222,9 @@ export default class CRenderer extends Component

this.views.forEach(view => {
if(!view.renderer.xr.isPresenting) {
const start = (performance || Date).now();
view.render();
this.outs.framerate.value = this.outs.framerate.value *0.9 + 0.1*1000/((performance || Date).now() -start);
}
});

Expand Down
56 changes: 47 additions & 9 deletions libs/ff-three/source/CameraController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
Vector3,
Matrix4,
Box3,
Spherical,
Euler,
Quaternion,
} from "three";

import math from "@ff/core/math";
Expand All @@ -30,6 +33,9 @@ const _mat4 = new Matrix4();
const _box3 = new Box3();
const _vec3a = new Vector3();
const _vec3b = new Vector3();
const _vec3c = new Vector3();
const _eua = new Euler();
const _quat = new Quaternion();

enum EControllerMode { Orbit, FirstPerson }
enum EManipMode { Off, Pan, Orbit, Dolly, Zoom, PanDolly, Roll }
Expand All @@ -42,6 +48,7 @@ export default class CameraController implements IManip

orbit = new Vector3(0, 0, 0);
offset = new Vector3(0, 0, 50);
pivot = new Vector3(0, 0, 0);

minOrbit = new Vector3(-90, -Infinity, -Infinity);
maxOrbit = new Vector3(90, Infinity, Infinity);
Expand Down Expand Up @@ -146,15 +153,22 @@ export default class CameraController implements IManip
this.viewportHeight = height;
}

/**
* Copy the object's matrix into the controller's properties
* effectively the inverse operation of updateCamera
*/
updateController(object?: Object3D, adaptLimits?: boolean)
{
const camera = this.camera;
object = object || camera;

const orbit = this.orbit;
const offset = this.offset;
threeMath.decomposeOrbitMatrix(object.matrix, orbit, offset);
this.orbit.multiplyScalar(threeMath.RAD2DEG);
object.matrix.decompose(_vec3b, _quat, _vec3c);
//Rotation
_eua.setFromQuaternion(_quat, "YXZ");
_vec3a.setFromEuler(_eua).multiplyScalar(threeMath.RAD2DEG);
this.orbit.copy(_vec3a);
this.offset.copy(_vec3b.sub(this.pivot).applyQuaternion(_quat.invert()));

if (adaptLimits) {
this.minOffset.min(offset);
Expand All @@ -177,15 +191,32 @@ export default class CameraController implements IManip
return;
}


// _vec3a.copy(this.orbit).multiplyScalar(math.DEG2RAD);
// _eua.setFromVector3(_vec3a, "YXZ");
// _quat.setFromEuler(_eua);
// //Position, relative to pivot point
// _vec3b.copy(this.offset).applyEuler(_eua).add(this.pivot);
// //Keep scale
// _vec3c.setFromMatrixScale(object.matrix);
// //Compose everything
// object.matrix.compose(_vec3b, _quat, _vec3c);


// rotate box to camera space
_vec3a.copy(this.orbit).multiplyScalar(math.DEG2RAD);
_quat.setFromEuler(_eua.setFromVector3(_vec3a));
_vec3b.setScalar(0);
threeMath.composeOrbitMatrix(_vec3a, _vec3b, _mat4);

_vec3c.setScalar(1);
//Ignore the pivot point for now. Rotate the box into camera space
_mat4.compose(_vec3b, _quat, _vec3c);
_box3.copy(box).applyMatrix4(_mat4.transpose());
_box3.getSize(_vec3a);
_box3.getCenter(_vec3b);

_vec3c.copy(this.pivot).applyMatrix4(_mat4);
_vec3b.sub(_vec3c);

offset.x = _vec3b.x;
offset.y = _vec3b.y;

Expand Down Expand Up @@ -221,7 +252,17 @@ export default class CameraController implements IManip
}

_vec3a.copy(this.orbit).multiplyScalar(math.DEG2RAD);
_vec3b.copy(this.offset);
_eua.setFromVector3(_vec3a, "YXZ");
_quat.setFromEuler(_eua);
//Position, relative to pivot point
_vec3b.copy(this.offset).applyEuler(_eua).add(this.pivot);
//Keep scale
_vec3c.setFromMatrixScale(object.matrix);
//Compose everything
object.matrix.compose(_vec3b, _quat, _vec3c);


object.matrixWorldNeedsUpdate = true;

if (camera.isOrthographicCamera) {
_vec3b.z = this.maxOffset.z; // fixed distance = maxOffset.z
Expand All @@ -230,9 +271,6 @@ export default class CameraController implements IManip
camera.updateProjectionMatrix();
}

threeMath.composeOrbitMatrix(_vec3a, _vec3b, object.matrix);
object.matrixWorldNeedsUpdate = true;

return true;
}

Expand Down
3 changes: 3 additions & 0 deletions libs/ff-three/source/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ const math = {
DEG2RAD: 0.01745329251994329576923690768489,
RAD2DEG: 57.295779513082320876798154814105,

/**
* one-step orbit matrix composition when the pivot point is (0, 0, 0).
*/
composeOrbitMatrix: function(orientation: Vector3, offset: Vector3, result?: Matrix4): Matrix4
{
const pitch = orientation.x;
Expand Down
Loading