public static void RepositionKeyframesForConstantSpeed(SpherePointKeyframeGroup group) { if (group.GetKeyFrameCount() < 2) { return; } // Because time is always 1, no need to divide by it. float totalDistance = GetTotalDistanceBetweenKeyframes(group); float targetSpeed = totalDistance; int keyFrameCount = group.GetKeyFrameCount(); for (int j = 0; j < keyFrameCount; j++) { for (int i = keyFrameCount - 2; i >= 0; i--) { int nextIndex = i + 1; SpherePointKeyframe keyframe = group.keyframes[i]; SpherePointKeyframe nextKeyframe = group.keyframes[nextIndex]; MoveKeyframeTimeToMatchSpeed(keyframe, nextKeyframe, targetSpeed); } // This is a hack, we resort and re-calculated edges since durations were changed. group.SortKeyframes(); } }
private void InsertKeyframeInSpherePointGroup(float time, SpherePointKeyframeGroup group) { SpherePointKeyframe previousKeyFrame = group.GetPreviousKeyFrame(time); SpherePointKeyframe newKeyFrame = new SpherePointKeyframe(previousKeyFrame); newKeyFrame.time = time; group.AddKeyFrame(newKeyFrame); KeyframeInspectorWindow.SetKeyframeData( newKeyFrame, group, KeyframeInspectorWindow.KeyType.SpherePoint, m_ActiveSkyProfile); }
public SpherePoint GetSpherePointPropertyValue(string propertyKey, float timeOfDay) { SpherePointKeyframeGroup group = GetGroup <SpherePointKeyframeGroup>(propertyKey); if (group == null) { Debug.LogError("Can't find a sphere point group with property key: " + propertyKey); return(null); } return(group.SpherePointForTime(timeOfDay)); }
public static float GetTotalDistanceBetweenKeyframes(SpherePointKeyframeGroup group) { float total = 0; for (int i = 0; i < group.GetKeyFrameCount(); i++) { int nextIndex = (i + 1) % group.GetKeyFrameCount(); SpherePointKeyframe currentKeyframe = group.keyframes[i]; SpherePointKeyframe nextKeyframe = group.keyframes[nextIndex]; total += GetDistanceBetweenKeyframes(currentKeyframe, nextKeyframe); } return(total); }
private void ShowSpherePointKeyframesInSkybox(SpherePointKeyframeGroup group) { int debugPoints = 0; for (int i = 0; i < group.keyframes.Count; i++) { SpherePointKeyframe keyframe = group.keyframes[i]; Vector3 direction = keyframe.spherePoint.GetWorldDirection(); float isActiveKeyframe = SkyEditorUtility.IsKeyframeActiveInInspector(keyframe) ? 1.0f : 0.0f; Vector4 pointData = new Vector4(direction.x, direction.y, direction.z, isActiveKeyframe); if (i < MAX_DEBUG_POINTS) { m_DebugPoints[i] = pointData; debugPoints += 1; } } ShowDebugPoints(m_DebugPoints, debugPoints); }
public static void RenderSpherePointRow(Rect rect, SkyProfile profile, SpherePointKeyframeGroup group) { bool sortGroup = false; RenderColorGradients(rect, group); for (int i = 0; i < group.keyframes.Count; i++) { SpherePointKeyframe currentKey = group.GetKeyframe(i); // Track key marker mouse events and render. bool didSingleClick = false; bool isDragging = false; bool keyframeUpdated = false; SkyEditorUtility.DrawHorizontalKeyMarker(rect, currentKey, profile, out didSingleClick, out isDragging, out keyframeUpdated); if (keyframeUpdated) { sortGroup = true; } // Show the color keyframe property window. if (didSingleClick || isDragging) { // Load info about this keyframe and show the editor window. KeyframeInspectorWindow.SetKeyframeData( currentKey, group, KeyframeInspectorWindow.KeyType.SpherePoint, profile); if (didSingleClick) { KeyframeInspectorWindow.ShowWindow(); } } } if (sortGroup) { group.SortKeyframes(); } }
private bool RenderSpherePointPropertyGroup(ProfileGroupDefinition def) { EditorGUILayout.BeginHorizontal(); bool valueChanged = false; SpherePointKeyframeGroup group = m_Profile.GetGroup <SpherePointKeyframeGroup>(def.propertyKey); if (m_Profile.IsManagedByTimeline(def.propertyKey)) { EditorGUILayout.PrefixLabel(new GUIContent(def.groupName, def.tooltip)); RenderManagedOnTimlineMessage(); } else { SpherePointKeyframe frame = group.GetKeyframe(0); EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent(group.name, def.tooltip)); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUI.BeginChangeCheck(); EditorGUI.indentLevel += 1; SpherePoint selectedPoint = SpherePointGUI.SpherePointField( frame.spherePoint, true, frame.id); EditorGUI.indentLevel -= 1; if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(m_Profile, "Changed sphere point"); frame.spherePoint = selectedPoint; } EditorGUILayout.EndVertical(); } EditorGUILayout.EndHorizontal(); return(valueChanged); }
public static void RenderColorGradients(Rect rect, SpherePointKeyframeGroup group) { if ((int)rect.width == 0) { return; } // Generate speed colors to visual rate of transition with distances and time. List <Vector4> shaderColors = GenerateColorSpeedPoints(group); for (int i = 0; i < shaderColors.Count; i++) { m_DebugPointsArray[i] = shaderColors[i]; } if (m_RectangleMesh == null) { m_RectangleMesh = new Mesh() { hideFlags = HideFlags.HideInHierarchy }; m_RectangleMesh.MarkDynamic(); } // Create a mesh that fits the aspect ratio PopulateRectangleMesh(Mathf.Floor(rect.width), Mathf.Floor(rect.height), m_RectangleMesh); int textureSize = Mathf.NextPowerOfTwo((int)rect.width); RenderTexture targetTexture = RenderTexture.GetTemporary( textureSize, textureSize, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB); RenderTexture oldRenderTexture = RenderTexture.active; GL.PushMatrix(); GL.LoadPixelMatrix(0, Mathf.Floor(rect.width), 0, Mathf.Floor(rect.height)); RenderTexture.active = targetTexture; GL.Clear(true, true, Color.white); // Configure the shader. Material gradientMaterial = new Material(Shader.Find("Hidden/Funly/SkyStudio/MultiColorGradient")) { hideFlags = HideFlags.HideInHierarchy }; gradientMaterial.SetVectorArray("_ColorPoints", m_DebugPointsArray); gradientMaterial.SetInt("_NumColorPoints", shaderColors.Count); gradientMaterial.SetPass(0); Graphics.DrawMeshNow(m_RectangleMesh, Vector3.zero, Quaternion.identity); GL.PopMatrix(); RenderTexture.active = oldRenderTexture; GUI.DrawTexture(rect, targetTexture); RenderTexture.ReleaseTemporary(targetTexture); }
// Color based on last edge speed. public static List <Vector4> GenerateColorSpeedPoints(SpherePointKeyframeGroup group) { List <Vector4> colorPoints = new List <Vector4>(); if (group.GetKeyFrameCount() <= 1) { colorPoints.Add(new Vector4(0.0f, m_AvgColor.r, m_AvgColor.g, m_AvgColor.b)); colorPoints.Add(new Vector4(1.0f, m_AvgColor.r, m_AvgColor.g, m_AvgColor.b)); return(colorPoints); } float gradientOffset = .02f; const float maxSpeed = 1200.0f; for (int i = 0; i < group.keyframes.Count; i++) { int nextIndex = (i + 1) % group.GetKeyFrameCount(); SpherePointKeyframe currentKeyframe = group.keyframes[i]; SpherePointKeyframe nextKeyframe = group.keyframes[nextIndex]; // Last keyframe has special rules if (i == group.keyframes.Count - 1) { float speed = GetSpeedBetweenKeyframes(currentKeyframe, nextKeyframe); Color speedColor = Color.Lerp(m_AvgColor, m_MaxColor, speed / maxSpeed); float gradientBeginTime = currentKeyframe.time + gradientOffset; float gradientEndTime = 1.0f; if (gradientBeginTime >= 1.0f) { gradientBeginTime = currentKeyframe.time; } colorPoints.Add( new Vector4(gradientBeginTime, speedColor.r, speedColor.g, speedColor.b)); colorPoints.Add( new Vector4(gradientEndTime, speedColor.r, speedColor.g, speedColor.b)); // Now bridge gap if any to first keyframe. if (!SkyEditorUtility.IsKeyFrameAtStart(nextKeyframe)) { gradientBeginTime = 0.0f; gradientEndTime = nextKeyframe.time - gradientOffset; if (gradientEndTime < 0) { gradientEndTime = nextKeyframe.time; } colorPoints.Insert(0, new Vector4(gradientEndTime, speedColor.r, speedColor.g, speedColor.b)); colorPoints.Insert(0, new Vector4(gradientBeginTime, speedColor.r, speedColor.g, speedColor.b)); } else { colorPoints.Insert( 0, new Vector4(0, speedColor.r, speedColor.g, speedColor.b)); } } else { float gradientBeginTime = currentKeyframe.time + gradientOffset; float gradientEndTime = nextKeyframe.time - gradientOffset; // Need to play with these to see how they look. Maybe use a percentage between them instead? if (gradientBeginTime >= nextKeyframe.time) { gradientBeginTime = currentKeyframe.time; } if (gradientEndTime <= currentKeyframe.time) { gradientEndTime = nextKeyframe.time; } float speed = GetSpeedBetweenKeyframes(currentKeyframe, nextKeyframe); Color speedColor = Color.Lerp(m_AvgColor, m_MaxColor, speed / maxSpeed); colorPoints.Add( new Vector4(gradientBeginTime, speedColor.r, speedColor.g, speedColor.b)); colorPoints.Add( new Vector4(gradientEndTime, speedColor.r, speedColor.g, speedColor.b)); } } return(colorPoints); }
private void AddSpherePointGroup(string propKey, string groupName, SpherePoint point) { SpherePointKeyframeGroup group = new SpherePointKeyframeGroup(groupName, new SpherePointKeyframe(point, 0)); keyframeGroups[propKey] = group; }
// Render a timeline of sphere point keyframes. private void RenderSpherePointRowAndAdvance(ref Rect rect, SkyProfile profile, SpherePointKeyframeGroup group, ProfileGroupDefinition groupDefinition) { rect.height = SPHERE_POINT_ROW_HEIGHT; UpdateActiveSelectedRow(rect, group.id, groupDefinition.propertyKey); Rect valueRowRect; Rect nameRowRect; bool isActive; LoadRowInformation(ref rect, group.id, SPHERE_POINT_ROW_HEIGHT, out valueRowRect, out nameRowRect, out isActive); // Render debug points if this is active. if (isActive) { ShowSpherePointKeyframesInSkybox(group); } RenderRowTitle(nameRowRect, group.name, isActive, groupDefinition); SpherePointTimelineRow.RenderSpherePointRow(valueRowRect, profile, group); }