public ModelContainer LoadModel(string path) { List <MeshIndexed> _meshesIndexed = new List <MeshIndexed>(); Loader3DS loader = new Loader3DS(); loader.Load(new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read))); loader.LoadAllMeshes(_meshesIndexed, 3.0f); List <Mesh> meshes = new List <Mesh>(); foreach (var item in _meshesIndexed) { meshes.Add(CopyMesh(item)); } return(new ModelContainer(meshes, path)); }
private void ReadKeyFrameData(FileContext ctx) { while (ctx.ReadChunk()) { switch (ctx.chunk.id) { case kKeyFrameHdr: { ushort revision = ctx.PopWord(); string cstr = ctx.PopString(); uint animlen = ctx.PopDword(); Loader3DS.WriteDebug("KeyFrame Header: rev: 0x{0:x04}, animlen: 0x{1:x08}, cstr: {2}", revision, animlen, cstr); } break; case kKeyFrameSegment: { uint start = ctx.PopDword(); uint end = ctx.PopDword(); Loader3DS.WriteDebug("KeyFrame Segment: start: 0x{0:x08}, end: 0x{1:x08}", start, end); } break; case kKeyFrameCurtime: { uint curtime = ctx.PopDword(); Loader3DS.WriteDebug("KeyFrame curtime: 0x{0:x08}", curtime); } break; case kObjectNodeTag: ReadObjectNode(ctx); break; default: ctx.SkipChunk(); break; } } }
private void ReadObjectNode(FileContext ctx) { string name = "<unnamed>"; while (ctx.ReadChunk()) { switch (ctx.chunk.id) { case kKeyFrameNodeID: { ushort nodeID = ctx.PopWord(); Loader3DS.WriteDebug("KeyFrame ID: 0x{0:x04}", nodeID); } break; case kKeyFrameNodeHdr: { name = ctx.PopString(); ushort flags1 = ctx.PopWord(); ushort flags2 = ctx.PopWord(); ushort heirarchy = ctx.PopWord(); Loader3DS.WriteDebug("KeyFrame NodeHdr: {0}, flags1: 0x{1:x04}, flags2: 0x{2:x04}, heirarchy: 0x{3:x04}", name, flags1, flags2, heirarchy); } break; case kKeyFramePos: { ushort flags = ctx.PopWord(); ushort[] unk = new ushort[4]; unk[0] = ctx.PopWord(); unk[1] = ctx.PopWord(); unk[2] = ctx.PopWord(); unk[3] = ctx.PopWord(); ushort keys = ctx.PopWord(); ushort unk2 = ctx.PopWord(); ushort framenum = ctx.PopWord(); uint unk3 = ctx.PopDword(); float x = ctx.PopFloat(); float y = ctx.PopFloat(); float z = ctx.PopFloat(); Loader3DS.WriteDebug("KeyFrame POS: flags: 0x{0:x04}, keys: 0x{1:x04}, frame: 0x{2:x04}", flags, keys, framenum); Loader3DS.WriteDebug("KeyFrame POS: x: {0:f2}, y: {1:f2}, z: {2:f2}", x, y, z); Loader3DS.WriteDebug("KeyFrame POS: unk[{0},{1},{2},{3}], unk2: {4}, unk3: {5}", unk[0], unk[1], unk[2], unk[3], unk2, unk3); if (framenum == 0 && name != String.Empty) { MeshObject mesh; if (LookupMeshByName(name, out mesh)) { Matrix tranmtx = Matrix.CreateTranslation(-x, -y, -z); mesh.lmat *= tranmtx; } } } break; case kKeyFramePivot: { float x = ctx.PopFloat(); float y = ctx.PopFloat(); float z = ctx.PopFloat(); Loader3DS.WriteDebug("KeyFrame Pivot: x: {0:f2}, y: {1:f2}, z: {2:f2}", x, y, z); if (name != String.Empty) { MeshObject mesh; if (LookupMeshByName(name, out mesh)) { Matrix tranmtx = Matrix.CreateTranslation(-x, -y, -z); mesh.lmat *= tranmtx; } } } break; case kKeyFrameRot: { ushort flags = ctx.PopWord(); ushort[] unk = new ushort[4]; unk[0] = ctx.PopWord(); unk[1] = ctx.PopWord(); unk[2] = ctx.PopWord(); unk[3] = ctx.PopWord(); ushort keys = ctx.PopWord(); ushort unk2 = ctx.PopWord(); ushort framenum = ctx.PopWord(); uint unk3 = ctx.PopDword(); float r = ctx.PopFloat(); float x = ctx.PopFloat(); float y = ctx.PopFloat(); float z = ctx.PopFloat(); if (framenum == 0 && name != String.Empty) { MeshObject mesh; if (LookupMeshByName(name, out mesh)) { Matrix rotmtx = Matrix.CreateFromAxisAngle(new Vector3(x, y, z), r); //mesh.lmat *= rotmtx; } } } break; case kKeyFrameScale: { ushort flags = ctx.PopWord(); ushort[] unk = new ushort[4]; unk[0] = ctx.PopWord(); unk[1] = ctx.PopWord(); unk[2] = ctx.PopWord(); unk[3] = ctx.PopWord(); ushort keys = ctx.PopWord(); ushort unk2 = ctx.PopWord(); ushort framenum = ctx.PopWord(); uint unk3 = ctx.PopDword(); float x = ctx.PopFloat(); float y = ctx.PopFloat(); float z = ctx.PopFloat(); if (framenum == 0 && name != String.Empty) { MeshObject mesh; if (LookupMeshByName(name, out mesh)) { Matrix sclmtx = Matrix.CreateScale(1 / x, 1 / y, 1 / z); //mesh.lmat *= sclmtx;; } } } break; case kKeyFrameFov: case kKeyFrameRoll: case kKeyFrameCol: case kKeyFrameMorph: default: ctx.SkipChunk(); break; } } }