Ejemplo n.º 1
0
 public void loadDataFormDB(SQLiteConnection connection)
 {
     using (SQLiteCommand cmd = new SQLiteCommand(connection))
     {
         cmd.CommandText = "SELECT startTime, endTime, version, filename, threadCount, convertStatus, timeElapsed, tileCompleteCount, tileTotalCount, totalReceivedBytes, totalWroteBytes, netWorkSpeed, totalWroteCount FROM TimeNameMap order by version DESC";
         SQLiteDataReader reader = cmd.ExecuteReader();
         while (reader.Read())
         {
             current = new MBVersion()
             {
                 start         = reader.GetInt64(0),
                 end           = reader.GetInt64(1),
                 version       = reader.GetInt64(2),
                 name          = reader.GetString(3),
                 threadCount   = reader.GetInt64(4),
                 status        = reader.GetString(5),
                 timeSpan      = reader.GetDouble(6),
                 completeCount = reader.GetInt64(7),
                 totalCount    = reader.GetInt64(8),
                 receivedBytes = reader.GetInt64(9),
                 wroteBytes    = reader.GetInt64(10),
                 networkSpeed  = reader.GetDouble(11),
                 wroteCounts   = reader.GetInt64(12)
             };
             addOneVersion(current);
         }
         joinCircle();
     }
 }
Ejemplo n.º 2
0
        public static string ConvertFullPathToProjectRelativePath(string path)
        {
            if (path != null && path.Length > 0)
            {
                Uri    projectFolder = new Uri(Application.dataPath);
                Uri    outputFolder  = new Uri(path);
                Uri    relativeUri   = projectFolder.MakeRelativeUri(outputFolder);
                string relativePath  = MBVersion.UnescapeURL(relativeUri.ToString());
                if (relativePath.Length == 0)
                {
                    relativePath = "Assets/";
                }

                if (!relativePath.StartsWith("Assets/"))
                {
                    Debug.LogError("Bad folder path. The folder must be in the project Assets folder.");
                    return("");
                }
                else
                {
                    return(relativePath);
                }
            }
            else
            {
                return(path);
            }
        }
Ejemplo n.º 3
0
            private MBVersion addOneVersion(MBVersion toAdd)
            {
                MBVersion temp = head;

                while (temp.next != null)
                {
                    if (temp.next.version > toAdd.version)
                    {
                        break;
                    }
                    temp = temp.next;
                }
                if (temp.version == toAdd.version)
                {
                    return(null);
                }
                else if (temp.version < toAdd.version)
                {
                    toAdd.next = temp.next;
                    temp.next  = toAdd;
                    versionCount++;
                    if (toAdd.next == null)
                    {
                        last = toAdd;
                    }
                }
                return(temp);
            }
Ejemplo n.º 4
0
 public void RecordDownloadRecord(MBVersion version, string downloadRule)
 {
     lock (_locker)
     {
         cacheForhot.insertOneVersion(version, downloadRule);
     }
 }
Ejemplo n.º 5
0
 public Index()
 {
     OSArchitecture = RuntimeInformation.OSArchitecture.ToString();
     OSDescription  = RuntimeInformation.OSDescription.ToString();
     Runtime        = RuntimeInformation.FrameworkDescription.ToString();
     Version        = MBVersion.MaterialBlazorVersion();
 }
Ejemplo n.º 6
0
 private void joinCircle()
 {
     last = head;
     while (last.next != null)
     {
         last = last.next;
     }
     last.next = head.next;
     head      = head.next;
     current   = head;
 }
