Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Load from NIF
- bool Mesh::CreateFromNIF(String filename)
- {
- struct NIF
- {
- struct ShortString
- {
- UByte Length;
- String Text;
- };
- struct SizedString
- {
- UInt Length;
- String Text;
- };
- struct Header
- {
- // Header
- String Name;
- UByte4 Version;
- Byte Endianess;
- UInt UserVersion;
- UInt NumBlocks;
- UInt UserVersion2;
- // Export information
- ShortString Creator;
- ShortString Info1;
- ShortString Info2;
- // Header again
- UShort NumBlockTypes;
- // Types of Blocks
- Array<SizedString> Types; // [NumBlockTypes];
- // Block Type ID linking thingy, idk
- Array<UShort> BlockTypeIndex; // [NumBlocks];
- // omg why
- Array<UInt> BlockSize; // [NumBlocks];
- // finally
- UInt NumStrings;
- UInt MaxStringLength;
- // or not, you're killing me
- Array<SizedString> Strings; // [NumStrings];
- // I give up
- UInt Unknown;
- };
- struct Node
- {
- Int Name; // String Reference
- UInt NumExtraData;
- //UInt ExtraData[NumExtraData];
- Int Controller; // Object Reference
- UShort Flags;
- UShort Unknown;
- Float3 Translation;
- Float3x3 Rotation;
- Float Scale;
- Int CollisionObject; // Object Reference
- UInt NumChildren;
- //Int Children[NumChildren];
- UInt NumEffects;
- //Int Effects[NumEffects];
- };
- struct DecalPlacement
- {
- Int Name; // String Reference
- UShort NumArrays;
- // Arrays
- UShort NumVectors;
- // Array
- //Float3 Points[NumVectors];
- //Float3 Normals[NumVectors];
- };
- };
- // Temporary stuffs
- File meshFile;
- // Open the mesh file
- ZeroMemory(&meshFile, sizeof(File));
- meshFile.Open(filename, File::Mode::Read);
- Log::Singleton->Write("Importing 3DS mesh: " + filename);
- // Begin importing the mesh
- NIF::Header header;
- // Load the header
- // Begin reading the string located at the beginning of the file
- Byte letter;
- header.Name = "";
- while((letter = meshFile.Read<Byte>()) != 0x0A) { header.Name += letter; };
- // Now read each data element individually because I can't be arsed to make this more efficient
- header.Version = meshFile.Read<UByte4>();
- header.Endianess = meshFile.Read<Byte>();
- header.UserVersion = meshFile.Read<UInt>();
- header.NumBlocks = meshFile.Read<UInt>();
- header.UserVersion2 = meshFile.Read<UInt>();
- // Export information
- header.Creator.Length = meshFile.Read<UByte>();
- header.Creator.Text += meshFile.Read<char>(header.Creator.Length);
- header.Info1.Length = meshFile.Read<UByte>();
- header.Info1.Text += meshFile.Read<char>(header.Info1.Length);
- header.Info2.Length = meshFile.Read<UByte>();
- header.Info2.Text += meshFile.Read<char>(header.Info2.Length);
- // Header again
- header.NumBlockTypes = meshFile.Read<UShort>();
- // Types of Blocks
- header.Types.resize(header.NumBlockTypes);
- for(Byte i = 0; i < header.NumBlockTypes; ++i)
- {
- header.Types[i].Length = meshFile.Read<UInt>();
- header.Types[i].Text += meshFile.Read<char>(header.Types[i].Length);
- }
- // Block Type ID linking thingy, idk
- header.BlockTypeIndex.resize(header.NumBlocks);
- meshFile.Read<UShort>(header.BlockTypeIndex.data(), header.NumBlocks);
- // omg why
- header.BlockSize.resize(header.NumBlocks);
- meshFile.Read<UInt>(header.BlockSize.data(), header.NumBlocks);
- // finally
- header.NumStrings = meshFile.Read<UInt>();
- header.MaxStringLength = meshFile.Read<UInt>();
- // or not, you're killing me
- header.Strings.resize(header.NumStrings);
- for(Byte i = 0; i < header.NumStrings; ++i)
- {
- header.Strings[i].Length = meshFile.Read<UInt>();
- header.Strings[i].Text += meshFile.Read<char>(header.Strings[i].Length);
- }
- // I give up
- header.Unknown = meshFile.Read<UInt>();
- meshFile.Close();
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement