public void ApplyCache(VertexEditFlags editFlags) { if ((editFlags & VertexEditFlags.Position) != 0) { meshStream.SetVertices(cachedPos); meshStream.RecalculateNormals(); meshStream.RecalculateBounds(); } if ((editFlags & VertexEditFlags.Color) != 0) { meshStream.SetColors(cachedColors); } if ((editFlags & VertexEditFlags.UV3) != 0) { meshStream.SetUVs(3, cachedUV3); } }
private void OnSceneGUI() { var current = Event.current; if (current.type == EventType.KeyDown && current.keyCode == KeyCode.Tab) { Repaint(); shouldDoBrush = !shouldDoBrush; } Tools.hidden = false; if (!shouldDoBrush) { return; } if (GUIUtility.hotControl != 0) { return; } HandleUtility.AddDefaultControl(GUIUtility.GetControlID(GUIUtility.GetControlID("SuperBlend".GetHashCode(), FocusType.Keyboard), FocusType.Keyboard)); Tools.hidden = true; Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); // Update brush if (RXLookingGlass.IntersectRayMesh(ray, blendee.meshFilter, out lastHit)) { Handles.CircleHandleCap(0, lastHit.point, Quaternion.LookRotation(lastHit.normal, Vector3.up), maxRadius, EventType.Repaint); onMesh = true; } else { onMesh = false; } if (onMesh && current.modifiers == EventModifiers.None) { VertexEditFlags useFlags = VertexEditFlags.None; int vertCount = blendee.cachedPos.Count; for (int i = 0; i < vertCount; i++) { Vector3 worldSpacePos = blendee.transform.TransformPoint(blendee.cachedPos[i]); Vector3 vertToMouse = worldSpacePos - lastHit.point; if (maxRadius >= vertToMouse.magnitude) { // Repaint vert indicators if (displayVertices && current.type == EventType.Repaint) { Handles.color = blendee.cachedColors[i].WithAlpha(1); Handles.CubeHandleCap(0, worldSpacePos, Quaternion.identity, HandleUtility.GetHandleSize(worldSpacePos) * 0.05f, EventType.Repaint); } // Handle click if ((current.type == EventType.MouseDown || current.type == EventType.MouseDrag) && current.button == 0) { Undo.RecordObject(blendee, "Edited Mesh"); if (doColorBrush) { blendee.cachedColors[i] = paintColor; useFlags |= VertexEditFlags.Color; } if (doHeightBrush) { Vector4 copy = blendee.cachedUV3[i]; copy.z = texCoord3.z; blendee.cachedUV3[i] = copy; useFlags |= VertexEditFlags.UV3; } if (doFalloffBrush) { Vector4 copy = blendee.cachedUV3[i]; copy.w = texCoord3.w; blendee.cachedUV3[i] = copy; useFlags |= VertexEditFlags.UV3; } } } }// end for each vertex if (useFlags != 0) { current.Use(); blendee.ApplyCache(useFlags); } } }