private bool MergeRenderableObjs(RenderableObj from, RenderableObj to) { bool ret = false; if (Config.mergeObjectID) { for (int i = 0; i < from.Count; i++) { if (ret) { break; } for (int j = 0; j < to.Count; j++) { ret = MergeCondition(from[i], to[j]); if (ret) { break; } } } if (ret) { to.Add(from); from.Clear(); } } return(ret); }
private void ProcessAndMergeMeshRenders() { if (Config.IsBatchMode) { Debug.LogFormat("batch mode Generate Game Object Id"); } else { Util.Progress("生成ObjectId", "获取所有Mesh Render ...", 0.0f); } var meshList = GetSceneMeshes(); if (Config.mergeObjectID == false) { renderableSet.RemoveEmptyRenerableObject(); return; } for (int i = 0; i < meshList.Count; i++) { var meshtobeMerged = meshList[i]; RenderableObj obj = GetRenderableObjectByMeshRenderer(meshtobeMerged); if (!Config.IsBatchMode) { Util.Progress("生成ObjectId", String.Format("合并Mesh Render {0}/{1} ...", i + 1, meshList.Count), ((float)i + 1) / meshList.Count); } for (int j = i + 1; j < meshList.Count; j++) { var mesh = meshList[j]; RenderableObj obj2 = GetRenderableObjectByMeshRenderer(mesh); if (MergeRenderableObjs(obj, obj2)) { break; } } } if (Config.IsBatchMode) { Debug.LogFormat("Delete Invalid Renderable Object."); } else { Util.Progress("生成ObjectId", "删除无效对象", 0.0f); } renderableSet.RemoveEmptyRenerableObject(); }
//---------------------------- #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); }
public void SetRenderableObjectVisible(RenderableObj obj, bool vis) { renderableSet.SetRenderableObjectVisible(obj, vis); }
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)) //{ //} //} } } }
private void RotateCameraDir(Vector3 forward, HashSet <RenderableObj> ret) { Camera.main.transform.forward = forward.normalized; OCProfiler.Start(); HashSet <MeshRenderer> visList = null; if (Config.SoftRenderer) { if (owner.owner.Owner == null) { var renders = owner.owner.treeMesh.GetWithinFrustum(Camera.main); visList = owner.owner._renderer.GetVisibleModels(renders); } else { var renders = owner.owner.Owner.treeMesh.GetWithinFrustum(Camera.main); visList = owner.owner._renderer.GetVisibleModels(renders); } } else { visList = owner.owner._renderer.GetVisibleModels(); } var calcVisTime = OCProfiler.Stop(); OCProfiler.Start(); foreach (var mr in visList) { RenderableObj renderObj = null; if (owner.owner.Owner == null) { renderObj = owner.owner.GetRenderableObjectByMeshRenderer(mr); } else { MultiScene world = owner.owner.Owner as MultiScene; renderObj = world.GetRenderableObjectByMeshRenderer(mr); } if (renderObj == null) { string log = string.Format("batch mode renderObj name:{0}, scene name: {1} is null!", mr.gameObject.name, mr.gameObject.scene.name); Debug.LogError(log); continue; } if (!visibleModelList.Contains(renderObj)) { visibleModelList.Add(renderObj); } if (ret != null && !ret.Contains(renderObj)) { ret.Add(renderObj); } } var updateVisTime = OCProfiler.Stop(); }