Exemplo n.º 1
0
    public void Initialize(Vector3Int minCorner, Vector3Int size, int seed)
    {
        _size      = size;
        _minCorner = minCorner;
        _seed      = seed;

        //UnityEngine.Random.InitState(_seed);
        //_seedOffset = new Vector2Int(Random.Range(int.MinValue, int.MaxValue), Random.Range(int.MinValue, int.MaxValue));

        this.transform.position  = minCorner;
        this.gameObject.isStatic = true;

        _blocks = new Block[size.x, size.y, size.z];

        _atlasReader = new AtlasReader(blockAtlas, 8);

        for (int x = 0; x < _size.x; x++)
        {
            for (int z = 0; z < _size.z; z++)
            {
                for (int y = 0; y < _size.y; y++)
                {
                    BlockType type = GetBlockType(x + _minCorner.x, y + _minCorner.y, z + _minCorner.z, _seed);

                    if (type != null)
                    {
                        _blocks[x, y, z] = new Block(type);
                    }
                }
            }
        }
    }
        public static string Skel2Json(string inputFilePath, string outputPath)
        {
            string filePath  = inputFilePath.Replace(".skel", "");
            string atlasPath = filePath + ".atlas";
            string skelPath  = filePath + ".skel";

            using (var fs = File.OpenRead(atlasPath))
                using (var tr = new StreamReader(fs))
                    using (var input = File.OpenRead(skelPath))
                        using (var warningOut = File.OpenWrite(outputPath + ".txt"))
                            using (var warning = new StreamWriter(warningOut))
                            {
                                var atlasReader = new AtlasReader(tr);
                                var reader      = new SpineBin2Json35.BinaryReader(input, atlasReader, warning);
                                var obj         = reader.Convert();

                                using (var output = File.OpenWrite(outputPath))
                                    using (var sw = new StreamWriter(output)) sw.Write(Newtonsoft.Json.JsonConvert.SerializeObject(obj));
                                string message = "";
                                if (input.Length == input.Position)
                                {
                                    message += string.Format("文件长度: {0}\n读取长度: {1}\n 请您检查输出的txt文件来查看龙骨不支持的特性", input.Length, input.Position);
                                }
                                else
                                {
                                    message += message += string.Format("文件长度: {0}\n读取长度: {1}\n 好像哪里不太对劲", input.Length, input.Position);
                                }
                                return(message);
                            }
        }
Exemplo n.º 3
0
 public Mesh GenerateMesh(bool[] faceIsVisible, AtlasReader atlasReader)
 {
     if (this.type.isBillboard)
     {
         return(GenerateBillboardFaces(atlasReader));
     }
     else
     {
         return(GenerateCubeFaces(faceIsVisible, atlasReader));
     }
 }
Exemplo n.º 4
0
    public void Initialize(BlockType blockType, Material material, ChunkManager chunkManager)
    {
        base.Initialize();
        _chunkManager = chunkManager;
        _blockType    = blockType;
        AtlasReader reader = new AtlasReader((Texture2D)material.mainTexture, 8);

        for (int i = 0; i < _faces.Length; i++)
        {
            MeshRenderer mr = _faces[i].GetComponent <MeshRenderer>();
            mr.sharedMaterial = material;
            Mesh           mesh     = _faces[i].GetComponent <MeshFilter>().mesh;
            Vector2Int     atlasPos = i >= blockType.atlasPositions.Length ? blockType.atlasPositions[0] : blockType.atlasPositions[i];
            List <Vector2> uvs      = reader.GetUVs(atlasPos.x, atlasPos.y);
            var            temp     = uvs[0];
            uvs[0] = uvs[1];
            uvs[1] = temp;
            mesh.SetUVs(0, uvs);
        }
    }
