Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/PenguinMod/PenguinMod-Vm
Browse files Browse the repository at this point in the history
…into develop
  • Loading branch information
jwklong committed Dec 1, 2024
2 parents 723e63f + 817cf0c commit a734a6a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/compiler/jsgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -1239,14 +1239,14 @@ class JSGenerator {
}
case 'control.repeatForSeconds': {
const duration = this.localVariables.next();
this.source += `thread.timer = timer();\n`;
this.source += `thread.timer2 = timer();\n`;
this.source += `var ${duration} = Math.max(0, 1000 * ${this.descendInput(node.times).asNumber()});\n`;
this.requestRedraw();
this.source += `while (thread.timer.timeElapsed() < ${duration}) {\n`;
this.source += `while (thread.timer2.timeElapsed() < ${duration}) {\n`;
this.descendStack(node.do, new Frame(true, 'control.repeatForSeconds'));
this.yieldLoop();
this.source += `}\n`;
this.source += 'thread.timer = null;\n';
this.source += 'thread.timer2 = null;\n';
break;
}
case 'control.stopAll':
Expand Down
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 a734a6a

Please sign in to comment.