Skip to content
11 changes: 8 additions & 3 deletions blocks/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
38 changes: 36 additions & 2 deletions ui/blockmesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -333,6 +333,8 @@ export function updateMeshFromBlock(mesh, block, changeEvent) {
"load_character",
"create_map",
"rotate_to",
"scale",
"resize"
].includes(block.type)
) {
color = block
Expand Down Expand Up @@ -460,13 +462,23 @@ 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"),
y: block.getInput("Y").connection.targetBlock().getFieldValue("NUM"),
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,
Expand Down Expand Up @@ -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"
Expand All @@ -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,
Expand Down