diff --git a/blocks/transform.js b/blocks/transform.js index 9c9835ae..d6bd15e2 100644 --- a/blocks/transform.js +++ b/blocks/transform.js @@ -16,9 +16,14 @@ export function defineTransformBlocks() { if (flock.blockDebug) console.log("The ID of this change event is", changeEventBlock.id); const changeEventParentBlock = changeEventBlock.getParent(); if (!changeEventParentBlock) return; - const changeEventBlockType = changeEventParentBlock.type; - if (flock.blockDebug) console.log("The type of this change event is", changeEventBlockType); - if (changeEventBlockType != "rotate_to") return; + const blockTypeList = ["rotate_to", "scale", "resize"]; + const changeEventBlockType = changeEventBlock.type; + const changeEventParentBlockType = changeEventParentBlock.type; + if (flock.blockDebug) console.log("The type of this change event is", changeEventParentBlockType); + if ( + !blockTypeList.includes(changeEventParentBlockType) + && !blockTypeList.includes(changeEventBlockType) + ) return; const handleChange = handleFieldOrChildChange(block, changeEvent) if (flock.blockDebug) console.log(handleChange); } diff --git a/ui/blockmesh.js b/ui/blockmesh.js index b3208a26..42d8914e 100644 --- a/ui/blockmesh.js +++ b/ui/blockmesh.js @@ -148,7 +148,7 @@ export function getMeshFromBlock(block) { return flock?.scene?.getMeshByName("ground"); } - if (block && block.type === "rotate_to") { + if (block && ["rotate_to", "scale", "resize"].includes(block.type)) { block = block.getParent(); } @@ -333,6 +333,8 @@ export function updateMeshFromBlock(mesh, block, changeEvent) { "load_character", "create_map", "rotate_to", + "scale", + "resize" ].includes(block.type) ) { color = block @@ -460,6 +462,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"), @@ -467,6 +470,15 @@ export function updateMeshFromBlock(mesh, block, changeEvent) { z: block.getInput("Z").connection.targetBlock().getFieldValue("NUM"), }; + if (["scale", "resize"].includes(block.type)) { + origin = { + x: block.getFieldValue("X_ORIGIN"), + y: block.getFieldValue("Y_ORIGIN"), + z: block.getFieldValue("Z_ORIGIN"), + }; + if (flock.blockDebug || flock.meshDebug) console.log("origin"); + } + let colors, width, height, @@ -671,7 +683,7 @@ export function updateMeshFromBlock(mesh, block, changeEvent) { flock.changeColor(mesh.name, { color }); } } - if (["X", "Y", "Z"].includes(changed)) { + if (["X", "Y", "Z"].includes(changed) || (changed === "DO" && ["scale", "resize"].includes(shapeType))) { switch (block.type) { case "rotate_to": /* The "position" X, Y and Z values are automatically picked up from the "rotate_to" @@ -684,6 +696,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,