public void addControlPoint(VideoKeyFrame vk) { // first instantiante a beizer point in the real world ControlPoint b = Instantiate(beizerPathGroup.controlPointPrefab, beizerPathGroup.transform).GetComponent <ControlPoint>(); b.transform.localScale = new Vector3(1, 1, 1); b.videoKeyframe = vk; vk.controlPoint = b; b.beizerTime = vk.keyframeTime; // set the transform positions here b.transform.position = vk.retrieveTransformPositionFromVideoKeyframe(); // this has no info on the left control point or right control point beizerPoints.Add(b); sortBeizerPointsByTime(); // add this control point inside the beizer Curve Keyframe xControl = new Keyframe(vk.keyframeTime, b.transform.position.x); Keyframe yControl = new Keyframe(vk.keyframeTime, b.transform.position.y); Keyframe zControl = new Keyframe(vk.keyframeTime, b.transform.position.z); // add the keyframes in the curve specific to this beizer point addKeyFrameToBeizerCurve(xControl, AnimationCurveToUpdate.x); addKeyFrameToBeizerCurve(yControl, AnimationCurveToUpdate.y); addKeyFrameToBeizerCurve(zControl, AnimationCurveToUpdate.z); }
// for beizer curves , use beizer curve calculator public void addIntermediateKeyframes(Vector3[] intermediatePositions, float t1, float t2, out VideoKeyFrame[] intermediateVideoKeyframes) { float dt = intermediatePositions.Length / (t2 - t1); float currTime = t1; intermediateVideoKeyframes = new VideoKeyFrame[intermediatePositions.Length]; int i = 0; foreach (Vector3 intermediatePoint in intermediatePositions) { Keyframe pointX = new Keyframe(currTime, intermediatePoint.x); Keyframe pointY = new Keyframe(currTime, intermediatePoint.y); Keyframe pointZ = new Keyframe(currTime, intermediatePoint.z); animTrack.animCurve.addKeyFrameToCurve(pointX, AnimationCurveToUpdate.x); animTrack.animCurve.addKeyFrameToCurve(pointY, AnimationCurveToUpdate.y); animTrack.animCurve.addKeyFrameToCurve(pointZ, AnimationCurveToUpdate.z); int keyFrameXindex = retrieveKeyframeIndex(pointX, AnimationCurveToUpdate.x); int keyFrameYindex = retrieveKeyframeIndex(pointY, AnimationCurveToUpdate.x); int keyFrameZindex = retrieveKeyframeIndex(pointY, AnimationCurveToUpdate.x); VideoKeyFrame intermediateKeyframe = new VideoKeyFrame(); intermediateKeyframe.keyframeXindex = keyFrameXindex; intermediateKeyframe.keyframeYindex = keyFrameYindex; intermediateKeyframe.keyframeZindex = keyFrameZindex; intermediateVideoKeyframes[i] = intermediateKeyframe; i += 1; currTime += dt; } }
public virtual void SetBeizerPoint(VideoKeyFrame vKeyframe) { videoKeyframe = vKeyframe; float p1x = videoKeyframe.animTrack.animatedObject.beizerPathGroup.beizerPathData.curveXbeizer.keys[videoKeyframe.keyframeXindex].value; float p1y = videoKeyframe.animTrack.animatedObject.beizerPathGroup.beizerPathData.curveYbeizer.keys[videoKeyframe.keyframeYindex].value; float p1z = videoKeyframe.animTrack.animatedObject.beizerPathGroup.beizerPathData.curveZbeizer.keys[videoKeyframe.keyframeZindex].value; transform.position = new Vector3(p1x, p1y, p1z); }
private Vector3 beizerPointPositionFromVideoKeyframeOfBeizerCurves(VideoKeyFrame vk) { Vector3 animObjTransformPos; float x = curveXbeizer.keys[vk.keyframeXindex].value; float y = curveYbeizer.keys[vk.keyframeYindex].value; float z = curveZbeizer.keys[vk.keyframeZindex].value; animObjTransformPos = new Vector3(x, y, z); return(animObjTransformPos); }
/// <summary> /// This is called after a new keyframe has been added. Takes the previous position keyframe nad the new position keyframe, and generates keyframe postions as such /// </summary> /// <param name="k1"></param> /// <param name="k2"></param> public void generateBeizerCurve(VideoKeyFrame k1, VideoKeyFrame k2) { int controlPointIndexOne; int controlPointIndexTwo; generateBeizerControlPoints(k1, k2, out controlPointIndexOne, out controlPointIndexTwo); generateIntermediatePoints(controlPointIndexOne, controlPointIndexTwo); /// change the realtime beizer points to this saved beizer points realTimeBeizerPoints = beizerPoints; }
// if the control points private VideoKeyFrame[] retrieveVideoKeyFramesFromBeizerPoint(int beizerPointIndexOne, int beizerPointIndexTwo) { int countDiff = beizerPointIndexTwo - (beizerPointIndexOne + 1); VideoKeyFrame[] videoKeyframes = new VideoKeyFrame[countDiff]; for (int i = beizerPointIndexOne + 1; i < countDiff; i++) { videoKeyframes[i] = beizerPoints[i].videoKeyframe; } return(videoKeyframes); }
// don't use this because this is assuming we generate control points two at a time. doesn't work like this private void generateBeizerControlPoints(VideoKeyFrame k1, VideoKeyFrame k2, out int beizerPointIndexOne, out int beizerPointIndexTwo) { ControlPoint c1 = new ControlPoint(); ControlPoint c2 = new ControlPoint(); c1.SetBeizerPoint(k1); c2.SetBeizerPoint(k2); beizerPoints.Add(c1); beizerPointIndexOne = beizerPoints.IndexOf(c1); beizerPointIndexTwo = beizerPoints.IndexOf(c2); c1.rightControlPoint = c2; c2.leftControlPoint = c1; }
public void RemoveKeyFrameUI(VideoKeyFrame vk) { videoKeyFrames.Remove(vk); animCurve.RemoveKeyFrameFromCurve(vk.keyframeXindex, AnimationCurveToUpdate.x); animCurve.RemoveKeyFrameFromCurve(vk.keyframeYindex, AnimationCurveToUpdate.y); animCurve.RemoveKeyFrameFromCurve(vk.keyframeZindex, AnimationCurveToUpdate.z); animCurve.RemoveKeyFrameFromCurve(vk.keyframeRotateXindex, AnimationCurveToUpdate.rotationX); animCurve.RemoveKeyFrameFromCurve(vk.keyframeRotateYindex, AnimationCurveToUpdate.rotationY); animCurve.RemoveKeyFrameFromCurve(vk.keyframeRotateZindex, AnimationCurveToUpdate.rotationZ); // remove from beizer curve as well animatedObject.beizerPathGroup.beizerPathData.removeControlPoint(vk); Destroy(vk.gameObject); UpdateCurve(); UpdateKeyframeUI(); sortVideoKeyframesByTime(); // remove the beizerPoint }
// question - should this be invoked after the keyframe has been added to the curve? - answer, YES, after anim Curve has completed curve data update for all 3 positions public void AddKeyFrameUI(float time, out VideoKeyFrame newK) { int keyframeIndex; if (isVideoKeyFrameHere(time, out keyframeIndex)) { Destroy(videoKeyFrames[keyframeIndex].gameObject); } GameObject keyframeObj = Instantiate(timeline.keyframePrefab.gameObject, transform); newK = keyframeObj.GetComponent <VideoKeyFrame>(); newK.keyframeTime = time; videoKeyFrames.Add(newK); if (!isTimeWithinTimelineClampedTime(newK.keyframeTime)) { newK.gameObject.SetActive(false); } else { UpdateKeyframeUI(); } sortVideoKeyframesByTime(); // ensure the correct indices in the track for proper retrival of keyframes newK.animTrack = this; // get keyframe indices and insert them onto videokeyframe int keyframePosIndexX = animCurve.getKeyframeIndicesFromCurve(timeline.timelineTicker.currentTime, AnimationCurveToUpdate.x); int keyframePosIndexY = animCurve.getKeyframeIndicesFromCurve(timeline.timelineTicker.currentTime, AnimationCurveToUpdate.y); int keyframePosIndexZ = animCurve.getKeyframeIndicesFromCurve(timeline.timelineTicker.currentTime, AnimationCurveToUpdate.z); Debug.Log("keyframeIndexX " + keyframePosIndexX + " keyframePosIndexY " + keyframePosIndexY + " keyframeIndexZ " + keyframePosIndexZ); newK.keyframeXindex = keyframePosIndexX; newK.keyframeYindex = keyframePosIndexY; newK.keyframeZindex = keyframePosIndexZ; }
/// <summary> /// This is invoked when the UI menu button has been pressed and /// /// We are basically sending a new path (w/ the customized control points), with lots of manipulated control points and intermediate points, to the animation curve. /// /// Have customized /// /// make sure the control points have reference to the keyframe index number /// /// Basically, this is a more customized version of how to /// </summary> /// // we should keep the beizer curve animationcurves Sepearate from the Regular linear path curves (toggle) // case 1) complete linear path ---- save that curve in curveX, curveY, curveZ // case 2) complete beizer path ---- save those curves as beizerCurveX, beizerCurveY, beizerCurveZ, but make sure you have reference / distinguish between control points and beizer points // case 3) have a button that toggles back and forth that chooses between which curve to set // saving this beizer curve arrangement deserves a separate button public void saveUpdatedBeizerCurve() { // we're going to create a new animation curve, from these positions, for x,y,z // and then send them to the clip for playing AnimationCurve curveX = new AnimationCurve(); AnimationCurve curveY = new AnimationCurve(); AnimationCurve curveZ = new AnimationCurve(); updateRealTimeBeizerPoints(); // get keyframes ready to set to curve Keyframe[] xKeys = new Keyframe[realTimeBeizerPoints.Count]; Keyframe[] yKeys = new Keyframe[realTimeBeizerPoints.Count]; Keyframe[] zKeys = new Keyframe[realTimeBeizerPoints.Count]; // generate keyframe per position and time for (int i = 0; i < realTimeBeizerPoints.Count; i++) { Vector3 pos = realTimeBeizerPoints[i].transform.position; xKeys[i] = new Keyframe(realTimeBeizerPoints[i].beizerTime, pos.x); yKeys[i] = new Keyframe(realTimeBeizerPoints[i].beizerTime, pos.y); zKeys[i] = new Keyframe(realTimeBeizerPoints[i].beizerTime, pos.z); } // set a new list of VideoKeyframes // animTrack.DestoryExistingKeyframesUI(); List <VideoKeyFrame> videoKeyFrames = new List <VideoKeyFrame>(); for (int i = 0; i < realTimeBeizerPoints.Count; i++) { int curveXindex = curveX.AddKey(xKeys[i]); int curveYindex = curveY.AddKey(yKeys[i]); int curveZindex = curveZ.AddKey(zKeys[i]); VideoKeyFrame vk = new VideoKeyFrame(); vk.animTrack = animTrack; vk.keyframeXindex = curveXindex; vk.keyframeYindex = curveYindex; vk.keyframeZindex = curveZindex; videoKeyFrames.Add(vk); } /// include place holder and ? -- do we want to have a sepearate method for this -> because it seems much easier just to generate new curve, adjust key frames, etc. /// assess time it takes to create other methods, versus time saved here. // animTrack.clip.SetCurve("", typeof(Transform), "localPosition.x", curveX); //animTrack.clip.SetCurve("", typeof(Transform), "localPosition.y", curveY); //animTrack.clip.SetCurve("", typeof(Transform), "localPosition.z", curveZ); // call animTrack to recreate a new list of VideoKeyframes, which are sent from here //animTrack.videoKeyFrames = videoKeyFrames; // we need to save these video key frame positions // animTrack.UpdateKeyframeUI(); curveXbeizer = curveX; curveYbeizer = curveY; curveZbeizer = curveZ; }
public void removeControlPoint(VideoKeyFrame vk) { }