Ejemplo n.º 7
0
            private void breakCircle()
            {
                MBVersion temp = new MBVersion()
                {
                    version = 0
                };

                temp.next = head;
                head      = temp;
                last.next = null;
            }
    void CreatePackageForExampleMaterials()
    {
        // Check if examples folder is "Assets/MeshBaker/Examples"
        // Get all materials in examples.
        string unityPackageFilename;
        string examplesPathRelative = GetRelativeExamplesPath();

        if (examplesPathRelative == null)
        {
            Debug.LogError("Cannot package example materials as no Mesh Baker Example scenes were found. Renaming example scenes may cause this error.");
            return;
        }

        MBVersion.PipelineType pipelineType = MBVersion.DetectPipeline();
        if (pipelineType == MBVersion.PipelineType.Default)
        {
            unityPackageFilename = examplesPathRelative + "/Examples_Default.unitypackage";
        }
        else if (pipelineType == MBVersion.PipelineType.HDRP)
        {
            unityPackageFilename = examplesPathRelative + "/Examples_HDRP.unitypackage";
        }
        else if (pipelineType == MBVersion.PipelineType.URP)
        {
            unityPackageFilename = examplesPathRelative + "/Examples_URP.unitypackage";
        }
        else
        {
            Debug.LogError("Unknown pipeline type.");
            return;
        }

        string[]      matGIDs            = AssetDatabase.FindAssets("t:Material", new string[] { examplesPathRelative });
        string[]      assetPathNames     = new string[matGIDs.Length];
        List <string> assetPathNamesList = new List <string>();

        for (int i = 0; i < matGIDs.Length; i++)
        {
            string path = AssetDatabase.GUIDToAssetPath(matGIDs[i]);
            if (!path.Contains("SceneBasicTextureArrayAssets") && !path.EndsWith(".fbx")) // don't do texture array assets.
            {
                assetPathNamesList.Add(path);
                // Debug.Log(path);
            }
        }
        assetPathNames = assetPathNamesList.ToArray();

        Debug.Log("Found " + assetPathNames.Length + " materials in " + examplesPathRelative);

        AssetDatabase.ExportPackage(assetPathNames, unityPackageFilename);

        Debug.Log("Create Unity Package: " + unityPackageFilename);
    }
    public string GetShaderNameForPipeline()
    {
        if (MBVersion.DetectPipeline() == MBVersion.PipelineType.URP)
        {
            return("Universal Render Pipeline/Lit");
        }
        else if (MBVersion.DetectPipeline() == MBVersion.PipelineType.HDRP)
        {
            return("HDRP/Lit");
        }

        return("Diffuse");
    }
Ejemplo n.º 10
0
        public string getCacheFile(string time, string cacheType)
        {
            MBVersion version = null;

            if ("hot".Equals(cacheType))
            {
                version = cacheForhot.getVersionFromTime(long.Parse(time));
            }
            else if ("traffic".Equals(cacheType) || "TrafficHis".Equals(cacheType))
            {
                version = cacheForTraffic.getVersionFromTime(long.Parse(time));
            }
            return(version == null ? null : version.name);
        }
Ejemplo n.º 11
0
 private void fixPriorVersionEnd(MBVersion previousVersion, MBVersion currentVersion, SQLiteConnection versionConn)
 {
     if (previousVersion.version == currentVersion.version - 1)
     {
         previousVersion.end = currentVersion.start - 1;
         using (SQLiteCommand cmd = new SQLiteCommand(versionConn))
         {
             cmd.CommandText = "UPDATE TimeNameMap SET endTime = @endTime WHERE version = @version";
             cmd.Parameters.AddWithValue("endTime", previousVersion.end);
             cmd.Parameters.AddWithValue("version", previousVersion.version.ToString());
             cmd.ExecuteNonQuery();
         }
     }
 }
Ejemplo n.º 12
0
            public override string ToString()
            {
                string    result = "Last Version is: " + (last == null ? "null" : last.version.ToString()) + ". [\n";
                int       seq    = 0;
                MBVersion temp   = head;

                while (temp != last)
                {
                    result += "{ \"seq\" : " + seq + ", \"version\" : " + temp.version + ", \"start\" : " + temp.start + ", \"end\" : " + temp.end + "},\n";
                    temp    = temp.next;
                    seq     = seq + 1;
                }
                result += "{ \"seq\" : " + seq + ", \"version\" : " + temp.version + ", \"start\" : " + temp.start + ", \"end\" : " + temp.end + "}\n]";
                return(result);
            }
