| 140 | } |
| 141 | |
| 142 | boost::optional<tinygltf::Model> GltfForwardTranslator::toGltfModel(const model::Model& model, std::function<void(double)> updatePercentage) { |
| 143 | // MAIN PIPELINE TO TRANSLATE OPENSTUDIO MODEL -> GLTF MODEL |
| 144 | |
| 145 | bool triangulateSurfaces = true; //we're always triangulating the surfaces to get the best possible output. |
| 146 | |
| 147 | // TODO: cleanup |
| 148 | tinygltf::Model gltfModel; |
| 149 | std::string err; |
| 150 | std::string warning; |
| 151 | path p; |
| 152 | |
| 153 | std::vector<tinygltf::Accessor>& accessors = gltfModel.accessors; |
| 154 | std::vector<tinygltf::Material>& materials = gltfModel.materials; |
| 155 | std::vector<tinygltf::Mesh>& meshes = gltfModel.meshes; |
| 156 | std::vector<tinygltf::Node>& nodes = gltfModel.nodes; |
| 157 | |
| 158 | tinygltf::Scene& scene = gltfModel.scenes.emplace_back(); |
| 159 | tinygltf::Buffer& buffer = gltfModel.buffers.emplace_back(); |
| 160 | |
| 161 | // Note: Can't emplace_back twice and store refs (before a reserve at least), |
| 162 | // because the first ref would be invalidated by the second emplace_back, so just resize and get refs after that |
| 163 | gltfModel.bufferViews.resize(2); |
| 164 | tinygltf::BufferView& indicesBv = gltfModel.bufferViews.front(); |
| 165 | tinygltf::BufferView& coordinatesBv = gltfModel.bufferViews.back(); |
| 166 | std::vector<unsigned char> indicesBuffer; |
| 167 | std::vector<unsigned char> coordinatesBuffer; |
| 168 | |
| 169 | // Start Region INIT |
| 170 | |
| 171 | // Define the asset. The version is required |
| 172 | gltfModel.asset.version = "2.0"; |
| 173 | gltfModel.asset.generator = "OpenStudio"; |
| 174 | |
| 175 | // Init the scene |
| 176 | // aware of all other nodes, meshes, materials, BufferViews, Accessors tightly |
| 177 | // tied up in a Hierarchy using indices pointing one to other. |
| 178 | scene.nodes = {0}; |
| 179 | |
| 180 | // I'm going to be emplacing back elements in nodes a bunch later, which is going to invalidate the references, so limit scope |
| 181 | { |
| 182 | tinygltf::Node& topNode = nodes.emplace_back(); |
| 183 | topNode.name = "Z_UP"; |
| 184 | topNode.matrix = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}; |
| 185 | } |
| 186 | |
| 187 | initBufferViews(indicesBv, coordinatesBv); |
| 188 | |
| 189 | // End Region INIT |
| 190 | |
| 191 | /* |
| 192 | |
| 193 | This comprises of the other nodes that GLTF provides |
| 194 | for further addition of complex details, textures, lights, etc. |
| 195 | |
| 196 | std::vector<tinygltf::Scene> scenes; |
| 197 | std::vector<tinygltf::Buffer> buffers; |
| 198 | std::vector<tinygltf::Animation> animations; |
| 199 | std::vector<tinygltf::Texture> textures; |
nothing calls this directly
no test coverage detected