public static Dictionary <string, dynamic> parseGameObj(CrpReader reader, bool saveFile, string saveFileName, long fileSize, bool verbose) { Dictionary <string, dynamic> retVal = new Dictionary <string, dynamic>(); long fileContentBegin = reader.BaseStream.Position; retVal["tag"] = reader.ReadString(); retVal["layer"] = reader.ReadInt32(); retVal["enabled"] = reader.ReadBoolean(); int numProperties = reader.ReadInt32(); for (int i = 0; i < numProperties; i++) { bool isNull = reader.ReadBoolean(); if (!isNull) { string assemblyQualifiedName = reader.ReadString(); string propertyType = assemblyQualifiedName.Split(new char[] { ',' })[0]; string propertyName = i + "_" + propertyType; if (propertyType.Contains("[]")) { retVal[propertyName] = reader.readUnityArray(propertyType); } else { retVal[propertyName] = reader.readUnityObj(propertyType); } } } if ((reader.BaseStream.Position - fileContentBegin) != fileSize) { int bytesToRead = (int)(fileSize - (reader.BaseStream.Position - fileContentBegin)); reader.ReadBytes(bytesToRead); } string json = JsonConvert.SerializeObject(retVal, Formatting.Indented, new Newtonsoft.Json.Converters.StringEnumConverter()); if (verbose) { Console.WriteLine(json); } if (saveFile) { StreamWriter file = new StreamWriter(new FileStream(saveFileName + ".json", FileMode.Create)); file.Write(json); file.Close(); } return(retVal); }
public static Dictionary<string, dynamic> parseInfoGen(CrpReader reader, bool saveFile, string saveFileName, long fileSize, bool verbose) { Dictionary<string, dynamic> retVal = new Dictionary<string, dynamic>(); long fileContentBegin = reader.BaseStream.Position; int numProperties = reader.ReadInt32(); for (int i = 0; i < numProperties; i++) { bool isNull = reader.ReadBoolean(); if (!isNull) { string assemblyQualifiedName = reader.ReadString(); string propertyType = assemblyQualifiedName.Split(new char[] { ',' })[0]; string propertyName = reader.ReadString(); if (propertyType.Contains("[]")) { retVal[propertyName] = reader.readUnityArray(propertyType); } else { retVal[propertyName] = reader.readUnityObj(propertyType); } } } if ((reader.BaseStream.Position - fileContentBegin) != fileSize) { int bytesToRead = (int)(fileSize - (reader.BaseStream.Position - fileContentBegin)); reader.ReadBytes(bytesToRead); } string json = JsonConvert.SerializeObject(retVal, Formatting.Indented, new Newtonsoft.Json.Converters.StringEnumConverter()); string fileName = saveFileName + ".json"; if (verbose) { Console.WriteLine("Read info file {0}", fileName); Console.WriteLine(json); } if (saveFile) { StreamWriter file = new StreamWriter(new FileStream(fileName, FileMode.Create)); file.Write(json); file.Close(); } return retVal; }
public static Mesh parseMesh(CrpReader reader, bool saveFile, string saveFileName, long fileSize, bool verbose) { long fileContentBegin = reader.BaseStream.Position; Mesh retVal = new Mesh(); retVal.vertices = reader.readUnityArray("UnityEngine.Vector3"); retVal.colors = reader.readUnityArray("UnityEngine.Color"); retVal.uv = reader.readUnityArray("UnityEngine.Vector2"); retVal.normals = reader.readUnityArray("UnityEngine.Vector3"); retVal.tangents = reader.readUnityArray("UnityEngine.Vector4"); retVal.boneWeights = reader.readUnityArray("UnityEngine.BoneWeight"); retVal.bindPoses = reader.readUnityArray("UnityEngine.Matrix4x4"); retVal.subMeshCount = reader.ReadInt32(); for (int i = 0; i < retVal.subMeshCount; i++) { int[] triangles = reader.readUnityArray("System.Int32"); retVal.triangles.AddRange(triangles); } if ((reader.BaseStream.Position - fileContentBegin) != fileSize) { int bytesToRead = (int)(fileSize - (reader.BaseStream.Position - fileContentBegin)); reader.ReadBytes(bytesToRead); } string fileName = saveFileName + ".obj"; if (verbose) { Console.WriteLine("Read {0} bytes into image file {1}", (reader.BaseStream.Position - fileContentBegin), fileName); } if (saveFile) { StreamWriter file = new StreamWriter(new FileStream(fileName, FileMode.Create)); file.Write(retVal.exportObj()); file.Close(); } return(retVal); }