Ejemplo n.º 13
0
        public void DrawGUI(MB_IMeshBakerSettings momm, bool settingsEnabled)
        {
            EditorGUILayout.BeginVertical(editorStyles.editorBoxBackgroundStyle);
            GUI.enabled = settingsEnabled;
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(doNorm, gc_doNormGUIContent);
            EditorGUILayout.PropertyField(doTan, gc_doTanGUIContent);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(doUV, gc_doUVGUIContent);
            EditorGUILayout.PropertyField(doUV3, gc_doUV3GUIContent);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(doUV4, gc_doUV4GUIContent);
            EditorGUILayout.PropertyField(doCol, gc_doColGUIContent);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.PropertyField(doBlendShapes, gc_doBlendShapeGUIContent);

            if (momm.lightmapOption == MB2_LightmapOptions.preserve_current_lightmapping)
            {
                if (MBVersion.GetMajorVersion() == 5)
                {
                    EditorGUILayout.HelpBox("The best choice for Unity 5 is to Ignore_UV2 or Generate_New_UV2 layout. Unity's baked GI will create the UV2 layout it wants. See manual for more information.", MessageType.Warning);
                }
            }

            if (momm.lightmapOption == MB2_LightmapOptions.generate_new_UV2_layout)
            {
                EditorGUILayout.HelpBox("Generating new lightmap UVs can split vertices which can push the number of vertices over the 64k limit.", MessageType.Warning);
            }

            EditorGUILayout.PropertyField(lightmappingOption, gc_lightmappingOptionGUIContent);
            if (momm.lightmapOption == MB2_LightmapOptions.generate_new_UV2_layout)
            {
                EditorGUILayout.PropertyField(uv2OutputParamsHardAngle, gc_uv2HardAngleGUIContent);
                EditorGUILayout.PropertyField(uv2OutputParamsPackingMargin, gc_uv2PackingMarginUV3GUIContent);
                EditorGUILayout.Separator();
            }

            EditorGUILayout.PropertyField(renderType, gc_renderTypeGUIContent);
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(clearBuffersAfterBake, gc_clearBuffersAfterBakeGUIContent);
            EditorGUILayout.PropertyField(centerMeshToBoundsCenter, gc_CenterMeshToBoundsCenter);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.PropertyField(optimizeAfterBake, gc_OptimizeAfterBake);
            GUI.enabled = true;
            EditorGUILayout.EndVertical();
        }
        public static string ValidatePlayerSettingsDefineSymbols()
        {
            // Check that the needed defines exist or are present when they should not be.
            MBVersion.PipelineType pipelineType = MBVersion.DetectPipeline();
            BuildTargetGroup       targetGroup  = EditorUserBuildSettings.selectedBuildTargetGroup;
            string scriptDefines = PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup);

            string s = "";

            if (pipelineType == MBVersion.PipelineType.HDRP)
            {
                if (!scriptDefines.Contains(MBVersion.MB_USING_HDRP))
                {
                    s += "The GraphicsSettings -> Render Pipeline Asset is configured to use HDRP. Please add 'MB_USING_HDRP' to PlayerSettings -> Scripting Define Symbols for all the build platforms " +
                         " that you are targeting. If there are compile errors check that the MeshBakerCore.asmdef file has references for:\n\n" +
                         "   Unity.RenderPipelines.HighDefinition.Runtime\n" +
                         "   Unity.RenderPipelines.HighDefinition.Config.Runtime (Unity 2019.3+)\n";
                }

                /*
                 * Type tp = Type.GetType("UnityEngine.Rendering.HighDefinition.HDAdditionalCameraData");
                 * if (tp == null)
                 * {
                 *  s += "The class 'HDAdditionalCameraData' cannot be found by the MeshBaker assembly. Ensure that the following assemblies are referenced by the MeshBaker.asmdef file: \n" +
                 *      "    Unity.RenderPipelines.HighDefinition.Runtime\n" +
                 *      "    Unity.RenderPipelines.HighDefinition.Config.Runtime (Unity 2019.3+)\n\n"+
                 *      "Or download the HDRP version of the package from the asset store.";
                 * }
                 */
            }
            else
            {
                if (scriptDefines.Contains(MBVersion.MB_USING_HDRP))
                {
                    s += "Please remove 'MB_USING_HDRP' from PlayerSettings -> Scripting Define Symbols for the current build platform. If this define is present there may be compile errors because Mesh Baker tries to access classes which only exist in the HDRP API.";
                }
            }

            if (s.Length > 0)
            {
                return(s);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 15
0
            public void clearInvalid(long earlisetTime)
            {
                breakCircle();
                MBVersion temp = head.next;

                while (temp != null)
                {
                    if (temp.end < earlisetTime)
                    {
                        head.next = temp.next;
                        temp.next = null;
                    }
                    temp = temp.next;
                }
                joinCircle();
                return;
            }
Ejemplo n.º 16
0
            public void insertOneVersion(MBVersion toAdd, string downloadRule)
            {
                breakCircle();
                MBVersion previous = addOneVersion(toAdd);

                if (previous != null)
                {
                    using (SQLiteConnection conn = new SQLiteConnection("Data source = versions.db"))
                    {
                        conn.Open();
                        SQLiteTransaction recordTransaction = conn.BeginTransaction();
                        using (SQLiteCommand cmd = new SQLiteCommand(conn))
                        {
                            cmd.CommandText = "INSERT INTO TimeNameMap VALUES (@filename, @startTime, @endTime, @version, @threadCount, @convertStatus, @timeElapsed, @tileCompleteCount, @tileTotalCount, @totalReceivedBytes, @totalWroteBytes, @netWorkSpeed, @totalWroteCount)";
                            cmd.Parameters.AddWithValue("filename", toAdd.name);
                            cmd.Parameters.AddWithValue("startTime", toAdd.start);
                            cmd.Parameters.AddWithValue("endTime", toAdd.end);
                            cmd.Parameters.AddWithValue("version", toAdd.version);
                            cmd.Parameters.AddWithValue("threadCount", toAdd.threadCount);
                            cmd.Parameters.AddWithValue("convertStatus", toAdd.status);
                            cmd.Parameters.AddWithValue("timeElapsed", toAdd.timeSpan);
                            cmd.Parameters.AddWithValue("tileCompleteCount", toAdd.completeCount);
                            cmd.Parameters.AddWithValue("tileTotalCount", toAdd.totalCount);
                            cmd.Parameters.AddWithValue("totalReceivedBytes", toAdd.receivedBytes);
                            cmd.Parameters.AddWithValue("totalWroteBytes", toAdd.wroteBytes);
                            cmd.Parameters.AddWithValue("netWorkSpeed", toAdd.networkSpeed);
                            cmd.Parameters.AddWithValue("totalWroteCount", toAdd.wroteCounts);
                            cmd.ExecuteNonQuery();
                        }
                        if (BaiDuMapManager.inst.RunMode == "ONLINE" && downloadRule == "BYROUND")
                        {
                            forcecastVersionTime(previous, toAdd, conn);
                        }

                        fixPriorVersionEnd(previous, toAdd, conn);
                        fixLatestVersionEnd(conn);
                        recordTransaction.Commit();
                        recordTransaction.Dispose();
                        conn.Close();
                    }
                }
                joinCircle();
            }
Ejemplo n.º 17
0
            public void reloadDataFromDB()
            {
                breakCircle();
                MBVersion temp = head.next;

                while (temp != null)
                {
                    head.next = temp.next;
                    temp.next = null;
                    temp      = head.next;
                }
                versionCount = 0;
                using (SQLiteConnection _conn = new SQLiteConnection("Data source = versions.db"))
                {
                    _conn.Open();
                    loadDataFormDB(_conn);
                    _conn.Close();
                }
            }
Ejemplo n.º 18
0
            public MBVersion getVersionFromTime(long timeStamp)
            {
                MBVersion result = null, temp;

                temp = head;
                if (last.start <= timeStamp && last.end >= timeStamp)
                {
                    return(last);
                }
                while (temp != last)
                {
                    if (temp.start <= timeStamp && temp.end >= timeStamp)
                    {
                        result = temp;
                        break;
                    }
                    temp = temp.next;
                }
                return(result);
            }
    public bool YisFlipped()
    {
        string graphicsDeviceVersion = SystemInfo.graphicsDeviceVersion.ToLower();
        bool   flipY;

        if (!MBVersion.GraphicsUVStartsAtTop())
        {
            flipY = false;
        }
        else
        {
            // "opengl es, direct3d"
            flipY = true;
        }

        if (LOG_LEVEL == MB2_LogLevel.debug)
        {
            Debug.Log("Graphics device version is: " + graphicsDeviceVersion + " flipY:" + flipY);
        }
        return(flipY);
    }
Ejemplo n.º 20
0
 public void AdjustTime()
 {
     using (SQLiteConnection conn = new SQLiteConnection("Data source = versions.db"))
     {
         conn.Open();
         SQLiteTransaction recordTransaction = conn.BeginTransaction();
         using (SQLiteCommand cmd = new SQLiteCommand(conn))
         {
             cmd.CommandText = "UPDATE TimeNameMap SET startTime = startTime + @count * @interval, endTime = endTime + @count * @interval  WHERE version = @version";
             cmd.Parameters.AddWithValue("version", current.version);
             cmd.Parameters.AddWithValue("count", versionCount);
             cmd.Parameters.AddWithValue("interval", BaiDuMapManager.inst.refreshInterval);
             cmd.ExecuteNonQuery();
         }
         recordTransaction.Commit();
         recordTransaction.Dispose();
         current.start += versionCount * BaiDuMapManager.inst.refreshInterval;
         current.end   += versionCount * BaiDuMapManager.inst.refreshInterval;
         Utility.Log(LogLevel.Info, null, "Adjusted version: " + current.version + ", versionCount is: " + versionCount);
         current = current.next;
     }
 }
Ejemplo n.º 21
0
 public void exportToNewFile()
 {
     if (!File.Exists("merge.mbtiles"))
     {
         SQLiteConnection.CreateFile("merge.mbtiles");
         SQLiteConnection conn = new SQLiteConnection("Data source = merge.mbtiles");
         conn.Open();
         using (SQLiteTransaction transaction = conn.BeginTransaction())
         {
             using (SQLiteCommand cmd = new SQLiteCommand(conn))
             {
                 cmd.CommandText = "CREATE TABLE TimeNameMap (filename TEXT, startTime INT8, endTime INT8, version INTEGER, threadCount INTEGER, convertStatus TEXT, timeElapsed REAL, tileCompleteCount INTEGER, tileTotalCount INTEGER, totalReceivedBytes INTEGER, totalWroteBytes INTEGER, netWorkSpeed REAL, totalWroteCount INTEGER)";
                 cmd.ExecuteNonQuery();
                 for (int i = 0; i < versionCount; i++)
                 {
                     cmd.CommandText = "INSERT INTO TimeNameMap VALUES (@filename, @startTime, @endTime, @version, @threadCount, @convertStatus, @timeElapsed, @tileCompleteCount, @tileTotalCount, @received, @wrote, @speed, @wroteCount)";
                     cmd.Parameters.AddWithValue("filename", current.name);
                     cmd.Parameters.AddWithValue("startTime", current.start);
                     cmd.Parameters.AddWithValue("endTime", current.end);
                     cmd.Parameters.AddWithValue("version", current.version);
                     cmd.Parameters.AddWithValue("threadCount", current.threadCount);
                     cmd.Parameters.AddWithValue("convertStatus", current.status);
                     cmd.Parameters.AddWithValue("timeElapsed", current.timeSpan);
                     cmd.Parameters.AddWithValue("tileCompleteCount", current.completeCount);
                     cmd.Parameters.AddWithValue("tileTotalCount", current.totalCount);
                     cmd.Parameters.AddWithValue("received", current.receivedBytes);
                     cmd.Parameters.AddWithValue("wrote", current.wroteBytes);
                     cmd.Parameters.AddWithValue("speed", current.networkSpeed);
                     cmd.Parameters.AddWithValue("wroteCount", current.wroteCounts);
                     current = current.next;
                     cmd.ExecuteNonQuery();
                 }
             }
             transaction.Commit();
             transaction.Dispose();
         }
     }
 }
    void Start()
    {
#if UNITY_2018_4_OR_NEWER
        MBVersion.PipelineType pipelineType = MBVersion.DetectPipeline();
        int materialPipeline = GetMaterialPipelineType();
        // Do not prompt if example materials cannot be found, are using an unsupported shader, or are already suitable for the current pipeline
        if (materialPipeline != -1 && pipelineType != (MBVersion.PipelineType)materialPipeline)
        {
            if (pipelineType != MBVersion.PipelineType.Unsupported)
            {
                bool convert = EditorUtility.DisplayDialog(
                    "Different Pipline Detected",
                    "Would you like to try converting the default Mesh Baker example scene materials to suit the " + pipelineType + " pipeline?",
                    "Yes",
                    "No");

                if (convert)
                {
                    MigrateMaterials();
                    if (pipelineType == MBVersion.PipelineType.HDRP)
                    {
                        Debug.LogWarning("If the Mesh Baker Example Scenes appear dark, try adding an Empty GameObject to the scene, adding a 'Volume' component to it, and assigning that volume one of the default profiles.");
                    }
                }
            }
            else
            {
                Debug.LogWarning("Mesh Baker's example scenes only support the Default Pipeline, URP, and HDRP.");
            }
        }
#endif
#if !MB_ALLOW_ADD_MIGRATE_MAT_SCRIPT
        // Add the MB_ALLOW_ADD_MIGRATE_MAT_SCRIPT to script defines to add this to scenes.
        DestroyImmediate(this.gameObject);
#endif
    }
Ejemplo n.º 23
0
    public static bool DoCombinedValidate(MB3_MeshBakerRoot mom, MB_ObjsToCombineTypes objToCombineType, MB2_EditorMethodsInterface editorMethods, MB2_ValidationLevel validationLevel)
    {
        if (mom.textureBakeResults == null)
        {
            Debug.LogError("Need to set Texture Bake Result on " + mom);
            return(false);
        }
        if (mom is MB3_MeshBakerCommon)
        {
            MB3_MeshBakerCommon momMB = (MB3_MeshBakerCommon)mom;
            MB3_TextureBaker    tb    = momMB.GetTextureBaker();
            if (tb != null && tb.textureBakeResults != mom.textureBakeResults)
            {
                Debug.LogWarning("Texture Bake Result on this component is not the same as the Texture Bake Result on the MB3_TextureBaker.");
            }
        }

        Dictionary <int, MB_Utility.MeshAnalysisResult> meshAnalysisResultCache = null;

        if (validationLevel == MB2_ValidationLevel.robust)
        {
            meshAnalysisResultCache = new Dictionary <int, MB_Utility.MeshAnalysisResult>();
        }
        List <GameObject>             objsToMesh  = mom.GetObjectsToCombine();
        Dictionary <string, Material> matName2Mat = new Dictionary <string, Material>();

        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 at " + i + " and " + j);
                    return(false);
                }
            }

            Material[] mats = MB_Utility.GetGOMaterials(go);
            if (mats.Length == 0)
            {
                Debug.LogError("Object " + go + " in the list of objects to be combined does not have a material");
                return(false);
            }
            Mesh m = MB_Utility.GetMesh(go);
            if (m == null)
            {
                Debug.LogError("Object " + go + " in the list of objects to be combined does not have a mesh");
                return(false);
            }
            if (m != null)              //This check can be very expensive and it only warns so only do this if we are in the editor.
            {
                if (!Application.isEditor &&
                    Application.isPlaying &&
                    mom.textureBakeResults.doMultiMaterial &&
                    validationLevel >= MB2_ValidationLevel.robust)
                {
                    MB_Utility.MeshAnalysisResult mar;
                    if (!meshAnalysisResultCache.TryGetValue(m.GetInstanceID(), out mar))
                    {
                        MB_Utility.doSubmeshesShareVertsOrTris(m, ref mar);
                        meshAnalysisResultCache.Add(m.GetInstanceID(), mar);
                    }
                    if (mar.hasOverlappingSubmeshVerts)
                    {
                        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.");
                    }
                }
            }

            if (MBVersion.IsUsingAddressables())
            {
                HashSet <string> materialsWithDuplicateNames = new HashSet <string>();
                for (int matIdx = 0; matIdx < mats.Length; matIdx++)
                {
                    if (mats[matIdx] != null)
                    {
                        if (matName2Mat.ContainsKey(mats[matIdx].name))
                        {
                            if (mats[matIdx] != matName2Mat[mats[matIdx].name])
                            {
                                // This is an error. If using addressables we consider materials that have the same name to be the same material when baking at runtime.
                                // Two different material must NOT have the same name.
                                materialsWithDuplicateNames.Add(mats[matIdx].name);
                            }
                        }
                        else
                        {
                            matName2Mat.Add(mats[matIdx].name, mats[matIdx]);
                        }
                    }
                }

                if (materialsWithDuplicateNames.Count > 0)
                {
                    String[] stringArray = new String[materialsWithDuplicateNames.Count];
                    materialsWithDuplicateNames.CopyTo(stringArray);
                    string matsWithSameName = string.Join(",", stringArray);
                    Debug.LogError("The source objects use different materials that have the same name (" + matsWithSameName + "). " +
                                   "If using addressables, materials with the same name are considered to be the same material when baking meshes at runtime. " +
                                   "If you want to use this Material Bake Result at runtime then all source materials must have distinct names. Baking in edit-mode will still work.");
                }
            }
        }


        List <GameObject> objs = objsToMesh;

        if (mom is MB3_MeshBaker)
        {
            objs = mom.GetObjectsToCombine();
            //if (((MB3_MeshBaker)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 MB3_MeshBaker && ((MB3_MeshBaker)mom).meshCombiner.settings.renderType == MB_RenderType.skinnedMeshRenderer)
            {
                if (!editorMethods.ValidateSkinnedMeshes(objs))
                {
                    return(false);
                }
            }
        }

        if (editorMethods != null)
        {
            editorMethods.CheckPrefabTypes(objToCombineType, objsToMesh);
        }
        return(true);
    }
    /// <summary>
    /// If using addressables and baking meshes at runtime with atlases that were baked in the editor.
    /// This method should be called after asset bundles have completed loading but before baking meshes.
    ///
    /// In this case materials used by a mesh at runtime may have been loaded from somewhere other
    /// than the build. These materials will be different instances than the Material assets in the project folder.
    /// Looking up assets will fail.
    /// </summary>
    public IEnumerator FindRuntimeMaterialsFromAddresses(CoroutineResult isComplete)
    {
        yield return(MBVersion.FindRuntimeMaterialsFromAddresses(this, isComplete));

        isComplete.isComplete = true;
    }
