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

How to fill shape inside of GUI?

Asked by
y3_th 176
6 years ago
Edited 6 years ago

I am creating a cloth simulation, and I have decided that the best method is to create a cage made of Parts and SpringConstraints inside of the Workspace service, then use Camera:WorldToScreenPoint() to generate a wire-frame with edges and vertices inside of the UI. My only problem is being able to generate faces, which require filling in the space in-between edges. So far, the simulation is very realistic, and I do not want to abandon it.

Here is what the simulation looks like so far.

If you want the source code for edges and vertices, here it is. They are all LocalScripts under Frames.

VERTEX:

01local RunService = game:GetService("RunService") --RUNSERVICE
02 
03--CAMERA
04local camera = workspace.CurrentCamera
05 
06--PART OF CAGE
07local vertex = workspace:WaitForChild("vertex1")
08 
09local point = script.Parent --FRAME
10 
11--DRAW--
12RunService.RenderStepped:Connect(function()
13    --FIND WHERE POINT IS ON SCREEN
14    local vertPos, vertOnScreen = camera:WorldToScreenPoint(vertex.Position)
15 
View all 27 lines...

EDGE:

01local RunService = game:GetService("RunService") --RUNSERVICE
02 
03--CAMERA
04local camera = workspace.CurrentCamera
05 
06--PARTS OF CAGE
07local vertex1 = workspace:WaitForChild("vertex1")
08local vertex2 = workspace:WaitForChild("vertex2")
09 
10--FRAME
11local edge = script.Parent
12 
13--DRAW--
14RunService.RenderStepped:Connect(function()
15    --FIND WHERE POINT IS ON SCREEN
View all 39 lines...

How should I approach filling in the faces?

EDIT: Actually, using knowledge from vector graphics, it could be possible to use the three edges as an "enclosed vector curve", and then create a grid of pixels confined to that group of edges, allowing for custom shapes.

Here is what I am talking about.

So far, I have gotten the grid to track to the triangle by taking the minimum and maximum points, and then positioning and scaling the grid based on those points.

Here's a screenshot.

Here's the current script for the face. I had to modify the size of each "pixel" from 3 pixels to 5 pixels to reduce lag.

01local RunService = game:GetService("RunService") --RUNSERVICE
02 
03local camera = workspace.CurrentCamera --CAMERA
04 
05--PARTS OF CAGE
06local vertex1 = workspace:WaitForChild("vertex1")
07local vertex2 = workspace:WaitForChild("vertex2")
08local vertex3 = workspace:WaitForChild("vertex14")
09 
10--CONTAINER OF PIXELS
11local face = script.Parent
12 
13--DRAW--
14RunService.RenderStepped:Connect(function()
15    --VERTICES THAT MAKE UP TRI
View all 82 lines...

Actually, now that I think about it, spamming edges would be the most efficient method, as spamming pixels generates more lag. Thanks, @StreamG0D!

0
So do you want the faces to be flexible too or are they static within the wire frame? SteamG00B 1633 — 6y
0
I do want the faces to be flexible, as the whole point of using the UI was to create a deformable mesh based on the cage. y3_th 176 — 6y
0
The easiest solution I can think of is to use a bunch of edges as a way to fill the grid, but I doubt the engine could handle that. SteamG00B 1633 — 6y
0
I guess you could place a false CanCollided Part and make it swing with the Cloth, but that'd be exceptionally hard. TheOnlySmarts 233 — 6y
0
So I was just looking throug unanswered questions and came across this old one, I am glad you thought my answer was best, but did it actually solve your problem or does it still lag a lot? SteamG00B 1633 — 6y

1 answer

Log in to vote
0
Answered by
EgoMoose 802 Moderation Voter
6 years ago
Edited 6 years ago

Yeah so this is a bit of an old question, but I think I have a different answer to all those previously posted.

You can draw 2D triangles if you use image labels and a little bit of math.

You can read this post for the math/code

And for the image labels I recommend checking out Quenty's post as opposed to the images I uploaded as they'll get rid of the black line issue that mine have.

Hope this helps!

Ad

Answer this question