Example #1
0
        // height in meters
        public static void AssignBuildings(Building type, float min, float max, AbstractMap map, bool combineMesh = false)
        {
            if (type == Building.Road)
            {
                return;
            }

            VectorSubLayerProperties vectorSubLayerProperties = new VectorSubLayerProperties();

            vectorSubLayerProperties.colliderOptions.colliderType           = ColliderType.MeshCollider;
            vectorSubLayerProperties.coreOptions.combineMeshes              = false;
            vectorSubLayerProperties.coreOptions.geometryType               = VectorPrimitiveType.Polygon;
            vectorSubLayerProperties.coreOptions.layerName                  = "building";
            vectorSubLayerProperties.coreOptions.snapToTerrain              = true;
            vectorSubLayerProperties.coreOptions.combineMeshes              = combineMesh;
            vectorSubLayerProperties.extrusionOptions.extrusionType         = ExtrusionType.PropertyHeight;
            vectorSubLayerProperties.extrusionOptions.extrusionScaleFactor  = 1.3203f;
            vectorSubLayerProperties.extrusionOptions.propertyName          = "height";
            vectorSubLayerProperties.extrusionOptions.extrusionGeometryType = ExtrusionGeometryType.RoofAndSide;
            vectorSubLayerProperties.moveFeaturePositionTo                  = PositionTargetType.CenterOfVertices;
            vectorSubLayerProperties.coreOptions.sublayerName               = type.ToString();

            string    atlasPath = "Atlases/" + type.ToString() + "BuildingAtlas";
            AtlasInfo atlasInfo = Resources.Load(atlasPath) as AtlasInfo;
            Material  material  = Resources.Load(Constants.buildingMaterialPath) as Material;
            GeometryMaterialOptions materialOptions = new GeometryMaterialOptions();

            materialOptions.SetDefaultMaterialOptions();
            materialOptions.customStyleOptions.texturingType             = UvMapType.Atlas;
            materialOptions.customStyleOptions.materials[0].Materials[0] = material;
            materialOptions.customStyleOptions.materials[1].Materials[0] = material;
            materialOptions.customStyleOptions.atlasInfo = atlasInfo;
            materialOptions.SetStyleType(StyleTypes.Custom);
            vectorSubLayerProperties.materialOptions        = materialOptions;
            vectorSubLayerProperties.buildingsWithUniqueIds = true;
            if (min < 100)
            {
                vectorSubLayerProperties.filterOptions.AddNumericFilterInRange("height", min, max);
                vectorSubLayerProperties.filterOptions.AddNumericFilterEquals("height", max);
            }
            else
            {
                vectorSubLayerProperties.filterOptions.AddNumericFilterGreaterThan("height", min);
            }

            map.VectorData.AddFeatureSubLayer(vectorSubLayerProperties);
        }