private void BuildObject(IGameObject goWrapper, Canvas canvas, Rule rule, TerrainMeshData meshData,
                                 Vector3[] vertices, int[] triangles, Color[] colors)
        {
            var gameObject = goWrapper.GetComponent <GameObject>();

            gameObject.isStatic = true;

            var mesh = new Mesh();

            mesh.vertices  = vertices;
            mesh.triangles = triangles;
            mesh.colors    = colors;
            mesh.RecalculateNormals();

            gameObject.AddComponent <MeshRenderer>().sharedMaterial = rule
                                                                      .GetMaterial("material_background", _customizationService);
            gameObject.AddComponent <MeshFilter>().mesh = mesh;
            gameObject.AddComponent <MeshCollider>();

            gameObject.AddComponent <MeshIndexBehaviour>().Index = meshData.Index;
            meshData.Dispose();

            var behaviourTypes = rule.GetModelBehaviours(_customizationService);

            foreach (var behaviourType in behaviourTypes)
            {
                var behaviour = gameObject.AddComponent(behaviourType) as IModelBehaviour;
                if (behaviour != null)
                {
                    behaviour.Apply(goWrapper, canvas);
                }
            }
        }
        private void BuildCell(Canvas canvas, Rule rule, IGameObject terrainObject, MeshCell cell,
                               RenderMode renderMode, string name)
        {
            var cellGameObject = _gameObjectFactory.CreateNew(name, terrainObject);

            var meshData = new TerrainMeshData(_objectPool);

            meshData.GameObject = cellGameObject;
            meshData.Index      = renderMode == RenderMode.Scene
                ? new TerrainMeshIndex(16, 16, cell.Rectangle, meshData.Triangles)
                : (IMeshIndex)DummyMeshIndex.Default;

            // build canvas and extra layers
            BuildBackground(rule, meshData, cell.Background, renderMode);
            BuildWater(rule, meshData, cell, renderMode);
            BuildCarRoads(rule, meshData, cell, renderMode);
            BuildPedestrianLayers(rule, meshData, cell, renderMode);
            foreach (var surfaceRegion in cell.Surfaces)
            {
                BuildSurface(rule, meshData, surfaceRegion, renderMode);
            }

            Trace.Debug(LogTag, "Total triangles: {0}", meshData.Triangles.Count.ToString());

            meshData.Index.Build();

            BuildObject(cellGameObject, canvas, rule, meshData);
        }
        /// <summary> Builds real game object. </summary>
        protected virtual void BuildObject(IGameObject cellGameObject, Canvas canvas, Rule rule,
                                           TerrainMeshData meshData)
        {
            Vector3[] vertices;
            int[]     triangles;
            Color[]   colors;
            meshData.GenerateObjectData(out vertices, out triangles, out colors);

            Observable.Start(() => BuildObject(cellGameObject, canvas, rule,
                                               meshData, vertices, triangles, colors), Scheduler.MainThread);
        }
Example #4
0
        public void CanUseCanvas(string path, bool canUseExprTree)
        {
            // ARRANGE
            var stylesheet = MapCssHelper.GetStylesheetFromFile(path, canUseExprTree);
            var canvas     = new Canvas(TestHelper.GetObjectPool());

            // ACT
            var rule     = stylesheet.GetModelRule(canvas, MapConsts.MaxZoomLevel);
            var material = rule.Evaluate <string>("material");

            // ASSERT
            Assert.AreEqual("Terrain", material);
        }
 protected override void BuildObject(IGameObject cellGameObject, Canvas canvas, Rule rule,
                                     TerrainMeshData meshData)
 {
     MeshData = meshData;
     meshData.GenerateObjectData(out Vertices, out Triangles, out Colors);
 }