Skip to content

Commit

Permalink
Basic meshes touching
Browse files Browse the repository at this point in the history
  • Loading branch information
tracygardner committed Jul 17, 2024
1 parent 6dd06f0 commit 9dce72e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dev-dist/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ define(['./workbox-07658ed7'], (function (workbox) { 'use strict';
"revision": "3ca0b8505b4bec776b69afdba2768812"
}, {
"url": "index.html",
"revision": "0.lvf0phfdjeo"
"revision": "0.gnq4vmpjcjo"
}], {});
workbox.cleanupOutdatedCaches();
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
Expand Down
55 changes: 53 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,10 @@ const toolbox = {
kind: "block",
type: "key_pressed",
},
{
kind: "block",
type: "meshes_touching",
},
],
},
{
Expand Down Expand Up @@ -2533,6 +2537,31 @@ Blockly.Blocks["key_pressed"] = {
},
};

Blockly.Blocks["meshes_touching"] = {
init: function () {
this.jsonInit({
type: "meshes_are_touching",
message0: "%1 touching %2",
args0: [
{
type: "field_variable",
name: "MESH1",
variable: "mesh",
},
{
type: "field_variable",
name: "MESH2",
variable: "mesh2",
},
],
output: "Boolean",
colour: 210,
tooltip:
"Returns true if the two selected meshes are touching, with retries for loading.",
helpUrl: "",
});
},
};
Blockly.Blocks["move_forward"] = {
init: function () {
this.jsonInit({
Expand Down Expand Up @@ -3670,8 +3699,6 @@ javascriptGenerator.forBlock["clear_effects"] = function (block) {

return `window.whenModelReady(${modelName}, function(mesh) {
if (mesh) {
console.log("Removing effects");
window.highlighter.removeMesh(mesh);
mesh.renderOverlay = false;
Expand Down Expand Up @@ -3947,6 +3974,30 @@ javascriptGenerator.forBlock["key_pressed"] = function (block) {
return [code, javascriptGenerator.ORDER_NONE];
};

javascriptGenerator.forBlock["meshes_touching"] = function (block) {
const mesh1VarName = javascriptGenerator.nameDB_.getName(
block.getFieldValue("MESH1"),
Blockly.Names.NameType.VARIABLE,
);
const mesh2VarName = javascriptGenerator.nameDB_.getName(
block.getFieldValue("MESH2"),
Blockly.Names.NameType.VARIABLE,
);

const code = `
(function () {
const mesh1 = scene.getMeshByName(${mesh1VarName});
const mesh2 = scene.getMeshByName(${mesh2VarName});
if (mesh1 && mesh2 && mesh2.isEnabled()) {
return mesh1.intersectsMesh(mesh2, false);
} else {
return false;
}
})()
`;
return [code, javascriptGenerator.ORDER_ATOMIC];
};

const createScene = function () {
window.scene = new BABYLON.Scene(engine);
window.scene.eventListeners = [];
Expand Down

0 comments on commit 9dce72e

Please sign in to comment.