public string GetOCDataFileName() { string fileName; if (IsStreamScene) { fileName = MultiScene.GetOCDataFileName(SceneNamePattern); } else { fileName = SingleScene.GetOCDataFileName(SceneNamePattern); } return(fileName); }
//---------------------------- #if UNITY_EDITOR public RenderableObj GetRenderableObjectByMeshRenderer(MeshRenderer mesh) { RenderableObj ret = null; foreach (var pair in tileMap) { SingleScene singleScene = pair.Value as SingleScene; var temp = singleScene.GetRenderableObjectByMeshRenderer(mesh); if (temp != null) { ret = temp; break; } } return(ret); }
public RenderableObj GetRenderableObject(int id) { RenderableObj ret = null; if (ret == null) { foreach (var pair in tileMap) { SingleScene tile = pair.Value as SingleScene; ret = tile.GetRuntimeOCObject(id); if (ret != null) { break; } } } return(ret); }
bool RotateCameraAndRender(SingleScene scene, Texture2D tex, Vector3 dir) { bool ret = true; dir.Normalize(); cam.transform.forward = dir; int width = tex.width; int height = tex.height; scene.UndoCulling(); cam.Render(); tex.ReadPixels(new Rect(0, 0, width, height), 0, 0); tex.Apply(); Color[] p1s = tex.GetPixels(0); scene.DoCulling(cam.transform.position); cam.Render(); tex.ReadPixels(new Rect(0, 0, width, height), 0, 0); tex.Apply(); Color[] p2s = tex.GetPixels(0); //compare pixels for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { Color c1 = p1s[i * width + j]; Color c2 = p2s[i * width + j]; Color delta = c2 - c1; if (delta.r > errorRange || delta.g > errorRange || delta.b > errorRange || delta.a > errorRange) { ret = false; //Debug.LogFormat("pixel i{0},j{1}; c1 r{2},g{3},b{4} c2 r{5},g{6},b{7}", i, j, c1.r, c1.g, c1.b, c2.r, c2.g, c2.b); } } } scene.UndoCulling(); return(ret); }
public void CopyOCDataTo(string temporaryContainer) { foreach (var pair in tileMap) { SingleScene scene = pair.Value as SingleScene; if (scene.TileIndex.Equals(_currentIndex)) { try { var dataFilePath = scene.GetOCDataFilePath(); if (File.Exists(dataFilePath)) { if (!Directory.Exists(temporaryContainer)) { Debug.LogWarningFormat("Can not find temporay directory for container {0}, create it", temporaryContainer); Directory.CreateDirectory(temporaryContainer); } var paths = dataFilePath.Split('/'); var fileName = paths[paths.Length - 1]; var filePath = Path.Combine(temporaryContainer, fileName); if (File.Exists(filePath)) { File.Delete(filePath); } File.Copy(dataFilePath, filePath); } else { Debug.LogErrorFormat("Can not find oc file{0}", dataFilePath); } } catch (Exception e) { Debug.LogException(e); throw; } break; } } }
public Cell GetCurrentCell(Vector3 pos) { Cell cell = null; if (cell == null) { foreach (var tile in tileMap) { SingleScene scene = tile.Value as SingleScene; cell = scene.GetCurrentCell(pos); if (cell != null) { break; } } } return(cell); }
void MoveCamera(SingleScene scene, Texture2D tex, Vector3 pos) { //bool bSame = true; cam.transform.position = pos; bool bSameF = RotateCameraAndRender(scene, tex, Vector3.forward); bool bSameB = RotateCameraAndRender(scene, tex, Vector3.back); bool bSameL = RotateCameraAndRender(scene, tex, Vector3.left); bool bSameR = RotateCameraAndRender(scene, tex, Vector3.right); //bool bSameU = RotateCameraAndRender(scene, tex, Vector3.up); //bool bSameD = RotateCameraAndRender(scene, tex, Vector3.down); if (bSameF == false) { Debug.LogError("Forward is not the same color!" + pos); } if (bSameB == false) { Debug.LogError("Back is not the same color!" + pos); } if (bSameL == false) { Debug.LogError("left is not the same color!" + pos); } if (bSameR == false) { Debug.LogError("right is not the same color!" + pos); } //if (bSameU == false) //Debug.Log("up is not the same color!"); //if (bSameD == false) //Debug.Log("down is not the same color!"); //bSame = bSameF && bSameB && bSameL && bSameR && bSameU && bSameD; //bSame = bSameF && bSameB && bSameL && bSameR; //if (bSame == false) // Debug.LogFormat("Camera pos: x{0},y{1},z{2} is not the same color!", cam.transform.position.x, cam.transform.position.y, cam.transform.position.z); }
public RenderableObj(SingleScene owner) { _owner = owner; _visible = true; }
public void Do() { if (config.IsStreamScene) { var ocDataFilePath = MultiScene.GetOCDataFilePath(config.GetSceneAssetPath(), config.SceneNamePattern); if (!File.Exists(ocDataFilePath)) { EditorUtility.DisplayDialog("文件不存在", string.Format("OC 数据文件 {0} 不存在!", ocDataFilePath), "确定"); return; } int TileDimension = config.TileDimension; byte[] data = null; using (var fileStream = File.Open(ocDataFilePath, FileMode.Open)) { data = new byte[fileStream.Length]; if (fileStream.Read(data, 0, data.Length) != data.Length) { EditorUtility.DisplayDialog("文件读取失败", string.Format("读取 OC 数据文件 {0} 失败!", ocDataFilePath), "确定"); return; } } streamScene = new MultiScene(config.GetSceneAssetPath(), config.SceneNamePattern, TileDimension, config.TileSize, data); for (int i = 0; i < config.TileDimension; i++) { for (int j = 0; j < config.TileDimension; j++) { streamScene.Load(i, j); } } } else { singleScene = new OC.SingleScene(config.GetSceneAssetPath(), config.SceneNamePattern, Index.InValidIndex); singleScene.TestLoad(); } //var name = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name; //SingleScene scene = new OC.SingleScene("", name, null); //scene.Load(); int width = _width; int height = _height; RenderTexture renderTex = RenderTexture.GetTemporary(width, height, 16, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB); RenderTexture.active = renderTex; cam.targetTexture = renderTex; Texture2D tex = new Texture2D(width, height, TextureFormat.ARGB32, false); if (config.IsStreamScene) { foreach (var tile in streamScene.tileMap) { var scene = tile.Value as SingleScene; for (int v = 0; v < scene.volumelList.Count; v++) { string title = "test volume " + v + "/" + scene.volumelList.Count; string info = ""; var volume = scene.volumelList[v]; int finalCellCount = volume.cellList.Count; for (int i = 0; i < finalCellCount; i++) { info = "cell " + i + "/" + finalCellCount; bool bCancel = EditorUtility.DisplayCancelableProgressBar(title, info, (float)i / finalCellCount); if (bCancel) { break; } var cell = volume.cellList[i]; MoveCamera(scene, tex, cell.aabb.center); } } } } else { for (int v = 0; v < singleScene.volumelList.Count; v++) { string title = "test volume " + v + "/" + singleScene.volumelList.Count; string info = ""; var volume = singleScene.volumelList[v]; int finalCellCount = volume.cellList.Count; for (int i = 0; i < finalCellCount; i++) { info = "cell " + i + "/" + finalCellCount; bool bCancel = EditorUtility.DisplayCancelableProgressBar(title, info, (float)i / finalCellCount); if (bCancel) { break; } var cell = volume.cellList[i]; MoveCamera(singleScene, tex, cell.aabb.center); } } } EditorUtility.ClearProgressBar(); }
public RenderableObjectSet(SingleScene owner) { _owner = owner; }
public void Do() { if (owner.owner.Owner == null) { foreach (var pair in visFlagDic) { var key = pair.Key; var visFlags = pair.Value; for (int i = 0; i < visFlags.Count; i++) { RenderableObj go = owner.owner.GetRuntimeOCObject(i); if (go != null) { owner.owner.SetRenderableObjectVisible(go, visFlags[i]); } } } return; } //----------------- foreach (var pair in visFlagDic) { var key = pair.Key; var visFlags = pair.Value; Index selfIndex = owner.owner.TileIndex; Index targetIndex = Index.InValidIndex; targetIndex.x = selfIndex.x + key.x; targetIndex.y = selfIndex.y + key.y; Tile tile = null; owner.owner.Owner.tileMap.TryGetValue(targetIndex, out tile); if (tile == null) { continue; } for (int i = 0; i < visFlags.Count; i++) { SingleScene curScene = tile as SingleScene; RenderableObj go = curScene.GetRuntimeOCObject(i); if (go != null) { owner.owner.SetRenderableObjectVisible(go, visFlags[i]); } //if (key.Equals(Index.InValidIndex) == false) //{ //if (owner.owner.Owner.IsValidIndex(selfIndex)) //{ //} //} } } }
public void Save(OCDataWriter writer) { writer.Write(aabb.center); //OCProfiler.Start(); if (owner.owner.Owner == null) { var flag = new BitArray(owner.owner.MaxGameObjectIDCount); flag.SetAll(false); visFlagDic.Add(new Index(0, 0), flag); } else { //var mainFlag = new BitArray(0); //mainFlag.SetAll(false); //visFlagDic.Add(Index.InValidIndex, mainFlag); Index currentIndex = owner.owner.TileIndex; for (int i = -1; i < 2; i++) { for (int j = -1; j < 2; j++) { Index newIndex = new Index(i, j) + currentIndex; if (owner.owner.Owner.IsValidIndex(newIndex)) { var multiScene = owner.owner.Owner as MultiScene; if (multiScene.tileMap.Count > 9) { Debug.LogError("batch mode tile count=" + multiScene.tileMap.Count); } var scene = multiScene.ExistTile(newIndex) as SingleScene; if (scene != null) { var flag = new BitArray(scene.MaxGameObjectIDCount); flag.SetAll(false); visFlagDic.Add(new Index(i, j), flag); } else { Debug.LogError("batch mode Cell::SaveData error!"); } } } } } foreach (var obj in visibleModelList) { SingleScene scene = obj.Owner; if (scene.Owner != null) { if (scene.Owner.IsValidIndex(scene.TileIndex)) { int deltaX = scene.TileIndex.x - owner.owner.TileIndex.x; int deltaY = scene.TileIndex.y - owner.owner.TileIndex.y; visFlagDic[new Index(deltaX, deltaY)].Set(obj.GUID, true); } else { //main scene //visFlagDic[Index.InValidIndex].Set(obj.GUID, true); } } else { visFlagDic[new Index(0, 0)].Set(obj.GUID, true); } } //var cellSaveInitTime = OCProfiler.Stop(); foreach (var bitArray in visFlagDic) { writer.Write(OC.Util.ConvertBitArray(bitArray.Value)); } writer.Write(children.Count); foreach (var child in children) { writer.Write(child.aabb.center); } Clear(); }