Пример #1
0
 public void Init()
 {
     _renderer = GetComponent <MeshRenderer>();
     _filter   = GetComponent <MeshFilter>();
     _genMesh  = new GeneratableMesh(64);
     _inited   = true;
 }
Пример #2
0
        static void AddUVs(this GeneratableMesh meshInfo, Vector2[] uvs)
        {
            var uvsList = meshInfo.UVs;

            for (int i = 0; i < uvs.Length; i++)
            {
                uvsList.Add(uvs[i]);
            }
        }
Пример #3
0
        static void AddTriangles(this GeneratableMesh meshInfo, int[] indexes, int rootIndex)
        {
            var trisList = meshInfo.Triangles;

            for (int i = 0; i < indexes.Length; i++)
            {
                trisList.Add(indexes[i] + rootIndex);
            }
        }
Пример #4
0
        static void AddVerticesWithPos(this GeneratableMesh meshInfo, Vector3[] verts, Vector3 rootPos)
        {
            var vertsList = meshInfo.Vertices;

            for (int i = 0; i < verts.Length; i++)
            {
                vertsList.Add(verts[i] + rootPos);
            }
        }
Пример #5
0
 public ChunkMesher(BlockInfoProvider library, int chunkMeshCapacity, int capacity, Vector3 originPos)
 {
     _opaqueCollidedMesh      = new GeneratableMesh(chunkMeshCapacity);
     _translucentPassableMesh = new GeneratableMesh(chunkMeshCapacity / 8);
     _opaquePassableMesh      = new GeneratableMesh(chunkMeshCapacity / 8);
     _library   = library;
     _originPos = originPos;
     Blocks     = new List <MesherBlockInput>(capacity);
 }
Пример #6
0
 public static void AddPlaneWithUVs(GeneratableMesh meshInfo, Vector3[] verts, Vector2[] uvs, Vector3 rootPos, int pointer, Color32 color)
 {
     meshInfo.AddVerticesWithPos(verts, rootPos);
     meshInfo.AddTriangles(_planeTris, pointer);
     meshInfo.AddUVs(uvs);
     //Ага
     meshInfo.Colors.Add(color);
     meshInfo.Colors.Add(color);
     meshInfo.Colors.Add(color);
     meshInfo.Colors.Add(color);
 }
Пример #7
0
 public static void AddPlaneInv(GeneratableMesh meshInfo, Vector3[] verts, TilesetHelper helper, Byte2 tile, Vector3 rootPos, int pointer, Color32 color)
 {
     meshInfo.AddVerticesWithPos(verts, rootPos);
     meshInfo.AddTriangles(_planeTrisInverted, pointer);
     meshInfo.AddPlaneUVs(tile);
     //Ага
     meshInfo.Colors.Add(color);
     meshInfo.Colors.Add(color);
     meshInfo.Colors.Add(color);
     meshInfo.Colors.Add(color);
 }
Пример #8
0
        public static void AddBlock(GeneratableMesh meshInfo, BlockDescription desc, ref Vector3 rootPos, ref MesherBlockInput input)
        {
            if (desc == null)
            {
                return;
            }
            var data       = input.Block;
            var visibility = input.Visibility;
            var light      = input.Lighting;

            switch (desc.ModelType)
            {
            case BlockModelType.None:
                return;

            case BlockModelType.FullBlockSimple:
                GenerateFullBlockSimple(meshInfo, desc, data, rootPos, visibility, light);
                return;

            case BlockModelType.FullBlockComplex:
                GenerateFullBlockComplex(meshInfo, desc, data, rootPos, visibility, light);
                return;

            case BlockModelType.HalfBlockDown:
                GenerateHalfBlockDown(meshInfo, desc, data, rootPos, visibility, light);
                return;

            case BlockModelType.HalfBlockUp:
                return;

            case BlockModelType.Stairs:
                return;

            case BlockModelType.Plate:
                return;

            case BlockModelType.Grass:
                return;

            case BlockModelType.HorizontalPlane:
                GenerateHorizontalPlane(meshInfo, desc, data, rootPos, visibility);
                return;

            case BlockModelType.SmallerBlock:
                return;

            case BlockModelType.CrossedVPlanes:
                GenerateCrossedVPlanes(meshInfo, desc, data, rootPos, visibility);
                return;

            default:
                return;
            }
        }
