Example #1
0
        /// <summary>
        /// Build up renderable geometry from input height neighborhood and material map.
        /// </summary>
        /// <param name="neighbors"></param>
        /// <param name="colorMap"></param>
        /// <returns></returns>
        public bool MakeGeometry(VirtualMap.HeightMapNeighbors heightNeighbors, VirtualMap.ColorMapNeighbors colorNeighbors)
        {
            MakeMinLut(heightNeighbors);

            bool notEmpty = MakeRenderables(heightNeighbors, colorNeighbors);

            CheckIndices(heightNeighbors[(int)VirtualMap.HeightMapNeighbors.Dir.Center].Size);

            return(notEmpty);
        }
Example #2
0
        /// <summary>
        /// Build up renderable geometry for each possible material. Discard empties.
        /// </summary>
        /// <param name="neighbors"></param>
        /// <param name="colorMap"></param>
        /// <returns></returns>
        private bool MakeRenderables(
            VirtualMap.HeightMapNeighbors heightNeighbors,
            VirtualMap.ColorMapNeighbors colorNeighbors)
        {
            var heightMap = heightNeighbors[VirtualMap.HeightMapNeighbors.Dir.Center];

            VirtualMap.ColorMap colorMap = colorNeighbors[VirtualMap.ColorMapNeighbors.Dir.Center];

            Renderable.PrepareToBuild(heightMap.Size, Min, minLut);

            //Dispose();
            //renderableDict.Clear();

            // Reset number of local vertices in each Renderable
            // since we're about to remake the list.
            ResetAllVertexCounts();


            Vector2 cubeSize = new Vector2(
                heightMap.Scale.X / (float)heightMap.Size.X,
                heightMap.Scale.Y / (float)heightMap.Size.Y);
            Vector2 halfSize = cubeSize * 0.5f;

            Point vert = new Point(0, 0);

            for (vert.X = 0; vert.X < heightMap.Size.X; vert.X += 1)
            {
                for (vert.Y = 0; vert.Y < heightMap.Size.Y; vert.Y += 1)
                {
                    float h = heightMap.GetHeightUnsafe(vert.X, vert.Y);
                    if (h != 0)
                    {
                        ushort color = colorMap[vert.X, vert.Y];

                        //Debug.Assert(TerrainMaterial.IsValid(color, false, true));

                        if (TerrainMaterial.IsValid(color, false, true))
                        {
                            Vector3 pos = new Vector3(
                                (float)vert.X * cubeSize.X + halfSize.X,
                                (float)vert.Y * cubeSize.Y + halfSize.Y,
                                h);

                            Renderable r = GetOrMakeRenderable(colorMap[vert.X, vert.Y]);

                            r.AddVertices(pos, halfSize, vert, heightNeighbors, colorNeighbors);
                        }
                    }
                }
            }

            return(FinishGeometry(cubeSize, halfSize));
        }