예제 #1
0
        void DrawExtraActions()
        {
            PolybrushMesh polybrushmesh = target as PolybrushMesh;
            MeshRenderer  mr            = polybrushmesh.gameObject.GetComponent <MeshRenderer>();

            using (new EditorGUILayout.HorizontalScope())
            {
                // Export button
                if (GUILayout.Button(Styles.k_ExportButtonLabel))
                {
                    PolyEditorUtility.SaveMeshAsset(polybrushmesh.polyMesh.ToUnityMesh());
                }

                // Reset button
                if (GUILayout.Button(Styles.k_DeleteButtonLabel))
                {
                    if (EditorUtility.DisplayDialog(Styles.k_DisplayDialogTitle,
                                                    Styles.k_DisplayDialogMessage, Styles.k_DisplayDialogOkLabel, Styles.k_DisplayDialogCancelLabel))
                    {
                        foreach (PolybrushMesh polybrushMesh in targets)
                        {
                            if (polybrushMesh == null)
                            {
                                continue;
                            }

                            polybrushmesh.SetMesh(polybrushmesh.sourceMesh);
                            Undo.DestroyObjectImmediate(polybrushmesh);
                        }
                    }
                }
            }
        }
예제 #2
0
        public override void OnInspectorGUI()
		{
			serializedObject.Update();

			SerializedProperty mesh = serializedObject.FindProperty("m_Mesh");

			if(mesh != null)
				EditorGUILayout.PropertyField(mesh);

			Mesh m = (Mesh) mesh.objectReferenceValue;

			if(m != null)
			{
				ModelSource source = PolyEditorUtility.GetMeshGUID(m);
                GameObject go = ((MeshFilter)serializedObject.targetObject).gameObject;
                bool isPBMesh = ProBuilderInterface.IsProBuilderObject(go);

                if (source == ModelSource.Scene && !isPBMesh)
				{
					if(GUILayout.Button(m_GCSaveButton))
						PolyEditorUtility.SaveMeshAsset(m);
				}
			}

			serializedObject.ApplyModifiedProperties();
		}
예제 #3
0
        /// <summary>
        /// Create a Composite Mesh from AdditionnalVertexStreams
        /// </summary>
        /// <param name="vertexStream">the object used to create the composite mesh</param>
        /// <param name="applyToCurrent">Create a new Mesh or apply it directly to the current one?</param>
        /// <param name="path">where to save the new mesh</param>
        void CreateComposite(PolybrushMesh polyMesh, bool applyToCurrent, string path = null)
        {
            GameObject go = polyMesh.gameObject;

            Mesh source = go.GetMesh();
            Mesh mesh   = polyMesh.storedMesh;

            if (source == null || mesh == null)
            {
                Debug.LogWarning("Mesh filter or vertex stream mesh is null, cannot continue.");
                return;
            }

            if (applyToCurrent)
            {
                CreateCompositeMesh(source, mesh, polyMesh.sourceMesh);

                MeshRenderer renderer = go.GetComponent <MeshRenderer>();

                if (renderer != null)
                {
                    renderer.additionalVertexStreams = null;
                }

                Undo.DestroyObjectImmediate(polyMesh);
            }
            else
            {
                Mesh composite = new Mesh();
                CreateCompositeMesh(source, mesh, composite);

                if (string.IsNullOrEmpty(path))
                {
                    PolyEditorUtility.SaveMeshAsset(composite, go.GetComponent <MeshFilter>(), go.GetComponent <SkinnedMeshRenderer>());
                }
                else
                {
                    AssetDatabase.CreateAsset(composite, path);

                    MeshFilter mf = go.GetComponent <MeshFilter>();

                    SkinnedMeshRenderer smr = go.GetComponent <SkinnedMeshRenderer>();

                    if (mf != null)
                    {
                        mf.sharedMesh = composite;
                    }
                    else if (smr != null)
                    {
                        smr.sharedMesh = composite;
                    }
                }


                Undo.DestroyObjectImmediate(polyMesh);
            }
        }