private bool SpawnVoxelFaces() { // Faces if (!Data) { return(false); } Vector3 pos, rot, scl; Data.GetModelTransform(CurrentModelIndex, out pos, out rot, out scl); int[,,] voxels = Data.Voxels[CurrentModelIndex]; bool tooLargeAsked = false; int sizeX = voxels.GetLength(0); int sizeY = voxels.GetLength(1); int sizeZ = voxels.GetLength(2); float maxSize = Mathf.Max(sizeX, sizeY, sizeZ); CameraSizeMin = 5f; CameraSizeMax = maxSize * 2f; SetCameraSize((CameraSizeMin + CameraSizeMax) * 0.5f); SetCameraFarClip(maxSize * 4f); SetCameraPosition(new Vector3(0f, 0f, -maxSize * 2f)); ContainerTF.localPosition = -new Vector3(sizeX / 2f, sizeY / 2f, sizeZ / 2f); for (int x = 0; x < sizeX; x++) { EditorUtil.ProgressBar("", "Importing...", ((float)x / (sizeX - 1)) * 0.5f + 0.5f); for (int y = 0; y < sizeY; y++) { for (int z = 0; z < sizeZ; z++) { if (voxels[x, y, z] == 0) { continue; } AddQuad(x, y, z, voxels[x, y, z], sizeX, sizeY, sizeZ); if (!tooLargeAsked && ContainerTF.childCount > MAX_QUAD_COUNT) { EditorUtil.ClearProgressBar(); bool go = EditorUtil.Dialog("", "This model is too large. Still want to edit it ?", "Yes", "Cancel"); tooLargeAsked = true; if (!go) { return(false); } } } } } return(true); }
private static void DoTask(Task task) { if (TaskMap.Count == 0) { return; } if (PathExportMod == ExportMod.AskEverytime && !BrowseExportPath()) { return; } RefreshMergeSetting(); string failMessage = "[Voxel] Failed to create model for {0} model{1}."; int successedNum = 0; int failedNum = 0; int taskCount = TaskMap.Count; var resultList = new List <VoxelCore.Result>(); EditorUtil.ProgressBar("Creating", "Starting task...", 0f); EditorUtil.StartWatch(); ForAllSelection((pathData) => { try { string fileName = Util.GetNameWithoutExtension(pathData.Path); EditorUtil.ProgressBar("Creating", string.Format("[{1}/{2}] Creating {0}", fileName, successedNum + failedNum + 1, taskCount), (float)(successedNum + failedNum + 1) / (taskCount + 1)); VoxelData voxelData = null; switch (task) { case Task.Prefab: case Task.Lod: case Task.Obj: // Model voxelData = VoxelFile.GetVoxelData(Util.FileToByte(pathData.Path), pathData.Extension == ".vox"); if (pathData.Extension == ".vox" || pathData.Extension == ".qb") { var result = VoxelCore.CreateLodModel(voxelData, ModelScale, task == Task.Lod ? LodNum : 1, LightMapSupportMode); if (PathExportMod == ExportMod.OriginalPath) { result.ExportRoot = Util.GetParentPath(pathData.Path); result.ExportSubRoot = ""; } else { result.ExportRoot = ExportPath; result.ExportSubRoot = pathData.Root; } result.FileName = fileName; result.Extension = task == Task.Obj ? ".obj" : ".prefab"; result.IsRigged = false; result.WithAvatar = false; resultList.Add(result); } break; case Task.ToJson: if (pathData.Extension == ".vox" || pathData.Extension == ".qb") { // Voxel To Json voxelData = VoxelFile.GetVoxelData(Util.FileToByte(pathData.Path), pathData.Extension == ".vox"); var json = VoxelCore.VoxelToJson(voxelData); string path = PathExportMod == ExportMod.OriginalPath ? Util.ChangeExtension(pathData.Path, ".json") : Util.CombinePaths(ExportPath, pathData.Root, fileName + ".json"); Util.CreateParent(path); Util.Save(json, path); } break; case Task.ToVox: case Task.ToQb: // Json To Voxel string aimEx = task == Task.ToVox ? ".vox" : ".qb"; if (pathData.Extension == ".json") { voxelData = VoxelCore.JsonToVoxel(Util.Load(pathData.Path)); } else if (pathData.Extension == ".vox" || pathData.Extension == ".qb") { if (aimEx != pathData.Extension) { voxelData = VoxelFile.GetVoxelData(Util.FileToByte(pathData.Path), pathData.Extension == ".vox"); } } if (voxelData) { string aimPath = PathExportMod == ExportMod.OriginalPath ? Util.ChangeExtension(pathData.Path, aimEx) : Util.CombinePaths(ExportPath, pathData.Root, fileName + aimEx); Util.ByteToFile( VoxelFile.GetVoxelByte(voxelData, task == Task.ToVox), aimPath ); } break; } successedNum++; } catch (System.Exception ex) { failMessage += "\n" + ex.Message; failedNum++; } }); // File try { EditorVoxelCore.CreateFileForResult(resultList, TheShader, ModelScale); double taskTime = EditorUtil.StopWatchAndGetTime(); // Log Messages if (successedNum > 0) { string msg = string.Format("[Voxel] {0} model{1} created in {2}sec.", successedNum, (successedNum > 1 ? "s" : ""), taskTime.ToString("0.00")); if (LogMessage) { Debug.Log(msg); } if (ShowDialog) { EditorUtil.Dialog("Success", msg, "OK"); } } if (failedNum > 0) { string msg = string.Format(failMessage, failedNum.ToString(), (failedNum > 1 ? "s" : "")); if (LogMessage) { Debug.LogWarning(msg); } if (ShowDialog) { EditorUtil.Dialog("Warning", msg, "OK"); } } } catch (System.Exception ex) { Debug.LogError(ex.Message); } EditorUtil.ClearProgressBar(); }