From 3a540d522b0633f0a5d4fa5f53f6d21ed4ebfc55 Mon Sep 17 00:00:00 2001 From: Zishan Rahman Date: Sat, 30 Aug 2025 08:03:16 +0200 Subject: [PATCH] Try to implement scale and resize block synchronisation Still doesn't fully work yet (for some reason) --- blocks/transform.js | 2 +- ui/blockmesh.js | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/blocks/transform.js b/blocks/transform.js index 0d46c0b..f0dac99 100644 --- a/blocks/transform.js +++ b/blocks/transform.js @@ -17,7 +17,7 @@ export function defineTransformBlocks() { if (!changeEventParentBlock) return; const changeEventBlockType= changeEventParentBlock.type; console.log("The type of this change event is", changeEventBlockType); - if (changeEventBlockType != "rotate_to") return; + if (!["rotate_to", "scale", "resize"].includes(changeEventBlockType)) return; console.log(handleFieldOrChildChange(block, changeEvent)); } Blockly.Blocks["move_by_xyz"] = { diff --git a/ui/blockmesh.js b/ui/blockmesh.js index ac2992d..61ddd87 100644 --- a/ui/blockmesh.js +++ b/ui/blockmesh.js @@ -98,7 +98,7 @@ export function deleteMeshFromBlock(blockId) { } export function getMeshFromBlock(block) { - if (block && block.type === "rotate_to") { + if (block && !["rotate_to", "scale", "resize"].includes(block.type)) { block = block.getParent(); } @@ -253,7 +253,9 @@ export function updateMeshFromBlock(mesh, block, changeEvent) { "load_multi_object", "load_character", "create_map", - "rotate_to" + "rotate_to", + "scale", + "resize" ].includes(block.type) ) { color = block @@ -381,6 +383,7 @@ export function updateMeshFromBlock(mesh, block, changeEvent) { // Retrieve the position values (X, Y, Z) from the connected blocks let position; + let origin; position = { x: block.getInput("X").connection.targetBlock().getFieldValue("NUM"), @@ -388,6 +391,15 @@ export function updateMeshFromBlock(mesh, block, changeEvent) { z: block.getInput("Z").connection.targetBlock().getFieldValue("NUM"), }; + if (["scale", "resize"].includes(block.type)) { + origin = { + x: block.getInput("X").connection.targetBlock().getFieldValue("TEXT"), + y: block.getInput("Y").connection.targetBlock().getFieldValue("TEXT"), + z: block.getInput("Z").connection.targetBlock().getFieldValue("TEXT"), + }; + console.log("origin"); + } + let colors, width, height, @@ -589,6 +601,28 @@ export function updateMeshFromBlock(mesh, block, changeEvent) { }); break; + case "scale": + flock.scale(mesh.name, { + x: position.x, + y: position.y, + z: position.z, + xOrigin: origin.x, + yOrigin: origin.y, + zOrigin: origin.z, + }); + break; + + case "resize": + flock.resize(mesh.name, { + x: position.x, + y: position.y, + z: position.z, + xOrigin: origin.x, + yOrigin: origin.y, + zOrigin: origin.z, + }); + break; + default: flock.positionAt(mesh.name, { x: position.x,