-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
760 lines (672 loc) · 49.2 KB
/
Program.cs
File metadata and controls
760 lines (672 loc) · 49.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
using GBX.NET;
using GBX.NET.Engines.Plug;
//using GBX.NET.LZO;
using System.Numerics;
//using System.Reflection.Metadata.Ecma335;
using System.Text.Json;
namespace VPM
{
public class SurfaceData
{
public string? Name { get; set; }
public Dictionary<string, float>? Position { get; set; }
public Dictionary<string, float>? Rotation { get; set; }
public string? Type { get; set; }
public Dictionary<string, float>? Parameters { get; set; }
}
public class Axle
{
public float PositionZ { get; set; }
public float WheelPositionX { get; set; }
public float WheelRadius { get; set; }
public float WheelWidthHalf { get; set; }
public Dictionary<string, bool>? FlagsLeft { get; set; }
public Dictionary<string, bool>? FlagsRight { get; set; }
}
public class Chassis
{
public float GroundHeight { get; set; }
public Axle? AxleFront { get; set; }
public Axle? AxleRear { get; set; }
}
public class VehiclePhyModelData
{
public string? Version { get; set; }
public Chassis? Chassis { get; set; }
public SurfaceData[]? BodySurfs { get; set; }
}
public enum WheelIndex : int
{
FrontLeft,
FrontRight,
RearRight,
RearLeft
}
public class Program
{
public const string VERSION = "0.0.2";
static void Main(string[] args)
{
// Checking for user error
if (args.Length == 0)
{
System.Console.WriteLine("Please drag a file on this executable or start it in the command line, e.g.");
System.Console.WriteLine("\n\t\"VehiclePhyModeler.exe CanyonCar.VehiclePhyModel.Gbx\"\n");
System.Console.WriteLine("\n\t\"VehiclePhyModeler.exe ValleyCar.VehiclePhyModel.json StadiumCar.VehiclePhyModel.Gbx\"\n");
return;
}
// Reading GBX file
GBX.NET.Lzo.SetLzo(typeof(GBX.NET.LZO.MiniLZO));
try
{
if (args.Length == 1)
{
GBX.NET.Node? vpm = GameBox.ParseNode(args[0]);
if (vpm is CPlugVehiclePhyModel vehiclePhyModel)
{
CPlugVehicleCarPhyShape? ps = vehiclePhyModel.PhyShape;
if (ps is not null)
{
if (ps.Chunk0910E000u is Chunk0910E000U phyShape)
{
CPlugSurface? surface = phyShape.U03;
CPlugVehicleWheelPhyModel[]? wheels = phyShape.U04;
List<Tuple<bool, string?>> surfs = new List<Tuple<bool, string?>>();
Chassis chassis = new Chassis
{
GroundHeight = phyShape.U07,
AxleFront = new Axle
{
PositionZ = phyShape.U08,
WheelPositionX = phyShape.U10,
WheelRadius = phyShape.U12,
WheelWidthHalf = phyShape.U14
},
AxleRear = new Axle
{
PositionZ = phyShape.U09,
WheelPositionX = phyShape.U11,
WheelRadius = phyShape.U13,
WheelWidthHalf = phyShape.U15
}
};
List<SurfaceData> wheelDatas = new List<SurfaceData>();
if (wheels is not null)
{
for (int i = 0; i < wheels.Length; i++)
{
Dictionary<string, bool> flags = new Dictionary<string, bool>
{
["IsDriving"] = wheels[i].IsDriving,
["IsSteering"] = wheels[i].IsSteering
};
SurfaceData wheelSurf = new SurfaceData
{
Name = wheels[i].Id,
Type = "Ellipsoid"
};
switch ((WheelIndex)i)
{
case WheelIndex.FrontLeft:
chassis.AxleFront.FlagsLeft = flags;
wheelSurf.Position = new Dictionary<string, float>
{
["x"] = chassis.AxleFront.WheelPositionX,
["y"] = chassis.GroundHeight + chassis.AxleFront.WheelRadius,
["z"] = chassis.AxleFront.PositionZ
};
wheelSurf.Parameters = new Dictionary<string, float>
{
["x"] = chassis.AxleFront.WheelWidthHalf,
["y"] = chassis.AxleFront.WheelRadius,
["z"] = chassis.AxleFront.WheelRadius
};
break;
case WheelIndex.FrontRight:
chassis.AxleFront.FlagsRight = flags;
wheelSurf.Position = new Dictionary<string, float>
{
["x"] = -chassis.AxleFront.WheelPositionX,
["y"] = chassis.GroundHeight + chassis.AxleFront.WheelRadius,
["z"] = chassis.AxleFront.PositionZ
};
wheelSurf.Parameters = new Dictionary<string, float>
{
["x"] = chassis.AxleFront.WheelWidthHalf,
["y"] = chassis.AxleFront.WheelRadius,
["z"] = chassis.AxleFront.WheelRadius
};
break;
case WheelIndex.RearRight:
chassis.AxleRear.FlagsRight = flags;
wheelSurf.Position = new Dictionary<string, float>
{
["x"] = -chassis.AxleRear.WheelPositionX,
["y"] = chassis.GroundHeight + chassis.AxleRear.WheelRadius,
["z"] = chassis.AxleRear.PositionZ
};
wheelSurf.Parameters = new Dictionary<string, float>
{
["x"] = chassis.AxleRear.WheelWidthHalf,
["y"] = chassis.AxleRear.WheelRadius,
["z"] = chassis.AxleRear.WheelRadius
};
break;
case WheelIndex.RearLeft:
chassis.AxleRear.FlagsLeft = flags;
wheelSurf.Position = new Dictionary<string, float>
{
["x"] = chassis.AxleRear.WheelPositionX,
["y"] = chassis.GroundHeight + chassis.AxleRear.WheelRadius,
["z"] = chassis.AxleRear.PositionZ
};
wheelSurf.Parameters = new Dictionary<string, float>
{
["x"] = chassis.AxleRear.WheelWidthHalf,
["y"] = chassis.AxleRear.WheelRadius,
["z"] = chassis.AxleRear.WheelRadius
};
break;
}
wheelDatas.Add(wheelSurf);
}
}
else
{
Console.WriteLine("\nChunk0910E000.U04 (CPlugVehicleWheelPhyModel) is null.");
}
List<SurfaceData> bodyDatas = [];
if (surface is not null)
{
CPlugSkel? skel = surface.Skel;
CPlugSurface.ISurf? surf = surface.Surf;
if (skel is not null)
{
string? name = skel.Name;
CPlugSkel.Joint[] joints = skel.Joints;
Console.WriteLine("\nSkeleton \"" + (name is not null ? name : "\\null") + "\":");
for (int i = 0; i < joints.Length; i++)
{
string? jointName = joints[i].Name;
short parentIndex = joints[i].ParentIndex;
GBX.NET.Quat? rotation = joints[i].GlobalJoint;
GBX.NET.Vec3? position = joints[i].U01;
GBX.NET.Iso4? transform = joints[i].U02;
Console.WriteLine("\nJoint \"" + (jointName is not null ? jointName : "\\null") + "\":");
Console.WriteLine("parentIndex\t\t" + parentIndex);
Console.WriteLine("rotation (quat.)\t" + (rotation is not null ? rotation : "\\null"));
Console.WriteLine("position\t\t" + (position is not null ? position : "\\null"));
Console.WriteLine("transform\t\t" + (transform is not null ? transform : "\\null"));
bool isWheel = false;
for (int j = 0; j < wheelDatas.Count; j++)
{
if (wheelDatas[j].Name == jointName)
{
isWheel = true;
break;
}
}
if (!isWheel)
{
bodyDatas.Add(new()
{
Name = jointName,
Position = (transform.HasValue ? new Dictionary<string, float>
{
["x"] = transform.Value.TX,
["y"] = transform.Value.TY,
["z"] = transform.Value.TZ
} : null),
Rotation = (rotation.HasValue ? new Dictionary<string, float>
{
["x"] = rotation.Value.X,
["y"] = rotation.Value.Y,
["z"] = rotation.Value.Z,
["w"] = rotation.Value.W
} : null)
});
}
surfs.Add(new Tuple<bool, string?>(isWheel, jointName));
}
}
else
{
Console.WriteLine("\nNo CPlugSkel found.");
}
if (surf is not null)
{
int parseSurface(CPlugSurface.ISurf surface, int surfIndex)
{
int surfId = surface.Id;
Console.WriteLine("Surface is " + surface.ToString() + " (Id = " + surfId + ").");
switch (surface)
{
case CPlugSurface.Compound compound:
CPlugSurface.ISurf[] surfaces = compound.Surfaces;
GBX.NET.Vec3? compoundU01 = compound.U01;
GBX.NET.Iso4[] transforms = compound.U02;
ushort[] compoundU03 = compound.U03;
Console.WriteLine("Compound.U01 (Vec3)\t" + (compoundU01 is not null ? compoundU01 : "\\null"));
Console.WriteLine("\n" + surfaces.Length + " surfaces found in Surface Compound.");
for (int i = 0; i < surfaces.Length; i++)
{
Console.WriteLine("\nCompound surface #" + i + ":");
surfIndex = parseSurface(surfaces[i], surfIndex + 1);
}
for (int i = 0; i < transforms.Length; i++)
{
Console.WriteLine("\nTransform #" + i + ":");
Console.WriteLine(transforms[i]);
}
for (int i = 0; i < compoundU03.Length; i++)
{
Console.WriteLine("\nCompound.U03[" + i + "]:");
Console.WriteLine(compoundU03[i]);
}
break;
case CPlugSurface.Ellipsoid ellipsoid:
Vec3 size = ellipsoid.Size;
Vec3? ellipsoidU01 = ellipsoid.U01;
ushort ellipsoidU02 = ellipsoid.U02;
Console.WriteLine("Size\t\t\t" + size);
Console.WriteLine("Ellipsoid.U01 (Vec3)\t" + (ellipsoidU01 is not null ? ellipsoidU01 : "\\null"));
Console.WriteLine("Ellipsoid.U02 (ushort)\t" + ellipsoidU02);
bool isWheel = surfs[surfIndex].Item1;
string? surfName = surfs[surfIndex].Item2;
if (isWheel)
{
break; // Wheel data here is duplicate data, seemingly taking no effect.
}
else
{
for (int i = 0; i < bodyDatas.Count; i++)
{
if (bodyDatas[i].Name == surfName)
{
bodyDatas[i].Type = "Ellipsoid";
bodyDatas[i].Parameters = new Dictionary<string, float>
{
["x"] = size.X,
["y"] = size.Y,
["z"] = size.Z
};
break; // Each name should only occur once, otherwise I'm already running into deeper trouble...
}
}
}
break;
default:
Console.WriteLine("Parsing of this surface type is not yet implemented.");
break;
}
return surfIndex;
}
Console.WriteLine("\nCPlugSurface.Surf:");
parseSurface(surf, -1); // This surfIndex = -1 assumes that the first Surface will ALWAYS be a Compound. This way, when parseSurface(... , surfIndex + 1) is called for the FIRST Surface of this Compound, it passes surfIndex = 0.
}
else
{
Console.WriteLine("\nCPlugSurface.Surf (CPlugSurface.ISurf) is null.");
}
}
else
{
Console.WriteLine("\nChunk0910E000.U03 (CPlugSurface) is null.");
}
VehiclePhyModelData vehiclePhyModelData = new VehiclePhyModelData
{
Version = VERSION,
BodySurfs = bodyDatas.ToArray(),
Chassis = chassis
//WheelSurfs = wheelDatas.ToArray()
};
JsonSerializerOptions? jsonOptions = new JsonSerializerOptions { WriteIndented = true };
string jsonString = JsonSerializer.Serialize(vehiclePhyModelData, jsonOptions);
Console.WriteLine("\n\n" + jsonString);
Console.WriteLine("\nSuccessfully parsed GBX-VehiclePhyModel and serialized as JSON-VehiclePhyModel. Saving JSON to disk...");
File.WriteAllText(args[0].Replace(".gbx", ".json", true, null), jsonString);
}
else
{
Console.WriteLine("\nNo CPlugVehicleCarPhyShape.Chunk0910E000 found.");
}
}
else
{
Console.WriteLine("\nCPlugVehiclePhyModel.PhyShape is null.");
}
}
else
{
Console.WriteLine("\nSupplied file is not a CPlugVehiclePhyModel.");
}
}
else if (args.Length == 2)
{
try
{
bool firstIsJSON = args[0].EndsWith(".json", true, null);
string jsonString = File.ReadAllText(args[firstIsJSON ? 0 : 1]);
VehiclePhyModelData? vehiclePhyModelData = JsonSerializer.Deserialize<VehiclePhyModelData>(jsonString);
if (vehiclePhyModelData is not null)
{
Console.WriteLine("\nSuccessfully deserialized JSON-VehiclePhyModel. Building GBX-VehiclePhyModel...");
if(vehiclePhyModelData.Version != VERSION)
{
Console.WriteLine("\nThis is VehiclePhyModeler v" + VERSION + ", supplied file is v" + vehiclePhyModelData.Version + ". Canceling build.");
return;
}
try
{
GBX.NET.Node? vpm = GameBox.ParseNode(args[firstIsJSON ? 1 : 0]);
if (vpm is CPlugVehiclePhyModel vehiclePhyModel)
{
//CPlugVehicleCarPhyShape? ps = vehiclePhyModel.PhyShape;
if (vehiclePhyModel.PhyShape is CPlugVehicleCarPhyShape ps)
{
// CPlugVehicleCarPhyShape.Chunk0910E000? phyShape = ps.GetChunk<CPlugVehicleCarPhyShape.Chunk0910E000>();
if (ps.chunk0910E000u is Chunk0910E000U phyShape)
{
//CPlugSurface? surface = phyShape.U03;
if (phyShape.U03 is CPlugSurface surface)
{
// Building the skeleton //////////////////////////////////////
List<Tuple<bool, string?>> surfs = [];
List<SurfaceData> bodyDatas = [];
if (surface.Skel is CPlugSkel skel) // This is required to be true! CPlugSkel cannot be initialized so if the base input file have surface.Skel == null it will not work.
{
skel.Name = "";
List<CPlugSkel.Joint> jointList = [];
List<Iso4> iso4List = [];
List<ushort> ushortList = [];
CPlugSkel.Joint getJoint(SurfaceData body)
{
CPlugSkel.Joint joint = new CPlugSkel.Joint();
joint.Name = body.Name;
joint.ParentIndex = -1; // Potentially different for Compounds of Compounds?
Quat rotation = new();
Vec3 position = new();
if (body.Rotation is Dictionary<string, float> rotDict)
{
try
{
rotation = new Quat(rotDict["x"], rotDict["y"], rotDict["z"], rotDict["w"]);
}
catch (KeyNotFoundException knfe)
{
rotation = new Quat(0.0f, 0.0f, 0.0f, 1.0f);
}
}
if (body.Position is Dictionary<string, float> posDict)
{
try
{
position = new Vec3(posDict["x"], posDict["y"], posDict["z"]);
}
catch (KeyNotFoundException knfe)
{
position = new Vec3(0.0f, 0.0f, 0.0f);
}
}
joint.GlobalJoint = rotation;
joint.U01 = position;
Matrix4x4 m = Matrix4x4.CreateFromQuaternion(new Quaternion(rotation.X, rotation.Y, rotation.Z, rotation.W));
Iso4 iso4 = new Iso4(m.M11, m.M21, m.M31, m.M12, m.M22, m.M32, m.M13, m.M23, m.M33, position.X, position.Y, position.Z);
joint.U02 = iso4;
iso4List.Add(iso4);
ushortList.Add((ushort)ushortList.Count);
return joint;
}
// Wheels //////////////////////////////////////
List<SurfaceData> wheelSurfs = [];
if (vehiclePhyModelData.Chassis is Chassis chassis)
{
List<CPlugVehicleWheelPhyModel> wheelsList = new List<CPlugVehicleWheelPhyModel>();
for (int i = 0; i < 4; i++)
{
CPlugVehicleWheelPhyModel wheel = new();
SurfaceData wheelSurf = new SurfaceData
{
Type = "Ellipsoid"
};
switch ((WheelIndex)i)
{
case WheelIndex.FrontLeft:
{
wheel.Id = wheelSurf.Name = "FLSurf";
if (chassis.AxleFront is Axle axle)
{
wheelSurf.Position = new Dictionary<string, float>
{
["x"] = axle.WheelPositionX,
["y"] = chassis.GroundHeight + axle.WheelRadius,
["z"] = axle.PositionZ
};
wheelSurf.Parameters = new Dictionary<string, float>
{
["x"] = axle.WheelWidthHalf,
["y"] = axle.WheelRadius,
["z"] = axle.WheelRadius
};
if (axle.FlagsLeft is not null)
{
wheel.IsDriving = axle.FlagsLeft["IsDriving"];
wheel.IsSteering = axle.FlagsLeft["IsSteering"];
}
}
break;
}
case WheelIndex.FrontRight:
{
wheel.Id = wheelSurf.Name = "FRSurf";
if (chassis.AxleFront is Axle axle)
{
wheelSurf.Position = new Dictionary<string, float>
{
["x"] = -axle.WheelPositionX,
["y"] = chassis.GroundHeight + axle.WheelRadius,
["z"] = axle.PositionZ
};
wheelSurf.Parameters = new Dictionary<string, float>
{
["x"] = axle.WheelWidthHalf,
["y"] = axle.WheelRadius,
["z"] = axle.WheelRadius
};
if (axle.FlagsRight is not null)
{
wheel.IsDriving = axle.FlagsRight["IsDriving"];
wheel.IsSteering = axle.FlagsRight["IsSteering"];
}
}
break;
}
case WheelIndex.RearRight:
{
wheel.Id = wheelSurf.Name = "RRSurf";
if (chassis.AxleRear is Axle axle)
{
wheelSurf.Position = new Dictionary<string, float>
{
["x"] = -axle.WheelPositionX,
["y"] = chassis.GroundHeight + axle.WheelRadius,
["z"] = axle.PositionZ
};
wheelSurf.Parameters = new Dictionary<string, float>
{
["x"] = axle.WheelWidthHalf,
["y"] = axle.WheelRadius,
["z"] = axle.WheelRadius
};
if (axle.FlagsRight is not null)
{
wheel.IsDriving = axle.FlagsRight["IsDriving"];
wheel.IsSteering = axle.FlagsRight["IsSteering"];
}
}
break;
}
case WheelIndex.RearLeft:
{
wheel.Id = wheelSurf.Name = "RLSurf";
if (chassis.AxleRear is Axle axle)
{
wheelSurf.Position = new Dictionary<string, float>
{
["x"] = axle.WheelPositionX,
["y"] = chassis.GroundHeight + axle.WheelRadius,
["z"] = axle.PositionZ
};
wheelSurf.Parameters = new Dictionary<string, float>
{
["x"] = axle.WheelWidthHalf,
["y"] = axle.WheelRadius,
["z"] = axle.WheelRadius
};
if (axle.FlagsLeft is not null)
{
wheel.IsDriving = axle.FlagsLeft["IsDriving"];
wheel.IsSteering = axle.FlagsLeft["IsSteering"];
}
}
break;
}
}
wheelsList.Add(wheel);
wheelSurfs.Add(wheelSurf);
jointList.Add(getJoint(wheelSurf));
}
vehiclePhyModel.PhyShape!.chunk0910E000u.U04 = wheelsList.ToArray();
vehiclePhyModel.PhyShape!.chunk0910E000u.U07 = chassis.GroundHeight;
if (chassis.AxleFront is not null)
{
vehiclePhyModel.PhyShape!.chunk0910E000u.U08 = chassis.AxleFront.PositionZ;
vehiclePhyModel.PhyShape!.chunk0910E000u.U10 = chassis.AxleFront.WheelPositionX;
vehiclePhyModel.PhyShape!.chunk0910E000u.U12 = chassis.AxleFront.WheelRadius;
vehiclePhyModel.PhyShape!.chunk0910E000u.U14 = chassis.AxleFront.WheelWidthHalf;
}
if (chassis.AxleRear is not null)
{
vehiclePhyModel.PhyShape!.chunk0910E000u.U09 = chassis.AxleRear.PositionZ;
vehiclePhyModel.PhyShape!.chunk0910E000u.U11 = chassis.AxleRear.WheelPositionX;
vehiclePhyModel.PhyShape!.chunk0910E000u.U13 = chassis.AxleRear.WheelRadius;
vehiclePhyModel.PhyShape!.chunk0910E000u.U15 = chassis.AxleRear.WheelWidthHalf;
}
}
// Body //////////////////////////////////////
if (vehiclePhyModelData.BodySurfs is SurfaceData[] bodiesSurfs)
{
for (int i = 0; i < bodiesSurfs.Length; i++)
{
jointList.Add(getJoint(bodiesSurfs[i]));
}
}
skel.Joints = jointList.ToArray();
// Building the Compound Surface //////////////////////////////////
CPlugSurface.Compound compound = new CPlugSurface.Compound();
List<CPlugSurface.ISurf> surfaces = new List<CPlugSurface.ISurf>();
CPlugSurface.ISurf buildSurface(SurfaceData surf)
{
switch (surf.Type)
{
case ("Ellipsoid"):
CPlugSurface.Ellipsoid ellipsoid = new CPlugSurface.Ellipsoid();
Vec3 size = new();
if (surf.Parameters is Dictionary<string, float> sizeDict)
{
try
{
size = new(sizeDict["x"], sizeDict["y"], sizeDict["z"]);
}
catch (KeyNotFoundException knfe)
{
size = new(0.0f, 0.0f, 0.0f);
Console.WriteLine("\n[ERROR]\tIncorrect parameters for Ellipsoid.");
}
}
ellipsoid.Size = size;
ellipsoid.U01 = null; // No idea what these 2 values do but I saw them like this a lot.
ellipsoid.U02 = 0; //
return ellipsoid;
default:
Console.WriteLine("\n[ERROR]\tUnsupported Surface type \"" + surf.Type + "\".");
break;
}
CPlugSurface.Ellipsoid ellipsoidNull = new()
{
Size = new Vec3(0.0f, 0.0f, 0.0f),
U01 = null,
U02 = 0
};
return ellipsoidNull;
}
for (int i = 0; i < wheelSurfs.Count; i++)
{
surfaces.Add(buildSurface(wheelSurfs[i]));
}
if (vehiclePhyModelData.BodySurfs is SurfaceData[] bodySurfs)
{
for (int i = 0; i < bodySurfs.Length; i++)
{
surfaces.Add(buildSurface(bodySurfs[i]));
}
}
compound.Surfaces = surfaces.ToArray();
compound.U01 = null;
compound.U02 = iso4List.ToArray();
compound.U03 = ushortList.ToArray();
surface.Surf = compound;
}
else
{
Console.WriteLine("\n[ERROR]\tNo CPlugSurface.Skel found.");
}
}
else
{
Console.WriteLine("\nNo Chunk0910E000U.U03 (CPlugSurface) found.");
}
}
else
{
Console.WriteLine("\nNo CPlugVehicleCarPhyShape.Chunk0910E000u found.");
}
}
else
{
Console.WriteLine("\nCPlugVehiclePhyModel.PhyShape is null.");
}
vehiclePhyModel.Save(args[firstIsJSON ? 0 : 1] + ".Gbx");
}
else
{
Console.WriteLine("\nSupplied file is not a CPlugVehiclePhyModel.");
}
}
catch (Exception exc)
{
Console.WriteLine(exc.Message);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
else
{
Console.WriteLine("\n\n[ERROR]\tPlease supply 1 GBX-VehiclePhyModel file to export to JSON, or supply 1 JSON-VehiclePhyModel & 1 GBX-VehiclePhyModel as a base to import the changes into, e.g.");
Console.WriteLine("\n\t\"VehiclePhyModeler.exe CanyonCar.VehiclePhyModel.Gbx\"\n");
Console.WriteLine("\n\t\"VehiclePhyModeler.exe ValleyCar.VehiclePhyModel.json StadiumCar.VehiclePhyModel.Gbx\"\n");
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.WriteLine("\n\nFinished VehiclePhyModeler program.");
return;
}
}
}