Elaztek Developer Hub
Blamite Game Engine - Tool (Library)
A command-line utility that aids in the creation of Blamite Cache (.map) Files.
RenderModelCommand.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Strings/components/utils/io/io.h>
4 #include <Strings/components/utils/string/string.h>
5 #include <Strings/components/utils/converters/converters.h>
6 #include <Strings/components/logger/logger.h>
7 
8 #include <HEKGuerilla/components/tags/importers/render_model/render_model.h>
9 #include <HEKGuerilla/components/tags/tags.h>
10 #include <HEKGuerilla/components/settings/config/config.h>
11 
12 #include "../ToolCommand.hpp"
13 #include "../console.h"
14 #include "components/utils/utils.h"
15 
16 #ifdef TOOL_LIB_EXPORTS
17 #define TOOL_LIB_API __declspec(dllexport)
18 #else
19 #define TOOL_LIB_API __declspec(dllimport)
20 #endif
21 
29 {
30 private:
31  std::vector<std::string> supported_formats =
32  {
33  "3D", "3DS", "3MF", "AC", "AC3D", "ACC", "AMJ", "ASE", "ASK", "B3D", "BVH", "CSM", "COB", "DAE/Collada",
34  "DXF", "ENFF", "FBX", "glTF 1.0 + GLB", "glTF 2.0", "HMB", "IFC-STEP", "IQM", "IRR / IRRMESH", "LWO",
35  "LWS", "LXO", "M3D", "MD2", "MD3", "MD5", "MDC", "MDL", "MESH / MESH.XML", "MOT", "MS3D", "NDO", "NFF",
36  "OBJ", "OFF", "OGEX", "PLY", "PMX", "PRJ", "Q3O", "Q3S", "RAW", "SCN", "SIB", "SMD", "STP", "STL", "TER",
37  "UC", "USD", "VTA", "X", "X3D", "XGL", "ZGL"
38  };
39 
40  std::vector<std::string> supported_extensions =
41  {
42  "3D", "3DS", "3MF", "AC", "AC3D", "ACC", "AMJ", "ASE", "ASK", "B3D", "BVH", "CSM", "COB", "DAE",
43  "DXF", "ENFF", "FBX", "GLTF", "HMB", "IFCXML", "IQM", "IRR", "IRRMESH", "LWO",
44  "LWS", "LXO", "M3D", "MD2", "MD3", "MD5", "MDC", "MDL", "MESH", "MESH.XML", "MOT", "MS3D", "NDO", "NFF",
45  "OBJ", "OFF", "OGEX", "PLY", "PMX", "PRJ", "Q3O", "Q3S", "RAW", "SCN", "SIB", "SMD", "STP", "STL", "TER",
46  "UC", "USD", "VTA", "X", "X3D", "XGL", "ZGL"
47  };
48 
49 public:
51  {
52  command = "render-model";
53  syntax = "render-model <file>";
54  description = "imports a model file as a render_model. will not create or update any [hlmt] model tag."
55  "supported formats: " + BlamStrings::Utils::String::BuildFromList(supported_formats);
56  }
57 
58  int execute(std::vector<std::string> args)
59  {
60  std::string import_base_dir = BlamStrings::Utils::IO::NormalizePath(BlamTool::Utils::GetProjectRoot() + "data/");
61  std::string output_base_dir = BlamStrings::Utils::IO::NormalizePath(BlamTool::Utils::GetProjectRoot() + "tags/");
62 
63  std::string input_file = "";
64  std::string output_directory = "";
65 
66  if (args.size() == 0)
67  {
68  BlamStrings::Logger::LogEvent("no input file path was provided, cannot import model", BlamLogLevel::Warning);
69  return -1;
70  }
71 
72  if (args.size() > 1)
73  {
74  BlamStrings::Logger::LogEvent("too many arguments specified - skipping import. check your input and try again. "
75  "for additional help, use 'tool.exe help render-model'.", BlamLogLevel::Warning);
76  return -1;
77  }
78 
79  input_file = import_base_dir + args[0];
80  output_directory = output_base_dir + BlamStrings::Utils::IO::GetContainingFolder(args[0], false);
81 
82  /*if (!BlamStrings::Utils::String::EndsWithAny(input_file, supported_extensions, true))
83  {
84  BlamStrings::Logger::LogEvent("model appears to use unsupported/unknown format '"
85  + BlamStrings::Utils::IO::GetFileExtension(input_file, true) + "', cannot import model "
86  "(use 'tool.exe help render-model' for a list of supported formats)'", BlamLogLevel::Warning);
87  return -1;
88  }*/
89 
90  Guerilla::Tags::LoadPlugins({ "./plugins/", BlamTool::Utils::GetProjectRoot() + "/plugins/" });
91 
92  if (!Guerilla::Tags::Importers::RenderModel::ImportRenderModel(input_file, output_directory))
93  {
94  BlamStrings::Logger::LogEvent("failed to import render model '" + input_file + "'", WSV_WARNING);
95  }
96  else
97  {
98  BlamStrings::Logger::LogEvent("successfully imported render model '" + input_file + "' to directory '" + output_directory + "'");
99  }
100 
101  Guerilla::Tags::ReleasePlugins();
102 
103  BlamStrings::Logger::LogEvent("finished.");
104  return 0;
105  }
106 };
RenderModelCommand::execute
int execute(std::vector< std::string > args)
Executes the command.
Definition: RenderModelCommand.hpp:58
RenderModelCommand
Class for the render-model command.
Definition: RenderModelCommand.hpp:28
utils.h
ToolCommand::syntax
std::string syntax
The syntax of the command. This should include the command name, as well as any arguments.
Definition: ToolCommand.hpp:19
RenderModelCommand::RenderModelCommand
RenderModelCommand()
Definition: RenderModelCommand.hpp:50
ToolCommand::command
std::string command
The name of the command.
Definition: ToolCommand.hpp:18
ToolCommand
Base class representing a Tool command.
Definition: ToolCommand.hpp:15
ToolCommand::description
std::string description
A description of the command.
Definition: ToolCommand.hpp:20
BlamTool::Utils::GetProjectRoot
TOOL_LIB_API std::string GetProjectRoot()
Retrieves the current project root.
Definition: utils.cpp:6