internal override void RegisterUndo(BrushTarget brushTarget) { #if PROBUILDER_4_0_OR_NEWER if (ProBuilderBridge.IsValidProBuilderMesh(brushTarget.gameObject)) { UnityEngine.Object pbMesh = ProBuilderBridge.GetProBuilderComponent(brushTarget.gameObject); if (pbMesh != null) { Undo.RegisterCompleteObjectUndo(pbMesh, UndoMessage); modifiedPbMeshes.Add(brushTarget.gameObject); } else { Undo.RegisterCompleteObjectUndo(brushTarget.editableObject.polybrushMesh, UndoMessage); modifiedMeshes.Add(brushTarget.editableObject.polybrushMesh.polyMesh); } } else #endif { Undo.RegisterCompleteObjectUndo(brushTarget.editableObject.polybrushMesh, UndoMessage); modifiedMeshes.Add(brushTarget.editableObject.polybrushMesh.polyMesh); } brushTarget.editableObject.isDirty = true; }
static bool MeshInstanceMatchesGameObject(Mesh mesh, GameObject go) { if (ProBuilderBridge.IsValidProBuilderMesh(go)) { return(true); } int gameObjectId = go.GetInstanceID(); int meshId = GetMeshId(mesh); // If the mesh id doesn't parse to an ID it's definitely not an instance if (meshId == -1) { return(false); } // If the mesh id matches the instance id, it's already a scene instance owned by this object. If doesn't match, // next check that the mesh id gameObject does not exist. If it does exist, that means this mesh was duplicated // and already belongs to another object in the scene. If it doesn't exist, then it just means that the GameObject // id was changed as a normal part of the GameObject lifecycle. if (meshId == gameObjectId) { return(true); } // If it is an instance, and the IDs don't match but no existing GameObject claims this mesh, claim it. if (EditorUtility.InstanceIDToObject(meshId) == null) { mesh.name = k_MeshInstancePrefix + go.GetInstanceID(); return(true); } // The mesh did not match the gameObject id, and the mesh id points to an already existing object in the scene. return(false); }
/// <summary> /// Tests if a GameObject is a ProBuilder mesh or not. /// </summary> /// <param name="gameObject"></param> /// <returns></returns> internal static bool IsProBuilderObject(GameObject gameObject) { if (ProBuilderBridge.ProBuilderExists()) { return(ProBuilderBridge.IsValidProBuilderMesh(gameObject)); } return(false); }
/// <summary> /// Tests if a GameObject is a ProBuilder mesh or not. /// </summary> /// <param name="gameObject"></param> /// <returns></returns> internal static bool IsProBuilderObject(GameObject gameObject) { #if PROBUILDER_4_0_OR_NEWER if (ProBuilderBridge.ProBuilderExists()) { return(ProBuilderBridge.IsValidProBuilderMesh(gameObject)); } return(false); #endif }
private void Initialize(GameObject go) { CheckBackwardCompatiblity(go); gameObjectAttached = go; isProBuilderObject = false; #if PROBUILDER_4_0_OR_NEWER if (ProBuilderBridge.ProBuilderExists()) { isProBuilderObject = ProBuilderBridge.IsValidProBuilderMesh(gameObjectAttached); } #endif Mesh mesh = null; MeshRenderer meshRenderer = gameObjectAttached.GetComponent <MeshRenderer>(); meshFilter = gameObjectAttached.GetComponent <MeshFilter>(); _skinMeshRenderer = gameObjectAttached.GetComponent <SkinnedMeshRenderer>(); originalMesh = go.GetMesh(); if (originalMesh == null && _skinMeshRenderer != null) { originalMesh = _skinMeshRenderer.sharedMesh; } m_PolybrushMesh = gameObjectAttached.GetComponent <PolybrushMesh>(); if (m_PolybrushMesh == null) { m_PolybrushMesh = Undo.AddComponent <PolybrushMesh>(gameObjectAttached); m_PolybrushMesh.Initialize(); m_PolybrushMesh.mode = (s_UseAdditionalVertexStreams) ? PolybrushMesh.Mode.AdditionalVertexStream : PolybrushMesh.Mode.Mesh; } //attach the skinmesh ref to the polybrushmesh //it will be used when making a prefab containing a skin mesh. The limitation here is that the skin mesh must comes from an asset (which is 99.9999% of the time) if (_skinMeshRenderer != null) { Mesh sharedMesh = _skinMeshRenderer.sharedMesh; if (AssetDatabase.Contains(sharedMesh)) { m_PolybrushMesh.skinMeshRef = sharedMesh; } } #if PROBUILDER_4_0_OR_NEWER // if it's a probuilder object rebuild the mesh without optimization if (isProBuilderObject) { if (ProBuilderBridge.IsValidProBuilderMesh(gameObjectAttached)) { ProBuilderBridge.ToMesh(gameObjectAttached); ProBuilderBridge.Refresh(gameObjectAttached); } } #endif if (meshRenderer != null || _skinMeshRenderer != null) { mesh = m_PolybrushMesh.storedMesh; if (mesh == null) { mesh = PolyMeshUtility.DeepCopy(originalMesh); hadVertexStreams = false; } else { //prevents leak if (!MeshInstanceMatchesGameObject(mesh, gameObjectAttached)) { mesh = PolyMeshUtility.DeepCopy(mesh); } } mesh.name = k_MeshInstancePrefix + gameObjectAttached.GetInstanceID(); } polybrushMesh.SetMesh(mesh); PrefabUtility.RecordPrefabInstancePropertyModifications(polybrushMesh); _graphicsMesh = m_PolybrushMesh.storedMesh; source = polybrushMesh.mode == PolybrushMesh.Mode.AdditionalVertexStream? ModelSource.AdditionalVertexStreams : PolyEditorUtility.GetMeshGUID(originalMesh); GenerateCompositeMesh(); }