public override void OnInspectorGUI() { SceneSDF scenesdf = target as SceneSDF; GUILayout.Space(8.0f); scenesdf.name = EditorGUILayout.TextField("Name", scenesdf.name); GUILayout.Space(8.0f); bool executeflag = EditorGUILayout.Toggle("Execute in Editor", scenesdf.isEditor, new GUILayoutOption[0]); if (executeflag != scenesdf.isEditor) { scenesdf.isEditor = executeflag; scenesdf.living = false; scenesdf.StopAllCoroutines(); //scenesdf.Init(); } scenesdf.operationType = (BooleanType)EditorGUILayout.EnumPopup("Operation", scenesdf.operationType); scenesdf.operationA = (MeshFilter)EditorGUILayout.ObjectField("OperandA", scenesdf.operationA, typeof(MeshFilter), true); scenesdf.operationB = (MeshFilter)EditorGUILayout.ObjectField("OperandB", scenesdf.operationB, typeof(MeshFilter), true); GUILayout.Space(8.0f); scenesdf.McShader = (ComputeShader)EditorGUILayout.ObjectField("McShader", scenesdf.McShader, typeof(ComputeShader), true); scenesdf.SdfShader = (ComputeShader)EditorGUILayout.ObjectField("SdfShader", scenesdf.SdfShader, typeof(ComputeShader), true); GUILayout.Space(8.0f); if (GUILayout.Button("Update Mesh")) { scenesdf.ExecuteOnClick(); } if (GUILayout.Button("Save Mesh", new GUILayoutOption[0]))//Save Prefab { //string text = EditorUtility.SaveFilePanelInProject("Save Result", scenesdf.gameObject.name, "prefab", "Please select where do you want to save the result?"); string text = EditorUtility.SaveFilePanelInProject("Save Result", scenesdf.gameObject.name, "obj", "Please select where do you want to save the result?"); if (text != null) { //保存预制体 //GameObject gameObject = (GameObject)Instantiate(scenesdf.gameObject); //DestroyImmediate(gameObject.GetComponent<SceneSDF>()); //AssetDatabase.Refresh(); //Mesh sharedMesh = scenesdf.GetComponent<MeshFilter>().sharedMesh; //if (!EditorUtility.IsPersistent(sharedMesh)) //{ // if (sharedMesh.name == "") // { // sharedMesh.name = "Result"; // } // AssetDatabase.CreateAsset(sharedMesh, text.Replace(".prefab", "_Mesh.asset")); //} //PrefabUtility.SaveAsPrefabAsset(gameObject, text); //AssetDatabase.Refresh(); //DestroyImmediate(gameObject); //保存网格.obj GameObject gameObject = (GameObject)Instantiate(scenesdf.gameObject); ExportMesh.ExportMeshToObj(gameObject, text); } } if (GUI.changed) { EditorUtility.SetDirty(target); } }
// For use only by FbxExportGlobals. internal static FbxMesh CreateFbxMesh(FbxExportGlobals G, GeometryPool pool, string poolName) { FbxMesh fbxMesh = FbxMesh.Create(G.m_manager, poolName); ExportMesh mesh = new ExportMesh(pool); int nVerts = mesh.m_pool.m_Vertices.Count; fbxMesh.InitControlPoints(nVerts); unsafe { fixed(Vector3 *f = mesh.m_pool.m_Vertices.GetBackingArray()) { Globals.SetControlPoints(fbxMesh, (IntPtr)f); } } List <int> triangles = mesh.m_pool.m_Tris; // Not available in Unity's wrappers // fbxMesh.ReservePolygonCount(triangles.Count / 3); // fbxMesh.ReservePolygonVertexCount(triangles.Count); for (int i = 0; i < triangles.Count; i += 3) { fbxMesh.BeginPolygon(-1 /* Material */, -1 /* Texture */, -1 /* Group */, false /* Legacy */); fbxMesh.AddPolygon(triangles[i]); fbxMesh.AddPolygon(triangles[i + 1]); fbxMesh.AddPolygon(triangles[i + 2]); fbxMesh.EndPolygon(); } FbxLayer layer0 = fbxMesh.GetLayer(0); if (layer0 == null) { fbxMesh.CreateLayer(); layer0 = fbxMesh.GetLayer(0); } var layerElementNormal = FbxLayerElementNormal.Create(fbxMesh, "normals"); layerElementNormal.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); layerElementNormal.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); CopyToFbx(layerElementNormal.GetDirectArray(), mesh.m_pool.m_Normals); layer0.SetNormals(layerElementNormal); var layerElementColor = FbxLayerElementVertexColor.Create(fbxMesh, "color"); layerElementColor.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); layerElementColor.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); CopyToFbx(layerElementColor.GetDirectArray(), mesh.m_linearColor); layer0.SetVertexColors(layerElementColor); var layerElementTangent = FbxLayerElementTangent.Create(fbxMesh, "tangents"); layerElementTangent.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); layerElementTangent.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); CopyToFbx(layerElementTangent.GetDirectArray(), mesh.m_pool.m_Tangents); layer0.SetTangents(layerElementTangent); // Compute and export binormals since Unity's FBX importer won't import the tangents without // them, even though they're not used. var layerElementBinormal = FbxLayerElementBinormal.Create(fbxMesh, "binormals"); layerElementBinormal.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); layerElementBinormal.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); var binormals = mesh.m_pool.m_Tangents .Select((tan, idx) => { var b3 = Vector3.Cross(tan, mesh.m_pool.m_Normals[idx]) * tan.w; return(new Vector4(b3.x, b3.y, b3.z, 1)); }) .ToList(); CopyToFbx(layerElementBinormal.GetDirectArray(), binormals); layer0.SetBinormals(layerElementBinormal); var layerElementMaterial = FbxLayerElementMaterial.Create(fbxMesh, "materials"); layerElementMaterial.SetMappingMode(FbxLayerElement.EMappingMode.eAllSame); layer0.SetMaterials(layerElementMaterial); // Export everything up to the last uvset containing data // even if some intermediate uvsets have no data. // Otherwise Unity will get the uvset numbering wrong on import List <List <Vector2> > uvSets = DemuxTexcoords(mesh.m_pool); for (int i = 0; i < uvSets.Count; i++) { FbxLayer layerN = fbxMesh.GetLayer(i); while (layerN == null) { fbxMesh.CreateLayer(); layerN = fbxMesh.GetLayer(i); } var layerElementUV = FbxLayerElementUV.Create(fbxMesh, String.Format("uv{0}", i)); layerElementUV.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); layerElementUV.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); List <Vector2> uvSet = uvSets[i]; if (uvSet == null) { // Do nothing // Replicates what the old fbx export code did; seems to work fine } else { Debug.Assert(uvSet.Count == nVerts); CopyToFbx(layerElementUV.GetDirectArray(), uvSet); } layerN.SetUVs(layerElementUV, FbxLayerElement.EType.eTextureDiffuse); } return(fbxMesh); }
public override void OnInspectorGUI() { SceneSDFArea scenesdfArea = target as SceneSDFArea; GUILayout.Space(8.0f); scenesdfArea.name = EditorGUILayout.TextField("Name", scenesdfArea.name); GUILayout.Space(8.0f); bool executeflag = EditorGUILayout.Toggle("Execute in Editor", scenesdfArea.isEditor, new GUILayoutOption[0]); if (executeflag != scenesdfArea.isEditor) { scenesdfArea.isEditor = executeflag; scenesdfArea.living = false; scenesdfArea.StopAllCoroutines(); } //scenesdfArea.Operations = EditorGUILayout.PropertyField(serializedObject.FindProperty("Operations"),new GUIContent("Operations"),true); var Operations = scenesdfArea.Operations; int count = Mathf.Max(0, EditorGUILayout.IntField("size", Operations.Count)); while (count < Operations.Count) { Operations.RemoveAt(Operations.Count - 1); } while (count > Operations.Count) { Operations.Add(null); } for (int i = 0; i < Operations.Count; i++) { Operations[i] = (MeshFilter)EditorGUILayout.ObjectField(Operations[i], typeof(MeshFilter)); } GUILayout.Space(8.0f); scenesdfArea.McShader = (ComputeShader)EditorGUILayout.ObjectField("McShader", scenesdfArea.McShader, typeof(ComputeShader), true); scenesdfArea.SdfShader = (ComputeShader)EditorGUILayout.ObjectField("SdfShader", scenesdfArea.SdfShader, typeof(ComputeShader), true); GUILayout.Space(8.0f); if (GUILayout.Button("Update Mesh")) { scenesdfArea.ExecuteOnClick(); } if (GUILayout.Button("Save Mesh", new GUILayoutOption[0]))//Save Prefab { //string text = EditorUtility.SaveFilePanelInProject("Save Result", scenesdf.gameObject.name, "prefab", "Please select where do you want to save the result?"); string text = EditorUtility.SaveFilePanelInProject("Save Result", scenesdfArea.gameObject.name, "obj", "Please select where do you want to save the result?"); if (text != null) { //±£´æÍø¸ñ.obj GameObject gameObject = (GameObject)Instantiate(scenesdfArea.gameObject); ExportMesh.ExportMeshToObj(gameObject, text); } } if (GUI.changed) { EditorUtility.SetDirty(target); } }