private void AddMaterials(GameObject theGameObject, Dictionary <GameObject, Material[]> dicMaterials) { Renderer theRenderer = theGameObject.GetComponent <Renderer>(); AutomaticLOD automaticLOD = theGameObject.GetComponent <AutomaticLOD>(); if (theRenderer != null && theRenderer.sharedMaterials != null && automaticLOD != null) { dicMaterials.Add(theGameObject, theRenderer.sharedMaterials); } for (int i = 0; i < theGameObject.transform.childCount; i++) { AddMaterials(theGameObject.transform.GetChild(i).gameObject, dicMaterials); } }
private void SetActiveObject(int index) { m_nSelectedIndex = index; AutomaticLOD automaticLOD = Instantiate(ShowcaseObjects[index].m_automaticLOD); automaticLOD.transform.position = ShowcaseObjects[index].m_position; automaticLOD.transform.rotation = Quaternion.Euler(ShowcaseObjects[index].m_angles); m_selectedAutomaticLOD = automaticLOD; automaticLOD.SetAutomaticCameraLODSwitch(false); m_objectMaterials = new Dictionary <GameObject, Material[]>(); AddMaterials(automaticLOD.gameObject, m_objectMaterials); m_bWireframe = false; }
private IEnumerator ComputeLODWithVertices(float fAmount) { foreach (KeyValuePair <GameObject, Material[]> pair in m_objectMaterials) { AutomaticLOD automaticLOD = pair.Key.GetComponent <AutomaticLOD>(); MeshFilter meshFilter = pair.Key.GetComponent <MeshFilter>(); SkinnedMeshRenderer skin = pair.Key.GetComponent <SkinnedMeshRenderer>(); if (automaticLOD && (meshFilter != null || skin != null)) { Mesh newMesh = null; if (meshFilter != null) { newMesh = Mesh.Instantiate(meshFilter.sharedMesh); } else if (skin != null) { newMesh = Mesh.Instantiate(skin.sharedMesh); } automaticLOD.GetMeshSimplifier().CoroutineEnded = false; StartCoroutine(automaticLOD.GetMeshSimplifier().ComputeMeshWithVertexCount(pair.Key, newMesh, Mathf.RoundToInt(fAmount * automaticLOD.GetMeshSimplifier().GetOriginalMeshUniqueVertexCount()), automaticLOD.name, Progress)); while (automaticLOD.GetMeshSimplifier().CoroutineEnded == false) { yield return(null); } if (meshFilter != null) { meshFilter.mesh = newMesh; } else if (skin != null) { skin.sharedMesh = newMesh; } } } m_strLastTitle = ""; m_strLastMessage = ""; m_nLastProgress = 0; }