Beispiel #1
0
    void AddCombine(SA3TextureCombine tb, string key, List <Renderer> gaws)
    {
        int numVerts = 0;

        for (int i = 0; i < gaws.Count; i++)
        {
            Mesh m = SAUtility.GetMesh(gaws[i].gameObject);
            if (m != null)
            {
                numVerts += m.vertexCount;
            }
        }

        GameObject nmb = new GameObject("CombineIn." + key);

        nmb.transform.position = Vector3.zero;
        SA3MeshCombineCommon newCombine;

        if (numVerts >= 65535)
        {
            newCombine = nmb.AddComponent <SA3MultiMeshCombine>();
            newCombine.useObjsToMeshFromTexBaker = false;
        }
        else
        {
            newCombine = nmb.AddComponent <SA3MeshCombine>();
            newCombine.useObjsToMeshFromTexBaker = false;
        }
        newCombine.textureBakeResults = tb.textureBakeResults;
        newCombine.transform.parent   = tb.transform;
        for (int i = 0; i < gaws.Count; i++)
        {
            newCombine.GetObjectsToCombine().Add(gaws[i].gameObject);
        }
    }
Beispiel #2
0
    static bool validateSubmeshOverlap(SA3MeshCombineRoot mom)
    {
        List <GameObject> objsToMesh = mom.GetObjectsToCombine();

        for (int i = 0; i < objsToMesh.Count; i++)
        {
            Mesh m = SAUtility.GetMesh(objsToMesh[i]);
            if (SAUtility.doSubmeshesShareVertsOrTris(m) != 0)
            {
                Debug.LogWarning("Object " + objsToMesh[i] + " in the list of objects to combine has overlapping submeshes (submeshes share vertices). If the UVs associated with the shared vertices are important then this bake may not work. If you are using multiple materials then this object can only be combined with objects that use the exact same set of textures (each atlas contains one texture). There may be other undesirable side affects as well. Mesh Master, available in the asset store can fix overlapping submeshes.");
                return(true);
            }
        }
        return(true);
    }
Beispiel #3
0
    public static bool DoCombinedValidate(SA3MeshCombineRoot mom, SAObjsToCombineTypes objToCombineType, SA2EditorMethodsInterface editorMethods)
    {
        if (mom.textureBakeResults == null)
        {
            Debug.LogError("Need to set Material Bake Result on " + mom);
            return(false);
        }
        if (!(mom is SA3TextureCombine))
        {
            SA3TextureCombine tb = mom.GetComponent <SA3TextureCombine>();
            if (tb != null && tb.textureBakeResults != mom.textureBakeResults)
            {
                Debug.LogWarning("Material Bake Result on this component is not the same as the Material Bake Result on the SA3TextureCombine.");
            }
        }

        List <GameObject> objsToMesh = mom.GetObjectsToCombine();

        for (int i = 0; i < objsToMesh.Count; i++)
        {
            GameObject go = objsToMesh[i];
            if (go == null)
            {
                Debug.LogError("The list of objects to combine contains a null at position." + i + " Select and use [shift] delete to remove");
                return(false);
            }
            for (int j = i + 1; j < objsToMesh.Count; j++)
            {
                if (objsToMesh[i] == objsToMesh[j])
                {
                    Debug.LogError("The list of objects to combine contains duplicates.");
                    return(false);
                }
            }
            if (SAUtility.GetGOMaterials(go) == null)
            {
                Debug.LogError("Object " + go + " in the list of objects to be combined does not have a material");
                return(false);
            }
            if (SAUtility.GetMesh(go) == null)
            {
                Debug.LogError("Object " + go + " in the list of objects to be combined does not have a mesh");
                return(false);
            }
        }

        if (mom.textureBakeResults.doMultiMaterial)
        {
            if (!validateSubmeshOverlap(mom))
            {//only warns currently
                return(false);
            }
        }

        List <GameObject> objs = objsToMesh;

        if (mom is SA3MeshCombine)
        {
            objs = mom.GetObjectsToCombine();
            //if (((SA3MeshCombine)mom).useObjsToMeshFromTexBaker && tb != null) objs = tb.GetObjectsToCombine();
            if (objs == null || objs.Count == 0)
            {
                Debug.LogError("No meshes to combine. Please assign some meshes to combine.");
                return(false);
            }
            if (mom is SA3MeshCombine && ((SA3MeshCombine)mom).meshCombiner.renderType == SARenderType.skinnedMeshRenderer)
            {
                if (!editorMethods.ValidateSkinnedMeshes(objs))
                {
                    return(false);
                }
            }
        }

        if (editorMethods != null)
        {
            editorMethods.CheckPrefabTypes(objToCombineType, objsToMesh);
        }
        return(true);
    }
