Example #1
0
        public static void BackUpScene()
        {
            CreateOptRoot();

            XOCp_OptimizerHandler xoh = XOGloble.Root.GetComponent <XOCp_OptimizerHandler>();

            xoh.olst.Clear();
            xoh.nlst.Clear();

            UnityEngine.Renderer[] rs = (UnityEngine.Renderer[])FindObjectsOfType(typeof(UnityEngine.Renderer));
            for (int i = 0; i < rs.Length; i++)
            {
                UnityEngine.Renderer r = rs[i];
                if (r is MeshRenderer)
                {
                    if (r.GetComponent <TextMesh>() != null)
                    {
                        continue;                         //don't add TextMeshes
                    }
                    if (r.GetComponent <XOCp_MarkIgnore>() != null)
                    {
                        continue;
                    }
                    if (r.gameObject.isStatic == true && r.gameObject.activeInHierarchy == true)
                    {
                        if (xoh != null)
                        {
                            xoh.olst.Add(r.gameObject);
                        }

                        if (XOMeshSplit.CanSplit(r.gameObject) == true)
                        {
                            XOMeshSplit.ExtractMaterialMeshes(r.gameObject);
                        }
                        else
                        {
                            UnityEngine.GameObject backobj = NewIterM(r.gameObject);
                            xoh.nlst.Add(backobj);
                            AddObjDic(r.gameObject, backobj);
                        }

                        xoh.bDisplayOrigin = false;
                        xoh.bDisplayNew    = true;
                        r.gameObject.SetActive(false);
                    }
                }
            }

            if (xoh != null)
            {
                xoh.CreateNodes();
            }
        }
Example #2
0
		public void RemoveRenderer(Renderer rend) {
			if(AffectedRenderers.Contains(rend)) {
				AffectedRenderers.Remove(rend);
				mset.SkyAnchor anchor = rend.GetComponent<mset.SkyAnchor>();
				if(anchor && anchor.CurrentApplicator == this) anchor.CurrentApplicator = null;
			}
		}
Example #3
0
		public void AddRenderer(Renderer rend) {
			mset.SkyAnchor anchor = rend.GetComponent<mset.SkyAnchor>();
			if(anchor != null) {
				if(anchor.CurrentApplicator != null) anchor.CurrentApplicator.RemoveRenderer(rend);
				anchor.CurrentApplicator = this;
			}
			AffectedRenderers.Add(rend);
		}
