summaryrefslogtreecommitdiff
path: root/public/App.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/App.js')
-rw-r--r--public/App.js46
1 files changed, 38 insertions, 8 deletions
diff --git a/public/App.js b/public/App.js
index c98b708..1f28482 100644
--- a/public/App.js
+++ b/public/App.js
@@ -1,7 +1,7 @@
import { Union, Record } from "./fable_modules/fable-library-js.4.24.0/Types.js";
-import { union_type, class_type, record_type, bool_type, string_type } from "./fable_modules/fable-library-js.4.24.0/Reflection.js";
-import { Replay_frames } from "./SomhairlesDream.Shared/Replay.js";
+import { union_type, obj_type, class_type, record_type, bool_type, string_type } from "./fable_modules/fable-library-js.4.24.0/Reflection.js";
import { comparePrimitives, defaultOf, equals, createAtom } from "./fable_modules/fable-library-js.4.24.0/Util.js";
+import { Replay_frames } from "./SomhairlesDream.Shared/Replay.js";
import { sortBy, map, equalsWith, tryFind, iterateIndexed, item } from "./fable_modules/fable-library-js.4.24.0/Array.js";
import { join, isNullOrWhiteSpace, printf, toText } from "./fable_modules/fable-library-js.4.24.0/String.js";
import { MeshData_triangleIndices, MeshData_positionData } from "./SomhairlesDream.Shared/Domain.js";
@@ -26,20 +26,25 @@ export function RunSelection_$reflection() {
}
export class ViewState extends Record {
- constructor(Renderer, Scene, Camera, Group, Canvas) {
+ constructor(Renderer, Scene, Camera, Group, Canvas, Controls) {
super();
this.Renderer = Renderer;
this.Scene = Scene;
this.Camera = Camera;
this.Group = Group;
this.Canvas = Canvas;
+ this.Controls = Controls;
}
}
export function ViewState_$reflection() {
- return record_type("SomhairlesDream.Frontend.App.ViewState", [], ViewState, () => [["Renderer", string_type], ["Scene", string_type], ["Camera", string_type], ["Group", string_type], ["Canvas", class_type("Browser.Types.HTMLCanvasElement", undefined)]]);
+ return record_type("SomhairlesDream.Frontend.App.ViewState", [], ViewState, () => [["Renderer", string_type], ["Scene", string_type], ["Camera", string_type], ["Group", string_type], ["Canvas", class_type("Browser.Types.HTMLCanvasElement", undefined)], ["Controls", obj_type]]);
}
+export let lastInteractionMs = createAtom(0);
+
+export const idleSpinDelayMs = 3500;
+
export class LoadOwner extends Record {
constructor(ProjectId, RunId, Path) {
super();
@@ -263,6 +268,14 @@ export function frameObject(view, node) {
camera.far = (distance + (radius * 4));
camera.lookAt(0, 0, 0);
camera.updateProjectionMatrix();
+ const matchValue_3 = view.Controls;
+ if (equals(matchValue_3, defaultOf())) {
+ }
+ else {
+ const controls = matchValue_3;
+ controls.target.copy({ x: 0, y: 0, z: 0 });
+ controls.update();
+ }
}
}
}
@@ -297,25 +310,42 @@ export function initializeView() {
scene.background = (new THREE.Color("#11171a"));
const camera = new THREE.PerspectiveCamera(34, (width / height), 0.1, 100);
camera.position.set(6.4, 4.6, 7.2);
- camera.lookAt(0, 1.2, 0);
+ camera.lookAt(0, 0, 0);
const group = new THREE.Group();
scene.add(group);
scene.add(new THREE.AmbientLight("#f0e6c8", 1.9));
const keyLight = new THREE.DirectionalLight("#f2c76b", 2.8);
keyLight.position.set(4, 7, 5);
scene.add(keyLight);
- const view = new ViewState(renderer, scene, camera, group, canvas);
+ const controls = new OrbitControls(camera, canvas);
+ controls.target.copy({ x: 0, y: 0, z: 0 });
+ controls.enableDamping = true;
+ controls.autoRotateSpeed = 0.7;
+ const view = new ViewState(renderer, scene, camera, group, canvas, controls);
viewState(view);
freezeRotation((new URLSearchParams(window.location.search).get("freeze")) === "1");
- window.SOMHAIRLES_VIEWER = { camera: camera, scene: scene, group: group, canvas: canvas };
+ controls.autoRotate = !freezeRotation();
+ window.SOMHAIRLES_VIEWER = { camera: camera, scene: scene, group: group, canvas: canvas, controls: controls };
renderFrame(selectedFrame());
window.addEventListener("resize", (_arg) => {
resizeView(view);
});
- const animate = (_arg_1) => {
+ canvas.addEventListener("pointerdown", (_arg_1) => {
+ lastInteractionMs(Date.now());
+ });
+ canvas.addEventListener("wheel", (_arg_2) => {
+ lastInteractionMs(Date.now());
+ });
+ canvas.addEventListener("touchstart", (_arg_3) => {
+ lastInteractionMs(Date.now());
+ });
+ const animate = (nowMs) => {
+ controls.update();
if (!freezeRotation()) {
group.rotation.y = (group.rotation.y + 0.003);
}
+ const interacting = (nowMs - lastInteractionMs()) < idleSpinDelayMs;
+ controls.autoRotate = (!freezeRotation() && !interacting);
renderer.render(scene, camera);
requestAnimationFrame(animate);
};