Пример #9
0
        //Неполные блоки не рисуем только если они полностью ограждены полными блоками.
        public static void GenerateHorizontalPlane(GeneratableMesh meshInfo, BlockDescription desc, BlockData data, Vector3 rootPos, VisibilityFlags visibility)
        {
            if (visibility == VisibilityFlags.None)
            {
                return;
            }
            var pointer   = meshInfo.Vertices.Count;
            var h         = (byte)(data.AddColor >> 8);
            var l         = (byte)(data.AddColor % 256);
            var calcColor = new Color32(data.SunLevel, data.LightLevel, h, l);

            AddPlane(meshInfo, _horizontalPlaneVerts, desc.Subtypes[Mathf.Clamp(data.Subtype, 0, desc.Subtypes.Count - 1)].FaceTiles[0], rootPos, pointer, calcColor);
        }
Пример #10
0
        public static void GenerateCrossedVPlanes(GeneratableMesh meshInfo, BlockDescription desc, BlockData data, Vector3 rootPos, VisibilityFlags visibility)
        {
            var pointer   = meshInfo.Vertices.Count;
            var tile      = desc.Subtypes[Mathf.Clamp(data.Subtype, 0, desc.Subtypes.Count - 1)].FaceTiles[0];
            var calcColor = new Color32(data.SunLevel, data.LightLevel, (byte)(data.AddColor >> 8), (byte)(data.AddColor % 256));

            AddPlane(meshInfo, _rotVertPlaneVerts_0, tile, rootPos, pointer, calcColor);
            pointer += 4;
            AddPlane(meshInfo, _rotVertPlaneVerts_1, tile, rootPos, pointer, calcColor);
            pointer += 4;
            AddPlaneInv(meshInfo, _rotVertPlaneVerts_0, _helper, tile, rootPos, pointer, calcColor);
            pointer += 4;
            AddPlaneInv(meshInfo, _rotVertPlaneVerts_1, _helper, tile, rootPos, pointer, calcColor);
            pointer += 4;
        }
Пример #11
0
        public static void GenerateFullBlockSimple(GeneratableMesh meshInfo, BlockDescription desc, BlockData data, Vector3 rootPos, VisibilityFlags visibility, LightInfo light)
        {
            var pointer = meshInfo.Vertices.Count;
            var tile    = desc.Subtypes[Mathf.Clamp(data.Subtype, 0, desc.Subtypes.Count - 1)].FaceTiles[0];
            var uvs     = GetCachedUVsForTile(tile);
            var h       = (byte)(data.AddColor >> 8);
            var l       = (byte)(data.AddColor % 256);

            if (VisibilityFlagsHelper.IsSet(visibility, VisibilityFlags.Backward))
            {
                var calcColor = new Color32(light.SunBackward, light.OBackward, h, l);
                AddPlaneWithUVs(meshInfo, _fullBlockBackSide, uvs, rootPos, pointer, calcColor);
                pointer += 4;
            }
            if (VisibilityFlagsHelper.IsSet(visibility, VisibilityFlags.Forward))
            {
                var calcColor = new Color32(light.SunForward, light.OForward, h, l);
                AddPlaneWithUVs(meshInfo, _fullBlockFrontSide, uvs, rootPos, pointer, calcColor);
                pointer += 4;
            }
            if (VisibilityFlagsHelper.IsSet(visibility, VisibilityFlags.Left))
            {
                var calcColor = new Color32(light.SunLeft, light.OLeft, h, l);
                AddPlaneWithUVs(meshInfo, _fullBlockLeftSide, uvs, rootPos, pointer, calcColor);
                pointer += 4;
            }
            if (VisibilityFlagsHelper.IsSet(visibility, VisibilityFlags.Right))
            {
                var calcColor = new Color32(light.SunRight, light.ORight, h, l);
                AddPlaneWithUVs(meshInfo, _fullBlockRightSide, uvs, rootPos, pointer, calcColor);
                pointer += 4;
            }
            if (VisibilityFlagsHelper.IsSet(visibility, VisibilityFlags.Up))
            {
                var calcColor = new Color32(light.SunUp, light.OUp, h, l);
                AddPlaneWithUVs(meshInfo, _fullBlockUpSide, uvs, rootPos, pointer, calcColor);
                pointer += 4;
            }
            if (VisibilityFlagsHelper.IsSet(visibility, VisibilityFlags.Down))
            {
                var calcColor = new Color32(light.SunDown, light.ODown, h, l);
                AddPlaneWithUVs(meshInfo, _fullBlockDownSide, uvs, rootPos, pointer, calcColor);
                pointer += 4;
            }
        }