Example #4
0
 private void DrawHierachy(TreeData treeData, Renderer renderer, Rect sizeRect)
 {
     if (styles == null)
     {
         styles = new Styles();
     }
     this.hierachySpread = this.hierachyNodeSize + this.hierachyNodeSpace;
     this.hierachyView = sizeRect;
     Event event2 = new Event(Event.current);
     List<HierachyNode> nodes = new List<HierachyNode>();
     this.BuildHierachyNodes(treeData, nodes, treeData.root, 0);
     this.LayoutHierachyNodes(nodes, sizeRect);
     float num = 16f;
     Vector2 zero = Vector2.zero;
     if (sizeRect.width < this.hierachyRect.width)
     {
         zero.y -= 16f;
     }
     bool changed = GUI.changed;
     this.hierachyDisplayRect = GUILayoutUtility.GetRect(sizeRect.width, this.hierachyRect.height + num);
     this.hierachyDisplayRect.width = sizeRect.width;
     GUI.Box(this.hierachyDisplayRect, GUIContent.none, styles.nodeBackground);
     this.hierachyScroll = GUI.BeginScrollView(this.hierachyDisplayRect, this.hierachyScroll, this.hierachyRect, false, false);
     GUI.changed = changed;
     this.HandleDragHierachyNodes(treeData, nodes);
     this.DrawHierachyNodes(treeData, nodes, treeData.root, (Vector2) (zero / 2f), 1f, 1f);
     if ((this.dragNode != null) && this.isDragging)
     {
         Vector2 vector2 = Event.current.mousePosition - this.dragClickPos;
         this.DrawHierachyNodes(treeData, nodes, this.dragNode.group, vector2 + ((Vector2) (zero / 2f)), 0.5f, 0.5f);
     }
     GUI.EndScrollView();
     MeshFilter component = renderer.GetComponent<MeshFilter>();
     if (((component != null) && (component.sharedMesh != null)) && (renderer != null))
     {
         int length = component.sharedMesh.vertices.Length;
         int num3 = component.sharedMesh.triangles.Length / 3;
         int num4 = renderer.sharedMaterials.Length;
         Rect position = new Rect((this.hierachyDisplayRect.xMax - 80f) - 4f, ((this.hierachyDisplayRect.yMax + zero.y) - 40f) - 4f, 80f, 40f);
         string text = TreeEditorHelper.GetGUIContent("Hierachy Stats").text.Replace("[v]", length.ToString()).Replace("[t]", num3.ToString()).Replace("[m]", num4.ToString()).Replace(" / ", "\n");
         GUI.Label(position, text, EditorStyles.helpBox);
     }
     if ((event2.type == EventType.ScrollWheel) && (Event.current.type == EventType.Used))
     {
         Event.current = event2;
     }
 }
    void listMaterialsInScene(bool generateMeshBakers)
    {
        Dictionary <UnityEngine.Shader, List <_GameObjectAndWarning> > shader2GameObjects = new Dictionary <UnityEngine.Shader, List <_GameObjectAndWarning> >();

        UnityEngine.Renderer[] rs = (UnityEngine.Renderer[])FindObjectsOfType(typeof(UnityEngine.Renderer));
//		Profile.StartProfile("listMaterialsInScene1");
        for (int i = 0; i < rs.Length; i++)
        {
            UnityEngine.Renderer r = rs[i];
            if (r is MeshRenderer || r is SkinnedMeshRenderer)
            {
                if (r.GetComponent <TextMesh>() != null)
                {
                    continue;                     //don't add TextMeshes
                }
                Material[] mms = r.sharedMaterials;
                List <_GameObjectAndWarning> gos;

                foreach (Material mm in mms)
                {
                    if (mm != null)
                    {
                        string warn = "";
                        if (shader2GameObjects.ContainsKey(mm.shader))
                        {
                            gos = shader2GameObjects[mm.shader];
                        }
                        else
                        {
                            gos = new List <_GameObjectAndWarning>();
                            shader2GameObjects.Add(mm.shader, gos);
                        }
                        //todo add warning for texture scaling
                        if (r.sharedMaterials.Length > 1)
                        {
                            warn += " [Uses multiple materials] ";
                        }

                        if (gos.Find(x => x.go == r.gameObject) == null)
                        {
                            gos.Add(new _GameObjectAndWarning(r.gameObject, warn, generate_LightmapOption));
                        }
                    }
                }
            }
        }

        foreach (UnityEngine.Shader m in shader2GameObjects.Keys)
        {
            int totalVerts = 0;
            List <_GameObjectAndWarning> gos = shader2GameObjects[m];
            for (int i = 0; i < gos.Count; i++)
            {
                Mesh mm     = MB_Utility.GetMesh(gos[i].go);
                int  nVerts = 0;
                if (mm != null)
                {
                    nVerts += mm.vertexCount;
                    Rect dummy = new Rect();
                    if (MB_Utility.hasOutOfBoundsUVs(mm, ref dummy))
                    {
                        int w = (int)dummy.width;
                        int h = (int)dummy.height;
                        gos[i].outOfBoundsUVs = true;
                        gos[i].warning       += " [WARNING: has uvs outside the range (0,1) tex is tiled " + w + "x" + h + " times]";
                    }
                    if (MB_Utility.doSubmeshesShareVertsOrTris(mm) != 0)
                    {
                        gos[i].submeshesOverlap = true;
                        gos[i].warning         += " [WARNING: Submeshes share verts or triangles. 'Multiple Combined Materials' feature may not work.]";
                    }
                }
                totalVerts += nVerts;
                UnityEngine.Renderer mr = gos[i].go.GetComponent <UnityEngine.Renderer>();
                if (!MB_Utility.validateOBuvsMultiMaterial(mr.sharedMaterials))
                {
                    gos[i].warning += " [WARNING: UnityEngine.Object uses same material on multiple submeshes. This may produce poor results when used with multiple materials or fix out of bounds uvs.]";
                }
            }
        }
        Dictionary <_GameObjectAndWarning, List <_GameObjectAndWarning> > gs2bakeGroupMap = new Dictionary <_GameObjectAndWarning, List <_GameObjectAndWarning> >();
        List <_GameObjectAndWarning> objsNotAddedToBaker = new List <_GameObjectAndWarning>();

        sortIntoBakeGroups2(generateMeshBakers, shader2GameObjects, gs2bakeGroupMap, objsNotAddedToBaker);

        if (generateMeshBakers)
        {
            createBakers(gs2bakeGroupMap, objsNotAddedToBaker);
            //Debug.Log( generateSceneAnalysisReport(gs2bakeGroupMap, objsNotAddedToBaker) );
        }
        else
        {
            Debug.Log(generateSceneAnalysisReport(gs2bakeGroupMap, objsNotAddedToBaker));
        }
    }
 private static bool HasNormals(Renderer renderer)
 {
   Mesh mesh = (Mesh) null;
   if (renderer is MeshRenderer)
   {
     MeshFilter component = renderer.GetComponent<MeshFilter>();
     if ((UnityEngine.Object) component != (UnityEngine.Object) null)
       mesh = component.sharedMesh;
   }
   else if (renderer is SkinnedMeshRenderer)
     mesh = (renderer as SkinnedMeshRenderer).sharedMesh;
   return InternalMeshUtil.HasNormals(mesh);
 }
