public bool SaveAnimation(MeshAnimator meshanim) { String name = AnimName; bool rc; Engine simroot; Engine oldroot; if (meshanim == null) { return(false); } if (BaseName != null) { name += "_" + BaseName; } oldroot = meshanim.Parent(); meshanim.Remove(false); simroot = new Engine(); simroot.Name = name + ".simroot"; meshanim.Stop(); meshanim.Disable(MeshAnimator.RECORD, Engine.CONTROL_CHILDREN); simroot.Append(meshanim); rc = SharedWorld.Get().SaveAsVix(simroot, name + ".vix"); if (!rc) { SharedWorld.LogError("Cannot save cloth animations " + name + ".vix"); } meshanim.Remove(false); oldroot.Append(meshanim); return(rc); }
override public void OnInspectorGUI() { this.serializedObject.Update(); EditorGUI.BeginDisabledGroup(Application.isPlaying); if (this.serializedObject.isEditingMultipleObjects) { EditorGUILayout.PropertyField(this.DirectionProperty, new GUIContent("Direction")); EditorGUILayout.PropertyField(this.AutoPlayProperty, new GUIContent("AutoPlay")); EditorGUILayout.PropertyField(this.LockedProperty, new GUIContent("Lock")); EditorGUILayout.PropertyField(this.IsLoopProperty, new GUIContent("Loop")); EditorGUILayout.PropertyField(this.FramerateProperty, new GUIContent("Framerate")); } else { MeshAnimator animator = this.serializedObject.targetObject as MeshAnimator; EditorGUILayout.PropertyField(this.DirectionProperty, new GUIContent("Direction")); FrameField(animator, new GUIContent("Frame")); EditorGUILayout.PropertyField(this.AutoPlayProperty, new GUIContent("AutoPlay")); EditorGUILayout.PropertyField(this.LockedProperty, new GUIContent("Lock")); EditorGUILayout.PropertyField(this.IsLoopProperty, new GUIContent("Loop")); EditorGUILayout.PropertyField(this.FramerateProperty, new GUIContent("Framerate")); } EditorGUI.EndDisabledGroup(); this.serializedObject.ApplyModifiedProperties(); // make sure the animators are up to date foreach (Object target in this.serializedObject.targetObjects) { MeshAnimator animator = null; animator = target as MeshAnimator; animator.Pull(); } }
private void Start() { _animator = GetComponentInChildren <MeshAnimator>(); enemyManager = GetComponentInParent <EnemyManager>(); InitialiseStateMachine(); }
public void Pause() { MeshAnimator animroot = _meshAnimRoot; if (animroot != null) { animroot.Stop(); } }
protected void SetTarget(Model root) { MeshAnimator tmp = _meshAnimRoot; if (tmp != null) { tmp.Target = root; } }
public MayaCacheFile(MeshAnimator root) : base() { _root = root; if (root == null) { _root = new MeshAnimator(); } }
public void Clear() { MeshAnimator tmp = _meshAnimRoot; if (tmp != null) { tmp.Clear(); } }
// ================================================================= // // Static Methods // ================================================================= // protected static int FrameField(MeshAnimator animator, GUIContent label) { int index = EditorGUILayout.IntSlider(label, animator.CurrentIndex, 0, animator.LastIndex); if (index != animator.CurrentIndex) { animator.Jump(index); } return(animator.CurrentIndex); }
public void OnMeshAnimatorStop(MeshAnimator animator) { if (this.StopAudioWithAnimation) { foreach (AudioPlayer audioPlayer in GetComponentsInChildren <AudioPlayer>()) { audioPlayer.Source.Stop(); } } }
public void OnMeshAnimatorJump(MeshAnimator animator) { if (animator.IsPlaying && this.Animation) { foreach (AudioAnimationElement element in this.Animation.ElementsAt(animator.CurrentIndex)) { PlayElement(element); } } }
public void Start() { MeshAnimator animroot = _meshAnimRoot; if (animroot != null) { animroot.Enable(Engine.ACTIVE); animroot.Start(); } }
// ================================================================= // // IMeshAnimatorObserver Methods // ================================================================= // public void OnMeshAnimatorJump(MeshAnimator animator) { #if SAGO_MESH_USE_SAGO_AUDIO if (animator.Animation && animator.IsPlaying) { foreach (AudioClip audioClip in animator.Animation.Frames[animator.CurrentIndex].AudioClips) { SagoAudio.AudioManager.Instance.Play(audioClip, this.GetComponent <Transform>()); } } #endif }
protected void AddMeshAnimators(Model root, Engine simroot) { try { if (root.IsClass((uint)SerialID.VX_Shape)) { Vixen.Shape shape = root as Vixen.Shape; Vixen.Geometry geo = shape.Geometry; if ((geo != null) && (geo.GetNumVtx() > 0)) { MeshAnimator meshanim; if (simroot.IsClass((uint)SerialID.VX_MeshAnimator)) { meshanim = simroot as MeshAnimator; } else { meshanim = new MeshAnimator(); meshanim.Name = root.Name + ".meshanim"; } meshanim.Target = geo; meshanim.Control = Engine.CONTROL_CHILDREN; meshanim.TimeInc = TimeInc; meshanim.Active = false; SharedWorld.Trace(meshanim.Name + " -> " + shape.Name); if (simroot != meshanim) { simroot.Append(meshanim); simroot = meshanim; } } } } catch (Exception ex) { SharedWorld.LogError(ex.Message); } root = root.First(); while (root != null) { AddMeshAnimators(root, simroot); root = root.Next(); } }
protected MeshAnimator AnimatorField(MeshAnimator value) { MeshAnimator[] animators; animators = new MeshAnimator[this.Mux.Animators.Length + 1]; animators[0] = null; this.Mux.Animators.CopyTo(animators, 1); string[] keys; keys = new string[this.Mux.Keys.Length + 1]; keys[0] = "None"; this.Mux.Keys.CopyTo(keys, 1); int index; index = Mathf.Max(System.Array.IndexOf(animators, value), 0); MeshAnimator animator; animator = animators[EditorGUILayout.Popup("Animator", index, keys)]; return(animator); }
protected void AddMeshSource(Model srcroot, Engine dstroot) { if (srcroot == null) { return; } if (dstroot.IsClass((uint)SerialID.VX_MeshAnimator)) { try { MeshAnimator meshanim = dstroot as MeshAnimator; Shape dstshape = meshanim.Target as Shape; String name = dstshape.Name; Shape srcshape; Mesh mesh; VertexArray verts; int p = name.IndexOf('.'); if (p > 0) { name = name.Substring(p); } srcshape = srcroot.Find(name, Group.FIND_DESCEND | Group.FIND_END) as Shape; mesh = srcshape.Geometry as Mesh; verts = mesh.Vertices; SharedWorld.Trace(meshanim.Name + " -> " + srcshape.Name); meshanim.SetSource(-1, verts); } catch (Exception ex) { SharedWorld.LogError(ex.Message); } } dstroot = dstroot.First() as Engine; while (dstroot != null) { AddMeshSource(srcroot, dstroot); dstroot = dstroot.Next() as Engine; } }
public void Record(bool record) { Scene scene = SharedWorld.MainScene; MeshAnimator animroot = _meshAnimRoot; if (animroot != null) { animroot.Stop(); if (record) { if (TimeInc > 0) { scene.TimeInc = TimeInc; } animroot.Enable(MeshAnimator.RECORD); } else { animroot.Disable(MeshAnimator.RECORD); scene.TimeInc = 0.0f; } } }
/// <summary> /// Calculates the full bounds of every frame of the animation. /// </summary> /// <returns>The full bounds.</returns> /// <param name="animator">Animator.</param> public static Bounds CalcFullBounds(this MeshAnimator animator) { Transform animT = animator.transform; Bounds bounds = new Bounds(animT.position, Vector3.zero); foreach (MeshAnimationFrame frame in animator.Animation.Frames) { foreach (var mesh in frame.Meshes) { Bounds meshBounds = mesh.bounds; Vector3[] corners = new Vector3[] { meshBounds.min, meshBounds.max, new Vector3(meshBounds.min.x, meshBounds.max.y), new Vector3(meshBounds.max.x, meshBounds.min.y) }; Vector3 min = new Vector3(Mathf.Infinity, Mathf.Infinity, 1f); Vector3 max = new Vector3(Mathf.NegativeInfinity, Mathf.NegativeInfinity, 1f); for (int i = 0; i < corners.Length; ++i) { corners[i] = animT.TransformPoint(corners[i]); min = Vector3.Min(min, corners[i]); max = Vector3.Max(max, corners[i]); } meshBounds.SetMinMax(min, max); bounds.Encapsulate(meshBounds); } } return(bounds); }
public MayaCacheFile() : base() { _root = new MeshAnimator(); }
override protected void Reset() { base.Reset(); this.IntroAnimator = GetComponentInChildren <MeshAnimator>(); this.NextSceneName = "Title"; }
/*! * Loads a Maya geometry cache for cloth presimulation. * @param g Garment which is being simulated by the cache * @param url URL or path to the cache description file (XML) * @param text if not null, this parameter is used as the XML cache description * @param scriptor Scriptor object to add this animation to * * @returns true if cache successfully loaded and connected, else false */ public static bool LoadMayaCache(Garment g, String url, String text, Scriptor scriptor) { dynamic d = g; if (g == null) { return(false); } if ((g.ClothSim == null) || !g.ClothSim.IsClass((uint)SerialID.VX_MeshAnimator)) { return(false); } LoadSceneEvent loadevent; string name = Path.GetFileNameWithoutExtension(url); MeshAnimator clothsim = g.ClothSim.Clone() as MeshAnimator; Animator anim; MayaIO.MayaCacheFile import = new MayaIO.MayaCacheFile(clothsim); String engname = d.name + ".meshanim"; String animname; /* * Make a MeshAnimator to control the cloth vertices in the cloth mesh. * The mesh sequence will be loaded into this engine. */ clothsim.Name = name; if (clothsim.Target == null) { clothsim.Target = g.ClothMesh; } /* * Make an Animator to control the mesh animation we are loading. * It is attached to the Scriptor that should control it. */ name += "." + engname; animname = name + ".anim"; anim = scriptor.MakeAnim(name, g.ClothMesh, false); anim.SetEngineName(engname); anim.SetFileName(url); SharedWorld.Get().Observe(Event.LOAD_SCENE, anim); /* * Make a load event to signal the mesh animation has been loaded. * The event will come from the Animator and will contain the * MeshAnimator with the mesh sequences loaded. */ loadevent = new LoadSceneEvent(Event.LOAD_SCENE); loadevent.Sender = anim; if (loadevent.Sender == null) { loadevent.Sender = clothsim; } loadevent.Object = clothsim; loadevent.FileName = url; /* * Start the import of the Maya me4sh sequence. * This occurs asynchronously in a separate thread. */ if (text != null) { import.FileName = url; import.LoadString(text, loadevent); } else { import.LoadFile(url, loadevent); } return(true); }
public void OnMeshAnimatorPlay(MeshAnimator animator) { OnMeshAnimatorJump(animator); }
public void OnMeshAnimatorStop(MeshAnimator animator) { }
public void OnMeshAnimatorPlay(MeshAnimator animator) { this.Animation = this.GetNextAudioAnimation(); OnMeshAnimatorJump(animator); }