public void AddAnimation(MeshAnimation anim) { actionFrameDict.Add("normal", anim); pictName = anim.texture; imageWidth = anim.imageWidth; imageHeight = anim.imageHeight; }
public MeshAnimation createAnimation(string imageName, int start, int end, float delay, bool isLoop = true) { List <SpriteFrame> animFrames = new List <SpriteFrame>(); if (start <= 0 && end <= 0) { SpriteFrame frame = SpriteFrameCache.getInstance().getSpriteFrame(imageName + ".png"); if (frame != null) { animFrames.Add(frame); } } else { for (int i = start; i <= end; i++) { SpriteFrame frame = SpriteFrameCache.getInstance().getSpriteFrame(imageName + i + ".png"); if (frame != null) { animFrames.Add(frame); } } } MeshAnimation anim = new MeshAnimation(); anim.createWithSpriteFrames(animFrames, delay, isLoop); return(anim); }
public void AddAnimation(MeshAnimation anim, string animName) { actionFrameDict.Add(animName, anim); pictName = anim.texture; imageWidth = anim.imageWidth; imageHeight = anim.imageHeight; }
private static MeshAnimation CreateWavingMeshAnimationWith60Fps() { const float WavingAnimationFramesPerSecond = 60; MeshAnimation animation = CreateAnimationWith75Frames(WavingAnimationFramesPerSecond); animation.LoadData(GetWavingAnimationData(WavingAnimationFramesPerSecond)); return(animation); }
public void CreateMeshAnimationByCreationData() { MeshAnimation animation = CreateAnimationWith75Frames(FramesPerSecond); Assert.AreEqual(NumberOfAnimationFrames, animation.NumberOfFrames); Assert.AreEqual(FramesPerSecond, animation.FramesPerSecond); Assert.AreEqual(NumberOfAnimationFrames, animation.Frames.Length); Assert.AreEqual(3, animation.Duration); }
private void DrawRenderTexture(MeshAnimation animation, int index, int width, int height) { if (animation && index >= 0 && index < animation.Frames.Length && width > 0 && height > 0) { RenderTexture.active = RenderTexture; Graphics.SetRenderTarget(RenderTexture); SagoMeshEditor.MeshAnimationEditor.DrawPreviewNow(animation, width, height, index); RenderTexture.active = null; } }
/// <summary> /// 停止动画 /// </summary> public void stopAnimate() { this.curActionName = ""; this.curAnimation = null; this.delay = 0.1f; this.isLoop = false; this.maxFrameNum = 1; this.curTime = 0; this.FrameNum = 0; this.active = false; }
// ================================================================= // // Methods // ================================================================= // override public string GetInfoString() { MeshAnimation animation = this.target as MeshAnimation; return(string.Format("{0} Frame{1} - {2} FPS - {3:0.0} Seconds", animation.Frames.Length, animation.Frames.Length == 0 ? "" : "s", animation.FramesPerSecond, animation.Duration )); }
private void WriteMeshAnimation(StringWriter writer, MeshAnimation animation) { var startDelay = animation.StartDelay; var resetTime = animation.ResetTime; var rotationSpeed = animation.RotationSpeed; var translationSpeed = animation.TranslationSpeed; writer.WriteLine("animation " + startDelay + " " + resetTime + " " + rotationSpeed.x + " " + rotationSpeed.y + " " + rotationSpeed.z + " " + translationSpeed.x + " " + translationSpeed.y + " " + translationSpeed.z); }
private void Awake() { if (!AnimPlayer.useMeshanim) { return; } this.curranimator = base.gameObject.GetComponentInChildren <Animator>(); this.currskrenderers = base.gameObject.GetComponentsInChildren <SkinnedMeshRenderer>(); this.mr = this.meshanim[0].GetComponent <MeshRenderer>(); this.ma = this.meshanim[0].GetComponent <MeshAnimation>(); }
public static Material DrawPreviewMaterial() { MeshAnimation animation = ScriptableObject.CreateInstance <MeshAnimation>(); string animationPath = AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(animation)); DestroyImmediate(animation, false); string materialPath; materialPath = animationPath.Replace("Scripts/MeshAnimation.cs", "Materials/OpaqueMesh.mat"); return(AssetDatabase.LoadAssetAtPath(materialPath, typeof(Material)) as Material); }
//创建一个不包含动作的动画 public void addAnimation(MeshAnimation animation, string name) { if (_animations.ContainsKey(name)) { MyAnimation anim = _animations[name]; anim.AddAnimation(animation); } else { MyAnimation anim = new MyAnimation(); anim.AddAnimation(animation); _animations.Add(name, anim); } }
//创建一个包含多个动作的动画 public void addAnimation(MeshAnimation animation, string name, string actionName) { //若该生物已创建,则只需要在对应动作增加 if (_animations.ContainsKey(name)) { MyAnimation anim = _animations[name]; anim.AddAnimation(animation, actionName); } //若该生物未创建,创建该生物,并增加对应动作 else { MyAnimation anim = new MyAnimation(); anim.AddAnimation(animation, actionName); _animations.Add(name, anim); } }
protected static GameObject CreateParts(GameObject gm, Vector3 ps, Quaternion rot, string partName, Material material) { Transform transform = gm.transform.FindChild(partName); if (null == transform) { GameObject gameObject = new GameObject(partName); gameObject.transform.parent = gm.transform; gameObject.transform.localPosition = Vector3.zero; MeshAnimation meshAnimation = gameObject.AddComponent <MeshAnimation>(); gameObject.AddComponent <MeshFilter>(); MeshRenderer meshRenderer = gameObject.AddComponent <MeshRenderer>(); meshRenderer.material = material; return(gameObject); } return(transform.gameObject); }
public void ResetAnimateVariable(string actionName, bool active) { this.curActionName = actionName; this.curAnimation = anim.getMeshAnimation(curActionName); if (this.curAnimation == null) { this.delay = 0.1f; this.isLoop = true; this.curAnimationFrameNum = 1; } else { this.delay = curAnimation.delay; this.isLoop = curAnimation.loop; this.curAnimationFrameNum = curAnimation.frameList.Count; } this.curTime = 0; this.FrameNum = 0; this.active = active; }
/// <summary> /// 开始动画 /// </summary> /// <param name="actionName">动作名</param> /// <param name="animTime">动画播放时间</param> public void startAnimate(string actionName, float animTime = 0) { MeshAnimation temp = anim.getMeshAnimation(actionName); if (temp == null) { stopAnimate(); return; } this.curActionName = actionName; this.curAnimation = temp; this.maxFrameNum = curAnimation.frameList.Count; Debug.Log("maxFrameNum = " + this.maxFrameNum); float frameDelta = animTime / this.maxFrameNum; this.delay = (frameDelta > 0) ? frameDelta : curAnimation.delay; this.isLoop = curAnimation.loop; this.curTime = 0; this.FrameNum = 0; this.active = true; }
void Finish() { DestroyImmediate(_MeshAnimation); _MeshAnimation = null; }
void OnGUI() { if (outputFilePath == null) { outputFolderPath = Application.streamingAssetsPath; } if (exportSettings == null) { exportSettings = new MeshAnimation(); } windowWidth = position.width; mainScrollPosition = EditorGUILayout.BeginScrollView(mainScrollPosition); //烘培定义角度转向 eulerAngle = EditorGUILayout.Vector3Field("Bake model after apply Rotation Offset XYZ", eulerAngle); EditorGUILayout.Space(); //默认路径 string defultPath = DEFAULT_OUTPUT_FOLDER; outputFilePath = defultPath; outputFolderPath = Path.GetDirectoryName(defultPath); EditorGUILayout.LabelField("Default Folder:" + outputFolderPath); EditorGUILayout.Space(); #region Base FBX File Setting EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField("Base FBX:", GUILayout.Width(EditorGUIUtility.labelWidth - 4)); GameObject newFbx = EditorGUILayout.ObjectField(fbx, typeof(GameObject), true) as GameObject; if (newFbx != null && newFbx != fbx) { // error if they drag the prefab itself, since it won't have any transform data if (PrefabUtility.GetPrefabParent(newFbx) != null) { fbx = newFbx; exportSettings.AnalysisFbx(newFbx, Quaternion.identity); guiNumberOfClips = exportSettings.GetClipCount(); guiNumberOfBones = exportSettings.GetBones(); } } } EditorGUILayout.EndHorizontal(); #endregion EditorGUILayout.Space(); #region Framerate Setting EditorGUILayout.FloatField("Capture Framerate:", IGGUtil.framerate); #endregion EditorGUILayout.Space(); #region Clip Count Setting guiNumberOfClips = EditorGUILayout.IntField("Number of Clips:", guiNumberOfClips); #endregion EditorGUILayout.Space(); labelWidth = GUILayout.Width(windowWidth * 0.35f); #region Animation Clip Setting EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField("Animation Name:", labelWidth); EditorGUILayout.LabelField("Animation File:", labelWidth); EditorGUILayout.LabelField("Frames:", GUILayout.Width(windowWidth * 0.2f)); } EditorGUILayout.EndHorizontal(); DrawAnimationArrayGui(); #endregion EditorGUILayout.Space(); #region Bone Count Setting guiNumberOfBones = EditorGUILayout.IntField("Number of Bones:", guiNumberOfBones); #endregion #region Clear and Save Buttons EditorGUILayout.BeginHorizontal(); { if (GUILayout.Button("Export_CPU_RGBA")) { //Save if (eulerAngle != Vector3.zero) { quaternion = Quaternion.Euler(eulerAngle); } CpuAniMesh_RGBAHalfExport exp = new CpuAniMesh_RGBAHalfExport(); exp.SetAniMeshData(exportSettings); exp.Export(outputFolderPath, quaternion, fbx.name); } if (GUILayout.Button("Export_GPU_RGBAHalf")) { //Save if (eulerAngle != Vector3.zero) { quaternion = Quaternion.Euler(eulerAngle); } GpuAniMesh_RGBAHalfExport exp = new GpuAniMesh_RGBAHalfExport(); exp.SetAniMeshData(exportSettings); exp.Export(outputFolderPath, quaternion, fbx.name); } if (GUILayout.Button("Export_GPU_3RHalf")) { //Save if (eulerAngle != Vector3.zero) { quaternion = Quaternion.Euler(eulerAngle); } GpuAniMesh_3RHalfExport exp = new GpuAniMesh_3RHalfExport(); exp.SetAniMeshData(exportSettings); exp.Export(outputFolderPath, quaternion, fbx.name); } if (GUILayout.Button("Export_GPU_RGBM")) { //Save if (eulerAngle != Vector3.zero) { quaternion = Quaternion.Euler(eulerAngle); } GpuAniMesh_RGBMExport exp = new GpuAniMesh_RGBMExport(); exp.SetAniMeshData(exportSettings); exp.Export(outputFolderPath, quaternion, fbx.name); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { if (GUILayout.Button("Export_CPUSkin")) { //Save if (eulerAngle != Vector3.zero) { quaternion = Quaternion.Euler(eulerAngle); } CpuSkin_RGBAExport exp = new CpuSkin_RGBAExport(); exp.SetAniMeshData(exportSettings); exp.Export(outputFolderPath, quaternion, fbx.name); } if (GUILayout.Button("Export_GPUSkin")) { //Save if (eulerAngle != Vector3.zero) { quaternion = Quaternion.Euler(eulerAngle); } GpuSkin_RGBAExport exp = new GpuSkin_RGBAExport(); exp.SetAniMeshData(exportSettings); exp.Export(outputFolderPath, quaternion, fbx.name); } if (GUILayout.Button("Export_GPUSkinInstance")) { //Save if (eulerAngle != Vector3.zero) { quaternion = Quaternion.Euler(eulerAngle); } GpuSkinInstance_Export exp = new GpuSkinInstance_Export(); exp.SetAniMeshData(exportSettings); exp.Export(outputFolderPath, quaternion, fbx.name); } } EditorGUILayout.EndHorizontal(); #endregion EditorGUILayout.EndScrollView(); }
public bool SampleAnimation(UnityEngine.Animation animation) { if (animation == null) { return(false); } SkinnedMeshRenderer skinnedMeshRenderer = animation.GetComponentInChildren <SkinnedMeshRenderer>(); if (skinnedMeshRenderer == null) { return(false); } Mesh mesh = skinnedMeshRenderer.sharedMesh; if (mesh == null) { return(false); } this.animation = new MeshAnimation(); this.animation.triangles = mesh.triangles; this.animation.normals = mesh.normals; this.animation.uv = mesh.uv; List <string> clipNames = new List <string>(); foreach (AnimationState animationState in animation) { clipNames.Add(animationState.name); } Mesh bakedMesh = new Mesh(); int numClips = clipNames.Count; for (int i = 0; i < numClips; ++i) { string clipName = clipNames[i]; if (this.animation.clips.ContainsKey(clipName)) { Debug.LogError("Repeated name of AnimationClip:" + clipName); continue; } animation.Play(clipName); { AnimationState animationState = animation[clipName]; Clip clip = new Clip(); clip.wrapMode = animationState.wrapMode; this.animation.clips.Add(clipName, clip); float length = animationState.length; float step = 1.0f / fps; for (float time = 0; time < length; time += step) { Keyframe keyframe = new Keyframe(); clip.keyframes.Add(keyframe); animationState.time = time; animation.Sample(); skinnedMeshRenderer.BakeMesh(bakedMesh); keyframe.vertices = bakedMesh.vertices; } } animation.Stop(clipName); } return(true); }
// ================================================================= // // Static Methods // ================================================================= // public static void DrawPreviewNow(MeshAnimation animation, int width, int height, int frame) { try { // setup the context GL.PushMatrix(); GL.LoadPixelMatrix(0, width, 0, height); GL.Clear(true, true, Color.clear); // set the active material Material material; material = DrawPreviewMaterial(); if (material != null) { material.SetPass(0); } // draw the frame if (animation != null && animation.Frames != null && animation.Frames.Length >= 0) { // calculate scale Vector2 nativeSize = animation.ContentSize * animation.PixelsPerMeter; float scale = Mathf.Min(width / nativeSize.x, height / nativeSize.y); Vector2 scaledSize = nativeSize * scale; // calculate matrix Matrix4x4 matrix = Matrix4x4.TRS( new Vector3(scaledSize.x * animation.AnchorPoint.x, scaledSize.y * animation.AnchorPoint.y, 0f), Quaternion.identity, new Vector3(scale, scale, 1) * animation.PixelsPerMeter ); // calculate frame index int frameIndex = 0; if (animation.Frames.Length == 0) { // TODO: error, frames should not be empty... } else if (animation.Frames.Length == 1) { frameIndex = 0; } else { frameIndex = frame % animation.Frames.Length; frameIndex += frameIndex < 0 ? animation.Frames.Length : 0; } // loop through each layer in the frame for (int layerIndex = animation.Layers.Length - 1; layerIndex >= 0; layerIndex--) { // draw the mesh Mesh mesh; mesh = animation.Frames[frameIndex].Meshes[layerIndex]; if (mesh != null) { Graphics.DrawMeshNow(mesh, matrix); } } } } catch (System.Exception e) { throw e; } finally { // clear the context GL.PopMatrix(); } }
// 设置mesh ani 数据 public void SetAniMeshData(MeshAnimation aniMesh) { m_AniMesh = aniMesh; }
//重新设置某个动作的时长 public void SetAnimateTime(string actionName, float time) { MeshAnimation temp = anim.getMeshAnimation(actionName); temp.setAnimTime(time); }
private void ResetSettings() { exportSettings = new MeshAnimation(); }
public void AddAnimation(MeshAnimation anim) { actionFrameDict.Add("normal", anim); pictName = anim.texture; }
// Start is called before the first frame update void Start() { meshAnimation = SceneLoader.INSTANCE.MeshAnimation; theObject = SceneLoader.INSTANCE.ActiveObject; CustomEventHandler.INSTANCE.ObjectNotDetected(); }
public void AddAnimation(MeshAnimation anim, string animName) { actionFrameDict.Add(animName, anim); pictName = anim.texture; }
public void OnEnable() { _MeshAnimation = (MeshAnimation)target; _BoneName = ""; _IsAddSubBone = false; }