Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

(Meshes) How is scale relative to offset?

Asked by 8 years ago

Hi, so I have a little question about meshes.. as the title suggests I would like to know how the 'Scale' of the mesh is relative to the mesh's 'Offset'.

Basically, I'm attempting to create a slider Gui that controls the window of a car, so to do this I used mesh scale and offset (due to meshes scaling from the center), the problem is, I'm not sure how to calculate the offset so the window will scale down, but keep the bottom in the same place.

I hope that was understandable.

Thanks, -Nen

1 answer

Log in to vote
1
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

The offset of a mesh is in measured in studs and the scale is measured in a percent multiplier of the actual size of the mesh. You want to offset the window by half as much as it scales down by, so you'll have to get these two things to the same units of measurements.

In order to do that, we will have to calculate the actual size of the mesh [i.e. the size the mesh is when it is scaled at 100% in all directions (scale = Vector3.new(1, 1, 1))]. The easiest way to do this right now is to copy the MeshId into a MeshPart and record the size of that part. This will be the size of the bounding box of the mesh.

In the case where the mesh doesn't have a MeshId or the edge of the mesh you want to 'stay still' doesn't extend up to the bounding box, you will have to figure out the size in a different way. What you will want to do is create a part and make the outside edges of the part line up (as close as you possibly can) with the edge you want it to resize from. Record the size of that part.

Now that we have the size of the part at 100% scale, we can calculate the offset we need to make the part to appear to scale from one direction instead of the origin.

Example: Shrink mesh down from the top face by half of original size

local size -- Size of the mesh at 100% scale you found earlier
local mesh -- Object hierarchy of the mesh to resize

local function scaleMesh(scale)
    mesh.Scale = scale
    mesh.Offset = (size*scale - size)/2
end

scaleMesh(Vector3.new(1, 0.5, 1))

Note that this will likely take some adjustments to get working correctly, but it is the only way I am aware of.

0
It doesn't have a MeshId, it's just a BlockMesh. Nengalore 25 — 8y
0
Okay, well because the BlockMesh resizes to match the size of the part it is in, the size property in the code snippet I posted would be the size of the part it is parented to (as the scale is relative to that size).  So basically ignore the 2nd and 3rd paragraphs in my answer. BlackJPI 2658 — 8y
0
Alright, I'll try it, thanks. Nengalore 25 — 8y
0
It works, thank you so much. :) Nengalore 25 — 8y
0
No problem :) BlackJPI 2658 — 8y
Ad

Answer this question