Core/Cinematic: Fixed reading camera files
This commit is contained in:
@@ -45,7 +45,7 @@ namespace Game.DataStorage
|
||||
}
|
||||
|
||||
// Number of cameras not used. Multiple cameras never used in 7.1.5
|
||||
static void readCamera(M2Camera cam, uint buffSize, BinaryReader buffer, CinematicCameraRecord dbcentry)
|
||||
static void readCamera(M2Camera cam, BinaryReader reader, CinematicCameraRecord dbcentry)
|
||||
{
|
||||
List<FlyByCamera> cameras = new List<FlyByCamera>();
|
||||
List<FlyByCamera> targetcam = new List<FlyByCamera>();
|
||||
@@ -56,19 +56,19 @@ namespace Game.DataStorage
|
||||
for (uint k = 0; k < cam.target_positions.timestamps.number; ++k)
|
||||
{
|
||||
// Extract Target positions
|
||||
M2Array targTsArray = new M2Array(buffer, cam.target_positions.timestamps.offset_elements);
|
||||
M2Array targTsArray = new M2Array(reader, cam.target_positions.timestamps.offset_elements);
|
||||
|
||||
buffer.BaseStream.Position = targTsArray.offset_elements;
|
||||
reader.BaseStream.Position = targTsArray.offset_elements;
|
||||
uint[] targTimestamps = new uint[targTsArray.number];
|
||||
for (var i = 0; i < targTsArray.number; ++i)
|
||||
targTimestamps[i] = buffer.ReadUInt32();
|
||||
targTimestamps[i] = reader.ReadUInt32();
|
||||
|
||||
M2Array targArray = new M2Array(buffer, cam.target_positions.values.offset_elements);
|
||||
M2Array targArray = new M2Array(reader, cam.target_positions.values.offset_elements);
|
||||
|
||||
buffer.BaseStream.Position = targArray.offset_elements;
|
||||
reader.BaseStream.Position = targArray.offset_elements;
|
||||
M2SplineKey[] targPositions = new M2SplineKey[targArray.number];
|
||||
for (var i = 0; i < targArray.number; ++i)
|
||||
targPositions[i] = new M2SplineKey(buffer);
|
||||
targPositions[i] = new M2SplineKey(reader);
|
||||
|
||||
// Read the data for this set
|
||||
uint currPos = targArray.offset_elements;
|
||||
@@ -90,19 +90,19 @@ namespace Game.DataStorage
|
||||
for (uint k = 0; k < cam.positions.timestamps.number; ++k)
|
||||
{
|
||||
// Extract Camera positions for this set
|
||||
M2Array posTsArray = buffer.ReadStruct<M2Array>(cam.positions.timestamps.offset_elements);
|
||||
M2Array posTsArray = reader.ReadStruct<M2Array>(cam.positions.timestamps.offset_elements);
|
||||
|
||||
buffer.BaseStream.Position = posTsArray.offset_elements;
|
||||
reader.BaseStream.Position = posTsArray.offset_elements;
|
||||
uint[] posTimestamps = new uint[posTsArray.number];
|
||||
for (var i = 0; i < posTsArray.number; ++i)
|
||||
posTimestamps[i] = buffer.ReadUInt32();
|
||||
posTimestamps[i] = reader.ReadUInt32();
|
||||
|
||||
M2Array posArray = new M2Array(buffer, cam.positions.values.offset_elements);
|
||||
M2Array posArray = new M2Array(reader, cam.positions.values.offset_elements);
|
||||
|
||||
buffer.BaseStream.Position = posArray.offset_elements;
|
||||
reader.BaseStream.Position = posArray.offset_elements;
|
||||
M2SplineKey[] positions = new M2SplineKey[posTsArray.number];
|
||||
for (var i = 0; i < posTsArray.number; ++i)
|
||||
positions[i] = new M2SplineKey(buffer);
|
||||
positions[i] = new M2SplineKey(reader);
|
||||
|
||||
// Read the data for this set
|
||||
uint currPos = posArray.offset_elements;
|
||||
@@ -196,7 +196,7 @@ namespace Game.DataStorage
|
||||
M2Camera cam = m2file.ReadStruct<M2Camera>(8 + header.ofsCameras);
|
||||
|
||||
m2file.BaseStream.Position = 8;
|
||||
readCamera(cam, (uint)m2file.BaseStream.Length - 8, m2file, cameraEntry);
|
||||
readCamera(cam, new BinaryReader(new MemoryStream(m2file.ReadBytes((int)m2file.BaseStream.Length - 8))), cameraEntry);
|
||||
}
|
||||
}
|
||||
catch (EndOfStreamException)
|
||||
@@ -208,7 +208,7 @@ namespace Game.DataStorage
|
||||
Log.outError(LogFilter.ServerLoading, "File {0} not found!!!!", filename);
|
||||
}
|
||||
}
|
||||
Log.outInfo(LogFilter.ServerLoading, "Loaded {0} cinematic waypoint sets in {1} ms", FlyByCameraStorage.Count, Time.GetMSTimeDiffToNow(oldMSTime));
|
||||
Log.outInfo(LogFilter.ServerLoading, "Loaded {0} cinematic waypoint sets in {1} ms", FlyByCameraStorage.Keys.Count, Time.GetMSTimeDiffToNow(oldMSTime));
|
||||
}
|
||||
|
||||
public static List<FlyByCamera> GetFlyByCameras(uint cameraId)
|
||||
|
||||
@@ -21,7 +21,7 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace Game.DataStorage
|
||||
{
|
||||
struct M2SplineKey
|
||||
public struct M2SplineKey
|
||||
{
|
||||
public M2SplineKey(BinaryReader reader)
|
||||
{
|
||||
@@ -35,82 +35,8 @@ namespace Game.DataStorage
|
||||
public Vector3 p2;
|
||||
}
|
||||
|
||||
struct M2Header
|
||||
public struct M2Header
|
||||
{
|
||||
/*
|
||||
public M2Header(BinaryReader reader)
|
||||
{
|
||||
Magic = null;/// reader.ReadStringFromChars(4);
|
||||
Version = reader.ReadUInt32();
|
||||
lName = reader.ReadUInt32();
|
||||
ofsName = reader.ReadUInt32();
|
||||
GlobalModelFlags = reader.ReadUInt32();
|
||||
nGlobalSequences = reader.ReadUInt32();
|
||||
ofsGlobalSequences = reader.ReadUInt32();
|
||||
nAnimations = reader.ReadUInt32();
|
||||
ofsAnimations = reader.ReadUInt32();
|
||||
nAnimationLookup = reader.ReadUInt32();
|
||||
ofsAnimationLookup = reader.ReadUInt32();
|
||||
nBones = reader.ReadUInt32();
|
||||
ofsBones = reader.ReadUInt32();
|
||||
nKeyBoneLookup = reader.ReadUInt32();
|
||||
ofsKeyBoneLookup = reader.ReadUInt32();
|
||||
nVertices = reader.ReadUInt32();
|
||||
ofsVertices = reader.ReadUInt32();
|
||||
nViews = reader.ReadUInt32();
|
||||
nSubmeshAnimations = reader.ReadUInt32();
|
||||
ofsSubmeshAnimations = reader.ReadUInt32();
|
||||
nTextures = reader.ReadUInt32();
|
||||
ofsTextures = reader.ReadUInt32();
|
||||
nTransparency = reader.ReadUInt32();
|
||||
ofsTransparency = reader.ReadUInt32();
|
||||
nUVAnimation = reader.ReadUInt32();
|
||||
ofsUVAnimation = reader.ReadUInt32();
|
||||
nTexReplace = reader.ReadUInt32();
|
||||
ofsTexReplace = reader.ReadUInt32();
|
||||
nRenderFlags = reader.ReadUInt32();
|
||||
ofsRenderFlags = reader.ReadUInt32();
|
||||
nBoneLookupTable = reader.ReadUInt32();
|
||||
ofsBoneLookupTable = reader.ReadUInt32();
|
||||
nTexLookup = reader.ReadUInt32();
|
||||
ofsTexLookup = reader.ReadUInt32();
|
||||
nTexUnits = reader.ReadUInt32();
|
||||
ofsTexUnits = reader.ReadUInt32();
|
||||
nTransLookup = reader.ReadUInt32();
|
||||
ofsTransLookup = reader.ReadUInt32();
|
||||
nUVAnimLookup = reader.ReadUInt32();
|
||||
ofsUVAnimLookup = reader.ReadUInt32();
|
||||
BoundingBox = new AxisAlignedBox(new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()) , new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()));
|
||||
BoundingSphereRadius = reader.ReadSingle();
|
||||
CollisionBox = new AxisAlignedBox(new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()), new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()));
|
||||
CollisionSphereRadius = reader.ReadSingle();
|
||||
nBoundingTriangles = reader.ReadUInt32();
|
||||
ofsBoundingTriangles = reader.ReadUInt32();
|
||||
nBoundingVertices = reader.ReadUInt32();
|
||||
ofsBoundingVertices = reader.ReadUInt32();
|
||||
nBoundingNormals = reader.ReadUInt32();
|
||||
ofsBoundingNormals = reader.ReadUInt32();
|
||||
nAttachments = reader.ReadUInt32();
|
||||
ofsAttachments = reader.ReadUInt32();
|
||||
nAttachLookup = reader.ReadUInt32();
|
||||
ofsAttachLookup = reader.ReadUInt32();
|
||||
nEvents = reader.ReadUInt32();
|
||||
ofsEvents = reader.ReadUInt32();
|
||||
nLights = reader.ReadUInt32();
|
||||
ofsLights = reader.ReadUInt32();
|
||||
nCameras = reader.ReadUInt32();
|
||||
ofsCameras = reader.ReadUInt32();
|
||||
nCameraLookup = reader.ReadUInt32();
|
||||
ofsCameraLookup = reader.ReadUInt32();
|
||||
nRibbonEmitters = reader.ReadUInt32();
|
||||
ofsRibbonEmitters = reader.ReadUInt32();
|
||||
nParticleEmitters = reader.ReadUInt32();
|
||||
ofsParticleEmitters = reader.ReadUInt32();
|
||||
nBlendMaps = reader.ReadUInt32();
|
||||
ofsBlendMaps = reader.ReadUInt32();
|
||||
}
|
||||
*/
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
|
||||
public char[] Magic; // "MD20"
|
||||
public uint Version; // The version of the format.
|
||||
@@ -182,7 +108,7 @@ namespace Game.DataStorage
|
||||
public uint ofsBlendMaps; // Same as above. Points to an array of uint16 of nBlendMaps entries -- From WoD information.};
|
||||
}
|
||||
|
||||
struct M2Array
|
||||
public struct M2Array
|
||||
{
|
||||
public M2Array(BinaryReader reader, uint offset)
|
||||
{
|
||||
@@ -197,38 +123,16 @@ namespace Game.DataStorage
|
||||
public uint offset_elements;
|
||||
}
|
||||
|
||||
struct M2Track
|
||||
public struct M2Track
|
||||
{
|
||||
public void Read(BinaryReader reader)
|
||||
{
|
||||
interpolation_type = reader.ReadUInt16();
|
||||
global_sequence = reader.ReadUInt16();
|
||||
timestamps = new M2Array(reader, 0);
|
||||
values = new M2Array(reader, 0);
|
||||
}
|
||||
|
||||
public ushort interpolation_type;
|
||||
public ushort global_sequence;
|
||||
public M2Array timestamps;
|
||||
public M2Array values;
|
||||
}
|
||||
|
||||
struct M2Camera
|
||||
public struct M2Camera
|
||||
{
|
||||
public void Read(BinaryReader reader, M2Header header)
|
||||
{
|
||||
reader.BaseStream.Position = header.ofsCameras;
|
||||
type = reader.ReadUInt32();
|
||||
far_clip = reader.ReadSingle();
|
||||
near_clip = reader.ReadSingle();
|
||||
positions.Read(reader);
|
||||
position_base = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
|
||||
target_positions.Read(reader);
|
||||
target_position_base = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
|
||||
rolldata.Read(reader);
|
||||
fovdata.Read(reader);
|
||||
}
|
||||
|
||||
public uint type; // 0: portrait, 1: characterinfo; -1: else (flyby etc.); referenced backwards in the lookup table.
|
||||
public float far_clip;
|
||||
public float near_clip;
|
||||
|
||||
Reference in New Issue
Block a user