How Can I Turn Wedges Intro Terrain?

Title kinda tells it all. There was someone else how ask this but they haven’t got the answer.

I am turning someone brick terrain into real terrain and would like to know a way I could do this.

1 Like

You can use this plugin by @Quenty

Tried that, it doesn’t work.

1 Like

Mm I guess you’re right.
Sorry about that!

I haven’t done anything like this code-wise, but I do know there’s an article here that might assist you.

I think you’ll have to do design your terrain using blocks though, unless there’s some way to get the Edges of a wedgepart and fill terrain in using that method.

Thanks. I am kinda asking for a function that I would make if I knew math.

Hmm, perfect.
Scroll down the page, you’ll be looking for “FillBlock” or the other region types.

You can also press Control + F and type in “FillBlock” to quickly get there if you’re lazy like me. :smile:

That’s my problem. Its fill block not wedge.

Mmm true.

You’ll probably need something that can obtain the edges of a Wedge part, and then use FillRegion() between each of the edges. The Flood Fill function looks promising for this. :slight_smile:

Depending on how much of this changing you have to do, you could try placing a brick on the slope of the wedge, resize it to cover the slope surface and change said brick to terrain.

That’s what I have been doing but I have a LOT of wedges

A wedge could be made by subtracting a block from another, FillBlock accepts CFrame rotations, and to negate you fill it with air. If your air block is replacing something else, you can generate your wedge on a clean place and then you can copy the region ignoring air.

Here’s the math all worked out for you :slight_smile:

local function fillWedge(wedgePart, mat)
	if not mat then
		mat = Enum.Material.Grass
	end
	
	local wedgeCF = wedgePart.CFrame
	local wedgeSize = wedgePart.Size
	
	local x = wedgeSize.Z
	local y = wedgeSize.Y
	local hypotenuse = math.sqrt(x^2 + y^2)
	local theta = math.atan(y/x)
	
	local cutoffSize = Vector3.new(wedgeSize.X, wedgeSize.Y, hypotenuse) -- the Y size will probably have to change incase you start getting floaty corners of terrain.
	
	local cutoffCFRaw = CFrame.fromAxisAngle(Vector3.new(-1,0,0), theta) * CFrame.new(0, cutoffSize.Y/2, 0)
	local cutoffCF = wedgeCF:toWorldSpace(cutoffCFRaw)
	
	terrain:FillBlock(wedgeCF, wedgeSize, mat)
	terrain:FillBlock(cutoffCF, cutoffSize, Enum.Material.Air)
end

It works and finds the shapes to fill, but wedges don’t come out all too great in terrain. They seem to get rounded off towards the skinny parts.

8 Likes

It works! Thank you so much. Can you make a CornerWegde function tho. You don’t need to but It’d be great if you did. :relaxed:

Well, considering a corner wedge is simply the space of two overlapping wedge parts, you can adapt that code to allow for wedge parts and corner wedge parts:

local WEDGE1_TRANSFORM = CFrame.fromAxisAngle(Vector3.new(0,1,0), math.pi/2) -- 90 degrees around y axis
local WEDGE2_TRANSFORM = CFrame.fromAxisAngle(Vector3.new(0,1,0), math.pi)   -- 180 degrees around y axis

-- new function, but the same logic as the old fillWedge func
local function fillWedgeFromData(wedgeCF, wedgeSize, mat, fillMatOverride, debugMode)
	if not mat then
		mat = Enum.Material.Grass
	end
		
	local x = wedgeSize.Z
	local y = wedgeSize.Y
	local hypotenuse = math.sqrt(x^2 + y^2)
	local theta = math.atan(y/x)
	
	local cutoffSize = Vector3.new(wedgeSize.X, wedgeSize.Y, hypotenuse) -- the Y size will probably have to change incase you start getting floaty corners of terrain.
	
	local cutoffCFRaw = CFrame.fromAxisAngle(Vector3.new(-1,0,0), theta) * CFrame.new(0, cutoffSize.Y/2, 0)
	local cutoffCF = wedgeCF:toWorldSpace(cutoffCFRaw)
	
	if debugMode then
		--terrain:FillBlock(wedgeCF, wedgeSize, mat)
		local part = Instance.new("Part")
		part.Anchored = true
		part.CFrame = cutoffCF
		part.Size = cutoffSize
		part.Parent = game.Workspace
	else
		if not fillMatOverride then
			terrain:FillBlock(wedgeCF, wedgeSize, mat)
		end
		terrain:FillBlock(cutoffCF, cutoffSize, Enum.Material.Air)
	end
end

local function fillWedge(wedgePart, mat, debugMode)	
	fillWedgeFromData(wedgePart.CFrame, wedgePart.Size, mat, false, debugMode)
end

local function fillCornerWedge(cornerWedgePart, mat, debugMode)
	local cwCF = cornerWedgePart.CFrame
	local cwSize = cornerWedgePart.Size
	
	local wedge1CF = cwCF * WEDGE1_TRANSFORM
	local wedge1Size = Vector3.new(cwSize.Z, cwSize.Y, cwSize.X) -- X and Z of CornerWedge are swapped to find wedge1's size
	local wedge2CF = cwCF * WEDGE2_TRANSFORM
	local wedge2Size = cwSize -- Wedge2 has the same size as CornerWedge
	
	fillWedgeFromData(wedge1CF, wedge1Size, mat, debugMode)
	fillWedgeFromData(wedge2CF, wedge2Size, mat, true, debugMode) 
	-- for the second wedge, fillMatOverride must be true, otherwise you'll refill some previously emptied space
end

Hopefully this works good enough for you, it has the same pitfalls as the other fillWedge function, but it works pretty well for large wedges.

3 Likes

Dude your a boss. Thank you so much!!

1 Like