Exemplo n.º 5
0
    public Mesh GenerateBillboardFaces(AtlasReader atlasReader)
    {
        Vector3[] baseVertices =
        {
            new Vector3(1.0f,  -1.0f, 0.0f),
            new Vector3(1.0f,   1.0f, 0.0f),
            new Vector3(-1.0f,  1.0f, 0.0f),
            new Vector3(-1.0f, -1.0f, 0.0f)
        };

        List <Vector3> vertices = new List <Vector3>();

        Quaternion[] rotations =
        {
            Quaternion.AngleAxis(45f,   Vector3.up),
            Quaternion.AngleAxis(-45f,  Vector3.up),
            Quaternion.AngleAxis(135f,  Vector3.up),
            Quaternion.AngleAxis(-135f, Vector3.up)
        };


        for (int i = 0; i < rotations.Length; i++)
        {
            Quaternion rotation = rotations[i];
            foreach (Vector3 vertex in baseVertices)
            {
                vertices.Add(rotation * vertex * 0.7071f);
            }
        }

        List <Vector3> normals = new List <Vector3>();
        Vector3        normal  = new Vector3(0f, 0f, 1f);

        for (int i = 0; i < vertices.Count; i++)
        {
            normals.Add(normal);
        }

        Vector2Int     atlasIndex = type.atlasPositions[0];
        List <Vector2> uvs        = new List <Vector2>();

        for (int i = 0; i < rotations.Length; i++)
        {
            uvs.AddRange(atlasReader.GetUVs(atlasIndex.x, atlasIndex.y));
        }

        int[] triangles =
        {
            0,           1,      2,      0,      2,     3,
            0 + 4,   1 + 4,  2 + 4,  0 + 4,  2 + 4, 3 + 4,
            0 + 8,   1 + 8,  2 + 8,  0 + 8,  2 + 8, 3 + 8,
            0 + 12, 1 + 12, 2 + 12, 0 + 12, 2 + 12, 3 + 12
        };


        Mesh mesh = new Mesh();

        mesh.SetVertices(vertices);
        mesh.SetNormals(normals);
        mesh.SetUVs(0, uvs);
        mesh.SetTriangles(triangles, 0);

        return(mesh);
    }
Exemplo n.º 6
0
    public Mesh GenerateCubeFaces(bool[] faceIsVisible, AtlasReader atlasReader)
    {
        List <List <Vector3> > vertexLists   = new List <List <Vector3> >();
        List <List <Vector3> > normalLists   = new List <List <Vector3> >();
        List <List <Vector2> > uvLists       = new List <List <Vector2> >();
        List <int[]>           triangleLists = new List <int[]>();

        for (int i = 0; i < FACE_DIRECTIONS.Length; i++)
        {
            if (faceIsVisible[i] == false)
            {
                continue; // Don't bother making a mesh for a face that can't be seen.
            }

            GenerateBlockFace(FACE_DIRECTIONS[i], out List <Vector3> vertices, out List <Vector3> normals, out int[] triangles);

            Vector2Int[] atlasPositions = type.atlasPositions;
            int          index          = atlasPositions.Length == 1 ? 0 : i;

            List <Vector2> uvs = atlasReader.GetUVs(atlasPositions[index].x, atlasPositions[index].y);


            vertexLists.Add(vertices);
            normalLists.Add(normals);
            uvLists.Add(uvs);
            triangleLists.Add(triangles);
        }

        List <Vector3> allVertices  = new List <Vector3>();
        List <Vector3> allNormals   = new List <Vector3>();
        List <Vector2> allUVs       = new List <Vector2>();
        List <int>     allTriangles = new List <int>();

        foreach (List <Vector3> vertexList in vertexLists)
        {
            allVertices.AddRange(vertexList);
        }

        foreach (List <Vector3> normalList in normalLists)
        {
            allNormals.AddRange(normalList);
        }

        foreach (List <Vector2> uvList in uvLists)
        {
            allUVs.AddRange(uvList);
        }

        for (int i = 0; i < triangleLists.Count; i++)
        {
            for (int j = 0; j < triangleLists[i].Length; j++)
            {
                triangleLists[i][j] += i * 4;
            }
            allTriangles.AddRange(triangleLists[i]);
        }

        Mesh mesh = new Mesh();

        mesh.SetVertices(allVertices);
        mesh.SetNormals(allNormals);
        mesh.SetUVs(0, allUVs);
        mesh.SetTriangles(allTriangles.ToArray(), 0);

        return(mesh);
    }
