Beispiel #1
0
 public void EnableDisableSourceObjectRenderers(bool show)
 {
     for (int i = 0; i < GetObjectsToCombine().Count; i++)
     {
         GameObject go = GetObjectsToCombine()[i];
         if (go != null)
         {
             Renderer mr = SAUtility.GetRenderer(go);
             if (mr != null)
             {
                 mr.enabled = show;
             }
         }
     }
 }
Beispiel #2
0
 public bool ValidateSkinnedMeshes(List <GameObject> objs)
 {
     for (int i = 0; i < objs.Count; i++)
     {
         Renderer r = SAUtility.GetRenderer(objs[i]);
         if (r is SkinnedMeshRenderer)
         {
             Transform[] bones = ((SkinnedMeshRenderer)r).bones;
             if (bones.Length == 0)
             {
                 Debug.LogWarning("SkinnedMesh " + i + " (" + objs[i] + ") in the list of objects to combine has no bones. Check that 'optimize game object' is not checked in the 'Rig' tab of the asset importer. Mesh Baker cannot combine optimized skinned meshes because the bones are not available.");
             }
         }
     }
     return(true);
 }
Beispiel #3
0
    List <GameObject> GetFilteredList()
    {
        List <GameObject>  newMomObjs = new List <GameObject>();
        SA3MeshCombineRoot mom        = (SA3MeshCombineRoot)target;

        if (mom == null)
        {
            Debug.LogError("Must select a target MeshBaker to add objects to");
            return(newMomObjs);
        }
        GameObject dontAddMe = null;
        Renderer   r         = SAUtility.GetRenderer(mom.gameObject);

        if (r != null)
        { //make sure that this MeshBaker object is not in list
            dontAddMe = r.gameObject;
        }

        int numInSelection      = 0;
        int numStaticExcluded   = 0;
        int numEnabledExcluded  = 0;
        int numLightmapExcluded = 0;
        int numOBuvExcluded     = 0;

        GameObject[] gos = Selection.gameObjects;
        if (gos.Length == 0)
        {
            Debug.LogWarning("No objects selected in hierarchy view. Nothing added.");
        }

        for (int i = 0; i < gos.Length; i++)
        {
            GameObject go  = gos[i];
            Renderer[] mrs = go.GetComponentsInChildren <Renderer>();
            for (int j = 0; j < mrs.Length; j++)
            {
                if (mrs[j] is MeshRenderer || mrs[j] is SkinnedMeshRenderer)
                {
                    if (mrs[j].GetComponent <TextMesh>() != null)
                    {
                        continue; //don't add TextMeshes
                    }
                    numInSelection++;
                    if (!newMomObjs.Contains(mrs[j].gameObject))
                    {
                        bool addMe = true;
                        if (!mrs[j].gameObject.isStatic && onlyStaticObjects)
                        {
                            numStaticExcluded++;
                            addMe = false;
                        }

                        if (!mrs[j].enabled && onlyEnabledObjects)
                        {
                            numEnabledExcluded++;
                            addMe = false;
                        }

                        if (lightmapIndex != -2)
                        {
                            if (mrs[j].lightmapIndex != lightmapIndex)
                            {
                                numLightmapExcluded++;
                                addMe = false;
                            }
                        }

                        Mesh mm = SAUtility.GetMesh(mrs[j].gameObject);
                        if (mm != null)
                        {
                            Rect dummy = new Rect();
                            if (SAUtility.hasOutOfBoundsUVs(mm, ref dummy) && excludeMeshesWithOBuvs)
                            {
                                if (shaderMat != null)
                                {
                                    numOBuvExcluded++;
                                    addMe = false;
                                }
                            }
                            else
                            {
                                Debug.LogWarning("Object " + mrs[j].gameObject.name + " uses uvs that are outside the range (0,1)" +
                                                 "this object can only be combined with other objects that use the exact same set of source textures (one image in each atlas)" +
                                                 " unless fix out of bounds UVs is used");
                            }
                        }

                        if (shaderMat != null)
                        {
                            Material[] nMats      = mrs[j].sharedMaterials;
                            bool       usesShader = false;
                            foreach (Material nMat in nMats)
                            {
                                if (nMat != null && nMat.shader == shaderMat.shader)
                                {
                                    usesShader = true;
                                }
                            }
                            if (!usesShader)
                            {
                                addMe = false;
                            }
                        }

                        if (mat != null)
                        {
                            Material[] nMats   = mrs[j].sharedMaterials;
                            bool       usesMat = false;
                            foreach (Material nMat in nMats)
                            {
                                if (nMat == mat)
                                {
                                    usesMat = true;
                                }
                            }
                            if (!usesMat)
                            {
                                addMe = false;
                            }
                        }

                        if (addMe && mrs[j].gameObject != dontAddMe)
                        {
                            if (!newMomObjs.Contains(mrs[j].gameObject))
                            {
                                newMomObjs.Add(mrs[j].gameObject);
                            }
                        }
                    }
                }
            }
        }
        Debug.Log("Total objects in selection " + numInSelection);
        if (numStaticExcluded > 0)
        {
            Debug.Log(numStaticExcluded + " objects were excluded because they were not static");
        }
        if (numEnabledExcluded > 0)
        {
            Debug.Log(numEnabledExcluded + " objects were excluded because they were disabled");
        }
        if (numOBuvExcluded > 0)
        {
            Debug.Log(numOBuvExcluded + " objects were excluded because they had out of bounds uvs");
        }
        if (numLightmapExcluded > 0)
        {
            Debug.Log(numLightmapExcluded + " objects did not match lightmap filter.");
        }
        return(newMomObjs);
    }