From a9838a2f0abf5e9e5395c333b68480fa34d38786 Mon Sep 17 00:00:00 2001 From: Casey_Nelson <91818705+CaseyNelson314@users.noreply.github.com> Date: Tue, 30 Jan 2024 21:43:10 +0900 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=9C=9F=E5=8C=96=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=82=92=E3=83=A1=E3=82=A4=E3=83=B3=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E3=81=AB=E7=B5=B1=E5=90=88=E3=81=97=E3=81=9F=E3=81=AE?= =?UTF-8?q?=E3=81=A7init.ts=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/script/init.ts | 98 ---------------------------------------------- 1 file changed, 98 deletions(-) delete mode 100644 app/script/init.ts diff --git a/app/script/init.ts b/app/script/init.ts deleted file mode 100644 index b598de3..0000000 --- a/app/script/init.ts +++ /dev/null @@ -1,98 +0,0 @@ -import * as THREE from 'three'; -import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'; -import { TransformControls } from 'three/examples/jsm/controls/TransformControls'; - -// シーンを作成 -export const CreateScene = () => new THREE.Scene(); - -// レンダラーを作成 -export const CreateRenderer = ( - dom: HTMLElement -) => { - - const renderer = new THREE.WebGLRenderer({ - antialias: true, - alpha: true - }); - - renderer.setSize(dom.offsetWidth, dom.offsetHeight); - renderer.setPixelRatio(window.devicePixelRatio); - - dom.appendChild(renderer.domElement); - - return renderer; - -}; - -// カメラを作成 -export const CreateCamera = ( - dom: HTMLElement -) => { - - const aspect = dom.offsetWidth / dom.offsetHeight; - const camera = new THREE.PerspectiveCamera(50, aspect); - - camera.position.set(150, 150, 150); - - return camera; - -}; - -// マウスコントロールを作成 -export const CreateControls = ( - camera: THREE.PerspectiveCamera, - dom: HTMLElement -) => { - - const controls = new OrbitControls(camera, dom); - - controls.autoRotate = true; // 自動回転 - controls.autoRotateSpeed = 1; // 自動回転の速度 - controls.enableDamping = true; // 視点の移動を滑らかにする - controls.dampingFactor = 0.2; // 滑らか度合い - - return controls; - -}; - -// ドラッグでオブジェクトを移動するためのコントロールを作成 -export const CreateTransformControls = ( - camera: THREE.PerspectiveCamera, - dom: HTMLElement, - controls: OrbitControls, - scene: THREE.Scene -) => { - - const transControls = new TransformControls(camera, dom); - - transControls.addEventListener('dragging-changed', (event) => { - controls.enablePan = !event.value; - controls.enableRotate = !event.value; - }); - - scene.add(transControls); - - return transControls; - -}; - -// リサイズ時のイベントを登録 -export const ResisterResizeObserver = ( - dom: HTMLElement, - renderer: THREE.WebGLRenderer, - camera: THREE.PerspectiveCamera -) => { - - const resizeObserver = new ResizeObserver((entries) => { - if (entries.length === 0) { - return; - } - const { width, height } = entries[0]!.contentRect; - renderer.setSize(width, height); - camera.aspect = width / height; - camera.updateProjectionMatrix(); - }); - - resizeObserver.observe(dom); - -} \ No newline at end of file