Example #7
0
		public void ApplyCorrectSky(Renderer rend) {
			//filter by ignored layers
			bool localCube = false;

			//if the anchor is a direct link to a sky, ignore applicators all together
			mset.SkyAnchor anchor = rend.GetComponent<SkyAnchor>();
			if(anchor && anchor.BindType == SkyAnchor.AnchorBindType.TargetSky) {
				anchor.Apply();
				localCube = true;	
			}

			//look for localized applicators to bind this renderer to
			foreach(mset.SkyApplicator app in skyApplicators) {
				if(localCube) app.RemoveRenderer(rend);
				else if(app.RendererInside(rend)) localCube = true;
			}

			//no local applicator found, but we have a global sky
			if(!localCube && _GlobalSky != null) {
				if(anchor != null) {
					if(anchor.CurrentApplicator != null) {
						anchor.CurrentApplicator.RemoveRenderer(rend);
						anchor.CurrentApplicator = null;
					}
					//start last blend to global sky and tell the anchor it's gone global
					anchor.BlendToGlobalSky(_GlobalSky);
				} else {
					//HACK: no applying to renderers outside of a sky anchor! it leaks memory.
					//_GlobalSky.Apply(rend,0);
				}

				if(!globalSkyChildren.Contains(rend)) globalSkyChildren.Add(rend);
			}

			//if a local cube was found or there is no global sky, remove rend
			if(localCube || _GlobalSky == null) { 
				if(globalSkyChildren.Contains(rend)) {
					globalSkyChildren.Remove(rend);
				}
			}
		}
Example #8
0
		public void RegisterNewRenderer(Renderer rend) {
			//filter by active
			if(!rend.gameObject.activeInHierarchy) return;

			//filter by ignored layers
			int layerFlag = 1 << rend.gameObject.layer;
			if((IgnoredLayerMask & layerFlag) != 0) return;

			//sort by static/dynamic
			if(rend.gameObject.isStatic) {
				if(!staticRenderers.Contains(rend)) {
					staticRenderers.Add(rend);
					ApplyCorrectSky(rend);
				}
			} else if(!dynamicRenderers.Contains(rend)) {
				dynamicRenderers.Add(rend);
				if(rend.GetComponent<mset.SkyAnchor>() == null) {
					rend.gameObject.AddComponent(typeof(mset.SkyAnchor));
				}
			}
		}
 private static bool HasNormals(Renderer renderer)
 {
     Mesh sharedMesh = null;
     if (renderer is MeshRenderer)
     {
         MeshFilter component = renderer.GetComponent<MeshFilter>();
         if (component != null)
         {
             sharedMesh = component.sharedMesh;
         }
     }
     else if (renderer is SkinnedMeshRenderer)
     {
         sharedMesh = (renderer as SkinnedMeshRenderer).sharedMesh;
     }
     return InternalMeshUtil.HasNormals(sharedMesh);
 }