Exemplo n.º 7
0
    public MeshData GenerateBillboardFaces(AtlasReader atlasReader)
    {
        Vector3[] baseVertices =
        {
            new Vector3(1.0f,  -1.0f, 0.0f),
            new Vector3(1.0f,   1.0f, 0.0f),
            new Vector3(-1.0f,  1.0f, 0.0f),
            new Vector3(-1.0f, -1.0f, 0.0f)
        };

        Color[] baseColors =
        {
            Color.black,
            Color.red,
            Color.red,
            Color.black,
        };

        List <Vector3> vertices = new List <Vector3>();
        List <Color>   colors   = new List <Color>();

        Quaternion[] rotations =
        {
            Quaternion.AngleAxis(45f,   Vector3.up),
            Quaternion.AngleAxis(-45f,  Vector3.up),
            Quaternion.AngleAxis(135f,  Vector3.up),
            Quaternion.AngleAxis(-135f, Vector3.up)
        };


        for (int i = 0; i < rotations.Length; i++)
        {
            Quaternion rotation = rotations[i];
            foreach (Vector3 vertex in baseVertices)
            {
                vertices.Add(rotation * vertex * 0.5f);
            }

            colors.AddRange(baseColors);
        }

        List <Vector3> normals = new List <Vector3>();
        Vector3        normal  = new Vector3(0f, 0f, 1f);

        for (int i = 0; i < vertices.Count; i++)
        {
            normals.Add(normal);
        }

        Vector2Int     atlasIndex = type.atlasPositions[0];
        List <Vector2> uvs        = new List <Vector2>();

        for (int i = 0; i < rotations.Length; i++)
        {
            uvs.AddRange(atlasReader.GetUVs(atlasIndex.x, atlasIndex.y));
        }

        int[] triangles =
        {
            0,           1,      2,      0,      2,     3,
            0 + 4,   1 + 4,  2 + 4,  0 + 4,  2 + 4, 3 + 4,
            0 + 8,   1 + 8,  2 + 8,  0 + 8,  2 + 8, 3 + 8,
            0 + 12, 1 + 12, 2 + 12, 0 + 12, 2 + 12, 3 + 12
        };

        MeshData data = new MeshData(vertices, normals, uvs, triangles, colors.ToArray());

        return(data);
    }
Exemplo n.º 8
0
    public MeshData GenerateCubeFaces(bool[] faceIsVisible, AtlasReader atlasReader)
    {
        List <List <Vector3> > vertexLists   = new List <List <Vector3> >();
        List <List <Vector3> > normalLists   = new List <List <Vector3> >();
        List <List <Vector2> > uvLists       = new List <List <Vector2> >();
        List <int[]>           triangleLists = new List <int[]>();

        for (int i = 0; i < FACE_DIRECTIONS.Length; i++)
        {
            if (faceIsVisible[i] == false)
            {
                continue; // Don't bother making a mesh for a face that can't be seen.
            }

            GenerateBlockFace(FACE_DIRECTIONS[i], out List <Vector3> vertices, out List <Vector3> normals, out int[] triangles);

            Vector2Int[] atlasPositions = type.atlasPositions;
            int          index          = atlasPositions.Length == 1 ? 0 : i;

            List <Vector2> uvs = atlasReader.GetUVs(atlasPositions[index].x, atlasPositions[index].y);


            vertexLists.Add(vertices);
            normalLists.Add(normals);
            uvLists.Add(uvs);
            triangleLists.Add(triangles);
        }

        List <Vector3> allVertices  = new List <Vector3>();
        List <Vector3> allNormals   = new List <Vector3>();
        List <Vector2> allUVs       = new List <Vector2>();
        List <int>     allTriangles = new List <int>();

        foreach (List <Vector3> vertexList in vertexLists)
        {
            allVertices.AddRange(vertexList);
        }

        foreach (List <Vector3> normalList in normalLists)
        {
            allNormals.AddRange(normalList);
        }

        foreach (List <Vector2> uvList in uvLists)
        {
            allUVs.AddRange(uvList);
        }

        for (int i = 0; i < triangleLists.Count; i++)
        {
            for (int j = 0; j < triangleLists[i].Length; j++)
            {
                triangleLists[i][j] += i * 4;
            }
            allTriangles.AddRange(triangleLists[i]);
        }

        List <Color> allColors = new List <Color>();

        if (this.type.isFluid)
        {
            foreach (var vertex in allVertices)
            {
                //Color color = vertex.y > 0.0f ? Color.blue : Color.black;
                allColors.Add(Color.blue);
            }
        }

        MeshData data = new MeshData(allVertices, allNormals, allUVs, allTriangles.ToArray(), allColors.ToArray());

        return(data);
    }