MCPcopy Create free account
hub / github.com/ddiakopoulos/polymer / import_environment

Method import_environment

libraries/lib-engine/src/scene.cpp:20–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18}
19
20void scene::import_environment(const std::string & import_path)
21{
22 manual_timer t;
23 t.start();
24
25 const std::string json_txt = read_file_text(import_path);
26 const json env_doc = json::parse(json_txt);
27
28 // Track parent-child relationships to establish after all entities created
29 struct parent_child_link
30 {
31 entity child_entity;
32 entity parent_entity;
33 };
34 std::vector<parent_child_link> parent_child_links;
35
36 for (auto entityIterator = env_doc.begin(); entityIterator != env_doc.end(); ++entityIterator)
37 {
38 const std::string entity_key = entityIterator.key();
39 const json & entity_json = entityIterator.value();
40
41 // Create entity with the parsed key as entity ID (must be valid GUID format)
42 entity parsed_entity = entity(entity_key);
43 base_object obj(parsed_entity);
44
45 // Parse identifier_component for name
46 if (entity_json.contains("@identifier_component"))
47 {
48 const json & id_json = entity_json["@identifier_component"];
49 if (id_json.contains("id")) obj.name = id_json["id"].get<std::string>();
50 }
51
52 // Parse local_transform_component
53 if (entity_json.contains("@local_transform_component"))
54 {
55 const json & xform_json = entity_json["@local_transform_component"];
56
57 transform_component xform_c;
58
59 if (xform_json.contains("local_pose")) xform_c.local_pose = xform_json["local_pose"].get<transform>();
60 if (xform_json.contains("local_scale")) xform_c.local_scale = xform_json["local_scale"].get<float3>();
61
62 obj.add_component(xform_c);
63
64 // Track parent relationship for later (parent should be GUID string or empty)
65 if (xform_json.contains("parent"))
66 {
67 const json & parent_val = xform_json["parent"];
68 entity parent_ent = kInvalidEntity;
69
70 if (parent_val.is_string())
71 {
72 std::string parent_str = parent_val.get<std::string>();
73 if (!parent_str.empty()) parent_ent = entity(parent_str);
74 }
75
76 if (parent_ent != kInvalidEntity) parent_child_links.push_back({parsed_entity, parent_ent});
77 }

Callers 1

import_sceneMethod · 0.80

Calls 12

read_file_textFunction · 0.85
add_componentMethod · 0.80
startMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
valueMethod · 0.45
containsMethod · 0.45
emptyMethod · 0.45
add_childMethod · 0.45
refreshMethod · 0.45
stopMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected