diff --git a/src/extensions/jg_3d/index.js b/src/extensions/jg_3d/index.js index 278b0182c61..f86cbb21afa 100644 --- a/src/extensions/jg_3d/index.js +++ b/src/extensions/jg_3d/index.js @@ -930,6 +930,43 @@ class Jg3DBlocks { const result = this.raycastResultToReadable(intersects); return JSON.stringify(result); } + + rayCollisionDistance(args) { + if (!this.scene) return ''; + const origin = new Three.Vector3( + Cast.toNumber(args.X), + Cast.toNumber(args.Y), + Cast.toNumber(args.Z), + ); + const direction = new Three.Vector3( + Cast.toNumber(args.DX), + Cast.toNumber(args.DY), + Cast.toNumber(args.DZ), + ); + const ray = new Three.Raycaster(origin, direction, 0, args.DIS); + const intersects = ray.intersectObjects(this.scene.children, true); + if (intersects.length === 0) return ''; + const first = intersects[0]; + return first.object.name; + } + rayCollisionArrayDistance(args) { + if (!this.scene) return '[]'; + const origin = new Three.Vector3( + Cast.toNumber(args.X), + Cast.toNumber(args.Y), + Cast.toNumber(args.Z), + ); + const direction = new Three.Vector3( + Cast.toNumber(args.DX), + Cast.toNumber(args.DY), + Cast.toNumber(args.DZ), + ); + const ray = new Three.Raycaster(origin, direction, 0, args.DIS); + const intersects = ray.intersectObjects(this.scene.children, true); + if (intersects.length === 0) return '[]'; + const result = this.raycastResultToReadable(intersects); + return JSON.stringify(result); + } } module.exports = Jg3DBlocks; diff --git a/src/extensions/jg_3d/info.js b/src/extensions/jg_3d/info.js index b338abb2792..288e9d5482f 100644 --- a/src/extensions/jg_3d/info.js +++ b/src/extensions/jg_3d/info.js @@ -400,6 +400,24 @@ module.exports = { DY: infoArgument(0), DZ: infoArgument(0), }, Icons.Raycast, true), + createReporterBlock("rayCollisionDistance", "first object in raycast from x: [X] y: [Y] z: [Z] with direction x: [DX] y: [DY] z: [DZ] with a max distance of [DIS]", { + X: infoArgument(0), + Y: infoArgument(0), + Z: infoArgument(0), + DX: infoArgument(0), + DY: infoArgument(0), + DZ: infoArgument(0), + DIS: infoArgument(10) + }, Icons.Raycast, true), + createReporterBlock("rayCollisionArrayDistance", "raycast result from x: [X] y: [Y] z: [Z] with direction x: [DX] y: [DY] z: [DZ] with a max distance of [DIS]", { + X: infoArgument(0), + Y: infoArgument(0), + Z: infoArgument(0), + DX: infoArgument(0), + DY: infoArgument(0), + DZ: infoArgument(0), + DIS: infoArgument(10) + }, Icons.Raycast, true), createReporterBlock("rayCollisionCamera", "first object from raycast in camera center", { }, Icons.Raycast, true), createReporterBlock("rayCollisionCameraArray", "raycast result starting from the camera center", {