public void AddIpl(BinaryIpl ipl, PhysicsModelLoadMode loadMode) { foreach (var inst in ipl.Insts) { if (loadMode == PhysicsModelLoadMode.Dff) { this.actions.Add(world => { var dff = this.assetCollection.GetDff(inst.Id); if (dff != null && this.dffMeshes.TryGetValue(dff, out var mesh)) { var euler = inst.Rotation.ToEuler(); euler = new Vector3(euler.X, euler.Y, -euler.Z); world.AddStatic(mesh, inst.Position, euler.ToQuaternion()); } }); } else { this.actions.Add(world => { var col = this.assetCollection.GetCol(inst.Id); if (col != null && this.colMeshes.TryGetValue(col, out var meshes)) { foreach (var mesh in meshes) { var euler = inst.Rotation.ToEuler(); euler = new Vector3(euler.X, euler.Y, -euler.Z); world.AddStatic(mesh, inst.Position, euler.ToQuaternion()); } } }); } } }
public PhysicsWorld CreatePhysicsWorldFromDat( string root, string datFilepath, string imgFilepath, PhysicsModelLoadMode loadMode = PhysicsModelLoadMode.LowDetail, Action <PhysicsWorldBuilder>?builderAction = null ) { return(CreatePhysicsWorldFromDat(root, new DatFile(datFilepath), new ImgFile(imgFilepath), loadMode, builderAction)); }
public PhysicsWorld CreatePhysicsWorldFromGtaDirectory( string directory, string datFile = "gta.dat", PhysicsModelLoadMode loadMode = PhysicsModelLoadMode.LowDetail, Action <PhysicsWorldBuilder>?builderAction = null ) { string datFilepath = Path.Join(directory, $"data/{datFile}"); string imgFilepath = Path.Join(directory, "models/gta3.img"); return(CreatePhysicsWorldFromDat(directory, new DatFile(datFilepath), new ImgFile(imgFilepath), loadMode, builderAction)); }
public PhysicsWorldBuilder(ILogger logger) { this.logger = logger; this.assetCollection = new(); this.actions = new(); this.imgs = new(); this.dffMeshes = new(); this.colMeshes = new(); this.namedColCombos = new(); this.loadMode = PhysicsModelLoadMode.Col; }
public PhysicsWorld CreatePhysicsWorldFromDat(string root, DatFile datFile, ImgFile imgFile, PhysicsModelLoadMode loadMode = PhysicsModelLoadMode.LowDetail, Action <PhysicsWorldBuilder>?builderAction = null ) { var world = CreateWorld(builder => { builder.AddImg(imgFile.Img); foreach (var ide in datFile.Dat.Ides) { var path = Path.Join(root, ide).TrimEnd('\r'); if (File.Exists(path)) { builder.AddIde(Path.GetFileNameWithoutExtension(path), new IdeFile(path).Ide, loadMode); } else { this.logger.LogWarning($"Unable to find .ide file {path}"); } } foreach (var ipl in datFile.Dat.Ipls) { var path = Path.Join(root, ipl).TrimEnd('\r'); if (File.Exists(path)) { builder.AddIpl(new IplFile(path).Ipl, loadMode); } else { this.logger.LogWarning($"Unable to find .ipl file {path}"); } } foreach (var ipl in imgFile.Img.IplFiles) { builder.AddIpl(new BinaryIplFile(imgFile.Img.DataEntries[ipl].Data).BinaryIpl, loadMode); } builderAction?.Invoke(builder); }); imgFile.Dispose(); return(world); }
public void AddIde(string ideName, Ide ide, PhysicsModelLoadMode loadMode) { if (loadMode == PhysicsModelLoadMode.Dff) { foreach (var obj in ide.Objs) { var dff = GetDff(obj.ModelName + ".dff"); if (dff != null) { this.assetCollection.RegisterDff(obj.Id, dff); this.actions.Add(world => { try { this.dffMeshes[dff] = world.CreateMesh(dff); } catch (Exception) { this.logger.LogTrace($"Unable to locate dff {obj.ModelName}"); } }); } } } else { foreach (var obj in ide.Objs) { if (this.namedColCombos.ContainsKey(obj.ModelName.ToLower())) { var colCombo = this.namedColCombos[obj.ModelName.ToLower()]; if (colCombo.Header.BoxCount + colCombo.Header.SphereCount + colCombo.Header.FaceCount > 0) { this.assetCollection.RegisterCol(obj.Id, colCombo); this.actions.Add(world => { try { var meshes = world.CreateMesh(colCombo); var resultMeshes = new List <IPhysicsMesh>(); if (meshes.Item1 != null) { resultMeshes.Add(meshes.Item1); } if (meshes.Item2 != null) { resultMeshes.Add(meshes.Item2); } this.colMeshes[colCombo] = resultMeshes.ToArray(); } catch (Exception) { this.logger.LogTrace($"Unable to locate col {obj.ModelName.ToLower()} in {ideName}"); } }); } } else { this.logger.LogTrace($"Unable to find col {obj.ModelName.ToLower()} in {ideName}"); } } } }
public void SetMode(PhysicsModelLoadMode loadMode) { this.loadMode = loadMode; }