src/gltf/GltfForwardTranslator.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #ifndef GLTF_GLTFFORWARDTRANSLATOR_HPP | ||
| 7 | #define GLTF_GLTFFORWARDTRANSLATOR_HPP | ||
| 8 | |||
| 9 | #include "GltfAPI.hpp" | ||
| 10 | |||
| 11 | #include "GltfMetaData.hpp" | ||
| 12 | #include "GltfUserData.hpp" | ||
| 13 | |||
| 14 | #include "../utilities/core/Path.hpp" | ||
| 15 | #include "../utilities/core/Logger.hpp" | ||
| 16 | #include "../utilities/core/StringStreamLogSink.hpp" | ||
| 17 | |||
| 18 | namespace tinygltf { | ||
| 19 | class Model; | ||
| 20 | } | ||
| 21 | |||
| 22 | namespace openstudio { | ||
| 23 | namespace model { | ||
| 24 | class Model; | ||
| 25 | } | ||
| 26 | |||
| 27 | namespace gltf { | ||
| 28 | |||
| 29 | // TODO: update this docstring, it's always been out of sync | ||
| 30 | |||
| 31 | /** GltfForwardTranslator converts an OpenStudio Model to GLTF format. There are two variations of the GLTF format, | ||
| 32 | * a triangulated one which is suitable for rendering with GLTF and non-triangulated one that preserves all vertices in a | ||
| 33 | * surface for conversion to OpenStudio Model format. | ||
| 34 | * | ||
| 35 | * The FloorplanJS in the Utilities/Geometry project converts a FloorspaceJS JSON file to GLTF format, code should be shared between these two classes as much as possible. | ||
| 36 | */ | ||
| 37 | class GLTF_API GltfForwardTranslator | ||
| 38 | { | ||
| 39 | public: | ||
| 40 | GltfForwardTranslator(); | ||
| 41 | |||
| 42 | /** Convert an OpenStudio Model to Gltf format */ | ||
| 43 | bool modelToGLTF(const model::Model& model, const path& outputPath); | ||
| 44 | bool modelToGLTF(const model::Model& model, std::function<void(double)> updatePercentage, const path& outputpath); | ||
| 45 | |||
| 46 | /** Convert an OpenStudio Model to Gltf format but as a JSON string */ | ||
| 47 | std::string modelToGLTFString(const model::Model& model); | ||
| 48 | |||
| 49 | /** @name QA / QC convenience methods */ | ||
| 50 | //@{ | ||
| 51 | /** load minimal gltf for QA/QC */ | ||
| 52 | bool loadGLTF(const path& inputPath, const path& inputNonEmbededpath); | ||
| 53 | /** load minimal gltf for QA/QC */ | ||
| 54 | bool loadGLTF(const path& inputPath); | ||
| 55 | |||
| 56 | GltfMetaData getMetaData() const; | ||
| 57 | std::vector<GltfUserData> getUserDataCollection() const; | ||
| 58 | boost::optional<GltfUserData> getUserDataBySurfaceName(const std::string& surfaceName) const; | ||
| 59 | |||
| 60 | /** Get warning messages generated by the last translation. */ | ||
| 61 | std::vector<LogMessage> warnings() const; | ||
| 62 | |||
| 63 | /** Get error messages generated by the last translation. */ | ||
| 64 | std::vector<LogMessage> errors() const; | ||
| 65 | //@} | ||
| 66 | |||
| 67 | private: | ||
| 68 | boost::optional<tinygltf::Model> toGltfModel(const model::Model& model, std::function<void(double)> updatePercentage); | ||
| 69 | |||
| 70 | − | REGISTER_LOGGER("openstudio.gltf.GltfForwardTranslator"); | |
| 71 | |||
| 72 | StringStreamLogSink m_logSink; | ||
| 73 | |||
| 74 | GltfMetaData m_gltfMetaData; | ||
| 75 | std::vector<GltfUserData> m_userDataCollection; | ||
| 76 | |||
| 77 | // TODO: make this a member? | ||
| 78 | // std::vector<GltfMaterialData> allMaterials; | ||
| 79 | }; | ||
| 80 | |||
| 81 | } // namespace gltf | ||
| 82 | } // namespace openstudio | ||
| 83 | |||
| 84 | #endif // GLTF_GLTFFORWARDTRANSLATOR_HPP | ||
| 85 |