Example #1
0
    public bool SaveToIso(string IsoName, byte[] icon_tex, out BSIsoData outData)
    {
        outData = null;
        if (m_SelectionBoxes.Count == 0)
        {
            return(false);
        }

        // Only the block can save to be ISO
        if (pattern.type != EBSVoxelType.Block)
        {
            Debug.LogWarning("The iso is not support the Voxel");
            return(false);
        }

        BSIsoData iso = new BSIsoData();

        iso.Init(pattern.type);
        iso.m_HeadInfo.Name = IsoName;

        BSTools.IntBox bound = BSTools.SelBox.CalculateBound(m_SelectionBoxes);

        iso.m_HeadInfo.xSize   = bound.xMax - bound.xMin + 1;
        iso.m_HeadInfo.ySize   = bound.yMax - bound.yMin + 1;
        iso.m_HeadInfo.zSize   = bound.zMax - bound.zMin + 1;
        iso.m_HeadInfo.IconTex = icon_tex;

        foreach (BSTools.SelBox box in m_SelectionBoxes)
        {
            for (int x = box.m_Box.xMin; x <= box.m_Box.xMax; x++)
            {
                for (int y = box.m_Box.yMin; y <= box.m_Box.yMax; y++)
                {
                    for (int z = box.m_Box.zMin; z <= box.m_Box.zMax; z++)
                    {
                        BSVoxel voxel = dataSource.SafeRead(x, y, z);
                        int     key   = BSIsoData.IPosToKey(x - bound.xMin, y - bound.yMin, z - bound.zMin);
                        if (!dataSource.VoxelIsZero(voxel, 1))
                        {
                            iso.m_Voxels.Add(key, voxel);
                        }
                    }
                }
            }
        }

        if (iso.m_Voxels.Count == 0)
        {
            return(false);
        }

        iso.CaclCosts();

        string FilePath = GameConfig.GetUserDataPath() + BuildingMan.s_IsoPath;

        /*bool r = */ SaveFile(FilePath, iso);

        if (SaveFile(FilePath, iso))
        {
            ClearSelection(m_Action);
            outData = iso;
            return(true);
        }
        else
        {
            return(false);
        }
    }
Example #2
0
    public bool SaveToIso(string IsoName, byte[] icon_tex, out BSIsoData outData)
    {
        outData = null;

        List <IntVector3> selections = GetSelectionPos();

        if (selections.Count == 0)
        {
            return(false);
        }

        // Only the block can save to be ISO
        if (pattern.type != EBSVoxelType.Block)
        {
            Debug.LogWarning("The iso is not support the Voxel");
            return(false);
        }

        BSIsoData iso = new BSIsoData();

        iso.Init(pattern.type);
        iso.m_HeadInfo.Name = IsoName;

        IntVector3 min = new IntVector3(selections[0]);
        IntVector3 max = new IntVector3(selections[0]);

        for (int i = 1; i < selections.Count; i++)
        {
            min.x = (min.x > selections[i].x ? selections[i].x:min.x);
            min.y = (min.y > selections[i].y ? selections[i].y:min.y);
            min.z = (min.z > selections[i].z ? selections[i].z:min.z);
            max.x = (max.x < selections[i].x ? selections[i].x:max.x);
            max.y = (max.y < selections[i].y ? selections[i].y:max.y);
            max.z = (max.z < selections[i].z ? selections[i].z:max.z);
        }

        iso.m_HeadInfo.xSize   = max.x - min.x + 1;
        iso.m_HeadInfo.ySize   = max.y - min.y + 1;
        iso.m_HeadInfo.zSize   = max.z - min.z + 1;
        iso.m_HeadInfo.IconTex = icon_tex;

        for (int i = 0; i < selections.Count; i++)
        {
            BSVoxel voxel = dataSource.SafeRead(selections[i].x, selections[i].y, selections[i].z);
            int     key   = BSIsoData.IPosToKey(selections[i].x - min.x, selections[i].y - min.y, selections[i].z - min.z);
            iso.m_Voxels.Add(key, voxel);
        }

        iso.CaclCosts();

        string FilePath = GameConfig.GetUserDataPath() + BuildingMan.s_IsoPath;

        /*bool r = */ SaveFile(FilePath, iso);

        if (SaveFile(FilePath, iso))
        {
            outData = iso;
            return(true);
        }
        else
        {
            return(false);
        }
    }