public static Dna Load(BulletReader dnaReader, bool swap) { var dna = new Dna(); dna.Init(dnaReader, swap); return(dna); }
protected void ParseInternal(FileVerboseMode verboseMode, byte[] memDna) { if ((_flags & FileFlags.OK) != FileFlags.OK) { return; } ChunkInd dna = new ChunkInd(); dna.OldPtr = 0; MemoryStream memory = new MemoryStream(_fileBuffer, false); BinaryReader reader = new BinaryReader(memory); int i = 0; while (memory.Position < memory.Length) { // looking for the data's starting position // and the start of SDNA decls byte[] code = reader.ReadBytes(4); string codes = ASCIIEncoding.ASCII.GetString(code); if (_dataStart == 0 && codes.Equals("REND")) { _dataStart = memory.Position; } if (codes.Equals("DNA1")) { // read the DNA1 block and extract SDNA reader.BaseStream.Position = i; if (GetNextBlock(out dna, reader, _flags) > 0) { string sdnaname = ASCIIEncoding.ASCII.GetString(reader.ReadBytes(8)); if (sdnaname.Equals("SDNANAME")) { dna.OldPtr = i + ChunkUtils.GetOffset(_flags); } else { dna.OldPtr = 0; } } else { dna.OldPtr = 0; } } else if (codes.Equals("SDNA")) { // Some Bullet files are missing the DNA1 block // In Blender it's DNA1 + ChunkUtils::getOffset() + SDNA + NAME // In Bullet tests its SDNA + NAME dna.OldPtr = i; dna.Length = (int)memory.Length - i; // Also no REND block, so exit now. if (_version == 276) { break; } } if (_dataStart != 0 && dna.OldPtr != 0) { break; } i++; memory.Position = i; } if (dna.OldPtr == 0 || dna.Length == 0) { //Console.WriteLine("Failed to find DNA1+SDNA pair"); _flags &= ~FileFlags.OK; reader.Dispose(); memory.Dispose(); return; } _fileDna = new Dna(); // _fileDna.Init will convert part of DNA file endianness to current CPU endianness if necessary memory.Position = dna.OldPtr; _fileDna.Init(reader, (_flags & FileFlags.EndianSwap) != 0); if (_version == 276) { for (i = 0; i < _fileDna.NumNames; i++) { if (_fileDna.GetName(i).Equals("int")) { _flags |= FileFlags.BrokenDna; } } if ((_flags & FileFlags.BrokenDna) == FileFlags.BrokenDna) { //Console.WriteLine("warning: fixing some broken DNA version"); } } //if ((verboseMode & FileVerboseMode.DumpDnaTypeDefinitions) == FileVerboseMode.DumpDnaTypeDefinitions) // _fileDna.DumpTypeDefinitions(); _memoryDna = new Dna(); using (MemoryStream memory2 = new MemoryStream(memDna, false)) { using (BinaryReader reader2 = new BinaryReader(memory2)) { _memoryDna.Init(reader2, !BitConverter.IsLittleEndian); } } if (_memoryDna.NumNames != _fileDna.NumNames) { _flags |= FileFlags.VersionVaries; //Console.WriteLine ("Warning, file DNA is different than built in, performance is reduced. Best to re-export file with a matching version/platform"); } if (_memoryDna.LessThan(_fileDna)) { //Console.WriteLine ("Warning, file DNA is newer than built in."); } _fileDna.InitCmpFlags(_memoryDna); ParseData(); ResolvePointers(verboseMode); UpdateOldPointers(); reader.Dispose(); memory.Dispose(); }
protected void ParseInternal(FileVerboseMode verboseMode, byte[] memDna) { if ((_flags & FileFlags.OK) != FileFlags.OK) { return; } ChunkInd dna = new ChunkInd(); dna.OldPtr = 0; MemoryStream memory = new MemoryStream(_fileBuffer, false); BinaryReader reader = new BinaryReader(memory); int i = 0; while (memory.Position < memory.Length) { // looking for the data's starting position // and the start of SDNA decls byte[] code = reader.ReadBytes(4); string codes = ASCIIEncoding.ASCII.GetString(code); if (_dataStart == 0 && codes.Equals("REND")) { _dataStart = memory.Position; } if (codes.Equals("DNA1")) { // read the DNA1 block and extract SDNA reader.BaseStream.Position = i; if (GetNextBlock(out dna, reader, _flags) > 0) { string sdnaname = ASCIIEncoding.ASCII.GetString(reader.ReadBytes(8)); if (sdnaname.Equals("SDNANAME")) { dna.OldPtr = i + ChunkUtils.GetOffset(_flags); } else { dna.OldPtr = 0; } } else { dna.OldPtr = 0; } } else if (codes.Equals("SDNA")) { // Some Bullet files are missing the DNA1 block // In Blender it's DNA1 + ChunkUtils::getOffset() + SDNA + NAME // In Bullet tests its SDNA + NAME dna.OldPtr = i; dna.Length = (int)memory.Length - i; // Also no REND block, so exit now. if (_version == 276) { break; } } if (_dataStart != 0 && dna.OldPtr != 0) { break; } i++; memory.Position = i; } if (dna.OldPtr == 0 || dna.Length == 0) { //Console.WriteLine("Failed to find DNA1+SDNA pair"); _flags &= ~FileFlags.OK; reader.Dispose(); memory.Dispose(); return; } _fileDna = new Dna(); // _fileDna.Init will convert part of DNA file endianness to current CPU endianness if necessary memory.Position = dna.OldPtr; _fileDna.Init(reader, (_flags & FileFlags.EndianSwap) != 0); if (_version == 276) { for (i = 0; i < _fileDna.NumNames; i++) { if (_fileDna.GetName(i).Equals("int")) { _flags |= FileFlags.BrokenDna; } } if ((_flags & FileFlags.BrokenDna) == FileFlags.BrokenDna) { //Console.WriteLine("warning: fixing some broken DNA version"); } } //if ((verboseMode & FileVerboseMode.DumpDnaTypeDefinitions) == FileVerboseMode.DumpDnaTypeDefinitions) // _fileDna.DumpTypeDefinitions(); _memoryDna = new Dna(); using (MemoryStream memory2 = new MemoryStream(memDna, false)) { using (BinaryReader reader2 = new BinaryReader(memory2)) { _memoryDna.Init(reader2, !BitConverter.IsLittleEndian); } } if (_memoryDna.NumNames != _fileDna.NumNames) { _flags |= FileFlags.VersionVaries; //Console.WriteLine ("Warning, file DNA is different than built in, performance is reduced. Best to re-export file with a matching version/platform"); } if (_memoryDna.LessThan(_fileDna)) { //Console.WriteLine ("Warning, file DNA is newer than built in."); } _fileDna.InitCmpFlags(_memoryDna); ParseData(); ResolvePointers(verboseMode); UpdateOldPointers(); reader.Dispose(); memory.Dispose(); }
public static Dna Load(BulletReader dnaReader, bool swap) { var dna = new Dna(); dna.Init(dnaReader, swap); return dna; }