I made an object renderer with triangles using canvasDraw module, but only for one object, how do I render more objects at the same time?
script
local Map = workspace:WaitForChild("Map"):GetDescendants()
local Camera = workspace.CurrentCamera
local CanvasModule = require(script.Parent.CanvasDraw)
local Canvas = CanvasModule.new(script.Parent.Parent.Frame, Vector2.new(150,150))
local brickTexture = CanvasModule.GetImageData(game.ReplicatedStorage.Textures.RedCube)
local a = 0
local b = -8
for _, Object in pairs(Map) do
if Object:IsA("BasePart") then
b += 8
for i = 1, 8 do
a += 1
local folder = script.Parent.Parent.Frames
local frame = Instance.new("Frame")
frame.Parent = script.Parent.Parent.Frames
frame.AnchorPoint = Vector2.new(0.5, 0.5)
frame.BackgroundColor3 = Color3.new(0,1,0)
frame.Name = "Frame".. a
coroutine.wrap(function()
while true do
local Corners = {
[1] = Object.CFrame * CFrame.new(Object.Size.X / 2, Object.Size.Y / 2, Object.Size.Z / 2),
[2] = Object.CFrame * CFrame.new(Object.Size.X / 2, Object.Size.Y / 2, Object.Size.Z / -2),
[3] = Object.CFrame * CFrame.new(Object.Size.X / 2, Object.Size.Y / -2, Object.Size.Z / 2),
[4] = Object.CFrame * CFrame.new(Object.Size.X / 2, Object.Size.Y / -2, Object.Size.Z / -2),
[5] = Object.CFrame * CFrame.new(Object.Size.X / -2, Object.Size.Y/ 2, Object.Size.Z / 2),
[6] = Object.CFrame * CFrame.new(Object.Size.X / -2, Object.Size.Y / -2, Object.Size.Z / 2),
[7] = Object.CFrame * CFrame.new(Object.Size.X / -2, Object.Size.Y / -2, Object.Size.Z / -2),
[8] = Object.CFrame * CFrame.new(Object.Size.X / -2, Object.Size.Y / 2, Object.Size.Z / -2)
}
local ViewportSize = Camera.ViewportSize
local AspectRatio = ViewportSize.X/ViewportSize.Y
local VerticalFoV = math.rad(Camera.FieldOfView)
local ScreenSizeY = 2*math.tan(VerticalFoV/2)
local ScreenSizeX = AspectRatio*ScreenSizeY
local RelativePosition1 = Camera.CFrame:Inverse() * Corners[i]
local ScreenPositionX1 = RelativePosition1.X/-RelativePosition1.Z
local ScreenPositionY1 = RelativePosition1.Y/-RelativePosition1.Z
frame.Position = UDim2.fromScale(
1/2 + ScreenPositionX1/ScreenSizeX,
1/2 - ScreenPositionY1/ScreenSizeY
)
local function frame(name)
return Vector2.new(folder:WaitForChild(name).Position.X.Scale, folder:WaitForChild(name).Position.Y.Scale) * 150
end
local function drawTriangle(num1 : number, num2 : number, num3 : number, Color : Color3)
Canvas:DrawTriangle(frame("Frame" .. num1), frame("Frame" .. num2), frame("Frame" .. num3), Color, true)
end
local function drawTexturedTriangle(num1 : number, num2 : number, num3 : number, ImagePos1, ImagePos2, ImagePos3, ImageData, Brighness)
Canvas:DrawTexturedTriangle(frame("Frame" .. num1), frame("Frame" .. num2), frame("Frame" .. num3), ImagePos1, ImagePos2, ImagePos3, ImageData, Brighness)
end
drawTriangle(1,2,3, Color3.new(1,1,0))
drawTriangle(2,3,4, Color3.new(1,1,0))
drawTriangle(2,4,8, Color3.new(0,1,0))
drawTriangle(8,4,7, Color3.new(0,1,0))
drawTriangle(5,7,8, Color3.new(0,0,1))
drawTriangle(5,6,7, Color3.new(0,0,1))
drawTriangle(1,6,5, Color3.new(0,1,1))
drawTriangle(1,6,3, Color3.new(0,1,1))
drawTriangle(1,5,8, Color3.new(1, 0, 0))
drawTriangle(1,8,2, Color3.new(1, 0, 0))
game:GetService("RunService").PreRender:Wait()
Canvas:Clear(Color3.new(1,1,1))
end
end) ()
end
end
end