YVR/XML conversion improvements

This commit is contained in:
dexy 2022-02-01 20:35:34 +11:00
parent defbbead62
commit 9d53fa9318
4 changed files with 165 additions and 85 deletions

View File

@ -4425,6 +4425,8 @@ namespace CodeWalker.GameFiles
if (rfe.NameLower.EndsWith(".yvr")) if (rfe.NameLower.EndsWith(".yvr"))
{ {
if (rfe.NameLower == "agencyprep001.yvr") continue; //this file seems corrupted
UpdateStatus(string.Format(entry.Path)); UpdateStatus(string.Format(entry.Path));
YvrFile yvr = new YvrFile(rfe); YvrFile yvr = new YvrFile(rfe);

View File

@ -107,21 +107,105 @@ namespace CodeWalker.GameFiles
// structure data // structure data
public uint Time; public uint Time;
public short VelocityX; public short VelocityX; //factor to convert to m/s is 273.0583 .. or 1/0.0036622214, or 32767/120
public short VelocityY; public short VelocityY;
public short VelocityZ; public short VelocityZ;
public sbyte RightX; public sbyte RightX;
public sbyte RightY; public sbyte RightY;
public sbyte RightZ; public sbyte RightZ;
public sbyte TopX; public sbyte ForwardX;
public sbyte TopY; public sbyte ForwardY;
public sbyte TopZ; public sbyte ForwardZ;
public byte SteeringAngle; public sbyte SteeringAngle; // factor to convert to game angle is 20 (ie radians)
public byte GasPedalPower; public sbyte GasPedalPower; //-100 to +100, negative = reverse
public byte BrakePedalPower; public sbyte BrakePedalPower;//0 to 100
public byte HandbrakeUsed; public byte HandbrakeUsed;//0 or 1
public Vector3 Position; public Vector3 Position;
public Vector3 Velocity
{
get
{
return new Vector3(VelocityX / 273.0583f, VelocityY / 273.0583f, VelocityZ / 273.0583f);
}
set
{
VelocityX = (short)Math.Round(value.X * 273.0583f);
VelocityY = (short)Math.Round(value.Y * 273.0583f);
VelocityZ = (short)Math.Round(value.Z * 273.0583f);
}
}
public Vector3 Forward
{
get
{
return new Vector3(ForwardX / 127.0f, ForwardY / 127.0f, ForwardZ / 127.0f);
}
set
{
ForwardX = (sbyte)Math.Round(value.X * 127.0f);
ForwardY = (sbyte)Math.Round(value.Y * 127.0f);
ForwardZ = (sbyte)Math.Round(value.Z * 127.0f);
}
}
public Vector3 Right
{
get
{
return new Vector3(RightX / 127.0f, RightY / 127.0f, RightZ / 127.0f);
}
set
{
RightX = (sbyte)Math.Round(value.X * 127.0f);
RightY = (sbyte)Math.Round(value.Y * 127.0f);
RightZ = (sbyte)Math.Round(value.Z * 127.0f);
}
}
public float Steering
{
get
{
return SteeringAngle / 20.0f;
}
set
{
SteeringAngle = (sbyte)Math.Round(value * 20.0f);
}
}
public float GasPedal
{
get
{
return GasPedalPower / 100.0f;
}
set
{
GasPedalPower = (sbyte)Math.Round(value * 100.0f);
}
}
public float BrakePedal
{
get
{
return BrakePedalPower / 100.0f;
}
set
{
BrakePedalPower = (sbyte)Math.Round(value * 100.0f);
}
}
public bool Handbrake
{
get
{
return HandbrakeUsed == 1;
}
set
{
HandbrakeUsed = value ? (byte)1 : (byte)0;
}
}
public override void Read(ResourceDataReader reader, params object[] parameters) public override void Read(ResourceDataReader reader, params object[] parameters)
{ {
// read structure data // read structure data
@ -132,12 +216,12 @@ namespace CodeWalker.GameFiles
this.RightX = (sbyte)reader.ReadByte(); this.RightX = (sbyte)reader.ReadByte();
this.RightY = (sbyte)reader.ReadByte(); this.RightY = (sbyte)reader.ReadByte();
this.RightZ = (sbyte)reader.ReadByte(); this.RightZ = (sbyte)reader.ReadByte();
this.TopX = (sbyte)reader.ReadByte(); this.ForwardX = (sbyte)reader.ReadByte();
this.TopY = (sbyte)reader.ReadByte(); this.ForwardY = (sbyte)reader.ReadByte();
this.TopZ = (sbyte)reader.ReadByte(); this.ForwardZ = (sbyte)reader.ReadByte();
this.SteeringAngle = reader.ReadByte(); this.SteeringAngle = (sbyte)reader.ReadByte();
this.GasPedalPower = reader.ReadByte(); this.GasPedalPower = (sbyte)reader.ReadByte();
this.BrakePedalPower = reader.ReadByte(); this.BrakePedalPower = (sbyte)reader.ReadByte();
this.HandbrakeUsed = reader.ReadByte(); this.HandbrakeUsed = reader.ReadByte();
this.Position = reader.ReadVector3(); this.Position = reader.ReadVector3();
} }
@ -151,12 +235,12 @@ namespace CodeWalker.GameFiles
writer.Write((byte)this.RightX); writer.Write((byte)this.RightX);
writer.Write((byte)this.RightY); writer.Write((byte)this.RightY);
writer.Write((byte)this.RightZ); writer.Write((byte)this.RightZ);
writer.Write((byte)this.TopX); writer.Write((byte)this.ForwardX);
writer.Write((byte)this.TopY); writer.Write((byte)this.ForwardY);
writer.Write((byte)this.TopZ); writer.Write((byte)this.ForwardZ);
writer.Write(this.SteeringAngle); writer.Write((byte)this.SteeringAngle);
writer.Write(this.GasPedalPower); writer.Write((byte)this.GasPedalPower);
writer.Write(this.BrakePedalPower); writer.Write((byte)this.BrakePedalPower);
writer.Write(this.HandbrakeUsed); writer.Write(this.HandbrakeUsed);
writer.Write(this.Position); writer.Write(this.Position);
} }
@ -164,31 +248,25 @@ namespace CodeWalker.GameFiles
{ {
YvrXml.ValueTag(sb, indent, "Time", Time.ToString()); YvrXml.ValueTag(sb, indent, "Time", Time.ToString());
YvrXml.SelfClosingTag(sb, indent, "Position " + FloatUtil.GetVector3XmlString(Position)); YvrXml.SelfClosingTag(sb, indent, "Position " + FloatUtil.GetVector3XmlString(Position));
YvrXml.SelfClosingTag(sb, indent, "Velocity " + string.Format("x=\"{0}\" y=\"{1}\" z=\"{2}\"", VelocityX.ToString(), VelocityY.ToString(), VelocityZ.ToString())); YvrXml.SelfClosingTag(sb, indent, "Velocity " + FloatUtil.GetVector3XmlString(Velocity));
YvrXml.SelfClosingTag(sb, indent, "Right " + string.Format("x=\"{0}\" y=\"{1}\" z=\"{2}\"", RightX.ToString(), RightY.ToString(), RightZ.ToString())); YvrXml.SelfClosingTag(sb, indent, "Forward " + FloatUtil.GetVector3XmlString(Forward));
YvrXml.SelfClosingTag(sb, indent, "Top " + string.Format("x=\"{0}\" y=\"{1}\" z=\"{2}\"", TopX.ToString(), TopY.ToString(), TopZ.ToString())); YvrXml.SelfClosingTag(sb, indent, "Right " + FloatUtil.GetVector3XmlString(Right));
YvrXml.ValueTag(sb, indent, "SteeringAngle", SteeringAngle.ToString()); YvrXml.ValueTag(sb, indent, "Steering", FloatUtil.ToString(Steering));
YvrXml.ValueTag(sb, indent, "GasPedalPower", GasPedalPower.ToString()); YvrXml.ValueTag(sb, indent, "GasPedal", FloatUtil.ToString(GasPedal));
YvrXml.ValueTag(sb, indent, "BrakePedalPower", BrakePedalPower.ToString()); YvrXml.ValueTag(sb, indent, "BrakePedal", FloatUtil.ToString(BrakePedal));
YvrXml.ValueTag(sb, indent, "HandbrakeUsed", HandbrakeUsed.ToString()); YvrXml.ValueTag(sb, indent, "Handbrake", Handbrake.ToString());
} }
public void ReadXml(XmlNode node) public void ReadXml(XmlNode node)
{ {
Time = Xml.GetChildUIntAttribute(node, "Time", "value"); Time = Xml.GetChildUIntAttribute(node, "Time", "value");
Position = Xml.GetChildVector3Attributes(node, "Position"); Position = Xml.GetChildVector3Attributes(node, "Position");
VelocityX = (short)Xml.GetChildIntAttribute(node, "Velocity", "x"); Velocity = Xml.GetChildVector3Attributes(node, "Velocity");
VelocityY = (short)Xml.GetChildIntAttribute(node, "Velocity", "y"); Forward = Xml.GetChildVector3Attributes(node, "Forward");
VelocityZ = (short)Xml.GetChildIntAttribute(node, "Velocity", "z"); Right = Xml.GetChildVector3Attributes(node, "Right");
RightX = (sbyte)Xml.GetChildIntAttribute(node, "Right", "x"); Steering = Xml.GetChildFloatAttribute(node, "Steering", "value");
RightY = (sbyte)Xml.GetChildIntAttribute(node, "Right", "y"); GasPedal = Xml.GetChildFloatAttribute(node, "GasPedal", "value");
RightZ = (sbyte)Xml.GetChildIntAttribute(node, "Right", "z"); BrakePedal = Xml.GetChildFloatAttribute(node, "BrakePedal", "value");
TopX = (sbyte)Xml.GetChildIntAttribute(node, "Top", "x"); Handbrake = Xml.GetChildBoolAttribute(node, "Handbrake", "value");
TopY = (sbyte)Xml.GetChildIntAttribute(node, "Top", "y");
TopZ = (sbyte)Xml.GetChildIntAttribute(node, "Top", "z");
SteeringAngle = (byte)Xml.GetChildUIntAttribute(node, "SteeringAngle", "value");
GasPedalPower = (byte)Xml.GetChildUIntAttribute(node, "GasPedalPower", "value");
BrakePedalPower = (byte)Xml.GetChildUIntAttribute(node, "BrakePedalPower", "value");
HandbrakeUsed = (byte)Xml.GetChildUIntAttribute(node, "HandbrakeUsed", "value");
} }
} }

