Esempio n. 1
0
        public static TextureSideWallModifierJob Get(GeometryExtrusionWithAtlasOptions options, CustomFeatureUnity feature,
                                                     ref MeshDataStruct output)
        {
            Bool skip = feature == null || feature.Points.Count < 1;

            return(new TextureSideWallModifierJob(skip, options, feature, ref output));
        }
Esempio n. 2
0
        public static JobHandle Schedule(JobHandle dependencies, GeometryExtrusionWithAtlasOptions options, CustomFeatureUnity feature,
                                         ref MeshDataStruct output)
        {
            Bool skip = feature == null || feature.Points.Count < 1;

            return(new TextureSideWallModifierJob(skip, options, feature, ref output).Schedule(dependencies));
        }
Esempio n. 3
0
        private TextureSideWallModifierJob(Bool skip, GeometryExtrusionWithAtlasOptions options, CustomFeatureUnity feature, ref MeshDataStruct output)
        {
            _vectors = default;
            _floats  = default;

            var minHeight = 0.0f;

            _maxHeight = 0.0f;
            if (feature.Properties.ContainsKey(options.propertyName))
            {
                _maxHeight = Convert.ToSingle(feature.Properties[options.propertyName]);
                if (feature.Properties.ContainsKey("min_height"))
                {
                    minHeight = Convert.ToSingle(feature.Properties["min_height"]);
                }
            }

            _currentFacade = options.atlasInfo.Textures[0];
            _currentFacade.CalculateParameters();
            _floats.extrusionScaleFactor = options.extrusionScaleFactor;
            _maxHeight     = _maxHeight * _floats.extrusionScaleFactor * Scale;
            minHeight      = minHeight * _floats.extrusionScaleFactor * Scale;
            _floats.height = _maxHeight - minHeight;
            _output        = output;
            _skip          = skip;
        }
Esempio n. 4
0
 public override void Run(CustomFeatureUnity feature, ref MeshDataStruct md)
 {
     TextureSideWallModifierJob.Schedule(default, _options, feature, ref md).Complete();
Esempio n. 5
0
 public virtual void Run(CustomFeatureUnity feature, ref MeshDataStruct md)
 {
 }
Esempio n. 6
0
        public override void Run(CustomFeatureUnity feature, ref MeshDataStruct md)
        {
            var counter = feature.Points.Count;
            var subset  = new List <List <Vector3> >(counter);

            Assets.Mapbox.Unity.MeshGeneration.Modifiers.MeshModifiers.Data flatData;
            List <int>       result;
            var              currentIndex       = 0;
            var              polygonVertexCount = 0;
            NativeList <int> triList            = default;

            for (var i = 0; i < counter; i++)
            {
                var sub = feature.Points[i];
                // ear cut is built to handle one polygon with multiple holes
                //point data can contain multiple polygons though, so we're handling them separately here

                var vertCount = md.Vertices.Length;
                if (IsClockwise(sub) && vertCount > 0)
                {
                    flatData           = Assets.Mapbox.Unity.MeshGeneration.Modifiers.MeshModifiers.EarcutLibrary.Flatten(subset);
                    result             = Assets.Mapbox.Unity.MeshGeneration.Modifiers.MeshModifiers.EarcutLibrary.Earcut(flatData.Vertices, flatData.Holes, flatData.Dim);
                    polygonVertexCount = result.Count;

                    if (!triList.IsCreated)
                    {
                        triList = new NativeList <int>(polygonVertexCount, Allocator.TempJob);
                    }
                    else
                    {
                        triList.Capacity = triList.Length + polygonVertexCount;
                    }

                    for (var j = 0; j < polygonVertexCount; j++)
                    {
                        triList.Add(result[j] + currentIndex);
                    }

                    currentIndex = vertCount;
                    subset.Clear();
                }

                subset.Add(sub);

                polygonVertexCount   = sub.Count;
                md.Vertices.Capacity = md.Vertices.Length + polygonVertexCount;
                md.Normals.Capacity  = md.Normals.Length + polygonVertexCount;
                md.Edges.Capacity    = md.Edges.Length + polygonVertexCount * 2;

                for (var j = 0; j < polygonVertexCount; j++)
                {
                    md.Edges.Add(vertCount + ((j + 1) % polygonVertexCount));
                    md.Edges.Add(vertCount + j);
                    md.Vertices.Add(sub[j]);
                    md.Normals.Add(Vector3.up);
                    if (_options.texturingType != UvMapType.Tiled)
                    {
                        continue;
                    }
                    md.UV.Add(new Vector2(sub[j].x, sub[j].z));
                }
            }

            flatData           = Assets.Mapbox.Unity.MeshGeneration.Modifiers.MeshModifiers.EarcutLibrary.Flatten(subset);
            result             = Assets.Mapbox.Unity.MeshGeneration.Modifiers.MeshModifiers.EarcutLibrary.Earcut(flatData.Vertices, flatData.Holes, flatData.Dim);
            polygonVertexCount = result.Count;

            if (_options.texturingType == UvMapType.Atlas || _options.texturingType == UvMapType.AtlasWithColorPalette)
            {
                _currentFacade = _options.atlasInfo.Roofs[UnityEngine.Random.Range(0, _options.atlasInfo.Roofs.Count)];

                var minx = float.MaxValue;
                var miny = float.MaxValue;
                var maxx = float.MinValue;
                var maxy = float.MinValue;

                var textureUvCoordinates = new Vector2[md.Vertices.Length];
                var textureDirection     = Quaternion.FromToRotation(md.Vertices[0] - md.Vertices[1], Vector3.right);
                textureUvCoordinates[0] = new Vector2(0, 0);

                for (var i = 1; i < md.Vertices.Length; i++)
                {
                    var vert = md.Vertices[i];
                    var vertexRelativePos = textureDirection * (vert - md.Vertices[0]);
                    textureUvCoordinates[i] = new Vector2(vertexRelativePos.x, vertexRelativePos.z);
                    if (vertexRelativePos.x < minx)
                    {
                        minx = vertexRelativePos.x;
                    }
                    if (vertexRelativePos.x > maxx)
                    {
                        maxx = vertexRelativePos.x;
                    }
                    if (vertexRelativePos.z < miny)
                    {
                        miny = vertexRelativePos.z;
                    }
                    if (vertexRelativePos.z > maxy)
                    {
                        maxy = vertexRelativePos.z;
                    }
                }

                var width  = maxx - minx;
                var height = maxy - miny;

                for (var i = 0; i < md.Vertices.Length; i++)
                {
                    md.UV.Add(new Vector2(
                                  (((textureUvCoordinates[i].x - minx) / width) * _currentFacade.TextureRect.width) + _currentFacade.TextureRect.x,
                                  (((textureUvCoordinates[i].y - miny) / height) * _currentFacade.TextureRect.height) + _currentFacade.TextureRect.y));
                }
            }

            if (!triList.IsCreated)
            {
                triList = new NativeList <int>(polygonVertexCount, Allocator.TempJob);
            }
            else
            {
                triList.Capacity = triList.Length + polygonVertexCount;
            }

            for (var i = 0; i < polygonVertexCount; i++)
            {
                triList.Add(result[i] + currentIndex);
            }
            md.Triangles.AddRange(triList);

            triList.Dispose();
        }