Skip to content

Commit

Permalink
arraaayyyyy distanceeee
Browse files Browse the repository at this point in the history
  • Loading branch information
Ianyourgod committed Nov 30, 2024
1 parent a691228 commit 817cf0c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/extensions/jg_3d/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
18 changes: 18 additions & 0 deletions src/extensions/jg_3d/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down

0 comments on commit 817cf0c

Please sign in to comment.