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; } }
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); }
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 } } }