示例#1
0
        private bool GenerateAreas()
        {
#if UNITY_EDITOR
            SgtHelper.MakeTextureReadable(texture);
            SgtHelper.MakeTextureTruecolor(texture);
#endif
            if (texture != null && splats != null)
            {
                splatCount = splats.Count;
                size       = new int2(texture.width, texture.height);

                SgtHelper.UpdateNativeArray(ref weights, size.x * size.y * splatCount);

                tempColors.Clear();

                foreach (var splat in splats)
                {
                    tempColors.Add(splat.Color);
                }

                var data = texture.GetRawTextureData <byte>();
                var offS = SgtHelper.GetStride(texture.format);
                var offR = SgtHelper.GetOffset(texture.format, 0);
                var offG = SgtHelper.GetOffset(texture.format, 1);
                var offB = SgtHelper.GetOffset(texture.format, 2);

                for (var y = 0; y < size.y; y++)
                {
                    for (var x = 0; x < size.x; x++)
                    {
                        var index = x + y * size.x;
                        var r     = data[index * offS + offR];
                        var g     = data[index * offS + offG];
                        var b     = data[index * offS + offB];

                        for (var s = 0; s < splatCount; s++)
                        {
                            weights[index * splatCount + s] = GetDistance(tempColors[s], r, g, b);
                        }
                    }
                }

                return(true);
            }

            return(false);
        }
        private void HandleScheduleHeights(NativeArray <double3> points, NativeArray <double> heights, ref JobHandle handle)
        {
            if (heightmap != null)
            {
                var job = new HeightsJob();

                job.Size         = new int2(heightmap.width, heightmap.height);
                job.Displacement = displacement;
                job.Stride       = SgtHelper.GetStride(heightmap.format);
                job.Offset       = SgtHelper.GetOffset(heightmap.format, (int)channel);
                job.Data         = heightmap.GetRawTextureData <byte>();
                job.Points       = points;
                job.Heights      = heights;

                handle = job.Schedule(heights.Length, 32, handle);
            }
        }