// Converts .json file from parsing arguments into... // TODO: Refactor to remove references to fbx files as they are no // longer a part of the Luminaire workflow. private static void ConvertFile(string gfxbin, string gpubin) { DefaultPrintFunction.SetDefaultPrintFunction(Console.WriteLine); var readData = File.ReadAllBytes(gfxbin); var gpubinReadData = File.ReadAllBytes(gpubin); // TODO don't hardcode var dependencies = new Dictionary <string, byte[]> { { /* "data://character/nh/nh00/model_010/nh00_010.gpubin"*/ gpubin, gpubinReadData } }; var unpackContext = new LmGfxBinUnpackContext { // Shorthand initialization for auto-implemented properties GpuBuffer = gpubinReadData // TODO don't hardcode }; var msgPck = new LmMsgPck(readData, unpackContext); var gmtlLoader = new LmGfxBinMaterialAssetLoader(); var gmdlLoader = new LmGfxBinAssetLoader(); // After tracing this dependencies variable as its passed through // various functions, it seems that the dictionary isn't actually // used anywhere. The reference in the deepest level of function // calls the place where this variable is used is commented out. gmdlLoader.BuildDependencyTable(unpackContext, msgPck, dependencies); var modelResourceNode = LmGfxBinAssetLoader.Convert(msgPck); var fbx = gpubin.Replace(gpubinExtension, fbxExtension); GmdlUnityAssetConverter.Convert(modelResourceNode, gfxbin, ""); }
public void LoadBinaryData(byte[] data, string filename, bool isShared) { var magicStr = System.Text.Encoding.UTF8.GetString(data.Take(12).ToArray()); if (magicStr != "Bonamik_2_47") { DefaultPrintFunction.Write($"Error loading Bonamik file. Please re-convert the bonamik file(file:{filename})"); return; } var solvers = BitConverter.ToUInt32(data, 4 * sizeof(int)); var bodies = BitConverter.ToUInt32(data, 5 * sizeof(int)); var links = BitConverter.ToUInt32(data, 6 * sizeof(int)); var planes = BitConverter.ToUInt32(data, 7 * sizeof(int)); var shapeMatchingGroups = BitConverter.ToUInt32(data, 8 * sizeof(int)); DefaultPrintFunction.Write($"[Bonamik] Imported : Solvers({solvers}), Bodies({bodies}), Links({links}), Planes({planes}) SM({shapeMatchingGroups})"); this.TotalKinematics = BitConverter.ToUInt32(data, 9 * sizeof(int)); this.TotalConstraints = BitConverter.ToUInt32(data, 10 * sizeof(int)); this.TotalCones = BitConverter.ToUInt32(data, 11 * sizeof(int)); this.TotalLinks = BitConverter.ToUInt32(data, 12 * sizeof(int)); this.TotalCollisions = BitConverter.ToUInt32(data, 13 * sizeof(int)); this.TotalSelfCollisions = BitConverter.ToUInt32(data, 14 * sizeof(int)); this.TotalChainRootParticles = BitConverter.ToUInt32(data, 15 * sizeof(int)); this.TotalGrassInteractBodies = BitConverter.ToUInt32(data, 16 * sizeof(int)); this.TotalPossessions = BitConverter.ToUInt32(data, 17 * sizeof(int)); DefaultPrintFunction.Write($"----------------- Kinematics({this.TotalKinematics}), Constraints({this.TotalConstraints}), Cones({this.TotalCones}), Links({this.TotalLinks}), Collisions({this.TotalCollisions}), Self-collisions({this.TotalSelfCollisions})"); DefaultPrintFunction.Write($"----------------- ChainRoot({this.TotalChainRootParticles}), GrassInteract.({this.TotalGrassInteractBodies}), Possessions({this.TotalPossessions})"); // TODO read scene managers // Read solvers var startPosition = 620; for (var i = 0; i < solvers; i++) { var position = startPosition; var groupId = BitConverter.ToUInt32(data, position); position += sizeof(uint); var groupName = ReadCString(data, position); position += groupName.Length + 1; // TODO startPosition += 296; } }
// Seems to be incomplete. Loads input .bnm file data into a bonamik // variable but doesn't do anything with that data after. private static void ConvertBonamik(string bnm) { // Reads contents of gfxbin file (which is binary) into a // bytearray. This implies that readData is a byte[]. DefaultPrintFunction.SetDefaultPrintFunction(Console.WriteLine); var readData = File.ReadAllBytes(bnm); // bonamik.LoadBinaryData() contains a few TODO annotations. It // looks like Sai might have been using this to inspect the // contents of bonamik files/data structures. var bonamik = new BonamikBinaryResource(); bonamik.LoadBinaryData(readData, bnm, false); Console.ReadLine(); }
public bool Load(LmMsgPck msg, IDictionary <string, byte[]> dependencies) { this.Version = (uint)msg.Read(); if (this.Version < 1) { DefaultPrintFunction.Write($"[LmGfxBin_V1]Version {this.Version}"); return(false); } else if (this.Version > 20160705) { DefaultPrintFunction.Write($"[LmGfxBin_V1]Version {this.Version}"); } else if (this.Version < 20150713) { DefaultPrintFunction.Write($"[LmGfxBin_V1]Version {this.Version}"); return(false); } var dependencyRefCount = msg.ReadMapCount(); for (var _ = 0; _ < dependencyRefCount; _++) { // TODO: This is actually Metadata, not Dependencies var dependencyRef = UnpackDependencyRef(msg); this.Dependencies.Add(dependencyRef); if (ulong.TryParse(dependencyRef.HashValue, out ulong parsedHash)) { // msg.UserData.DependencyTable.Put(parsedHash, dependencies[dependencyRef.Path]); } } // Next up is a repeat of all the hashes; skip them // ReadArrayCount is the problem fyi msg.UnpackArraySize(out int hashArrayCount); var hashes = new List <ulong>(); for (var _ = 0; _ < hashArrayCount; _++) { var hash = msg.ReadUint64(); hashes.Add(hash); } //msg.Skip(hashArrayCount * 9); return(true); }
// This function takes a gmtl file name as input and converts to // contents of that file to json format. It then writes that json // to a file in the same directory as the input file. The output // file will have the same name as the input file but with the // .json extension. private static void ConvertMaterial(string gfxbin) { DefaultPrintFunction.SetDefaultPrintFunction(Console.WriteLine); // Reads contents of gfxbin file (which is binary) into a // bytearray. This implies that readData is a byte[]. var readData = File.ReadAllBytes(gfxbin); var unpackContext = new LmGfxBinUnpackContext(); var msgPck = new LmMsgPck(readData, unpackContext); // Loads the unpacked message data into a MaterialGmtl. var gmtlLoader = new LmGfxBinMaterialAssetLoader(); var gmtl = gmtlLoader.Initialize(unpackContext, msgPck, null); // Make a string for the file path of the input file, but with // a .json file extension. The output file should be stored in // the same directory as the input file. var jsonPath = gfxbin.Replace(gmtlExtension, "json"); JsonConvert.Convert(gmtl, jsonPath); }
private void Setup(LmGeometry geometry) { // Create index buffer var indexBufferDescription = new IndexBufferDesc(geometry.IdxBufferSize, geometry.IdxType); this.IndexBuffer = new IndexBuffer(geometry.IdxBuffer, indexBufferDescription); // Create vertex buffers this.VertexCount = geometry.VtxNum; this.TotalTriangleCount = geometry.IdxNum / 3; this.TriangleCount = this.VertexCount; var meshVertexDeclaration = new MeshVertexDeclaration(); var readFunctions = MakeReadFunctions(); for (byte i = 0; i < geometry.VtxStreamGroupDesc.VtxStreamDescs.Count; i++) { var vtxStreamDesc = geometry.VtxStreamGroupDesc.VtxStreamDescs[i]; var structuredVBDesc = vtxStreamDesc.StructuredVBDesc; var vtxBufferDesc = new VertexBufferDesc(structuredVBDesc.Stride * this.VertexCount); // Ugly hack var vtxBuffer = new VertexBuffer(null, vtxBufferDesc); // new VertexBuffer(new ArraySegment<byte>(geometry.VtxBuffer, (int)structuredVBDesc.StartOffset, (int)vtxBufferDesc.Size), vtxBufferDesc); this.VertexBuffers.Add(vtxBuffer); if (i >= 8) { DefaultPrintFunction.Write("i<EBONY_COUNTOF(this->bufferStrides)"); } // Add vertex elements foreach (var vtxElementDesc in structuredVBDesc.VtxElementDescs) { var usage = LmVertexElementDesc.GetUsageFromSemantic(vtxElementDesc.Semantic); var size = LmVertexElementDesc.FormatToVertexComponentCount(vtxElementDesc.Format); var type = LmVertexElementDesc.FormatToVertexType(vtxElementDesc.Format); var vertexElement = new VertexElement(i, type, usage, 0, (ushort)vtxElementDesc.Offset, (ushort)size, vtxElementDesc.Semantic, 0); meshVertexDeclaration.AddVertexElement(vertexElement, vtxBuffer); } // Parse vertex buffer //var vertexElementArrays = new Dictionary<string, IList>(); foreach (var vtxElementDesc in structuredVBDesc.VtxElementDescs) { var values = CreateVertexElementArray(vtxElementDesc.Format); VertexElementArrays.Add(vtxElementDesc.Semantic, values); } var vertexBufferPosition = (int)structuredVBDesc.StartOffset; for (var j = 0; j < vtxBufferDesc.Size / structuredVBDesc.Stride; j++) { foreach (var vtxElementDesc in structuredVBDesc.VtxElementDescs) { var readFunction = readFunctions[vtxElementDesc.Format]; var size = LmVertexElementDesc.FormatToVertexComponentCount(vtxElementDesc.Format); for (var _ = 0; _ < size; _++) { var value = readFunction(geometry.VtxBuffer, vertexBufferPosition, out int componentSize); VertexElementArrays[vtxElementDesc.Semantic].Add(value); vertexBufferPosition += componentSize; } } } this.MainStreamSet = meshVertexDeclaration; this.BoneInstanceCount = geometry.InstanceNum; if (this.BoneInstanceCount != 0) { // TODO instance buffer } } }