import { DirectionalLight, Object3D, Vector3, Mesh, Material } from "three"; import { ThreeC } from "./ThreeC"; import { CameraC } from "./CameraC"; import { InputC, UpdateController } from "@24tools/playable_template"; export class TestSceneC { private static character: Object3D | null = null; static init() { this.loadMapModel(); this.loadCharacter(); // example of using InputC events InputC.onTouchDown.addDelegate((event) => { console.log("onMouseDown", event); }); // Update loop to follow character with camera UpdateController.Instance.onUpdate.addDelegate(() => { this.updateCameraFollow(); }); } private static loadMapModel() { const mapObject = ThreeC.getObject("map"); if (!mapObject) { console.warn("Map model resource not found: map"); return; } mapObject.position.set(0, 0, 0); ThreeC.setShadowsStateForChildren(mapObject, true, true); ThreeC.addToScene(mapObject); } private static updateCameraFollow() { if (!this.character || !CameraC.camera) return; // Position camera at 75 degree angle from horizontal, slightly to the side const charPos = this.character.position; const angle = 70 * (Math.PI / 180); // 75 degrees const distance = 10; const sideOffset = 5; // offset to the left side // Calculate vertical and horizontal distances based on 75 degree angle const verticalDistance = distance * Math.sin(angle); const horizontalDistance = distance * Math.cos(angle); CameraC.camera.position.set( charPos.x + sideOffset, charPos.y + verticalDistance, charPos.z + horizontalDistance ); CameraC.camera.lookAt(charPos.x, charPos.y + 1, charPos.z); } private static loadCharacter() { const charObject = ThreeC.getObject("character"); if (!charObject) { console.warn("Character model resource not found: character"); return; } // Place character near the map center; adjust Y for ground offset charObject.position.copy(new Vector3(0, 0, 32)); this.character = charObject; ThreeC.setShadowsStateForChildren(charObject, true, true); ThreeC.addToScene(charObject); } }