Loading...
Searching...
No Matches
NativeScene.hpp
1#pragma once
2#include <Threedim/LiveLink/Protocol.hpp>
3
4#include <ossia/dataflow/geometry_port.hpp>
5
6#include <memory>
7#include <string>
8#include <string_view>
9#include <unordered_map>
10#include <unordered_set>
11#include <vector>
12
13// Scenes sent in native frames (LiveLink/Protocol.hpp: mesh, image,
14// native_scene), built into the same scene_state GltfParser makes from a
15// .glb, so that everything downstream of the live link, and the live link's
16// own patches, removals and streamed values, cannot tell them apart.
17namespace Threedim::LiveLink
18{
19
20// The meshes and images received, by key, ready to be shared by the nodes
21// of any native scene that names them.
23{
24 // Primitives without material (each node using a mesh sets its own), and
25 // the mesh's morph targets as mesh_component holds them (MorphTargets.hpp).
26 struct mesh
27 {
28 std::vector<ossia::mesh_primitive> primitives;
29 ossia::small_vector<ossia::morph_target, 8> morph_targets;
30 };
31 std::unordered_map<std::string, mesh> meshes;
32 std::unordered_map<std::string, std::shared_ptr<ossia::texture_source>> images;
33
34 // A mesh sent again under the same key replaces the previous one, with new
35 // primitive ids: the renderer uploads it anew.
36 void add_mesh(
37 const mesh_message& m,
38 const std::vector<std::shared_ptr<std::vector<float>>>& tangents);
39 void add_image(const image_message& m);
40
41 // Drops what `used` does not name.
42 void keep_only(
43 const std::unordered_set<std::string>& used_meshes,
44 const std::unordered_set<std::string>& used_images);
45};
46
48{
49 std::shared_ptr<ossia::scene_state> state; // null when the JSON is invalid
50 std::vector<std::string> material_names; // parallel to state->materials
51 std::unordered_set<std::string> meshes, images; // the keys it uses
52 std::string error;
53};
54
55// `seq` makes material ids unique per native scene, as GltfParser's path does
56// per file: a material sent again is a new material to the renderer.
57native_scene build_native_scene(
58 std::string_view json, const native_resources& resources, uint64_t seq);
59
60}