View File

@ -41,9 +41,9 @@
this.RightXColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.RightXColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.RightYColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.RightYColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.RightZColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.RightZColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.TopXColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.ForwardXColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.TopYColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.ForwardYColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.TopZColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.ForwardZColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.SteeringAngleColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.SteeringAngleColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.GasPedalPowerColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.GasPedalPowerColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.BrakePedalPowerColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.BrakePedalPowerColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
@ -81,9 +81,9 @@
this.RightXColumn, this.RightXColumn,
this.RightYColumn, this.RightYColumn,
this.RightZColumn, this.RightZColumn,
this.TopXColumn, this.ForwardXColumn,
this.TopYColumn, this.ForwardYColumn,
this.TopZColumn, this.ForwardZColumn,
this.SteeringAngleColumn, this.SteeringAngleColumn,
this.GasPedalPowerColumn, this.GasPedalPowerColumn,
this.BrakePedalPowerColumn, this.BrakePedalPowerColumn,
@ -146,20 +146,20 @@
this.RightZColumn.Text = "Right Z"; this.RightZColumn.Text = "Right Z";
this.RightZColumn.Width = 48; this.RightZColumn.Width = 48;
// //
// TopXColumn // ForwardXColumn
// //
this.TopXColumn.Text = "Top X"; this.ForwardXColumn.Text = "Fwd X";
this.TopXColumn.Width = 44; this.ForwardXColumn.Width = 44;
// //
// TopYColumn // ForwardYColumn
// //
this.TopYColumn.Text = "Top Y"; this.ForwardYColumn.Text = "Fwd Y";
this.TopYColumn.Width = 44; this.ForwardYColumn.Width = 44;
// //
// TopZColumn // ForwardZColumn
// //
this.TopZColumn.Text = "Top Z"; this.ForwardZColumn.Text = "Fwd Z";
this.TopZColumn.Width = 44; this.ForwardZColumn.Width = 44;
// //
// SteeringAngleColumn // SteeringAngleColumn
// //
@ -236,9 +236,9 @@
private System.Windows.Forms.ColumnHeader RightXColumn; private System.Windows.Forms.ColumnHeader RightXColumn;
private System.Windows.Forms.ColumnHeader RightYColumn; private System.Windows.Forms.ColumnHeader RightYColumn;
private System.Windows.Forms.ColumnHeader RightZColumn; private System.Windows.Forms.ColumnHeader RightZColumn;
private System.Windows.Forms.ColumnHeader TopXColumn; private System.Windows.Forms.ColumnHeader ForwardXColumn;
private System.Windows.Forms.ColumnHeader TopYColumn; private System.Windows.Forms.ColumnHeader ForwardYColumn;
private System.Windows.Forms.ColumnHeader TopZColumn; private System.Windows.Forms.ColumnHeader ForwardZColumn;
private System.Windows.Forms.ColumnHeader SteeringAngleColumn; private System.Windows.Forms.ColumnHeader SteeringAngleColumn;
private System.Windows.Forms.ColumnHeader GasPedalPowerColumn; private System.Windows.Forms.ColumnHeader GasPedalPowerColumn;
private System.Windows.Forms.ColumnHeader BrakePedalPowerColumn; private System.Windows.Forms.ColumnHeader BrakePedalPowerColumn;

