public CalculateAutomaticWeights ( ) : void | ||
Результат | void |
private void Bind() { if (!spriteMeshCache.isBound && spriteMeshCache.spriteMeshInstance) { spriteMeshCache.RegisterUndo("Bind bones"); spriteMeshCache.BindBones(); spriteMeshCache.CalculateAutomaticWeights(); } }
protected override void DoWindow(int windowId) { GUI.color = Color.white; EditorGUILayout.BeginHorizontal(); sliceToggle = GUILayout.Toggle(sliceToggle, new GUIContent("Slice", "Slice the sprite"), EditorStyles.miniButton, GUILayout.Width(50f)); EditorGUILayout.Space(); bool holeToggle = GUILayout.Toggle(tool == MeshTool.Hole, new GUIContent("Hole", "Create holes (H)"), EditorStyles.miniButton, GUILayout.Width(50f)); if (holeToggle) { tool = MeshTool.Hole; } else { tool = MeshTool.None; } EditorGUILayout.Space(); EditorGUI.BeginDisabledGroup(!spriteMeshCache.spriteMeshInstance); if (GUILayout.Toggle(spriteMeshCache.isBound, new GUIContent("Bind", "Bind bones"), EditorStyles.miniButtonLeft, GUILayout.Width(50f))) { if (!spriteMeshCache.isBound && spriteMeshCache.spriteMeshInstance) { spriteMeshCache.RegisterUndo("Bind bones"); spriteMeshCache.BindBones(); spriteMeshCache.CalculateAutomaticWeights(); } } EditorGUI.EndDisabledGroup(); if (GUILayout.Toggle(!spriteMeshCache.isBound, new GUIContent("Unbind", "Clear binding data"), EditorStyles.miniButtonRight, GUILayout.Width(50f))) { if (spriteMeshCache.isBound) { spriteMeshCache.RegisterUndo("Clear weights"); spriteMeshCache.ClearWeights(); } } GUILayout.Space(1f); EditorGUILayout.EndHorizontal(); }
void DoWindow(int windowId) { Vertex selectedVertex = spriteMeshCache.selectedVertex; string[] names = GetBoneNames(); EditorGUIUtility.wideMode = true; float labelWidth = EditorGUIUtility.labelWidth; if (selectedVertex != null) { BoneWeight2 boneWeight = selectedVertex.boneWeight; int index0 = boneWeight.boneIndex0; int index1 = boneWeight.boneIndex1; int index2 = boneWeight.boneIndex2; int index3 = boneWeight.boneIndex3; float weight0 = boneWeight.weight0; float weight1 = boneWeight.weight1; float weight2 = boneWeight.weight2; float weight3 = boneWeight.weight3; EditorGUIUtility.labelWidth = 30f; EditorGUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); index0 = EditorGUILayout.Popup(index0, names, GUILayout.Width(100f)); weight0 = EditorGUILayout.Slider(weight0, 0f, 1f); if (boneWeight != null && EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(spriteMeshCache, "Modify Weights"); boneWeight.SetWeight(0, index0, weight0); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); index1 = EditorGUILayout.Popup(index1, names, GUILayout.Width(100f)); weight1 = EditorGUILayout.Slider(weight1, 0f, 1f); if (boneWeight != null && EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(spriteMeshCache, "Modify Weights"); boneWeight.SetWeight(1, index1, weight1); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); index2 = EditorGUILayout.Popup(index2, names, GUILayout.Width(100f)); weight2 = EditorGUILayout.Slider(weight2, 0f, 1f); if (boneWeight != null && EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(spriteMeshCache, "Modify Weights"); boneWeight.SetWeight(2, index2, weight2); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); index3 = EditorGUILayout.Popup(index3, names, GUILayout.Width(100f)); weight3 = EditorGUILayout.Slider(weight3, 0f, 1f); if (boneWeight != null && EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(spriteMeshCache, "Modify Weights"); boneWeight.SetWeight(3, index3, weight3); } EditorGUILayout.EndHorizontal(); } else { int index = spriteMeshCache.bindPoses.IndexOf(spriteMeshCache.selectedBone); EditorGUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); index = EditorGUILayout.Popup(index, names, GUILayout.Width(100f)); if (index >= 0 && index < spriteMeshCache.bindPoses.Count) { spriteMeshCache.selectedBone = spriteMeshCache.bindPoses[index]; } EditorGUI.BeginDisabledGroup(spriteMeshCache.selectedBone == null); if (Event.current.type == EventType.MouseUp || Event.current.type == EventType.MouseDown) { mLastWeight = 0f; mWeight = 0f; } mWeight = EditorGUILayout.Slider(mLastWeight, -1f, 1f); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(spriteMeshCache, "Modify Weights"); float delta = mWeight - mLastWeight; mLastWeight = mWeight; List <Vertex> vertices = spriteMeshCache.selectedVertices; if (vertices.Count == 0) { vertices = spriteMeshCache.texVertices; } foreach (Vertex vertex in vertices) { BoneWeight2 bw = vertex.boneWeight; bw.SetBoneIndexWeight(index, bw.GetBoneWeight(index) + delta); } } EditorGUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); } EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Smooth")) { Undo.RegisterCompleteObjectUndo(spriteMeshCache, "Smooth Weights"); List <Vertex> targetVertices = spriteMeshCache.texVertices; if (spriteMeshCache.selectedVertices.Count > 0) { targetVertices = spriteMeshCache.selectedVertices; } spriteMeshCache.SmoothVertices(targetVertices); } if (GUILayout.Button("Auto")) { Undo.RegisterCompleteObjectUndo(spriteMeshCache, "Calculate Weights"); List <Vertex> targetVertices = spriteMeshCache.texVertices; if (spriteMeshCache.selectedVertices.Count > 0) { targetVertices = spriteMeshCache.selectedVertices; } spriteMeshCache.CalculateAutomaticWeights(targetVertices); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); EditorGUIUtility.labelWidth = 50f; overlayColors = EditorGUILayout.Toggle("Overlay", overlayColors); EditorGUIUtility.labelWidth = 30f; showPie = EditorGUILayout.Toggle("Pies", showPie); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUIUtility.labelWidth = labelWidth; /* * boneScrollListPosition = EditorGUILayout.BeginScrollView(boneScrollListPosition); * * boneList.DoLayoutList(); * * EditorGUILayout.EndScrollView(); */ EatMouseInput(new Rect(0, 0, windowRect.width, windowRect.height)); }
protected override void DoWindow(int windowId) { float labelWidth = EditorGUIUtility.labelWidth; bool wideMode = EditorGUIUtility.wideMode; EditorGUIUtility.wideMode = true; EditorGUILayout.BeginHorizontal(); string[] names = spriteMeshCache.GetBoneNames("None"); int index = spriteMeshCache.bindPoses.IndexOf(spriteMeshCache.selectedBindPose); index = EditorGUILayout.Popup(index + 1, names, GUILayout.Width(75f)) - 1; if (index >= 0 && index < spriteMeshCache.bindPoses.Count) { spriteMeshCache.selectedBindPose = spriteMeshCache.bindPoses[index]; } else { spriteMeshCache.selectedBindPose = null; } EditorGUI.BeginChangeCheck(); EditorGUI.BeginDisabledGroup(spriteMeshCache.selectedBindPose == null); if (Event.current.type == EventType.MouseUp || Event.current.type == EventType.MouseDown) { m_Weight = 0f; m_TempWeights.Clear(); if (spriteMeshCache.selection.Count == 0) { m_TempWeights = spriteMeshCache.boneWeights.ToList(); } else { m_TempWeights = spriteMeshCache.selectedNodes.ConvertAll(n => spriteMeshCache.GetBoneWeight(n)); } } EditorGUIUtility.fieldWidth = 35f; m_Weight = EditorGUILayout.Slider(m_Weight, -1f, 1f); EditorGUIUtility.fieldWidth = 0f; if (EditorGUI.EndChangeCheck()) { spriteMeshCache.RegisterUndo("modify weights"); List <Node> nodes = null; if (spriteMeshCache.selection.Count == 0) { nodes = spriteMeshCache.nodes; } else { nodes = spriteMeshCache.selectedNodes; } for (int i = 0; i < nodes.Count; i++) { Node node = nodes[i]; BoneWeight tempWeight = m_TempWeights[i]; tempWeight.SetBoneIndexWeight(index, tempWeight.GetBoneWeight(index) + m_Weight, !EditorGUI.actionKey, true); spriteMeshCache.SetBoneWeight(node, tempWeight); } } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button(new GUIContent("Smooth", "Smooth weights"))) { spriteMeshCache.RegisterUndo("smooth weights"); List <Node> targetNodes = spriteMeshCache.nodes; if (spriteMeshCache.selection.Count > 0) { targetNodes = spriteMeshCache.selectedNodes; } spriteMeshCache.SmoothWeights(targetNodes); } if (GUILayout.Button(new GUIContent("Auto", "Calculate automatic weights"))) { spriteMeshCache.RegisterUndo("calculate weights"); List <Node> targetNodes = spriteMeshCache.nodes; if (spriteMeshCache.selection.Count > 0) { targetNodes = spriteMeshCache.selectedNodes; } spriteMeshCache.CalculateAutomaticWeights(targetNodes); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); EditorGUIUtility.labelWidth = 50f; overlayColors = EditorGUILayout.Toggle("Overlay", overlayColors); EditorGUIUtility.labelWidth = 30f; showPie = EditorGUILayout.Toggle("Pies", showPie); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUIUtility.labelWidth = labelWidth; EditorGUIUtility.wideMode = wideMode; }