Esempio n. 1
0
//            private int3 ToPosition(int index)
//            {
//                var axisSize = UnivoxDefine.AxisSize;
//                var x = index % axisSize;
//                var y = index / axisSize % axisSize;
//                var z = index / (axisSize * axisSize);
//                return new int3(x, y, z);
//            }
//            private int ToIndex(int3 position)
//            {
//                var axisSize = UnivoxDefine.AxisSize;
//                return position.x + position.y * axisSize + position.z * axisSize * axisSize;
//            }

            public void Execute(int blockIndex)
            {
                var blockPos = UnivoxUtil.GetPosition3(blockIndex);
//                Profiler.BeginSample("Process Block");

                var primaryActive = BlockActive[blockIndex];

                var hidden     = DirectionsX.AllFlag;
                var directions = DirectionsX.GetDirectionsNative(Allocator.Temp);

                for (var dirIndex = 0; dirIndex < directions.Length; dirIndex++)
                {
                    var direction      = directions[dirIndex];
                    var neighborPos    = blockPos + direction.ToInt3();
                    var neighborIndex  = UnivoxUtil.GetIndex(neighborPos);
                    var neighborActive = false;
                    if (UnivoxUtil.IsPositionValid(neighborPos))
                    {
                        neighborActive = BlockActive[neighborIndex];
                    }

                    if (primaryActive && !neighborActive)
                    {
                        hidden &= ~direction.ToFlag();
                    }
                }

                CulledFaces[blockIndex] = hidden;
                directions.Dispose();


//                Profiler.EndSample();
            }
Esempio n. 2
0
        private void ProccessPlane(PlaneInfo plane)
        {
            for (var major = 0; major < UnivoxDefine.AxisSize; major++)
            {
                for (var minor = 0; minor < UnivoxDefine.AxisSize; minor++)
                {
                    var planeIndex = UnivoxUtil.GetIndex(minor, major);
                    var chunkIndex = GetChunkIndex(plane, minor, major);

                    if (plane.Inspected[planeIndex])
                    {
                        continue;
                    }
//                plane.Inspected[yzIndex] = true;

                    if (CulledFaces[chunkIndex].Value.HasDirection(plane.direction) ||
                        !Materials[chunkIndex].Equals(BatchIdentity))
                    {
                        plane.Inspected[planeIndex] = true;
                        continue;
                    }

                    //Size excludes it's own voxel
                    int2 size      = int2.zero;
                    int  subMat    = SubMaterials[chunkIndex].Value[plane.direction];
                    var  cantMerge = false;
                    for (var majorSpan = 0; majorSpan < UnivoxDefine.AxisSize - major; majorSpan++)
                    {
                        if (majorSpan == 0)
                        {
                            for (var minorSpan = 1; minorSpan < UnivoxDefine.AxisSize - minor; minorSpan++)
                            {
                                var spanIndex      = UnivoxUtil.GetIndex(minor + minorSpan, major + majorSpan);
                                var chunkSpanIndex = GetChunkIndex(plane, minor + minorSpan, major + majorSpan);

                                if (ShouldBreakPlane(plane, spanIndex, chunkSpanIndex, chunkIndex, subMat))
                                {
                                    break;
                                }
                                size = new int2(minorSpan, 0);
                            }
                        }
                        else
                        {
                            for (var minorSpan = 0; minorSpan <= size.x; minorSpan++)
                            {
                                var spanIndex      = UnivoxUtil.GetIndex(minor + minorSpan, major + majorSpan);
                                var chunkSpanIndex = GetChunkIndex(plane, minor + minorSpan, major + majorSpan);

                                if (ShouldBreakPlane(plane, spanIndex, chunkSpanIndex, chunkIndex, subMat))
                                {
                                    cantMerge = true;
                                    break;
                                }
                            }

                            if (cantMerge)
                            {
                                break;
                            }

                            size = new int2(size.x, majorSpan);
                        }
                    }

                    for (var majorSpan = 0; majorSpan <= size.y; majorSpan++)
                    {
                        for (var minorSpan = 0; minorSpan <= size.x; minorSpan++)
                        {
                            var spanIndex = UnivoxUtil.GetIndex(minor + minorSpan, major + majorSpan);
                            plane.Inspected[spanIndex] = true;
                        }
                    }

                    Data.Enqueue(new PlanarData()
                    {
                        Direction   = plane.direction,
                        Position    = UnivoxUtil.GetPosition3(chunkIndex),
                        Shape       = Shapes[chunkIndex],
                        Size        = size,
                        SubMaterial = subMat
                    });
                }
            }
        }