I was trying to make vehicle deformation. The detection for close vertices didn’t work, I checked where are the vertices and found out they are placed like the model was 5 times the size
does anyone have any solution to this?
I was trying to make vehicle deformation. The detection for close vertices didn’t work, I checked where are the vertices and found out they are placed like the model was 5 times the size
The vertex positions are not the final position after scaling, so you need to undo any transformation first. You may need to trial and error this to see which transformations that is. You’ve already found a way to visualize it, so you should be able to tell when it’s right.
what do you mean by “transformation”? I am new to editable meshes and I don’t really understand
Here’s the typical way meshes go from modeling to rendering. The model has vertices with positions that do not change. For a static model (not a car or humanoid), there is one “World” transform which scales, positions, and rotates the model to the desired position, but the original vertex positions do not change, a new set is generated. This means that the vertex positions you get from the mesh will not be located where they appear in the world.
I’m, not 100% on how roblox does this so I need you to confirm something for me. If you move the car, will those positions youre getting stay the same or will they move with the car?
They do move with the car but not rotate
That is very unusual. Let me do a quick test to see how this works. I haven’t used editable meshes before.
It looks like I would have to verify my ID to use editable mesh so I cannot test this for you unfortunately. I still think there is a transformation that will map your vertices to the correct location. What does it look like if you transform the vertices using meshPart.CFrame:VectorToWorldSpace(point)?
you mean transform the visualizer? That’s what I am doing to make them show up
How have you transformed them in the picture you posted?
No I didn’t
.
Can you show the code you used to create the visualization? Just the part that gets the vertices from the mesh and creates the positions to draw the points at.
for _, verId in editableMesh:GetVertices() do
local part = Instance.new("Part")
part.Anchored = true
part.CanCollide = false
part.Transparency = 0.7
part.Color = Color3.new(1, 0, 0.0156863)
part.Position = LocalToWorldPosition(editableMesh:GetPosition(verId), mesh.Position)
part.Size = Vector3.new(0.5, 0.5, 0.5)
part.Shape = "Ball"
part.Parent = workspace
end
Okay but what doe LocalToWorldPosition do? That’s the part that I need to understand.
return position + Local
Although i’d like to see the whole function this already can’t be right because it doesn’t take into account the rotation or scale. It should be something like meshPart.CFrame:PointToWorldSpace(position)
it didn’t work before… the scale is still way too big
Ok but did the rotation and position line up?
yes… thanks
Just the scale needs to be fixed then. That could come from the Model (Scale property) or from a bone, if the model has bones. You need to undo this scale before the transform that sets the rotation and position. Try multiplying the vertex position (what comes from editableMesh:GetPosition(verId)
) by 0.2 just to see if it stays lined up. Then you just have to figure out what the actual number is.
I.e. you could do this:
...
local scale = 0.2
part.Position = LocalToWorldPosition(editableMesh:GetPosition(verId) * scale, mesh.Position)
...
All of the vertexes moved far away from the model but it got also resized