Ejemplo n.º 25
0
        public void DrawGUI(MB_IMeshBakerSettings momm, bool settingsEnabled, bool doingTextureArrays)
        {
            EditorGUILayout.BeginVertical(editorStyles.editorBoxBackgroundStyle);
            GUI.enabled = settingsEnabled;
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(doNorm, gc_doNormGUIContent);
            EditorGUILayout.PropertyField(doTan, gc_doTanGUIContent);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(doUV, gc_doUVGUIContent);
            EditorGUILayout.PropertyField(doUV3, gc_doUV3GUIContent);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(doUV4, gc_doUV4GUIContent);
            EditorGUILayout.PropertyField(doUV5, gc_doUV5GUIContent);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(doUV6, gc_doUV6GUIContent);
            EditorGUILayout.PropertyField(doUV7, gc_doUV7GUIContent);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(doUV8, gc_doUV8GUIContent);
            EditorGUILayout.PropertyField(doCol, gc_doColGUIContent);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.PropertyField(doBlendShapes, gc_doBlendShapeGUIContent);

            if (momm.lightmapOption == MB2_LightmapOptions.preserve_current_lightmapping)
            {
                if (MBVersion.GetMajorVersion() == 5)
                {
                    EditorGUILayout.HelpBox("The best choice for Unity 5 is to Ignore_UV2 or Generate_New_UV2 layout. Unity's baked GI will create the UV2 layout it wants. See manual for more information.", MessageType.Warning);
                }
            }

            if (momm.lightmapOption == MB2_LightmapOptions.generate_new_UV2_layout)
            {
                EditorGUILayout.HelpBox("Generating new lightmap UVs can split vertices which can push the number of vertices over the 64k limit.", MessageType.Warning);
            }

            EditorGUILayout.PropertyField(lightmappingOption, gc_lightmappingOptionGUIContent);
            if (momm.lightmapOption == MB2_LightmapOptions.generate_new_UV2_layout)
            {
                EditorGUILayout.PropertyField(uv2OutputParamsHardAngle, gc_uv2HardAngleGUIContent);
                EditorGUILayout.PropertyField(uv2OutputParamsPackingMargin, gc_uv2PackingMarginUV3GUIContent);
                EditorGUILayout.Separator();
            }

            UnityEngine.Object obj = null;
            obj = assignToMeshCustomizer.objectReferenceValue;


            EditorGUILayout.PropertyField(renderType, gc_renderTypeGUIContent);
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(clearBuffersAfterBake, gc_clearBuffersAfterBakeGUIContent);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.PropertyField(pivotLocationType, gc_PivotLocationType);
            if (pivotLocationType.enumValueIndex == (int)MB_MeshPivotLocation.customLocation)
            {
                EditorGUILayout.PropertyField(pivotLocation, gc_PivotLocation);
            }
            EditorGUILayout.PropertyField(optimizeAfterBake, gc_OptimizeAfterBake);
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Advanced", EditorStyles.boldLabel);

            // Don't use a PropertyField because we may not be able to use the assigned object. It may not implement requried interface.

            if (doingTextureArrays && assignToMeshCustomizer.objectReferenceValue == null)
            {
                EditorGUILayout.HelpBox("The Textures were baked into Texture Arrays. You probaly need to a customizer here" +
                                        " to embed the slice index in the mesh. You can use one of the included customizers or write your own. " +
                                        "See the example customizers in MeshBaker/Scripts/AssignToMeshCustomizers.", MessageType.Error);
            }
            obj = EditorGUILayout.ObjectField(gc_AssignMeshCusomizer, obj, typeof(UnityEngine.Object), true);
            if (obj == null || !(obj is IAssignToMeshCustomizer))
            {
                assignToMeshCustomizer.objectReferenceValue = null;
            }
            else
            {
                assignToMeshCustomizer.objectReferenceValue = obj;
            }

            GUI.enabled = true;
            EditorGUILayout.EndVertical();
        }
