예제 #1
0
 public virtual Serializable2DByteArray BlendSplats(SplatPrototypeWrapper splat,
                                                    int x, int z, int width, int height, int aRes, Serializable2DByteArray result)
 {
     //throw new NotImplementedException();
     //Debug.LogErrorFormat("BlendSplats is not implemented for {0} ({1})", name, GetType());
     return(result);
 }
예제 #2
0
        public override Serializable2DByteArray BlendSplats(SplatPrototypeWrapper splat, int x, int z, int width, int height, int aRes,
                                                            Serializable2DByteArray result)
        {
            var layerSplats = GetSplatmap(splat, x, z, width, height, aRes);

            if (layerSplats == null)
            {
                return(result);
            }

            var stencil = BlendMode == EMMTerrainLayerBlendMode.Stencil && IsValidStencil(Stencil) ? Stencil : null;

            BlendMMTerrainLayerUtility.BlendArray(ref result,
                                                  layerSplats,
                                                  stencil,
                                                  BlendMode,
                                                  new Common.Coord(x, z),
                                                  new Common.Coord(aRes, aRes));
            return(result);
        }
예제 #3
0
        public override Serializable2DByteArray GetSplatmap(SplatPrototypeWrapper prototype, int x, int z, int width, int height, int splatResolution)
        {
            if (SplatData == null)
            {
                return(null);
            }

            Serializable2DByteArray data;

            if (!SplatData.TryGetValue(prototype, out data))
            {
                return(null);
            }

            if (data.Width != splatResolution || data.Height != splatResolution)
            {
                SplatData.Remove(prototype);
                return(null);
            }

            var splats = new Serializable2DByteArray(width, height);

            for (var u = x; u < x + width; ++u)
            {
                for (var v = z; v < z + height; ++v)
                {
                    var hx = u - x;
                    var hz = v - z;
                    try
                    {
                        var splatSample = data[u, v];
                        splats[hx, hz] = splatSample;
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }
            return(splats);
        }
예제 #4
0
 public virtual Serializable2DByteArray GetSplatmap(SplatPrototypeWrapper prototype, int x, int z, int width,
                                                    int height, int splatResolution)
 {
     return(null);
 }
예제 #5
0
        public void SetSplatmap(SplatPrototypeWrapper prototype, int x, int z,
                                float[,] splats, int splatRes, Serializable2DFloatArray stencil = null)
        {
            if (splats == null || prototype == null)
            {
                return;
            }
            if (SplatData == null)
            {
                SplatData = new CompressedSplatDataLookup();
            }

            Serializable2DByteArray existingSplats;

            if (!SplatData.TryGetValue(prototype, out existingSplats) || existingSplats.Width != splatRes ||
                existingSplats.Height != splatRes)
            {
                existingSplats       = new Serializable2DByteArray(splatRes, splatRes);
                SplatData[prototype] = existingSplats;
            }

            var width  = splats.GetLength(0);
            var height = splats.GetLength(1);

            for (var u = x; u < x + width; ++u)
            {
                if (u < 0 || u >= splatRes)
                {
                    continue;
                }
                for (var v = z; v < z + height; ++v)
                {
                    if (v < 0 || v >= splatRes)
                    {
                        continue;
                    }

                    var hx = u - x;
                    var hz = v - z;

                    try
                    {
                        var splatSample = splats[hx, hz] * 255f;

                        if (stencil != null)
                        {
                            var stencilVal = stencil[hx, hz];
                            splatSample = (byte)Mathf.Clamp(Mathf.Lerp(existingSplats[u, v], splatSample, stencilVal), 0, 255);
                        }

                        existingSplats[u, v] = (byte)Mathf.Clamp(splatSample, 0, 255);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }


#if UNITY_EDITOR
            UnityEditor.EditorUtility.SetDirty(this);
#endif
        }