Editable Mesh - Flipping Normals || REDO

PROBLEM


I did this exact topic and hour ago and thought i found the solution. I didnt.

Sorry devs for the flag (Old topic - deleted).

I’m trying to make a render on a Mesh, using EditableMesh.

As you know, you are given an OPT “doublesided” button. When false/off the Normal ID inside the mesh is TRANSPARENT.

I want to make every front face to flip (normal) to the inside (TRANSPARENT) face, when not in range of Mesh.

When the “HumanoidRootPart.Position” and “Mesh.Position” are in range together (16 STUDS) the back (which is coming in range [TRANSPARENT]) will flip to the front to make that face visible.

Making a seamless transition of each face rendering.


SOLUTION

I’ve found out that this does in fact improve performance as crazy as it sounds although i haven’t got to it.

As well it fits towards my game.


CODE

--Services
local AssetService = game:GetService("AssetService")
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")

--Players
local player = game:GetService("Players").LocalPlayer

--Character
local character = player.Character or player.CharacterAdded:Wait()

--Folders
local Meshes = workspace:WaitForChild("Meshes")


--Tables
local Table = {}
local MeshTable = {}

--Character BaseParts
local HumanoidRootPart = character:FindFirstChild("HumanoidRootPart")	

local function onRenderStepped()
	
	--for loop Mesh
	for _, Mesh in ipairs(Meshes:GetDescendants()) do
		if Mesh:IsA("MeshPart") then
			
			--EditableMesh
			
			if not MeshTable[EditableMesh] then
				MeshTable[Mesh] = AssetService:CreateEditableMeshFromPartAsync(Mesh)
			end
			
			local EditableMesh = MeshTable[Mesh]
			local GetFaces = EditableMesh:GetFaces()
			local GetVertices = EditableMesh:GetVertices()

			
			--for loop GetFaces
			for _, Face in GetFaces do
				local GetFaceVertices = EditableMesh:GetFaceVertices(Face)
	
			--for loop each Vertex for each face
				for _, Vertex in GetVertices do
						
					if (HumanoidRootPart.Position - Mesh.Position).Magnitude < 16 then
							
						EditableMesh:SetFaceNormals(Face, {Enum.NormalId.Front})
						
						else
							
						EditableMesh:SetFaceNormals(Face, {Enum.NormalId.Bottom})
						
					end--end if statement

				end--end for loop each Vertex

			end--end for loop GetFaces
			
		
			------
		end
	end--end for loop Mesh

		
end--end function onRenderStepped


RunService.RenderStepped:Connect(onRenderStepped)

ERROR

“Number of attributes provided does not match face - Client - EditableMesh:57”

OR

“Invalid faceId - Client - EditableMesh:57” – if you change Face variable to Vertex

– this is due to it irritating through every face. idk how to stop it PLSS HELP :((

to put it in context this is what im trying to do

i see the vision. i personally dont have much experience in making a render engine from scratch but i wonder what would be the difference in simply just using general transparency instead of engine trying to flip normals of every object outside of x distance. yes, its not rendering and no vram but it sounds really overkill

yeah i just realised i was off by alot, i nearly got to this but having too many meshes in the same spot rendering through flipping all normals would crash my studio or even my computer. thats why im marking this solution. Thank you tho!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.