using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO; namespace VertexAnimationTools_30 { public class PointCacheData { public string Name; public FramesArray Frames; public PointCache.Clip clip; PointCache.Clip.ImportSettings cis; public PointCache pointCache; public int geometryVerticesCount; public bool IsMeshSequence; TasksStack tstack; public PointCacheData(PointCache.Clip _clip, PointCache _pointCache, int _geometryVerticesCount) { clip = _clip; cis = clip.PreImport; pointCache = _pointCache; geometryVerticesCount = _geometryVerticesCount; IsMeshSequence = Path.GetExtension(cis.FilePath) == ".obj"; tstack = new TasksStack(string.Format("Build clip {0} data", cis.Name)); if (IsMeshSequence) { MeshSequenceInfo msi = new MeshSequenceInfo(cis.FilePath, MeshSequenceInfo.SortModeEnum.ByNumber); tstack.Add("Read .obj sequence", msi.infos.Length + cis.TransitionFramesCount, 3f ); } else { tstack.Add("Read .pc2 file", cis.ImportRangeLength + cis.TransitionFramesCount); } if (cis.ChangeFramesCount) { tstack.Add("Change frames count", cis.ClampedCustomFramesCount); } if (cis.EnableMotionSmoothing) { tstack.Add("Motion smoothing", geometryVerticesCount); } if (cis.EnableNormalizeSpeed) { tstack.Add("Normalize speed", geometryVerticesCount); } if (cis.GenerageMotionPaths) { tstack.Add("Generage Motion Paths", geometryVerticesCount); } tstack.Normalize(); } Vector3[] ReadFrame(BinaryReader br, int vertsCount ) { Vector3[] vertices = new Vector3[vertsCount]; for (int v = 0; v < vertsCount; v++) { Vector3 pos = new Vector3(); pos.x = br.ReadSingle(); pos.y = br.ReadSingle(); pos.z = br.ReadSingle(); if (cis.SwapYZAxis) { pos.Set(pos.x, pos.z, pos.y); } pos = pos * cis.Scale; vertices[v] = pos; } return vertices; } public IEnumerable Build (){ Frames = new FramesArray(cis.IsLoop, cis.SubFrameInterpolation); FramesArray TransitionFrames = new FramesArray(false, InterpolateModeEnum.Linear); int readFramesCounter = 0; if (IsMeshSequence) { MeshSequenceInfo msi = new MeshSequenceInfo( cis.FilePath, MeshSequenceInfo.SortModeEnum.ByNumber ); for (int f = cis.EndTransitionFrom; f mPathVertList = new List(); cis.MotionPathsIndexStep = Mathf.Clamp(cis.MotionPathsIndexStep, 1, 1000); for (int v = 0; v< Frames.VerticesCount; v+= cis.MotionPathsIndexStep) { for (int f = 0; f < Frames.Count; f++) { mPathVertList.Add(Frames[f, v]); } clip.MotionPathsCount++; yield return tstack["Generage Motion Paths"].GetInfo(v); } clip.MotionPathVertices = mPathVertList.ToArray(); } yield return new TaskInfo("done", 1f); } public Vector3[] GetFrameVertices(int frameIdx ){ Vector3[] result = new Vector3[Frames.VerticesCount]; for(int v = 0; v