public ImportSettings(bool isPreImport) { PathToObj = ""; MSI = new MeshSequenceInfo("", MeshSequenceInfo.SortModeEnum.ByNumber); ImportCustomRange = false; ImportFromFrame = 0; ImportToFrame = 1; SwapYZAxis = false; PivotOffset = Vector3.zero; ScaleFactor = 1; FlipNormals = false; ImportUV = true; CalculateNormals = true; CalculateTangents = true; SmoothingGroupImportMode = ObjData.SmoothingGroupImportModeEnum.FromObjFile; NormalRecalculationMode = ObjData.NormalsRecalculationModeEnum.Default; MeshCompression = 0; OptimizeMesh = false; #if UNITY_2017_3_OR_NEWER IndexFormat = UnityEngine.Rendering.IndexFormat.UInt16; #endif GenerateMaterials = true; VColorSettings = new ObjData.VertexColorsSettings(false); NormalizedPerFrame = 0; FilesSortMode = MeshSequenceInfo.SortModeEnum.ByNumber; ImportDate = "none"; }
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(); }
bool GetPointCacheSourceStatistic(string path, ref string name, ref int vertCount, ref int framesCount, ref string message) { string extension = System.IO.Path.GetExtension(path); if (extension == ".obj") { MeshSequenceInfo msi = new MeshSequenceInfo(path, MeshSequenceInfo.SortModeEnum.ByNumber); name = msi.SequenceName; framesCount = msi.infos.Length; vertCount = 0; ObjData.GetObjInfo(path, ref vertCount); return(true); } else { name = (new System.IO.FileInfo(path)).Name; System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open); System.IO.BinaryReader binReader = new System.IO.BinaryReader(fs); binReader.ReadChars(12); binReader.ReadInt32(); vertCount = binReader.ReadInt32(); binReader.ReadSingle(); //start frame binReader.ReadSingle(); //sample rate framesCount = binReader.ReadInt32(); #if UNITY_WSA binReader.Dispose(); fs.Dispose(); #else binReader.Close(); fs.Close(); #endif return(vertCount > 0 && framesCount > 0); } }
public IEnumerable <TaskInfo> 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 < cis.EndTransitionTo; f++) { Vector3[] objVertices = ObjData.GetVerticesFromObj(msi.infos[f].fi.FullName, cis.SwapYZAxis, cis.Scale); TransitionFrames.AddFrame(objVertices); readFramesCounter++; yield return(tstack["Read .obj sequence"].GetInfo(readFramesCounter)); } for (int f = cis.ImportRangeFrom; f < cis.ImportRangeTo; f++) { Vector3[] objVertices = ObjData.GetVerticesFromObj(msi.infos[f].fi.FullName, cis.SwapYZAxis, cis.Scale); if (objVertices.Length != geometryVerticesCount) { yield return(new TaskInfo(string.Format("Error: frame {0} vertex count mismatch", msi.infos[f].fi.FullName), -1)); } Frames.AddFrame(objVertices); readFramesCounter++; yield return(tstack["Read .obj sequence"].GetInfo(readFramesCounter)); } for (int f = cis.BeginTransitionFrom; f < cis.BeginTransitionTo; f++) { Vector3[] objVertices = ObjData.GetVerticesFromObj(msi.infos[f].fi.FullName, cis.SwapYZAxis, cis.Scale); TransitionFrames.AddFrame(objVertices); readFramesCounter++; yield return(tstack["Read .obj sequence"].GetInfo(readFramesCounter)); } } else { Name = (new FileInfo(cis.FilePath)).Name; FileStream fs = new FileStream(cis.FilePath, FileMode.Open); BinaryReader binReader = new BinaryReader(fs); binReader.ReadChars(12); //signature binReader.ReadInt32(); //file version int VerticesCount = binReader.ReadInt32(); binReader.ReadSingle(); // start frame binReader.ReadSingle(); //sample rate binReader.ReadInt32(); // int sourceFramesCount; for (int f = 0; f < cis.EndTransitionFrom; f++) { for (int v = 0; v < VerticesCount; v++) { binReader.ReadSingle(); binReader.ReadSingle(); binReader.ReadSingle(); } } // end transition for (int f = cis.EndTransitionFrom; f < cis.EndTransitionTo; f++) { TransitionFrames.AddFrame(ReadFrame(binReader, geometryVerticesCount)); readFramesCounter++; yield return(tstack["Read .pc2 file"].GetInfo(readFramesCounter)); } // frames for (int f = cis.ImportRangeFrom; f < cis.ImportRangeTo; f++) { Frames.AddFrame(ReadFrame(binReader, geometryVerticesCount)); readFramesCounter++; yield return(tstack["Read .pc2 file"].GetInfo(readFramesCounter)); } // begin transition for (int f = cis.BeginTransitionFrom; f < cis.BeginTransitionTo; f++) { TransitionFrames.AddFrame(ReadFrame(binReader, geometryVerticesCount)); readFramesCounter++; yield return(tstack["Read .pc2 file"].GetInfo(readFramesCounter)); } #if UNITY_WSA binReader.Dispose(); fs.Dispose(); #else binReader.Close(); fs.Close(); #endif } if (cis.TransitionMode == TransitionModeEnum.Begin) { for (int f = 0; f < TransitionFrames.Count; f++) { float flv = f / (float)TransitionFrames.Count; flv = Extension.LinearToSin(flv); for (int v = 0; v < geometryVerticesCount; v++) { Vector3 sVert = Vector3.LerpUnclamped(TransitionFrames[f, v], Frames[f, v], flv); Frames[f, v] = sVert; } } } if (cis.TransitionMode == TransitionModeEnum.End) { for (int f = 0; f < TransitionFrames.Count; f++) { float flv = f / (float)TransitionFrames.Count; flv = Extension.LinearToSin(flv); int frameIdx = Frames.Count - f - 1; int transitionIdx = TransitionFrames.Count - f - 1; for (int v = 0; v < geometryVerticesCount; v++) { Vector3 sVert = Vector3.LerpUnclamped(TransitionFrames[transitionIdx, v], Frames[frameIdx, v], flv); Frames[frameIdx, v] = sVert; } } } if (cis.ChangeFramesCount) { FramesArray retimedFrames = new FramesArray(cis.ClampedCustomFramesCount, Frames.VerticesCount, cis.IsLoop, cis.SubFrameInterpolation); float step = cis.IsLoop ? 1f / (float)cis.CustomFramesCount : 1f / (cis.ClampedCustomFramesCount - 1); for (int f = 0; f < retimedFrames.Count; f++) { float persentage = f * step; for (int v = 0; v < Frames.VerticesCount; v++) { retimedFrames[f, v] = Frames[persentage, v]; } yield return(tstack["Change frames count"].GetInfo(f)); } Frames = retimedFrames; } if (cis.EnableMotionSmoothing) { foreach (TaskInfo ti in Frames.SmoothIE(cis.MotionSmoothIterations, cis.MotionSmoothAmountMin, cis.MotionSmoothAmountMax, cis.MotionSmoothEaseOffset, cis.MotionSmoothEaseLength)) { yield return(tstack["Motion smoothing"].GetInfo(ti.Persentage)); } } if (cis.EnableNormalizeSpeed) { for (int v = 0; v < Frames.VerticesCount; v++) { Vector3[] modified = Frames[v]; if (cis.IsLoop) { Vector3[] modifiedLooped = new Vector3[modified.Length + 1]; modified.CopyTo(modifiedLooped, 0); modifiedLooped[modifiedLooped.Length - 1] = modifiedLooped[0]; modified = modifiedLooped; } NormalizedSpline ns = new NormalizedSpline(modified); float stepMult = 1f / (modified.Length - 1); for (int f = 0; f < modified.Length; f++) { modified[f] = Vector3.LerpUnclamped(modified[f], ns.GetPoint(f * stepMult), cis.NormalizeSpeedPercentage); } Frames[v] = modified; yield return(tstack["Normalize speed"].GetInfo(v)); } } clip.MotionPathVertices = null; clip.MotionPathsCount = 0; if (cis.GenerageMotionPaths) { List <Vector3> mPathVertList = new List <Vector3>(); 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)); }