Пример #12
0
        public static void GenerateHalfBlockDown(GeneratableMesh meshInfo, BlockDescription desc, BlockData data, Vector3 rootPos, VisibilityFlags visibility, LightInfo light)
        {
            var pointer = meshInfo.Vertices.Count;
            var sub     = desc.Subtypes[Mathf.Clamp(data.Subtype, 0, desc.Subtypes.Count - 1)];
            var h       = (byte)(data.AddColor >> 8);
            var l       = (byte)(data.AddColor % 256);

            if (VisibilityFlagsHelper.IsSet(visibility, VisibilityFlags.Backward))
            {
                var calcColor = new Color32(light.SunBackward, light.OBackward, h, l);
                AddPlane(meshInfo, _halfBlockDBackSide, sub.FaceTiles[0], rootPos, pointer, calcColor);
                pointer += 4;
            }
            if (VisibilityFlagsHelper.IsSet(visibility, VisibilityFlags.Forward))
            {
                var calcColor = new Color32(light.SunForward, light.OForward, h, l);
                AddPlane(meshInfo, _halfBlockDFrontSide, sub.FaceTiles[1], rootPos, pointer, calcColor);
                pointer += 4;
            }
            if (VisibilityFlagsHelper.IsSet(visibility, VisibilityFlags.Left))
            {
                var calcColor = new Color32(light.SunLeft, light.OLeft, h, l);
                AddPlane(meshInfo, _halfBlockDLeftSide, sub.FaceTiles[2], rootPos, pointer, calcColor);
                pointer += 4;
            }
            if (VisibilityFlagsHelper.IsSet(visibility, VisibilityFlags.Right))
            {
                var calcColor = new Color32(light.SunRight, light.ORight, h, l);
                AddPlane(meshInfo, _halfBlockDRightSide, sub.FaceTiles[3], rootPos, pointer, calcColor);
                pointer += 4;
            }

            if (VisibilityFlagsHelper.IsSet(visibility, VisibilityFlags.Up))
            {
                var calcColor = new Color32(light.SunUp, light.OUp, h, l);
                AddPlane(meshInfo, _halfBlockDUpside, sub.FaceTiles[4], rootPos, pointer, calcColor);
                pointer += 4;
            }
            if (VisibilityFlagsHelper.IsSet(visibility, VisibilityFlags.Down))
            {
                var calcColor = new Color32(light.SunDown, light.ODown, h, l);
                AddPlane(meshInfo, _fullBlockDownSide, sub.FaceTiles[5], rootPos, pointer, calcColor);
                pointer += 4;
            }
        }
Пример #13
0
 static void AddPlaneUVs(this GeneratableMesh meshInfo, Byte2 tilePos)
 {
     meshInfo.AddUVs(GetCachedUVsForTile(tilePos));
 }