private static void WriteFrameChildren(XFrame frame, XofFileSaveData child) { if (frame.TransformMatrix != null) { WriteFrameTransformMatrix(frame, child); } foreach (var subFrame in frame.Frames) { WriteFrame(subFrame, child); } foreach (var mesh in frame.Meshes) { WriteMesh(mesh, child); } foreach (var frameMeshName in frame.MeshesNames) { WriteFrameMeshName(frameMeshName, child); } if (frame.CameraRotationScaler != 1.0f || frame.CameraMoveScaler != 1.0f) { WriteFrameCamera(frame, child); } }
private static void WriteFrame(XFrame frame, XofFileSaveData saveData) { using (var child = saveData.AddData(XofFileDefaultTemplates.FrameId, frame.Name, null, null)) { WriteFrameChildren(frame, child); } }
private static void WriteFrameTransformMatrix(XFrame frame, XofFileSaveData saveData) { byte[] data; using (var ms = new MemoryStream()) using (var writer = new BinaryWriter(ms)) { WriteMatrix4x4(frame.TransformMatrix, writer); data = ms.ToArray(); } using (saveData.AddData(XofFileDefaultTemplates.FrameTransformMatrixId, null, null, data)) { } }
private static void WriteFrameCamera(XFrame frame, XofFileSaveData saveData) { byte[] data; using (var ms = new MemoryStream()) using (var writer = new BinaryWriter(ms)) { writer.Write(frame.CameraRotationScaler); writer.Write(frame.CameraMoveScaler); data = ms.ToArray(); } using (saveData.AddData(XofFileDefaultTemplates.FrameMeshNameId, null, null, data)) { } }
private static void ReadFrameTransformMatrix(XFrame frame, XofFileEnumData enumData) { byte[] data = enumData.GetData(); using (var ms = new MemoryStream(data, false)) using (var reader = new BinaryReader(ms)) { frame.TransformMatrix = ReadMatrix4x4(reader); if (ms.Position != ms.Length) { throw new InvalidDataException(); } } if (enumData.GetChildrenCount() != 0) { throw new InvalidDataException(); } }
private static void ReadFrameCamera(XFrame frame, XofFileEnumData enumData) { byte[] data = enumData.GetData(); using (var ms = new MemoryStream(data, false)) using (var reader = new BinaryReader(ms)) { frame.CameraRotationScaler = reader.ReadSingle(); frame.CameraMoveScaler = reader.ReadSingle(); if (ms.Position != ms.Length) { throw new InvalidDataException(); } } if (enumData.GetChildrenCount() != 0) { throw new InvalidDataException(); } }
private static void ReadFrameMeshName(XFrame frame, XofFileEnumData enumData) { byte[] data = enumData.GetData(); using (var ms = new MemoryStream(data, false)) using (var reader = new BinaryReader(ms)) { int renderPass = reader.ReadInt32(); string fileName = ReadString(reader); frame.MeshesNames.Add(renderPass, fileName); if (ms.Position != ms.Length) { throw new InvalidDataException(); } } if (enumData.GetChildrenCount() != 0) { throw new InvalidDataException(); } }
private static XFrame ReadFrame(XofFileEnumData enumData) { var frame = new XFrame { Name = enumData.GetName() }; byte[] data = enumData.GetData(); if (data.Length != 0) { throw new InvalidDataException(); } bool frameTransformMatrixRead = false; bool frameCameraRead = false; int childrenCount = enumData.GetChildrenCount(); for (int childIndex = 0; childIndex < childrenCount; childIndex++) { using (var child = enumData.GetChild(childIndex)) { Guid type = child.GetTemplateType(); if (type == XofFileDefaultTemplates.FrameTransformMatrixId) { if (frameTransformMatrixRead) { throw new InvalidDataException(); } ReadFrameTransformMatrix(frame, child); frameTransformMatrixRead = true; } else if (type == XofFileDefaultTemplates.FrameId) { frame.Frames.Add(ReadFrame(child)); } else if (type == XofFileDefaultTemplates.MeshId) { frame.Meshes.Add(ReadMesh(child)); } else if (type == XofFileDefaultTemplates.FrameMeshNameId) { ReadFrameMeshName(frame, child); } else if (type == XofFileDefaultTemplates.FrameCameraId) { if (frameCameraRead) { throw new InvalidDataException(); } ReadFrameCamera(frame, child); frameCameraRead = true; } else { throw new InvalidDataException(); } } } return(frame); }