Пример #1
0
 static void DefineVertices(ref Vector3[] voxelVerts, JsonObjects.BlockModelElement element)
 {
     for (int i = 0; i < voxelVerts.Length; i++)
     {
         voxelVerts[i].x = voxelVerts[i].x == 0 ? element.from[0] / 16f : element.to[0] / 16f;
         voxelVerts[i].y = voxelVerts[i].y == 0 ? element.from[1] / 16f : element.to[1] / 16f;
         voxelVerts[i].z = voxelVerts[i].z == 0 ? element.from[2] / 16f : element.to[2] / 16f;
     }
 }
Пример #2
0
    static void RegisterFaceTexture(JsonObjects.BlockModel blockModel, JsonObjects.BlockModelElement element)
    {
        foreach (KeyValuePair <string, JsonObjects.BlockModelFace> pair in element.faces)
        {
            JsonObjects.BlockModelFace face = pair.Value;

            string realTexturePath = GetRealTexturePath(blockModel, face.texture);

            if (!textureUvs.ContainsKey(realTexturePath))
            {
                textureUvs.Add(realTexturePath, TextureManager.RegisterBlockTexture(realTexturePath));
            }
        }
    }
Пример #3
0
    static Model CreateModel(JsonObjects.BlockModel blockModel, JsonObjects.BlockModelElement element)
    {
        Vector3[] voxelVerts = VoxelData.voxelVerts;
        Vector3[] faceChecks = VoxelData.faceChecks;
        Vector2[,] voxelUvs = new Vector2[6, 6];
        List <int> tintedFaces = new List <int>();

        DefineVertices(ref voxelVerts, element);

        Dictionary <string, int> directions = new Dictionary <string, int>();

        directions.Add("down", 3);
        directions.Add("up", 2);
        directions.Add("north", 4);
        directions.Add("south", 5);
        directions.Add("east", 1);
        directions.Add("west", 0);

        List <string> definedDirections = new List <string>();

        List <string> textures = new List <string>();

        if (element.faces == null)
        {
            element.faces = new Dictionary <string, JsonObjects.BlockModelFace>();
        }

        RegisterFaceTexture(blockModel, element);

        foreach (KeyValuePair <string, JsonObjects.BlockModelFace> pair in element.faces)
        {
            CreateFace(blockModel, pair, directions, ref definedDirections, ref faceChecks, ref voxelUvs, ref tintedFaces);
        }

        /* Part blocks
         * foreach(KeyValuePair<string, int> pair in directions)
         * {
         *  if(!definedDirections.Contains(pair.Key))
         *  {
         *      Debug.Log(pair.Key);
         *      CreateFace(blockModel, new KeyValuePair<string, JsonObjects.BlockModelFace>(pair.Key, new JsonObjects.BlockModelFace("transparent", "all")), directions, ref definedDirections, ref faceChecks, ref voxelUvs);
         *  }
         * }
         */
        return(new Model(voxelVerts, faceChecks, VoxelData.voxelTris, tintedFaces, voxelUvs));
    }