Done.
I have shared my script below
let mouse_on_ground = false;
let canvas = document.getElementById("renderCanvas");
let engine = new BABYLON.Engine(canvas, true, {
preserveDrawingBuffer: true,
stencil: true,
disableWebGL2Support: false,
});
engine.setHardwareScalingLevel(0.5);
const scene = new BABYLON.Scene(engine);
const camera = new BABYLON.ArcRotateCamera(
"camera",
Math.PI / 2,
Math.PI / 2.5,
3,
new BABYLON.Vector3(0, 0, 4),
scene
);
scene.shadowsEnabled = true;
camera.wheelPrecision = 20;
camera.position = new BABYLON.Vector3(30,1,0);
camera.fov = 0.5;
camera.inertia = 0.8;
camera.target = new BABYLON.Vector3(0,0,0);
camera.attachControl(canvas, true);
// const light = new BABYLON.HemisphericLight(
// "light",
// new BABYLON.Vector3(0, 1, 0),
// scene
// );
let json_data;
let material_data;
var hdrTexture = new BABYLON.CubeTexture.CreateFromPrefilteredData(
"assets/textures/sample.env",
scene
);
scene.environmentTexture = hdrTexture;
scene.environmentIntensity = 0.4;
const ground = BABYLON.MeshBuilder.CreateGround("ground", { width: 40, height: 10 });
let material_gnd = new BABYLON.PBRMaterial("ground_material", scene);
const cursor_part = BABYLON.MeshBuilder.CreateGround("cursor_part", { width: 2, height: 2 });
const cursor_part_material = new BABYLON.PBRMaterial("cursor_part_material", scene);
cursor_part_material.unlit = true;
cursor_part_material.albedoColor = new BABYLON.Color3(1, 0, 0);
cursor_part_material.backFaceCulling = false;
cursor_part_material.albedoTexture = new BABYLON.Texture(
"./assets/textures/ring.webp",
scene
);
cursor_part_material.albedoTexture.uScale = 1;
cursor_part_material.albedoTexture.vScale = -1;
cursor_part_material.opacityTexture = new BABYLON.Texture(
"./assets/textures/ring.webp",
scene
);
cursor_part_material.opacityTexture.uScale = 1;
cursor_part_material.opacityTexture.vScale = -1;
cursor_part.material = cursor_part_material;
ground.material = material_gnd;
ground.position.y -= 2;
// scene.createDefaultSkybox(hdrTexture, true, 10000);
$.getJSON("assets/json/materials.json", function (json) {
let json_data = json;
material_data = json_data.Materials;
start();
});
var defaultPipeline = new BABYLON.DefaultRenderingPipeline(
"default",
true,
scene,
[camera]
);
defaultPipeline.fxaaEnabled = true;
function start() {
let ground_plane = scene.getMeshByName("ground");
interfacing_action_manager = new BABYLON.ActionManager(scene);
interfacing_action_manager.registerAction(
new BABYLON.ExecuteCodeAction(
BABYLON.ActionManager.OnPointerOverTrigger,
function (ev) {
let mesh_under_cursor = ev.meshUnderPointer.name;
mouse_on_ground = true;
}
)
);
interfacing_action_manager.registerAction(
new BABYLON.ExecuteCodeAction(
BABYLON.ActionManager.OnPointerOutTrigger,
function (ev) {
mouse_on_ground = false;
}
)
);
ground_plane.actionManager = interfacing_action_manager;
}
scene.onPointerMove = function (event, pickResult) {
if (mouse_on_ground) {
cursor_part.position = new BABYLON.Vector3(pickResult.pickedPoint.x, pickResult.pickedPoint.y + 0.1, pickResult.pickedPoint.z);
}
}
scene.onPointerDown = function (event, pickResult) {
if (mouse_on_ground) {
let camPosTo = new BABYLON.Vector3(pickResult.pickedPoint.x, pickResult.pickedPoint.y + 1, pickResult.pickedPoint.z);
camera.position = camPosTo;
camera.target = new BABYLON.Vector3(pickResult.pickedPoint.x,pickResult.pickedPoint.y + 1,pickResult.pickedPoint.z+1)
}
}
engine.runRenderLoop(function () {
if (scene && scene.activeCamera) {
scene.render();
}
});
window.addEventListener("resize", function () {
engine.resize();
});