void _bakeIntoCombined(MB2_MeshBakerCommon mom, MB_OutputOptions prefabOrSceneObject) { if (prefabOrSceneObject != MB_OutputOptions.bakeIntoPrefab && prefabOrSceneObject != MB_OutputOptions.bakeIntoSceneObject) { Debug.LogError("Paramater prefabOrSceneObject must be bakeIntoPrefab or bakeIntoSceneObject"); return; } //MB2_MeshBakerCommon mom = (MB2_MeshBakerCommon) target; MB2_TextureBaker tb = mom.GetComponent <MB2_TextureBaker>(); if (mom.textureBakeResults == null && tb != null) { Debug.Log("setting results"); mom.textureBakeResults = tb.textureBakeResults; } if (mom.useObjsToMeshFromTexBaker) { if (tb != null) { mom.objsToMesh.Clear(); mom.objsToMesh.AddRange(tb.objsToMesh); } } Mesh mesh; if (!MB_Utility.doCombinedValidate(mom, MB_ObjsToCombineTypes.sceneObjOnly)) { return; } if (prefabOrSceneObject == MB_OutputOptions.bakeIntoPrefab && mom.resultPrefab == null) { Debug.LogError("Need to set the Combined Mesh Prefab field."); return; } mom.ClearMesh(); mesh = mom.AddDeleteGameObjects(mom.objsToMesh.ToArray(), null, false, true); if (mesh != null) { mom.Apply(); updateProgressBar("Created mesh saving assets", .6f); if (prefabOrSceneObject == MB_OutputOptions.bakeIntoSceneObject) { // mom.BuildSceneMeshObject(); } else if (prefabOrSceneObject == MB_OutputOptions.bakeIntoPrefab) { string prefabPth = AssetDatabase.GetAssetPath(mom.resultPrefab); if (prefabPth == null || prefabPth.Length == 0) { Debug.LogError("Could not save result to prefab. Result Prefab value is not an Asset."); return; } string baseName = System.IO.Path.GetFileNameWithoutExtension(prefabPth); string folderPath = prefabPth.Substring(0, prefabPth.Length - baseName.Length - 7); string newFilename = folderPath + baseName + "-mesh"; mom.SaveMeshsToAssetDatabase(folderPath, newFilename); mom.RebuildPrefab(); // saveMeshToAssetDatabase(mom, mesh); // if (mom.renderType == MB_RenderType.skinnedMeshRenderer){ // Debug.LogWarning("Prefab will not be updated for skinned mesh. This is because all bones need to be included in the prefab for it to be usefull."); // } else { // rebuildPrefab(mom, mesh); // } } else { Debug.LogError("Unknown parameter"); } } }
public static void _bakeIntoCombined(MB2_MeshBakerCommon mom, MB_OutputOptions prefabOrSceneObject) { if (MB2_MeshCombiner.EVAL_VERSION && prefabOrSceneObject == MB_OutputOptions.bakeIntoPrefab) { Debug.LogError("Cannot BakeIntoPrefab with evaluation version."); return; } if (prefabOrSceneObject != MB_OutputOptions.bakeIntoPrefab && prefabOrSceneObject != MB_OutputOptions.bakeIntoSceneObject) { Debug.LogError("Paramater prefabOrSceneObject must be bakeIntoPrefab or bakeIntoSceneObject"); return; } //MB2_MeshBakerCommon mom = (MB2_MeshBakerCommon) target; MB2_TextureBaker tb = mom.GetComponent <MB2_TextureBaker>(); if (mom.textureBakeResults == null && tb != null) { Debug.Log("setting results"); mom.textureBakeResults = tb.textureBakeResults; } if (mom.useObjsToMeshFromTexBaker) { if (tb != null) { mom.objsToMesh.Clear(); mom.objsToMesh.AddRange(tb.objsToMesh); } } Mesh mesh; if (!MB2_MeshBakerRoot.doCombinedValidate(mom, MB_ObjsToCombineTypes.sceneObjOnly)) { return; } if (prefabOrSceneObject == MB_OutputOptions.bakeIntoPrefab && mom.resultPrefab == null) { Debug.LogError("Need to set the Combined Mesh Prefab field."); return; } mom.ClearMesh(); mesh = mom.AddDeleteGameObjects(mom.objsToMesh.ToArray(), null, false, true); if (mesh != null) { mom.Apply(); // updateProgressBar("Created mesh saving assets",.6f); if (prefabOrSceneObject == MB_OutputOptions.bakeIntoSceneObject) { // mom.BuildSceneMeshObject(); } else if (prefabOrSceneObject == MB_OutputOptions.bakeIntoPrefab) { string prefabPth = AssetDatabase.GetAssetPath(mom.resultPrefab); if (prefabPth == null || prefabPth.Length == 0) { Debug.LogError("Could not save result to prefab. Result Prefab value is not an Asset."); return; } string baseName = Path.GetFileNameWithoutExtension(prefabPth); string folderPath = prefabPth.Substring(0, prefabPth.Length - baseName.Length - 7); string newFilename = folderPath + baseName + "-mesh"; mom.SaveMeshsToAssetDatabase(folderPath, newFilename); if (mom.renderType == MB_RenderType.skinnedMeshRenderer) { Debug.LogWarning("Render type is skinned mesh renderer. " + "Can't create prefab until all bones have been added to the combined mesh object " + mom.resultPrefab + " Add the bones then drag the combined mesh object to the prefab."); } else { mom.RebuildPrefab(); } } else { Debug.LogError("Unknown parameter"); } } }