/** * If the provided topology asset is not null, instantiates it and uses the instance * as the current topology. */ protected void ResetTopology() { if (sharedTopology != null) { GameObject.DestroyImmediate(topology); topology = GameObject.Instantiate(sharedTopology); } }
void UpdateNormalMode() { EditorGUI.BeginChangeCheck(); ObiMeshTopology sourceTopology = EditorGUILayout.ObjectField("Source topology", skinMap.SourceTopology, typeof(ObiMeshTopology), false) as ObiMeshTopology; if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(skinMap, "Set skin source"); skinMap.SourceTopology = sourceTopology; } EditorGUI.BeginChangeCheck(); Mesh target = EditorGUILayout.ObjectField("Target mesh", skinMap.TargetMesh, typeof(Mesh), false) as Mesh; if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(skinMap, "Set skin target"); skinMap.TargetMesh = target; } // Print skin info: if (skinMap.bound) { EditorGUILayout.HelpBox("Skin info generated." + skinMap.baryPositions.Length, MessageType.Info); } // Error / warning messages bool errors = false; if (skinMap.SourceTopology == null) { EditorGUILayout.HelpBox("Please provide a source topology.", MessageType.Info); errors = true; } else { if (!skinMap.SourceTopology.Initialized || skinMap.SourceTopology.input == null) { EditorGUILayout.HelpBox("The provided source topology has no input mesh, or hasn't been initialized.", MessageType.Error); errors = true; } } if (skinMap.TargetMesh == null) { EditorGUILayout.HelpBox("Please provide a target mesh.", MessageType.Info); errors = true; } // Edit mode buttons: GUI.enabled = !errors; if (GUILayout.Button("Edit skin map")) { EditorApplication.delayCall += EnterSkinEditMode; } GUI.enabled = true; }
public void CopyDataFrom(ObiMeshTopology source) { if (source != null && source.initialized && initialized) { Oni.UnpinMemory(facesHandle); Oni.UnpinMemory(verticesHandle); Oni.UnpinMemory(halfEdgesHandle); Oni.UnpinMemory(orientationsHandle); Oni.UnpinMemory(normalsHandle); Oni.UnpinMemory(tangentsHandle); Oni.UnpinMemory(visualMapHandle); Array.Resize(ref heFaces, source.heFaces.Length); Array.Resize(ref heVertices, source.heVertices.Length); Array.Resize(ref heHalfEdges, source.heHalfEdges.Length); Array.Resize(ref heOrientations, source.heOrientations.Length); Array.Resize(ref normals, source.normals.Length); Array.Resize(ref tangents, source.tangents.Length); Array.Resize(ref visualMap, source.visualMap.Length); Array.Copy(source.heFaces, heFaces, source.heFaces.Length); Array.Copy(source.heVertices, heVertices, source.heVertices.Length); Array.Copy(source.heHalfEdges, heHalfEdges, source.heHalfEdges.Length); Array.Copy(source.heOrientations, heOrientations, source.heOrientations.Length); Array.Copy(source.normals, normals, source.normals.Length); Array.Copy(source.tangents, tangents, source.tangents.Length); Array.Copy(source.visualMap, visualMap, source.visualMap.Length); facesHandle = Oni.PinMemory(heFaces); verticesHandle = Oni.PinMemory(heVertices); halfEdgesHandle = Oni.PinMemory(heHalfEdges); orientationsHandle = Oni.PinMemory(heOrientations); normalsHandle = Oni.PinMemory(normals); tangentsHandle = Oni.PinMemory(tangents); visualMapHandle = Oni.PinMemory(visualMap); Oni.SetFaces(halfEdgeMesh, facesHandle.AddrOfPinnedObject(), heFaces.Length); Oni.SetVertices(halfEdgeMesh, verticesHandle.AddrOfPinnedObject(), heVertices.Length); Oni.SetHalfEdges(halfEdgeMesh, halfEdgesHandle.AddrOfPinnedObject(), heHalfEdges.Length); Oni.SetInverseOrientations(halfEdgeMesh, orientationsHandle.AddrOfPinnedObject()); Oni.SetVisualMap(halfEdgeMesh, visualMapHandle.AddrOfPinnedObject()); Oni.SetNormals(halfEdgeMesh, normalsHandle.AddrOfPinnedObject()); Oni.SetTangents(halfEdgeMesh, tangentsHandle.AddrOfPinnedObject()); } }
public void Awake() { // Grab a copy of the serialized topology reference. This happens when duplicating a cloth. if (topology != null) { topology = GameObject.Instantiate(topology); } // Or a copy of the shared topology, if there is no serialized reference to a topology. else if (sharedTopology != null) { topology = GameObject.Instantiate(sharedTopology); } if (sharedMesh != null && !sharedMesh.isReadable) { Debug.LogError(this.name + "'s cloth mesh is not readable. Please enable the read/write checkbox in the mesh importer inspector."); } }
public override void OnInspectorGUI() { serializedObject.UpdateIfDirtyOrScript(); GUI.enabled = cloth.Initialized; EditorGUI.BeginChangeCheck(); editMode = GUILayout.Toggle(editMode, new GUIContent("Edit particles", EditorGUIUtility.Load("Obi/EditParticles.psd") as Texture2D), "LargeButton"); if (EditorGUI.EndChangeCheck()) { // show wireframe EditorUtility.SetSelectedWireframeHidden(cloth.GetComponent <Renderer>(), false); SceneView.RepaintAll(); } GUI.enabled = true; EditorGUILayout.LabelField("Status: " + (cloth.Initialized ? "Initialized":"Not initialized")); GUI.enabled = (cloth.SharedTopology != null); if (GUILayout.Button("Initialize")) { if (!cloth.Initialized) { CoroutineJob job = new CoroutineJob(); routine = EditorCoroutine.StartCoroutine(job.Start(cloth.GeneratePhysicRepresentationForMesh())); EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } else { if (EditorUtility.DisplayDialog("Actor initialization", "Are you sure you want to re-initialize this actor?", "Ok", "Cancel")) { CoroutineJob job = new CoroutineJob(); routine = EditorCoroutine.StartCoroutine(job.Start(cloth.GeneratePhysicRepresentationForMesh())); EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } } } GUI.enabled = true; if (cloth.SharedTopology == null) { EditorGUILayout.HelpBox("No ObiMeshTopology asset present.", MessageType.Info); } GUI.enabled = cloth.Initialized; if (GUILayout.Button("Set Rest State")) { cloth.PullDataFromSolver(ParticleData.POSITIONS | ParticleData.VELOCITIES); } GUILayout.BeginHorizontal(); if (GUILayout.Button("Optimize")) { Undo.RecordObject(cloth, "Optimize"); cloth.Optimize(); } if (GUILayout.Button("Unoptimize")) { Undo.RecordObject(cloth, "Unoptimize"); cloth.Unoptimize(); } GUILayout.EndHorizontal(); GUI.enabled = true; EditorGUI.BeginChangeCheck(); ObiSolver solver = EditorGUILayout.ObjectField("Solver", cloth.Solver, typeof(ObiSolver), true) as ObiSolver; if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(cloth, "Set solver"); cloth.Solver = solver; } EditorGUI.BeginChangeCheck(); ObiMeshTopology topology = EditorGUILayout.ObjectField("Shared Topology", cloth.SharedTopology, typeof(ObiMeshTopology), true) as ObiMeshTopology; if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(cloth, "Set topology"); cloth.SharedTopology = topology; } bool newSelfCollisions = EditorGUILayout.Toggle(new GUIContent("Self collisions", "Enabling this allows particles generated by this actor to interact with each other."), cloth.SelfCollisions); if (cloth.SelfCollisions != newSelfCollisions) { Undo.RecordObject(cloth, "Set self collisions"); cloth.SelfCollisions = newSelfCollisions; } bool newUpdateTangents = EditorGUILayout.Toggle(new GUIContent("Update tangents", "If enabled, tangent space will be updated after each simulation step. Enable this if your cloth uses normal maps."), cloth.UpdateTangents); if (cloth.UpdateTangents != newUpdateTangents) { Undo.RecordObject(cloth, "Set update tangents"); cloth.UpdateTangents = newUpdateTangents; } Oni.NormalsUpdate newNormalsUpdate = (Oni.NormalsUpdate)EditorGUILayout.EnumPopup(new GUIContent("Update normals", "If set to recalculate, smooth normals will be recalculated each step. If set to skin, the original mesh normals will be rotated based on surface orientation."), cloth.NormalsUpdate); if (cloth.NormalsUpdate != newNormalsUpdate) { Undo.RecordObject(cloth, "Set normals update"); cloth.NormalsUpdate = newNormalsUpdate; } Editor.DrawPropertiesExcluding(serializedObject, "m_Script"); // Progress bar: EditorCoroutine.ShowCoroutineProgressBar("Generating physical representation...", routine); // Apply changes to the serializedProperty if (GUI.changed) { serializedObject.ApplyModifiedProperties(); } }
public void OnEnable() { halfEdge = (ObiMeshTopology)target; UpdatePreview(); }