Ejemplo n.º 26
0
            private void forcecastVersionTime(MBVersion previousVersion, MBVersion currentVersion, SQLiteConnection versionConn)
            {
                arrangeArea timeSplit = (gap, seq, start, end) =>
                {
                    long   parts = gap - 1;
                    long   timeTotal = end - start;
                    long   avg = timeTotal / parts;
                    long   another = timeTotal % parts;
                    long[] result = new long[2];
                    long   startSeq = seq - 1, endSeq = seq;
                    result[0] = start + (avg + 1) * (startSeq < another ? startSeq : another) + avg * (startSeq < another ? 0 : startSeq - another);
                    result[1] = start + (avg + 1) * (endSeq < another ? endSeq : another) + avg * (endSeq < another ? 0 : endSeq - another) - (gap - seq == 1 ? 0 : 1);
                    return(result);
                };
                long      wholeStart  = 0;
                long      wholeEnd    = 0;
                long      allGap      = 0;
                long      currentGap  = 0;
                long      versionSpan = 0;
                MBVersion nextVersion = currentVersion.next;

                if (previousVersion != null && previousVersion.version != 0)
                {
                    if (nextVersion != null && nextVersion.version != 0)
                    {
                        allGap      = nextVersion.version - previousVersion.version;
                        currentGap  = currentVersion.version - previousVersion.version;
                        versionSpan = (nextVersion.start - previousVersion.start) / allGap;
                        wholeStart  = previousVersion.start + versionSpan;
                        wholeEnd    = nextVersion.start - 1;
                    }
                    else
                    {
                        allGap     = currentVersion.version - previousVersion.version + 1;
                        currentGap = currentVersion.version - previousVersion.version;
                        wholeStart = previousVersion.start + 55 * 60000;
                        wholeEnd   = wholeStart + 55 * 60000 * (currentVersion.version - previousVersion.version);
                    }
                }
                else if (nextVersion != null && nextVersion.version != 0)
                {
                    allGap     = nextVersion.version - currentVersion.version + 1;
                    currentGap = 1;
                    wholeStart = nextVersion.start - 55 * 60000 * (nextVersion.version - currentVersion.version);
                    wholeEnd   = nextVersion.start - 1;
                }
                else
                {
                    allGap     = 2;
                    currentGap = 1;
                    wholeStart = baseline_time - (baseline_version - currentVersion.version) * 55 * 60000;
                    wholeEnd   = wholeStart + 55 * 60000 - 1;
                }
                long[] sectionResult = timeSplit(allGap, currentGap, wholeStart, wholeEnd);
                currentVersion.start = sectionResult[0];
                currentVersion.end   = sectionResult[1];
                string lastVersion = "";

                using (SQLiteCommand cmd = new SQLiteCommand(versionConn))
                {
                    cmd.CommandText = "UPDATE TimeNameMap SET startTime = @startTime, endTime = @endTime WHERE version = @version";
                    cmd.Parameters.AddWithValue("startTime", sectionResult[0]);
                    cmd.Parameters.AddWithValue("endTime", sectionResult[1]);
                    lastVersion = currentVersion.version.ToString();
                    cmd.Parameters.AddWithValue("version", lastVersion);
                    cmd.ExecuteNonQuery();
                }
                if (previousVersion.version == long.Parse(lastVersion) - 1)
                {
                    previousVersion.end = sectionResult[0] - 1;
                }
            }
    void MigrateMaterials()
    {
        HashSet <string> shaderNames = new HashSet <string>();

        string examplesPathRelative = GetRelativeExamplesPath();

        if (examplesPathRelative == null)
        {
            Debug.LogError("Cannot convert example materials as no Mesh Baker Example scenes were found. Renaming example scenes may cause this error.");
            return;
        }

        Debug.Log("Found Mesh Baker Examples at: " + examplesPathRelative);

        MBVersion.PipelineType pipelineType = MBVersion.DetectPipeline();

        Material[] mats;
        {
            string[]        matGIDs = AssetDatabase.FindAssets("t:Material", new string[] { examplesPathRelative });
            List <Material> matList = new List <Material>();
            for (int i = 0; i < matGIDs.Length; i++)
            {
                string path = AssetDatabase.GUIDToAssetPath(matGIDs[i]);
                if (!path.Contains("SceneBasicTextureArrayAssets") && !path.EndsWith(".fbx")) // don't do texture array assets.
                {
                    matList.Add(AssetDatabase.LoadAssetAtPath <Material>(path));
                    string shaderName = matList[matList.Count - 1].shader.name;
                    shaderNames.Add(shaderName);

                    if (MapDefault2OtherShader(shaderName, pipelineType) == null)
                    {
                        Debug.LogError("Could not find mapping for shader " + shaderName + " in mat " + path);
                        return;
                    }
                }
            }
            mats = matList.ToArray();
        }

        string nn = "";

        foreach (string n in shaderNames)
        {
            if (MapDefault2OtherShader(n, pipelineType) == null)
            {
                Debug.LogError("Could not find mapping for shader " + n);
                return;
            }

            nn += "'" + n + "' will map to '" + MapDefault2OtherShader(n, pipelineType) + "',\n";
        }

        Debug.Log(examplesPathRelative + " Found Mats: " + mats.Length + " Shaders Found " + nn);
        for (int i = 0; i < mats.Length; i++)
        {
            Material m = mats[i];
            RemapTextures_Default2OtherPipeline(m, pipelineType);
            EditorUtility.SetDirty(m);
        }

        AssetDatabase.SaveAssets();
    }
Ejemplo n.º 28
0
        public string getVersionFromTime(string time)
        {
            MBVersion version = cacheForhot.getVersionFromTime(long.Parse(time));

            return(version == null ? null : version.version.ToString());
        }