| 145 | } |
| 146 | |
| 147 | void scene::export_environment(const std::string & export_path) |
| 148 | { |
| 149 | manual_timer t; |
| 150 | t.start(); |
| 151 | |
| 152 | json scene_json; |
| 153 | |
| 154 | for (const auto & [e, obj] : graph.graph_objects) |
| 155 | { |
| 156 | if (!obj.serializable) continue; |
| 157 | |
| 158 | json entity_json; |
| 159 | |
| 160 | // Serialize identifier (name) |
| 161 | if (!obj.name.empty()) |
| 162 | { |
| 163 | entity_json["@identifier_component"] = json{{"id", obj.name}}; |
| 164 | } |
| 165 | |
| 166 | // Serialize transform |
| 167 | if (auto * xform = const_cast<base_object &>(obj).get_component<transform_component>()) |
| 168 | { |
| 169 | json xform_json; |
| 170 | xform_json["local_pose"] = xform->local_pose; |
| 171 | xform_json["local_scale"] = xform->local_scale; |
| 172 | |
| 173 | // Get parent from scene graph |
| 174 | entity parent = graph.get_parent(e); |
| 175 | if (parent != kInvalidEntity) |
| 176 | { |
| 177 | xform_json["parent"] = parent.as_string(); |
| 178 | } |
| 179 | else |
| 180 | { |
| 181 | xform_json["parent"] = ""; |
| 182 | } |
| 183 | |
| 184 | entity_json["@local_transform_component"] = xform_json; |
| 185 | } |
| 186 | |
| 187 | // Serialize mesh_component |
| 188 | if (auto * mesh = const_cast<base_object &>(obj).get_component<mesh_component>()) |
| 189 | { |
| 190 | entity_json["@mesh_component"] = *mesh; |
| 191 | } |
| 192 | |
| 193 | // Serialize material_component |
| 194 | if (auto * mat = const_cast<base_object &>(obj).get_component<material_component>()) |
| 195 | { |
| 196 | entity_json["@material_component"] = *mat; |
| 197 | } |
| 198 | |
| 199 | // Serialize geometry_component |
| 200 | if (auto * geom = const_cast<base_object &>(obj).get_component<geometry_component>()) |
| 201 | { |
| 202 | entity_json["@geometry_component"] = *geom; |
| 203 | } |
| 204 |
no test coverage detected