void Update() { if (smr != null && objects != null) { MB2_MeshCombiner.UpdateSkinnedMeshApproximateBoundsFromBoundsStatic(objects, smr); } }
void Update() { if (smr != null) { MB2_MeshCombiner.UpdateSkinnedMeshApproximateBoundsFromBonesStatic(bones, smr); } }
public CombinedMesh() { combinedMesh = new MB2_MeshCombiner(); extraSpace = MAX_VERTS_IN_MESH; gosToAdd = new List <GameObject>(); gosToDelete = new List <GameObject>(); gosToUpdate = new List <GameObject>(); }
public bool isDirty = false; //needs apply public CombinedMesh(int maxNumVertsInMesh){ combinedMesh = new MB2_MeshCombiner(); extraSpace = maxNumVertsInMesh; numVertsInListToDelete = 0; numVertsInListToAdd = 0; gosToAdd = new List<GameObject>(); gosToDelete = new List<int>(); gosToUpdate = new List<GameObject>(); }
public bool isDirty = false; //needs apply public CombinedMesh(int maxNumVertsInMesh) { combinedMesh = new MB2_MeshCombiner(); extraSpace = maxNumVertsInMesh; numVertsInListToDelete = 0; numVertsInListToAdd = 0; gosToAdd = new List <UnityEngine.GameObject>(); gosToDelete = new List <UnityEngine.GameObject>(); gosToUpdate = new List <UnityEngine.GameObject>(); }
void _setMBValues(MB2_MeshCombiner targ) { targ.renderType = renderType; targ.outputOption = MB2_OutputOptions.bakeIntoSceneObject; targ.lightmapOption = lightmapOption; targ.textureBakeResults = textureBakeResults; targ.doNorm = doNorm; targ.doTan = doTan; targ.doCol = doCol; targ.doUV = doUV; targ.doUV1 = doUV1; }
public static Mesh BakeMeshesInPlace(MB2_MeshCombiner mom, List<GameObject> objsToMesh, string saveFolder, ProgressUpdateDelegate updateProgressBar){ if (MB2_MeshCombiner.EVAL_VERSION) return null; Mesh mesh; if (!Directory.Exists(Application.dataPath + saveFolder.Substring(6,saveFolder.Length-6))){ Debug.Log((Application.dataPath + saveFolder)); Debug.Log(Path.GetFullPath(Application.dataPath + saveFolder)); Debug.LogError("The selected Folder For Meshes does not exist or is not inside the projects Assets folder. Please 'Choose Folder For Bake In Place Meshes' that is inside the project's assets folder."); return null; } MB2_EditorMethods editorMethods = new MB2_EditorMethods(); mom.DestroyMeshEditor(editorMethods); GameObject[] objs = new GameObject[1]; MB_RenderType originalRenderType = mom.renderType; Mesh outMesh = null; for (int i = 0; i < objsToMesh.Count; i++){ if (objsToMesh[i] == null){ Debug.LogError("The " + i + "th object on the list of objects to combine is 'None'. Use Command-Delete on Mac OS X; Delete or Shift-Delete on Windows to remove this one element."); return null; } string[] objNames = GenerateNames(objsToMesh); objs[0] = objsToMesh[i]; Renderer r = MB_Utility.GetRenderer(objsToMesh[i]); if (r is SkinnedMeshRenderer){ mom.renderType = MB_RenderType.skinnedMeshRenderer; } else { mom.renderType = MB_RenderType.meshRenderer; } mesh = mom.AddDeleteGameObjects(objs,null,false); if (mesh != null){ mom.Apply(); Mesh mf = MB_Utility.GetMesh(objs[0]); if (mf != null){ string newFilename = saveFolder + "/" + objNames[i]; if (updateProgressBar != null) updateProgressBar("Created mesh saving mesh on " + objs[0].name + " to asset " + newFilename,.6f); if (newFilename != null && newFilename.Length != 0){ Debug.Log("Creating mesh for " + objs[0].name + " with adjusted UVs at: " + newFilename); AssetDatabase.CreateAsset(mesh, newFilename); outMesh = (Mesh) AssetDatabase.LoadAssetAtPath(newFilename, typeof(Mesh)); } else { Debug.LogWarning("Could not save mesh for " + objs[0].name); } } } mom.DestroyMeshEditor(editorMethods); } mom.renderType = originalRenderType; return outMesh; }
public static GameObject buildSceneMeshObject(GameObject root, MB2_MeshCombiner mom, Mesh m, bool createNewChild = false) { GameObject mesh; MeshFilter mf = null; MeshRenderer mr = null; SkinnedMeshRenderer smr = null; Transform mt = null; if (!createNewChild) { foreach (Transform t in root.transform) { if (t.name.EndsWith("-mesh")) { mt = t; } } } if (mt == null) { mesh = new GameObject(mom.name + "-mesh"); } else { mesh = mt.gameObject; } if (mom.renderType == MB_RenderType.skinnedMeshRenderer) { smr = mesh.GetComponent <SkinnedMeshRenderer>(); if (smr == null) { smr = mesh.AddComponent <SkinnedMeshRenderer>(); } } else { mf = mesh.GetComponent <MeshFilter>(); if (mf == null) { mf = mesh.AddComponent <MeshFilter>(); } mr = mesh.GetComponent <MeshRenderer>(); if (mr == null) { mr = mesh.AddComponent <MeshRenderer>(); } } if (mom.textureBakeResults.doMultiMaterial) { Material[] sharedMats = new Material[mom.textureBakeResults.resultMaterials.Length]; for (int i = 0; i < sharedMats.Length; i++) { sharedMats[i] = mom.textureBakeResults.resultMaterials[i].combinedMaterial; } if (mom.renderType == MB_RenderType.skinnedMeshRenderer) { smr.materials = sharedMats; smr.bones = mom.GetBones(); smr.updateWhenOffscreen = true; //todo see if can remove //todo update bounds } else { mr.sharedMaterials = sharedMats; } } else { if (mom.renderType == MB_RenderType.skinnedMeshRenderer) { smr.material = mom.textureBakeResults.resultMaterial; smr.bones = mom.GetBones(); } else { mr.material = mom.textureBakeResults.resultMaterial; } } if (mom.renderType == MB_RenderType.skinnedMeshRenderer) { smr.sharedMesh = m; smr.lightmapIndex = mom.GetLightmapIndex(); } else { mf.mesh = m; mr.lightmapIndex = mom.GetLightmapIndex(); } if (mom.lightmapOption == MB2_LightmapOptions.preserve_current_lightmapping || mom.lightmapOption == MB2_LightmapOptions.generate_new_UV2_layout) { mesh.isStatic = true; } List <GameObject> gos = mom.GetObjectsInCombined(); if (gos.Count > 0) { bool tagsAreSame = true; bool layersAreSame = true; string tag = gos[0].tag; int layer = gos[0].layer; for (int i = 0; i < gos.Count; i++) { if (!gos[i].tag.Equals(tag)) { tagsAreSame = false; } if (gos[i].layer != layer) { layersAreSame = false; } } if (tagsAreSame) { root.tag = tag; mesh.tag = tag; } if (layersAreSame) { root.layer = layer; mesh.layer = layer; } } mesh.transform.parent = root.transform; return(mesh); }
/// <summary> /// Applys the changes to flagged properties of the mesh. This method is slow, and should only be called once per frame. The speed is directly proportional to the number of flags that are true. Only apply necessary properties. /// </summary> public abstract void Apply(bool triangles, bool vertices, bool normals, bool tangents, bool uvs, bool colors, bool uv1, bool uv2, bool bones=false, MB2_MeshCombiner.GenerateUV2Delegate uv2GenerationFunction=null);
/// <summary> /// Apply changes to the mesh. All channels set in this instance will be set in the combined mesh. /// </summary> public abstract void Apply(MB2_MeshCombiner.GenerateUV2Delegate uv2GenerationFunction=null);
public static Mesh BakeMeshesInPlace(MB2_MeshCombiner mom, List <GameObject> objsToMesh, string saveFolder, ProgressUpdateDelegate updateProgressBar) { if (MB2_MeshCombiner.EVAL_VERSION) { return(null); } Mesh mesh; if (!Directory.Exists(Application.dataPath + saveFolder.Substring(6, saveFolder.Length - 6))) { Debug.Log((Application.dataPath + saveFolder)); Debug.Log(Path.GetFullPath(Application.dataPath + saveFolder)); Debug.LogError("The selected Folder For Meshes does not exist or is not inside the projects Assets folder. Please 'Choose Folder For Bake In Place Meshes' that is inside the project's assets folder."); return(null); } MB2_EditorMethods editorMethods = new MB2_EditorMethods(); mom.DestroyMeshEditor(editorMethods); GameObject[] objs = new GameObject[1]; MB_RenderType originalRenderType = mom.renderType; Mesh outMesh = null; for (int i = 0; i < objsToMesh.Count; i++) { if (objsToMesh[i] == null) { Debug.LogError("The " + i + "th object on the list of objects to combine is 'None'. Use Command-Delete on Mac OS X; Delete or Shift-Delete on Windows to remove this one element."); return(null); } string[] objNames = GenerateNames(objsToMesh); objs[0] = objsToMesh[i]; Renderer r = MB_Utility.GetRenderer(objsToMesh[i]); if (r is SkinnedMeshRenderer) { mom.renderType = MB_RenderType.skinnedMeshRenderer; } else { mom.renderType = MB_RenderType.meshRenderer; } mesh = mom.AddDeleteGameObjects(objs, null, false); if (mesh != null) { mom.Apply(); Mesh mf = MB_Utility.GetMesh(objs[0]); if (mf != null) { string newFilename = saveFolder + "/" + objNames[i]; if (updateProgressBar != null) { updateProgressBar("Created mesh saving mesh on " + objs[0].name + " to asset " + newFilename, .6f); } if (newFilename != null && newFilename.Length != 0) { Debug.Log("Creating mesh for " + objs[0].name + " with adjusted UVs at: " + newFilename); AssetDatabase.CreateAsset(mesh, newFilename); outMesh = (Mesh)AssetDatabase.LoadAssetAtPath(newFilename, typeof(Mesh)); } else { Debug.LogWarning("Could not save mesh for " + objs[0].name); } } } mom.DestroyMeshEditor(editorMethods); } mom.renderType = originalRenderType; return(outMesh); }
public static void BakeMeshesInPlace(MB2_MeshCombiner mom, List <UnityEngine.GameObject> objsToMesh, ProgressUpdateDelegate updateProgressBar) { #if UNITY_EDITOR Mesh mesh; // if (!MB_Utility.doCombinedValidate(mom, MB_ObjsToCombineTypes.prefabOnly)) return; // List<UnityEngine.GameObject> objsToMesh = mom.objsToMesh; // if (mom.useObjsToMeshFromTexBaker && mom.GetComponent<MB2_TextureBaker>() != null){ // objsToMesh = mom.GetComponent<MB2_TextureBaker>().objsToMesh; // } mom.DestroyMesh(); UnityEngine.GameObject[] objs = new UnityEngine.GameObject[1]; List <string> usedNames = new List <string>(); MB_RenderType originalRenderType = mom.renderType; for (int i = 0; i < objsToMesh.Count; i++) { if (objsToMesh[i] == null) { Debug.LogError("The " + i + "th object on the list of objects to combine is 'None'. Use Command-Delete on Mac OS X; Delete or Shift-Delete on Windows to remove this one element."); return; } objs[0] = objsToMesh[i]; UnityEngine.Renderer r = MB_Utility.GetRenderer(objsToMesh[i]); if (r is SkinnedMeshRenderer) { mom.renderType = MB_RenderType.skinnedMeshRenderer; } else { mom.renderType = MB_RenderType.meshRenderer; } mesh = mom.AddDeleteGameObjects(objs, null, false); if (mesh != null) { //mom.ApplyAll(); mom.Apply(); Mesh mf = MB_Utility.GetMesh(objs[0]); if (mf != null) { string baseName, folderPath, newFilename; string pth = AssetDatabase.GetAssetPath(mf); if (pth != null && pth.Length != 0) { baseName = Path.GetFileNameWithoutExtension(pth) + "_" + objs[0].name + "_MB"; folderPath = Path.GetDirectoryName(pth); } else //try to get the name from prefab { pth = AssetDatabase.GetAssetPath(objs[0]); //get prefab name if (pth != null && pth.Length != 0) { baseName = Path.GetFileNameWithoutExtension(pth) + "_" + objs[0].name + "_MB"; folderPath = Path.GetDirectoryName(pth); } else //save in root { baseName = objs[0].name + "mesh_MB"; folderPath = "Assets"; } } //make name unique newFilename = Path.Combine(folderPath, baseName + ".asset"); int j = 0; while (usedNames.Contains(newFilename)) { newFilename = Path.Combine(folderPath, baseName + j + ".asset"); j++; } usedNames.Add(newFilename); updateProgressBar("Created mesh saving mesh on " + objs[0].name + " to asset " + newFilename, .6f); if (newFilename != null && newFilename.Length != 0) { Debug.Log("Creating mesh for " + objs[0].name + " with adjusted UVs at: " + newFilename); AssetDatabase.CreateAsset(mesh, newFilename); } else { Debug.LogWarning("Could not save mesh for " + objs[0].name); } } } mom.DestroyMesh(); } mom.renderType = originalRenderType; #endif }
public override void Apply(bool triangles, bool vertices, bool normals, bool tangents, bool uvs, bool colors, bool uv1, bool uv2, bool bones=false, MB2_MeshCombiner.GenerateUV2Delegate uv2GenerationMethod=null){ _update_MB2_MeshCombiner(); meshCombiner.Apply(triangles,vertices,normals,tangents,uvs,colors,uv1,uv2,bones); }
public override void Apply(MB2_MeshCombiner.GenerateUV2Delegate uv2GenerationMethod=null){ _update_MB2_MeshCombiner(); meshCombiner.Apply(uv2GenerationMethod); }
void _setMBValues(MB2_MeshCombiner targ){ targ.validationLevel = _validationLevel; targ.renderType = renderType; targ.outputOption = MB2_OutputOptions.bakeIntoSceneObject; targ.lightmapOption = lightmapOption; targ.textureBakeResults = textureBakeResults; targ.doNorm = doNorm; targ.doTan = doTan; targ.doCol = doCol; targ.doUV = doUV; targ.doUV1 = doUV1; }
public void Apply(bool triangles, bool vertices, bool normals, bool tangents, bool uvs, bool colors, bool uv1, bool uv2, bool bones=false, MB2_MeshCombiner.GenerateUV2Delegate uv2GenerationMethod=null){ for (int i = 0; i < meshCombiners.Count; i++){ if (meshCombiners[i].isDirty){ meshCombiners[i].combinedMesh.Apply(triangles,vertices,normals,tangents,uvs,colors,uv1,uv2,bones,uv2GenerationMethod); meshCombiners[i].isDirty = false; } } }
/* bool getIsGameObjectActive(GameObject g){ #if UNITY_3_5 return g.active; #else return g.activeInHierarchy; #endif } */ public void Apply(MB2_MeshCombiner.GenerateUV2Delegate uv2GenerationMethod=null){ for (int i = 0; i < meshCombiners.Count; i++){ if (meshCombiners[i].isDirty){ meshCombiners[i].combinedMesh.Apply(uv2GenerationMethod); meshCombiners[i].isDirty = false; } } }