Beispiel #4
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);
    }
Beispiel #5
0
    void _distributeAmongBakers(GameObject[] gos, int[] deleteGOinstanceIDs)
    {
        if (gos == null)
        {
            gos = empty;
        }
        if (deleteGOinstanceIDs == null)
        {
            deleteGOinstanceIDs = emptyIDs;
        }

        if (resultSceneObject == null)
        {
            resultSceneObject = new GameObject("SAMMesh-" + name);
        }

        //PART 2 ==== calculate which bakers to add objects to
        for (int i = 0; i < meshCombiners.Count; i++)
        {
            meshCombiners[i].extraSpace = _maxVertsInMesh - meshCombiners[i].combinedMesh.GetMesh().vertexCount;
        }
        //Profile.End//Profile("SA2MultiMeshCombiner.AddDeleteGameObjects1");

        //Profile.Start//Profile("SA2MultiMeshCombiner.AddDeleteGameObjects2.1");
        //first delete game objects from the existing combinedMeshes keep track of free space
        for (int i = 0; i < deleteGOinstanceIDs.Length; i++)
        {
            CombinedMesh c = null;
            if (obj2MeshCombinerMap.TryGetValue(deleteGOinstanceIDs[i], out c))
            {
                if (LOG_LEVEL >= SA2LogLevel.debug)
                {
                    SA2Log.LogDebug("SA2MultiMeshCombiner.Removing " + deleteGOinstanceIDs[i] + " from meshCombiner " + meshCombiners.IndexOf(c));
                }
                c.numVertsInListToDelete += c.combinedMesh.GetNumVerticesFor(deleteGOinstanceIDs[i]);  //m.vertexCount;
                c.gosToDelete.Add(deleteGOinstanceIDs[i]);
            }
            else
            {
                Debug.LogWarning("Object " + deleteGOinstanceIDs[i] + " in the list of objects to delete is not in the combined mesh.");
            }
        }
        for (int i = 0; i < gos.Length; i++)
        {
            GameObject   go       = gos[i];
            int          numVerts = SAUtility.GetMesh(go).vertexCount;
            CombinedMesh cm       = null;
            for (int j = 0; j < meshCombiners.Count; j++)
            {
                if (meshCombiners[j].extraSpace + meshCombiners[j].numVertsInListToDelete - meshCombiners[j].numVertsInListToAdd > numVerts)
                {
                    cm = meshCombiners[j];
                    if (LOG_LEVEL >= SA2LogLevel.debug)
                    {
                        SA2Log.LogDebug("SA2MultiMeshCombiner.Added " + gos[i] + " to combinedMesh " + j, LOG_LEVEL);
                    }
                    break;
                }
            }
            if (cm == null)
            {
                cm = new CombinedMesh(maxVertsInMesh, _resultSceneObject, _LOG_LEVEL);
                _setMBValues(cm.combinedMesh);
                meshCombiners.Add(cm);
                if (LOG_LEVEL >= SA2LogLevel.debug)
                {
                    SA2Log.LogDebug("SA2MultiMeshCombiner.Created new combinedMesh");
                }
            }
            cm.gosToAdd.Add(go);
            cm.numVertsInListToAdd += numVerts;
            //			obj2MeshCombinerMap.Add(go,cm);
        }
    }