I'm experimenting with a voxel "engine", and I'm trying to cull out the interior faces of the mesh that I'm generating, but it's just not working.
I can't wrap my head around why the below code is not working, to me the logic seems correct...
The code (I'll provide the project if you deem it necessary):
foreach (var voxel in Voxels)
if (voxel == null) continue;
var topVoxel = GetAdjacentVoxel(voxel, FaceDirections.Top);
var bottomVoxel = GetAdjacentVoxel(voxel, FaceDirections.Bottom);
var leftVoxel = GetAdjacentVoxel(voxel, FaceDirections.Left);
var rightVoxel = GetAdjacentVoxel(voxel, FaceDirections.Right);
var backVoxel = GetAdjacentVoxel(voxel, FaceDirections.Back);
var frontvoxel = GetAdjacentVoxel(voxel, FaceDirections.Front);
if (topVoxel != null && !topVoxel.IsActive || topVoxel == null) voxel.CreateTopFace(vertices, triangles, colors);
if (bottomVoxel != null && !bottomVoxel.IsActive || bottomVoxel == null) voxel.CreateBottomFace(vertices, triangles, colors);
if (leftVoxel != null && !leftVoxel.IsActive || leftVoxel == null) voxel.CreateLeftFace(vertices, triangles, colors);
if (rightVoxel != null && !rightVoxel.IsActive || rightVoxel == null) voxel.CreateRightFace(vertices, triangles, colors);
if (backVoxel != null && !backVoxel.IsActive || backVoxel == null) voxel.CreateBackFace(vertices, triangles, colors);
if (frontvoxel != null && !frontvoxel.IsActive || frontvoxel == null) voxel.CreateFrontFace(vertices, triangles, colors);
Another thing, would greedy meshing nullify the need to cull out the interior faces, or should they be used in conjunction with each other for the best result?
Best regards Marcus
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
105 People are following this question.
How to make a Tovel like cube (edge smooth?)
Mesh as polygon Colider
Multiple textures on Voxel mesh?
Unity3D: Objects destroy automatically
Geometry Permanently Disappearing after Editing Cubes