示例#1
0
    public void RebuildCache()
    {
        voxModelsCache.Clear();
        terIds.Clear();
        tilesFolder = tilesFolder.Trim();
        if (!Directory.Exists(tilesFolder))
        {
            return;
        }
        var       files          = Directory.GetFiles(tilesFolder, "*.vox");
        Texture2D terrainTexture = null;

        foreach (var file in files)
        {
            var name  = Path.GetFileNameWithoutExtension(file).ToLower();
            var model = new VOX.Model(file);

            if (terrainTexture == null)
            {
                scale          = 1.0f / model.sizeX;
                tileSize       = model.sizeX * scale;
                terrainTexture = VOX.Texture.FromModel(model, 16);
            }

            var mesh = VOX.Mesh.FromModel(model, scale, removeEdges, 1.0f / terrainTexture.width / 2.0f);
            voxModelsCache[name] = mesh;
            terIds[0]            = "t_null";
            int terId  = DDA.terId(name);
            int monId  = DDA.monId(name);
            int furnId = DDA.furnId(name);
            if (terId != 0)
            {
                terIds[terId] = name;
            }
            if (monId != -1)
            {
                monIds[monId] = name;
            }
            if (furnId != -1)
            {
                furnIds[furnId] = name;
            }
        }

        terrainMaterial = new UnityEngine.Material(Shader.Find("Standard"));
        terrainMaterial.SetTexture("_MainTex", terrainTexture);
        UpdateGrid();
        terrainMaterial.EnableKeyword("_SPECULARHIGHLIGHTS_OFF");
        terrainMaterial.SetFloat("_SpecularHighlights", 0f);
    }
示例#2
0
 private void AddToTilesCache(int code)
 {
     VOX.Model vox = new VOX.Model(Path.Combine(tilesPath, code + ".vox"));
     if (tileSizeX == 0 && vox.sizeX != 0 && vox.sizeY != 0 && vox.sizeZ != 0)
     {
         tileSizeX = vox.sizeX;
         tileSizeY = vox.sizeY;
         tileSizeZ = vox.sizeZ;
     }
     else if (vox.sizeX == 0)
     {
         vox = new VOX.Model(Path.Combine(tilesPath, "t_unknown.vox"));
         tilesCache.Add(code, vox);
     }
     else
     {
         tilesCache.Add(code, vox);
     }
 }
示例#3
0
    public static GameObject CreateGameObject(string path, float scale = 1f)
    {
        if (grid == null)
        {
            grid = Resources.Load("hlines") as Texture;
        }
        VOXGameObject.voxPath = path;
        VOXGameObject.scale   = scale;
        VOXGameObject.model   = new VOX.Model(path);
        if (VOXGameObject.model.sizeX == 0 &&
            VOXGameObject.model.sizeY == 0 &&
            VOXGameObject.model.sizeZ == 0)
        {
            return(new GameObject());
        }
        InitMaterials();
        var planes = CreateColorPlanes();

        return(CreateMesh(planes));
    }