@@ -41,6 +41,8 @@ export function createGrid(scene, meshes) {
4141 const gridTracker = createGridTracker ( scene , meshes ) ;
4242 let tools = createTools ( scene , meshes , gridTracker , grid ) ;
4343
44+
45+
4446 // Player starts on this cell, the mesh is already filled in.
4547 // gridTracker[Math.floor(gridSize / 2)][Math.floor(gridSize / 2)] = true; // Fill a cell
4648
@@ -49,59 +51,80 @@ export function createGrid(scene, meshes) {
4951 }
5052
5153 // Grid Input Actions //
52- // grid.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickTrigger, (evt) => {
53- // if (ON_MOBILE) {
54- // const { width, height } = scene.getEngine().getRenderingCanvas();
55- // if (evt.pointerY >= height * 0.6) {
56- // console.log("clicked bottom");
57- // CANVASES[1].style.zIndex = 1;
58- // return;
59- // }
60- // }
61- // const pickedPoint = evt.additionalData.pickedPoint;
62- // if (!pickedPoint) return;
63-
64- // const xIndex = Math.round(pickedPoint.x / cellSize);
65- // const zIndex = Math.round(pickedPoint.z / cellSize);
66- // let gridTrackerIndex = convert(xIndex, zIndex);
67- // // console.log(`Clicked gridTrackerIndex: (${gridTrackerIndex.x}, ${gridTrackerIndex.z})`);
68- // // console.log(`Clicked cell center: (${xIndex}, ${zIndex})`);
69-
70- // // Create or remove the floor mesh based on click type
71- // if (evt.sourceEvent.button === 0) { // Left click
72- // // Do current Selected Tool
73- // tools.selectedTool.click(xIndex, zIndex, gridTrackerIndex, gridTracker, pickedPoint);
74-
75- // // let floor = scene.getMeshByName(`floor_${xIndex}_${zIndex}`);
76- // // if (!floor) {
77- // // let removeFunction = function () {
78- // // disposeAnimation(scene, floor);
79- // // gridTracker[gridTrackerIndex.x][gridTrackerIndex.z] = false;
80- // // removeAllWalls(gridTrackerIndex.x, gridTrackerIndex.z);
81- // // updateCellAndSurronding(gridTrackerIndex, meshes);
82- // // };
83- // // floor = createFloor(scene, xIndex, zIndex, cellSize, meshes, removeFunction);
84- // // // Position at the exact center of the cell
85- // // floor.position = new BABYLON.Vector3((xIndex + 0.5) * cellSize - cellSize / 2, 0.1, (zIndex + 0.5) * cellSize - cellSize / 2);
86-
87- // // let completeFunction = function () {
88- // // gridTracker[gridTrackerIndex.x][gridTrackerIndex.z] = true;
89- // // updateCellAndSurronding(gridTrackerIndex, meshes);
90- // // }
91- // // floor.completeFunction = completeFunction;
92- // // entryAnimationFloor(scene, floor, meshes);
93-
94-
95- // // }
96- // }// else if (evt.sourceEvent.button === 2) { // Right click
97- // // const floor = scene.getMeshByName(`floor_${x}_${z}`);
98- // // if (floor) {
99- // // // Scale down and remove
100- // // floor.scaling = new BABYLON.Vector3(0, 0, 0); // Animate this for a smoother effect
101- // // setTimeout(() => floor.dispose(), 300); // Delay to show scaling
102- // // }
103- // // }
104- // }));
54+ grid . actionManager . registerAction ( new BABYLON . ExecuteCodeAction ( BABYLON . ActionManager . OnPickTrigger , ( evt ) => {
55+ if ( ON_MOBILE ) {
56+ const { width, height } = scene . getEngine ( ) . getRenderingCanvas ( ) ;
57+ if ( evt . pointerY >= height * 0.6 ) {
58+ console . log ( "clicked bottom" ) ;
59+ CANVASES [ 1 ] . style . zIndex = 1 ;
60+ return ;
61+ }
62+ }
63+ const pickedPoint = evt . additionalData . pickedPoint ;
64+ if ( ! pickedPoint ) return ;
65+
66+ const xIndex = Math . round ( pickedPoint . x / cellSize ) ;
67+ const zIndex = Math . round ( pickedPoint . z / cellSize ) ;
68+ let gridTrackerIndex = convert ( xIndex , zIndex ) ;
69+ // console.log(`Clicked gridTrackerIndex: (${gridTrackerIndex.x}, ${gridTrackerIndex.z})`);
70+ // console.log(`Clicked cell center: (${xIndex}, ${zIndex})`);
71+
72+ // Create or remove the floor mesh based on click type
73+ if ( evt . sourceEvent . button === 0 ) { // Left click
74+
75+ // Clicked Entire Building - Brings up Bubble Menu
76+ // // Swap Building Type
77+ // // Or Edit Position
78+ // const gizmoManager = new BABYLON.GizmoManager(scene);
79+ // gizmoManager.positionGizmoEnabled = true;
80+ // gizmoManager.rotationGizmoEnabled = true;
81+ // // gizmoManager.scaleGizmoEnabled = true;
82+ // gizmoManager.boundingBoxGizmoEnabled = true;
83+ // gizmoManager.usePointerToAttachGizmos = false;
84+ // gizmoManager.attachToMesh(gridTracker.parentNode);
85+ // // gizmoManager.attachableMeshes = [gridTracker.parentNode];
86+
87+ // Clicked Individual
88+
89+ // Clicked Terrain
90+ // Do current Selected Tool
91+ // tools.selectedTool.click(xIndex, zIndex, gridTrackerIndex, gridTracker, pickedPoint);
92+
93+ // let floor = scene.getMeshByName(`floor_${xIndex}_${zIndex}`);
94+ // if (!floor) {
95+ // let removeFunction = function () {
96+ // disposeAnimation(scene, floor);
97+ // gridTracker[gridTrackerIndex.x][gridTrackerIndex.z] = false;
98+ // removeAllWalls(gridTrackerIndex.x, gridTrackerIndex.z);
99+ // updateCellAndSurronding(gridTrackerIndex, meshes);
100+ // };
101+ // floor = createFloor(scene, xIndex, zIndex, cellSize, meshes, removeFunction);
102+ // // Position at the exact center of the cell
103+ // floor.position = new BABYLON.Vector3((xIndex + 0.5) * cellSize - cellSize / 2, 0.1, (zIndex + 0.5) * cellSize - cellSize / 2);
104+
105+ // let completeFunction = function () {
106+ // gridTracker[gridTrackerIndex.x][gridTrackerIndex.z] = true;
107+ // updateCellAndSurronding(gridTrackerIndex, meshes);
108+ // }
109+ // floor.completeFunction = completeFunction;
110+ // entryAnimationFloor(scene, floor, meshes);
111+
112+
113+ // }
114+ } // else if (evt.sourceEvent.button === 2) { // Right click
115+ // const floor = scene.getMeshByName(`floor_${x}_${z}`);
116+ // if (floor) {
117+ // // Scale down and remove
118+ // floor.scaling = new BABYLON.Vector3(0, 0, 0); // Animate this for a smoother effect
119+ // setTimeout(() => floor.dispose(), 300); // Delay to show scaling
120+ // }
121+ // }
122+ } ) ) ;
123+
124+
125+
126+ var parentNode = new BABYLON . TransformNode ( "parentNode" , scene ) ;
127+ gridTracker . parentNode = parentNode ;
105128
106129
107130
@@ -121,6 +144,9 @@ export function createGrid(scene, meshes) {
121144 }
122145 if ( pointerInfo . type === BABYLON . PointerEventTypes . POINTERUP ) {
123146 leftHeldDown = false ;
147+ if ( pointerInfo . event . button == 0 ) {
148+ if ( tools . selectedTool . mouseUp ) tools . selectedTool . mouseUp ( gridTracker ) ;
149+ }
124150 }
125151
126152 if ( pointerInfo . type === BABYLON . PointerEventTypes . POINTERMOVE ) {
0 commit comments