+
diff --git a/src/Viewer/Viewer.tsx b/src/Viewer/Viewer.tsx
index 283e18f5..09189e06 100644
--- a/src/Viewer/Viewer.tsx
+++ b/src/Viewer/Viewer.tsx
@@ -2,24 +2,19 @@ import * as THREE from "three";
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";
import { children, createEffect, createSignal, on, onMount } from "solid-js";
-export function Viewer(props: any) {
+type ViewerProps = {
+ size: [number, number];
+ children: any;
+};
+
+export function Viewer(props: ViewerProps) {
let container: HTMLDivElement;
const scene = new THREE.Scene();
- const camera = new THREE.PerspectiveCamera(75, 1.0, 0.1, 1000);
+ const camera = new THREE.PerspectiveCamera(45, 1.0, 0.1, 2 * 1e6); // supported view till 1e6
const renderer = new THREE.WebGLRenderer({ antialias: true });
const controls = new OrbitControls(camera, renderer.domElement);
- camera.position.set(0, 5, 10);
- controls.minDistance = 1;
- controls.maxDistance = 40;
- controls.update();
-
- // on control change
- controls.addEventListener("change", () => {
- renderer.render(scene, camera);
- });
-
onMount(() => {
container.appendChild(renderer.domElement);
@@ -35,6 +30,16 @@ export function Viewer(props: any) {
}).observe(container);
});
+ // on grid size change
+ createEffect(() => {
+ const gridSize = Math.abs(props.size[0]);
+ const z2fit = gridSize / 2 + gridSize / 2 / Math.tan(45 / 2);
+ camera.position.set(0, gridSize / 2, z2fit);
+ controls.minDistance = 1;
+ controls.maxDistance = z2fit * 1.5;
+ controls.update();
+ });
+
// on children (objects) change
createEffect(() => {
const objects = children(() => props.children).toArray();
@@ -47,6 +52,11 @@ export function Viewer(props: any) {
renderer.render(scene, camera);
});
+ // on control change
+ controls.addEventListener("change", () => {
+ renderer.render(scene, camera);
+ });
+
// on render action
createEffect(
on(renderAction, () => {
diff --git a/src/Viewer/objects/ElementResults2.stories.tsx b/src/Viewer/objects/ElementResults2.stories.tsx
index 6bc73a83..d36f6814 100644
--- a/src/Viewer/objects/ElementResults2.stories.tsx
+++ b/src/Viewer/objects/ElementResults2.stories.tsx
@@ -10,8 +10,8 @@ export default {
title: "ElementResults2",
render: () => (
-
-
+
+
grid.dispose());
+export function Grid(props: GridProps) {
+ const group = new THREE.Group();
+ let grid: THREE.GridHelper;
- return <>{grid}>;
+ createEffect(() => {
+ group.clear();
+ grid?.dispose();
+
+ grid = new THREE.GridHelper(props.size[0], 20, 0x666666, 0x404040);
+ group.add(grid);
+
+ setRenderAction((v) => v + 1);
+ });
+
+ onCleanup(() => grid?.dispose());
+
+ return <>{group}>;
}