Loading...
Searching...
No Matches
Components.hpp
1#pragma once
2#include <Threedim/LiveLink/Protocol.hpp>
3
4#include <ossia/dataflow/geometry_port.hpp>
5
6#include <cstring>
7
8// Light and camera components from their live link records: the mapping
9// GltfParser's to_light and to_camera make from the same glTF values, used
10// for streamed overrides and for native scenes alike.
11namespace Threedim::LiveLink
12{
13
14inline void apply_light(ossia::light_component& lc, const light_record& r)
15{
16 switch(r.type)
17 {
18 case light_record::directional:
19 lc.type = ossia::light_type::directional;
20 break;
21 case light_record::spot:
22 lc.type = ossia::light_type::spot;
23 break;
24 default:
25 lc.type = ossia::light_type::point;
26 break;
27 }
28 std::memcpy(lc.color, r.color, sizeof(lc.color));
29 lc.intensity = r.intensity;
30 lc.range = r.range;
31 lc.inner_cone_angle = r.inner_cone;
32 lc.outer_cone_angle = r.outer_cone;
33}
34
35inline void apply_camera(ossia::camera_component& cc, const camera_record& r)
36{
37 if(r.projection == camera_record::orthographic)
38 {
39 cc.projection = ossia::camera_projection::orthographic;
40 cc.xmag = r.xmag;
41 cc.ymag = r.ymag;
42 }
43 else
44 {
45 cc.projection = ossia::camera_projection::perspective;
46 cc.yfov = r.yfov;
47 cc.aspect_ratio = r.aspect > 0.f ? r.aspect : 1.f;
48 }
49 cc.znear = r.znear;
50 cc.zfar = r.zfar > 0.f ? r.zfar : 1000.f;
51}
52
53}