Example #1
0
    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);
    }