View File

@ -66,7 +66,7 @@ namespace CodeWalker.Forms
private string GenerateText() private string GenerateText()
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.AppendLine("PositionX, PositionY, PositionZ, Time, VelocityX, VelocityY, VelocityZ, RightX, RightY, RightZ, TopX, TopY, TopZ, SteeringAngle, GasPedalPower, BrakePedalPower, HandbrakeUsed"); sb.AppendLine("PositionX, PositionY, PositionZ, Time, VelocityX, VelocityY, VelocityZ, RightX, RightY, RightZ, ForwardX, ForwardY, ForwardZ, SteeringAngle, GasPedalPower, BrakePedalPower, HandbrakeUsed");
foreach (var entry in yvr.Records.Entries.data_items) foreach (var entry in yvr.Records.Entries.data_items)
{ {
sb.Append(FloatUtil.ToString(entry.Position.X)); sb.Append(FloatUtil.ToString(entry.Position.X));
@ -77,31 +77,31 @@ namespace CodeWalker.Forms
sb.Append(", "); sb.Append(", ");
sb.Append(entry.Time.ToString()); sb.Append(entry.Time.ToString());
sb.Append(", "); sb.Append(", ");
sb.Append(entry.VelocityX.ToString()); sb.Append(FloatUtil.ToString(entry.Velocity.X));
sb.Append(", "); sb.Append(", ");
sb.Append(entry.VelocityY.ToString()); sb.Append(FloatUtil.ToString(entry.Velocity.Y));
sb.Append(", "); sb.Append(", ");
sb.Append(entry.VelocityZ.ToString()); sb.Append(FloatUtil.ToString(entry.Velocity.Z));
sb.Append(", "); sb.Append(", ");
sb.Append(entry.RightX.ToString()); sb.Append(FloatUtil.ToString(entry.Right.X));
sb.Append(", "); sb.Append(", ");
sb.Append(entry.RightY.ToString()); sb.Append(FloatUtil.ToString(entry.Right.Y));
sb.Append(", "); sb.Append(", ");
sb.Append(entry.RightZ.ToString()); sb.Append(FloatUtil.ToString(entry.Right.Z));
sb.Append(", "); sb.Append(", ");
sb.Append(entry.TopX.ToString()); sb.Append(FloatUtil.ToString(entry.Forward.X));
sb.Append(", "); sb.Append(", ");
sb.Append(entry.TopY.ToString()); sb.Append(FloatUtil.ToString(entry.Forward.Y));
sb.Append(", "); sb.Append(", ");
sb.Append(entry.TopZ.ToString()); sb.Append(FloatUtil.ToString(entry.Forward.Z));
sb.Append(", "); sb.Append(", ");
sb.Append(entry.SteeringAngle.ToString()); sb.Append(FloatUtil.ToString(entry.Steering));
sb.Append(", "); sb.Append(", ");
sb.Append(entry.GasPedalPower.ToString()); sb.Append(FloatUtil.ToString(entry.GasPedal));
sb.Append(", "); sb.Append(", ");
sb.Append(entry.BrakePedalPower.ToString()); sb.Append(FloatUtil.ToString(entry.BrakePedal));
sb.Append(", "); sb.Append(", ");
sb.Append(entry.HandbrakeUsed.ToString()); sb.Append(entry.Handbrake.ToString());
sb.AppendLine(); sb.AppendLine();
} }
return sb.ToString(); return sb.ToString();
@ -118,19 +118,19 @@ namespace CodeWalker.Forms
FloatUtil.ToString(entry.Position.Y), FloatUtil.ToString(entry.Position.Y),
FloatUtil.ToString(entry.Position.Z), FloatUtil.ToString(entry.Position.Z),
entry.Time.ToString(), entry.Time.ToString(),
entry.VelocityX.ToString(), FloatUtil.ToString(entry.Velocity.X),
entry.VelocityY.ToString(), FloatUtil.ToString(entry.Velocity.Y),
entry.VelocityZ.ToString(), FloatUtil.ToString(entry.Velocity.Z),
entry.RightX.ToString(), FloatUtil.ToString(entry.Right.X),
entry.RightY.ToString(), FloatUtil.ToString(entry.Right.Y),
entry.RightZ.ToString(), FloatUtil.ToString(entry.Right.Z),
entry.TopX.ToString(), FloatUtil.ToString(entry.Forward.X),
entry.TopY.ToString(), FloatUtil.ToString(entry.Forward.Y),
entry.TopZ.ToString(), FloatUtil.ToString(entry.Forward.Z),
entry.SteeringAngle.ToString(), FloatUtil.ToString(entry.Steering),
entry.GasPedalPower.ToString(), FloatUtil.ToString(entry.GasPedal),
entry.BrakePedalPower.ToString(), FloatUtil.ToString(entry.BrakePedal),
entry.HandbrakeUsed.ToString(), entry.Handbrake.ToString(),
}; };
MainListView.Items.Add(new ListViewItem(row)); MainListView.Items.Add(new ListViewItem(row));
} }