Pose GeneratePose(float sampleTime) { if (go == null) { return(null); } if (animationClip == null) { return(null); } Animator animator = go.GetComponent <Animator>(); if (animator != null && animator.runtimeAnimatorController == null) { return(null); } if (!EditorApplication.isPlaying && AnimationMode.InAnimationMode()) { AnimationMode.BeginSampling(); AnimationMode.SampleAnimationClip(go, animationClip, sampleTime); AnimationMode.EndSampling(); SceneView.RepaintAll(); } return(CreatePose()); }
private void AnimationUpdate() { switch (mode) { case Mode.AnimationClips: if (!AnimationMode.InAnimationMode()) { AnimationMode.StartAnimationMode(); } AnimationMode.BeginSampling(); AnimationMode.SampleAnimationClip(gameObject, animationClips[currentClipIndex], currentClipTime); AnimationMode.EndSampling(); currentClipTime += clipFrameInterval; break; case Mode.AnimationStates: animator.Update(clipFrameInterval); break; case Mode.PlayableDirector: director.time = currentClipTime; director.Evaluate(); currentClipTime += clipFrameInterval; break; } }
public override void ResampleAnimation() { if (!this.state.disabled) { if (this.previewing) { if (this.canPreview) { if (this.state.activeAnimationClip != null) { AnimationMode.BeginSampling(); Undo.FlushUndoRecordObjects(); AnimationMode.SampleAnimationClip(this.state.activeRootGameObject, this.state.activeAnimationClip, this.time.time); if (this.m_CandidateClip != null) { AnimationMode.SampleCandidateClip(this.state.activeRootGameObject, this.m_CandidateClip, 0f); } AnimationMode.EndSampling(); SceneView.RepaintAll(); InspectorWindow.RepaintAllInspectors(); ParticleSystemWindow instance = ParticleSystemWindow.GetInstance(); if (instance) { instance.Repaint(); } } } } } }
public void SetToWeather(int index) { animator = GetComponent <Animator>(); if (animator != null) { animator.enabled = false; } else { return; } AnimationClip ac = GetFirstClip(); if (ac == null) { return; } maxIndex = GetKeyFrameNum(); index = Mathf.Clamp(index, 0, maxIndex - 1); float ratio = (float)index / (maxIndex - 1); // animator.Play (stateName, 0, ratio); AnimationMode.BeginSampling(); AnimationMode.SampleAnimationClip(this.gameObject, ac, ratio * ac.length); AnimationMode.EndSampling(); SceneView.RepaintAll(); }
public override void UpdateView(Rect editorRect, Rect percentageRect) { base.UpdateView(editorRect, percentageRect); if (!EditorApplication.isPlaying && AnimationMode.InAnimationMode()) { if (isAutoSampling) { elapseSamplingTime = Time.realtimeSinceStartup; if (elapseSamplingTime - startSamplingTime >= interval) { AutoSampling(); } } AnimationMode.BeginSampling(); { samplingTime = interval * AnimationEventControllerEditorWindow.Instance.current.timeline.frameIndex; AnimationClip clip = AnimationEventControllerEditorWindow.Instance.GetCurrentClip(); AnimationMode.SampleAnimationClip(animationEventController.animator.gameObject, clip, samplingTime); } AnimationMode.EndSampling(); SceneView.RepaintAll(); } }
private void BakeAnimationFrameMeshes() { GameObject animatedObject = Instantiate(referenceAnimatedObject); //animator = animatedObject.AddComponent<Animator>(); //animator.runtimeAnimatorController = animatorController; frameMeshes = new List <Mesh>(); AnimationMode.StartAnimationMode(); AnimationMode.BeginSampling(); var skinnedRenderer = animatedObject.GetComponentInChildren <SkinnedMeshRenderer>(); AnimationMode.SampleAnimationClip(animatedObject, referenceAnimationClip, 0); var bakedMesh = new Mesh(); skinnedRenderer.BakeMesh(bakedMesh); AssetDatabase.CreateAsset(bakedMesh, "Assets/BackedMesh.mesh"); for (float t = 0.0f; t <= referenceAnimationClip.length; t += 1f / frameRate) { AnimationMode.SampleAnimationClip(animatedObject, referenceAnimationClip, t); bakedMesh = new Mesh(); skinnedRenderer.BakeMesh(bakedMesh); frameMeshes.Add(bakedMesh); } AssetDatabase.SaveAssets(); AnimationMode.EndSampling(); AnimationMode.StopAnimationMode(); GameObject.DestroyImmediate(animatedObject); //SceneView.RepaintAll(); }
public virtual void UpdateTrack(GameObject obj, float time, float deltaTime) { _time += deltaTime; #if UNITY_EDITOR if (go == null) { return; } if (animationClip == null) { return; } // There is a bug in AnimationMode.SampleAnimationClip which crashes // Unity if there is no valid controller attached Animation animation = go.GetComponent <Animation>(); if (animation == null) { return; } if (!EditorApplication.isPlaying && AnimationMode.InAnimationMode()) { AnimationMode.BeginSampling(); animationClip.SampleAnimation(go, _time); AnimationMode.EndSampling(); SceneView.RepaintAll(); } #endif }
void Update() { if (go == null) { return; } if (animationClip == null) { return; } // There is a bug in AnimationMode.SampleAnimationClip which crashes // Unity if there is no valid controller attached Animator animator = go.GetComponent <Animator>(); if (animator != null && animator.runtimeAnimatorController == null) { return; } // Animate the GameObject if (!EditorApplication.isPlaying && AnimationMode.InAnimationMode()) { AnimationMode.BeginSampling(); AnimationMode.SampleAnimationClip(go, animationClip, time); AnimationMode.EndSampling(); SceneView.RepaintAll(); } }
private void StartAnimationUpdate() { switch (mode) { case Mode.AnimationClips: if (!AnimationMode.InAnimationMode()) { AnimationMode.StartAnimationMode(); } AnimationMode.BeginSampling(); AnimationMode.SampleAnimationClip(gameObject, animationClips[currentClipIndex], 0f); AnimationMode.EndSampling(); break; case Mode.AnimationStates: animator.enabled = false; animator.Play(animationStates[currentClipIndex], 0, 0f); break; case Mode.PlayableDirector: director.enabled = false; director.time = 0f; director.Evaluate(); break; } }
private void Maintain(EePreviewAvatar dummy) { dummy.Dummy.gameObject.SetActive(true); AnimationMode.StartAnimationMode(); AnimationMode.BeginSampling(); AnimationMode.SampleAnimationClip(dummy.Dummy.gameObject, _state.CurrentClip, 1 / 60f); AnimationMode.EndSampling(); }
private void SampleClip(EeRenderingSample eeRenderingSample) { WorkaroundAnimatedMaterialPropertiesIgnoredOnThirdSampling(); AnimationMode.BeginSampling(); PoseDummyUsing(eeRenderingSample.Clip); AnimationMode.EndSampling(); }
private static void WorkaroundAnimatedMaterialPropertiesIgnoredOnThirdSampling() { // https://github.com/hai-vr/combo-gesture-expressions-av3/issues/268 // When in animation mode, for some reason the 3rd sampling will fail to apply any animated material properties // Waiting a for a certain number of frames will not help. // The workaround is to sample nothing in the same frame (why does that work?!) AnimationMode.BeginSampling(); AnimationMode.EndSampling(); }
/// <summary> /// Draw a timeline that can be scrubbed to allow picking a specific normalized time of an animation /// </summary> public static void DrawScrub(Rect rect, StateMachineBehaviour target, SerializedProperty normalizedTime, SerializedProperty repeat, SerializedProperty atLeastOnce, SerializedProperty neverWhileExit) { bool updatePreview = false; float timeBefore = normalizedTime.floatValue; GUI.Label(new Rect(rect.x, rect.y, 50, 20), "Time"); EditorGUI.PropertyField(new Rect(rect.x + 50, rect.y, rect.width - 50 - 42, 20), normalizedTime, GUIContent.none); if (GUI.Button(new Rect(rect.x + rect.width - 40, rect.y, 40, 20), "View")) { updatePreview = true; } DrawSmallProperty(new Rect(rect.x, rect.y + 20, rect.width / 3f, 20), new GUIContent("Loop", "Enable this to allow execution every time the state loops. Otherwise it will only happen once."), repeat); DrawSmallProperty(new Rect(rect.x + rect.width / 3f, rect.y + 20, rect.width / 3f, 20), new GUIContent("At Least Once", "Execute when the exit transition ends if this hasn't been executed yet."), atLeastOnce); DrawSmallProperty(new Rect(rect.x + rect.width * 2f / 3f, rect.y + 20, rect.width / 3f, 20), new GUIContent("Never While Exit", "Prevent executing during the exit transition."), neverWhileExit); if (timeBefore != normalizedTime.floatValue) { updatePreview = true; } if (updatePreview) { if (!AnimationMode.InAnimationMode()) { AnimationMode.StartAnimationMode(); } AnimatorController ignore; Animator animator; GetCurrentAnimatorAndController(out ignore, out animator); var contexts = AnimatorController.FindStateMachineBehaviourContext(target); foreach (var context in contexts) { AnimatorState state = context.animatorObject as AnimatorState; if (null == state) { continue; } AnimationClip previewClip = GetFirstAvailableClip(state.motion); if (null == previewClip) { continue; } AnimationMode.BeginSampling(); AnimationMode.SampleAnimationClip(animator.gameObject, previewClip, normalizedTime.floatValue * previewClip.length); AnimationMode.EndSampling(); } } }
protected virtual void StartRecd() { if (target) { EventMgr.Emit(new EventRecordData()); track.SetFlag(TrackMode.Record, true); AnimationMode.StartAnimationMode(); AnimationMode.BeginSampling(); AnimationMode.SampleAnimationClip(target, animationClip, 0); } }
public void SetFrame(int frame, AnimationClip clip) { if (m_PreviewInstance && clip) { AnimationMode.BeginSampling(); AnimationMode.SampleAnimationClip(m_PreviewInstance, clip, AnimationWindowExtra.FrameToTime(frame)); AnimationMode.EndSampling(); IkUtils.UpdateIK(m_PreviewInstance, "", false); } }
/*********************************************** * ***********************************************/ public void ResampleAnimation() { if (AnimationMode.InAnimationMode()) { AnimationMode.BeginSampling(); AnimationMode.SampleAnimationClip(target, clip, time); AnimationMode.EndSampling(); } UnityEditorInternal.InternalEditorUtility.RepaintAllViews(); }
private static void ExportSkeletonAnimationClipData(Animator animator, bool autoPlay, BabylonSkeleton skeleton, Transform[] bones, BabylonMesh babylonMesh, AnimationClip clip) { var frameTime = 1.0f / clip.frameRate; int animationFrameCount = (int)(clip.length * clip.frameRate); if (autoPlay) { babylonMesh.autoAnimate = true; babylonMesh.autoAnimateFrom = 0; babylonMesh.autoAnimateTo = animationFrameCount; babylonMesh.autoAnimateLoop = true; } foreach (var bone in skeleton.bones) { var keys = new List <BabylonAnimationKey>(); var transform = bones.Single(b => b.name == bone.name); AnimationMode.BeginSampling(); for (var i = 0; i < animationFrameCount; i++) { clip.SampleAnimation(animator.gameObject, i * frameTime); var local = (transform.parent.localToWorldMatrix.inverse * transform.localToWorldMatrix); float[] matrix = new[] { local[0, 0], local[1, 0], local[2, 0], local[3, 0], local[0, 1], local[1, 1], local[2, 1], local[3, 1], local[0, 2], local[1, 2], local[2, 2], local[3, 2], local[0, 3], local[1, 3], local[2, 3], local[3, 3] }; var key = new BabylonAnimationKey { frame = i, values = matrix, }; keys.Add(key); } AnimationMode.EndSampling(); var babylonAnimation = new BabylonAnimation { name = bone.name + "Animation", property = "_matrix", dataType = (int)BabylonAnimation.DataType.Matrix, loopBehavior = (int)BabylonAnimation.LoopBehavior.Cycle, framePerSecond = (int)clip.frameRate, keys = keys.ToArray() }; bone.animation = babylonAnimation; } }
private void PreviewAnimationEvent(FAnimationEventEditor animEvtEditor, int frame) { FPlayAnimationEvent animEvt = (FPlayAnimationEvent)animEvtEditor._evt; if (animEvt._animationClip == null) { return; } bool isEditable = animEvt.IsAnimationEditable(); // render path if (isEditable) { TransformCurves transformCurves = new TransformCurves(animEvt.Owner, animEvt._animationClip); RenderTransformPath(transformCurves, animEvt.LengthTime, 1f / animEvt.Sequence.FrameRate); float t = (float)(frame + animEvt._startOffset - animEvt.Start) / animEvt.Sequence.FrameRate; if (animEvt.FrameRange.Contains(frame)) { // float t = (float)(frame + animEvt._startOffset - animEvt.Start) / animEvt.Sequence.FrameRate; RenderTransformAnimation(transformCurves, t); } // AnimationClipCurveData[] allCurves = AnimationUtility.GetAllCurves( animEvt._animationClip, true ); // foreach( AnimationClipCurveData curve in allCurves ) // { // // } } else if (animEvt.FrameRange.Contains(frame)) { float t = (float)(frame + animEvt._startOffset - animEvt.Start) / animEvt.Sequence.FrameRate; bool wasInAnimationMode = AnimationMode.InAnimationMode(); if (!AnimationMode.InAnimationMode()) { AnimationMode.StartAnimationMode(); } AnimationMode.BeginSampling(); AnimationMode.SampleAnimationClip(animEvt.Owner.gameObject, animEvt._animationClip, t); AnimationMode.EndSampling(); if (!wasInAnimationMode) { AnimationMode.StopAnimationMode(); } } }
// Sample our Skeleton at the time given in parameter for the currentAnimationClip private void samplePosture(float p_f_time) { // Check if the Game isn't running & the Animation Mode is enabled if (!EditorApplication.isPlaying && AnimationMode.InAnimationMode()) { // We need to BeginSampling before the SampleAnimationClip is called AnimationMode.BeginSampling(); // Samples the animationClip (m_animation) at the time (m_f_time) for the skeleton (m_skeleton) // If the GameObject & the AnimationClip are different -> no errors are trigger but nothing happen AnimationMode.SampleAnimationClip(m_skeleton, m_animationClip, p_f_time); // Ending the Sampling of the Animation AnimationMode.EndSampling(); // Repaint The SceneView as the skeleton has changed SceneView.RepaintAll(); // Repaint the GUI as we are changing the variable m_f_time on which we have a slider Repaint(); } }
private void EditorUpdate() { if (slicedParent == null || editorClip == null || !IsInEditorMode()) { return; } if (editorClipTime >= editorClip.length) { StopAnimation(); return; } AnimationMode.BeginSampling(); AnimationMode.SampleAnimationClip(slicedParent, editorClip, editorClipTime); AnimationMode.EndSampling(); editorClipTime += Time.deltaTime; }
private void ApplyAnimations(ref ChannelData channel) { if (Application.isPlaying) { _trackBinding.SetLayerData(channel._channel, channel._primaryAnimation, channel._backgroundAnimations.ToArray()); } #if UNITY_EDITOR //For previewing in editor can't blend between clips - the primary clip will play at full weight else { if (channel._primaryAnimation._animation != null) { AnimationMode.BeginSampling(); AnimationMode.SampleAnimationClip(_trackBinding.gameObject, channel._primaryAnimation._animation, channel._primaryAnimation._time); AnimationMode.EndSampling(); } } #endif }
void Update() { if (animateAutomate) { double current = EditorApplication.timeSinceStartup; float deltaTime = (float)(current - lastTime); lastTime = current; time += deltaTime * speed; if (time > animationClip.length) { time = 0; } } if (go == null) { return; } if (animationClip == null) { return; } // there is a bug in AnimationMode.SampleAnimationClip which crash unity if there is no valid controller attached Animator animator = go.GetComponent <Animator>(); if (animator != null && animator.runtimeAnimatorController == null) { return; } if (!EditorApplication.isPlaying && AnimationMode.InAnimationMode()) { AnimationMode.BeginSampling(); AnimationMode.SampleAnimationClip(go, animationClip, time); AnimationMode.EndSampling(); SceneView.RepaintAll(); } }
// Init the trajectories for each body joints for the current Animation Clip private void InitTrajectories() { // Enable the Animation Mode if disabled if (!AnimationMode.InAnimationMode()) { AnimationMode.StartAnimationMode(); } // Init Dictionnaries if (trajectories == null) { trajectories = new Dictionary <string, List <Vector3> >(); } if (toogleTrajectories == null) { toogleTrajectories = new Dictionary <string, bool>(); } trajectories.Clear(); toogleTrajectories.Clear(); for (int i = 0; i < bodyJoints.Count; i++) { trajectories.Add(bodyJoints[i].name, new List <Vector3>()); toogleTrajectories.Add(bodyJoints[i].name, true); } // Sample Animation & Add new bones positions for (float sampleTime = firstFrameTime; sampleTime < clipLength; sampleTime += 0.01f) { AnimationMode.BeginSampling(); AnimationMode.SampleAnimationClip(skeleton, clipToPlay, sampleTime); for (int i = 0; i < trajectories.Count; i++) { trajectories[bodyJoints[i].name].Add(bodyJoints[i].position); } AnimationMode.EndSampling(); } // Reset gameobject to base position AnimationMode.BeginSampling(); AnimationMode.SampleAnimationClip(skeleton, clipToPlay, 0.0f); AnimationMode.EndSampling(); }
public void SampleAnimations(float normalizedTime) { int count = _animators.Length; for (int i = 0; i < count; i++) { int clipIndex = _guiClips[i].selectedIndex; if (clipIndex > 0) { clipIndex--; Animator animator = _animators[i]; AnimationClip clip = animator.runtimeAnimatorController.animationClips[clipIndex]; AnimationMode.BeginSampling(); AnimationMode.SampleAnimationClip(animator.gameObject, clip, normalizedTime * clip.length); AnimationMode.EndSampling(); } } }
public override void ResampleAnimation() { if (state.disabled) { return; } if (previewing == false) { return; } if (canPreview == false) { return; } if (state.activeAnimationClip != null) { AnimationMode.BeginSampling(); Undo.FlushUndoRecordObjects(); AnimationMode.SampleAnimationClip(state.activeRootGameObject, state.activeAnimationClip, time.time); if (m_CandidateClip != null) { AnimationMode.SampleCandidateClip(state.activeRootGameObject, m_CandidateClip, 0f); } AnimationMode.EndSampling(); SceneView.RepaintAll(); InspectorWindow.RepaintAllInspectors(); // Particle editor needs to be manually repainted to refresh the animated properties var particleSystemWindow = ParticleSystemWindow.GetInstance(); if (particleSystemWindow) { particleSystemWindow.Repaint(); } } }
public void Evaluate(float time) { if (!AnimationMode.InAnimationMode()) { return; } m_SyncSceneToStreamLayer.Update(m_RigLayers); foreach (var layer in m_RigLayers) { if (layer.IsValid() && layer.active) { layer.Update(); } } AnimationMode.BeginSampling(); AnimationMode.SamplePlayableGraph(m_Graph, 0, time); AnimationMode.EndSampling(); }
public void Play(Animator animator, float time) { #if UNITY_EDITOR if (Clip != null && animator != null && !Application.isPlaying && AnimationMode.InAnimationMode()) { AnimationMode.BeginSampling(); AnimationMode.SampleAnimationClip(animator.gameObject, Clip, time); AnimationMode.EndSampling(); } //else if (animator != null){ // var animancer = animator.gameObject.GetComponent<AnimancerController>(); // if (animancer != null) { // animancer.StopAll(); // var state = animancer.GetOrCreateState(Clip); // state.Resume(); // state.NormalizedTime = time; // state.Pause(); // } //} #endif }
public override void ResampleAnimation() { if (!this.state.disabled) { if (this.previewing) { if (this.canPreview) { bool flag = false; AnimationMode.BeginSampling(); AnimationWindowSelectionItem[] array = this.state.selection.ToArray(); for (int i = 0; i < array.Length; i++) { AnimationWindowSelectionItem animationWindowSelectionItem = array[i]; if (animationWindowSelectionItem.animationClip != null) { Undo.FlushUndoRecordObjects(); AnimationMode.SampleAnimationClip(animationWindowSelectionItem.rootGameObject, animationWindowSelectionItem.animationClip, this.time.time - animationWindowSelectionItem.timeOffset); if (this.m_CandidateClip != null) { AnimationMode.SampleCandidateClip(animationWindowSelectionItem.rootGameObject, this.m_CandidateClip, 0f); } flag = true; } } AnimationMode.EndSampling(); if (flag) { SceneView.RepaintAll(); InspectorWindow.RepaintAllInspectors(); ParticleSystemWindow instance = ParticleSystemWindow.GetInstance(); if (instance) { instance.Repaint(); } } } } } }
void Update() { if (go == null) { return; } if (animationClip == null) { return; } Animator animator = go.GetComponent <Animator>(); if (animator != null && animator.runtimeAnimatorController == null) { return; } if (animator == null) { Animation animation = go.GetComponent <Animation>(); if (animation == null) { return; } } if (!EditorApplication.isPlaying && AnimationMode.InAnimationMode()) { AnimationMode.BeginSampling(); AnimationMode.SampleAnimationClip(go, animationClip, time); AnimationMode.EndSampling(); SceneView.RepaintAll(); } }
private void Update() { if (playingAnimationClip == null) { return; } if (AnimationMode.InAnimationMode()) { if (avatarInfo == null) { avatarInfo = FindAvatarObject(); if (avatarInfo == null) { ToggleAnimationMode(); return; } } AnimationMode.BeginSampling(); AnimationMode.SampleAnimationClip(avatarInfo.gameObject, playingAnimationClip, animationTime); AnimationMode.EndSampling(); SceneView.RepaintAll(); if (isAutoPlayAnimation) { animationTime += (Time.realtimeSinceStartup - lastUpdateTime); if (animationTime >= playingAnimationClip.length) { animationTime = 0.0f; } Repaint(); } } lastUpdateTime = Time.realtimeSinceStartup; }