Example #1
0
            public void Execute(int index)
            {
                var chunk = Chunks[index];

                var instanceBounds = chunk.GetNativeArray(WorldMeshRenderBoundsType);

                if (instanceBounds.Length == 0)
                {
                    return;
                }

                // TODO: Improve this approach
                // See: https://www.inf.ethz.ch/personal/emo/DoctThesisFiles/fischer05.pdf

                var chunkBounds = new WorldMeshRenderBounds();

                for (int j = 0; j < instanceBounds.Length; j++)
                {
                    chunkBounds.Center += instanceBounds[j].Center;
                }
                chunkBounds.Center /= instanceBounds.Length;

                for (int j = 0; j < instanceBounds.Length; j++)
                {
                    float r = math.distance(chunkBounds.Center, instanceBounds[j].Center) + instanceBounds[j].Radius;
                    chunkBounds.Radius = math.select(chunkBounds.Radius, r, r > chunkBounds.Radius);
                }

                ChunkBounds[index] = chunkBounds;
            }
Example #2
0
        public InsideResult Inside(WorldMeshRenderBounds bounds)
        {
            var center = new float4(bounds.Center.x, bounds.Center.y, bounds.Center.z, 1.0f);

            var leftDistance  = math.dot(Left, center);
            var rightDistance = math.dot(Right, center);
            var downDistance  = math.dot(Down, center);
            var upDistance    = math.dot(Up, center);
            var nearDistance  = math.dot(Near, center);
            var farDistance   = math.dot(Far, center);

            var leftOut  = leftDistance < -bounds.Radius;
            var rightOut = rightDistance < -bounds.Radius;
            var downOut  = downDistance < -bounds.Radius;
            var upOut    = upDistance < -bounds.Radius;
            var nearOut  = nearDistance < -bounds.Radius;
            var farOut   = farDistance < -bounds.Radius;
            var anyOut   = leftOut || rightOut || downOut || upOut || nearOut || farOut;

            var leftIn  = leftDistance > bounds.Radius;
            var rightIn = rightDistance > bounds.Radius;
            var downIn  = downDistance > bounds.Radius;
            var upIn    = upDistance > bounds.Radius;
            var nearIn  = nearDistance > bounds.Radius;
            var farIn   = farDistance > bounds.Radius;
            var allIn   = leftIn && rightIn && downIn && upIn && nearIn && farIn;


            if (anyOut)
            {
                return(InsideResult.Out);
            }
            if (allIn)
            {
                return(InsideResult.In);
            }
            return(InsideResult.Partial);
        }