File include/jrf/scene.h changed (mode: 100644) (index 63f49c5..de9fc6c) |
... |
... |
namespace jrf { struct Scene; struct SceneEntry; } |
6 |
6 |
|
|
7 |
7 |
struct jrf::SceneEntry |
struct jrf::SceneEntry |
8 |
8 |
{ |
{ |
9 |
|
Model model; |
|
10 |
|
jl::array<float, 3> pos; ///< position |
|
11 |
|
jl::array<uint32_t,3> shift; ///< shift of position |
|
12 |
|
jl::array<float, 9> transform; ///< transformation matrix 3x3 |
|
|
9 |
|
struct Options { |
|
10 |
|
void set_default() |
|
11 |
|
{ |
|
12 |
|
pos = {}; |
|
13 |
|
shift = {}; |
|
14 |
|
transform = {}; |
|
15 |
|
transform[0] = transform[4] = transform[8] = 1; |
|
16 |
|
} |
|
17 |
|
|
|
18 |
|
jl::array<float, 3> pos; ///< position |
|
19 |
|
jl::array<int32_t,3> shift; ///< shift of position |
|
20 |
|
jl::array<float, 9> transform; ///< transformation matrix 3x3 |
|
21 |
|
}; |
13 |
22 |
|
|
14 |
|
void destroy() { model.destroy(); } |
|
|
23 |
|
void destroy() { model_path.destroy(); } |
|
24 |
|
|
|
25 |
|
Options options; |
|
26 |
|
jl::string model_path; |
15 |
27 |
|
|
16 |
28 |
template<typename IO = jl::io_agent> |
template<typename IO = jl::io_agent> |
17 |
29 |
[[nodiscard]] Result read(IO *p_mediator) |
[[nodiscard]] Result read(IO *p_mediator) |
18 |
30 |
{ |
{ |
19 |
|
Result res = model.read(p_mediator); |
|
|
31 |
|
Result res = read_str(p_mediator, &model_path); |
20 |
32 |
if (res != Result::SUCCESS) |
if (res != Result::SUCCESS) |
21 |
33 |
return res; |
return res; |
22 |
34 |
|
|
23 |
35 |
jl::io_agent_alt<IO> *p_io = p_mediator; |
jl::io_agent_alt<IO> *p_io = p_mediator; |
24 |
|
if (not p_io->read_items(&pos)) |
|
25 |
|
return Result::MEDIATOR_ERROR; |
|
26 |
|
if (not p_io->read_items(&shift)) |
|
27 |
|
return Result::MEDIATOR_ERROR; |
|
28 |
|
if (p_io->read_items(&transform)) |
|
29 |
|
return Result::MEDIATOR_ERROR; |
|
|
36 |
|
if (not p_io->read_items(&options.pos)) |
|
37 |
|
goto CANCEL; |
|
38 |
|
if (not p_io->read_items(&options.shift)) |
|
39 |
|
goto CANCEL; |
|
40 |
|
if (p_io->read_items(&options.transform)) |
|
41 |
|
goto CANCEL; |
30 |
42 |
|
|
31 |
43 |
return Result::SUCCESS; |
return Result::SUCCESS; |
|
44 |
|
|
|
45 |
|
CANCEL: destroy(); |
|
46 |
|
return Result::MEDIATOR_ERROR; |
32 |
47 |
} |
} |
33 |
48 |
template<typename IO = jl::io_agent> |
template<typename IO = jl::io_agent> |
34 |
49 |
[[nodiscard]] Result write(IO *p_mediator) const |
[[nodiscard]] Result write(IO *p_mediator) const |
35 |
50 |
{ |
{ |
36 |
|
Result res = model.write(p_mediator); |
|
37 |
|
if (res != Result::SUCCESS) |
|
38 |
|
return res; |
|
|
51 |
|
if (p_mediator->write(model_path.begin(), model_path.size()) |
|
52 |
|
!= int64_t(model_path.size())) |
|
53 |
|
return Result::MEDIATOR_ERROR; |
39 |
54 |
|
|
40 |
55 |
auto *p_io = jl::io_agent_p_alt_cast(p_mediator); |
auto *p_io = jl::io_agent_p_alt_cast(p_mediator); |
41 |
|
if (not p_io->write_items(&pos)) |
|
|
56 |
|
if (not p_io->write_items(&options.pos)) |
42 |
57 |
return Result::MEDIATOR_ERROR; |
return Result::MEDIATOR_ERROR; |
43 |
|
if (not p_io->write_items(&shift)) |
|
|
58 |
|
if (not p_io->write_items(&options.shift)) |
44 |
59 |
return Result::MEDIATOR_ERROR; |
return Result::MEDIATOR_ERROR; |
45 |
|
if (p_io->write_items(&transform)) |
|
|
60 |
|
if (not p_io->write_items(&options.transform)) |
46 |
61 |
return Result::MEDIATOR_ERROR; |
return Result::MEDIATOR_ERROR; |
47 |
62 |
|
|
48 |
63 |
return Result::SUCCESS; |
return Result::SUCCESS; |
|
... |
... |
struct jrf::SceneEntry |
53 |
68 |
struct jrf::Scene |
struct jrf::Scene |
54 |
69 |
{ |
{ |
55 |
70 |
struct Options { |
struct Options { |
56 |
|
jl::array<uint32_t, 3> shift; ///< global shift of scene |
|
57 |
|
uint32_t shift_scale;///< scale applied to total shift |
|
|
71 |
|
void set_default_value() { *this = {{}, 1 }; } |
|
72 |
|
jl::array<int32_t, 3> shift; ///< global shift of scene |
|
73 |
|
int32_t shift_scale;///< scale applied to total shift |
58 |
74 |
}; |
}; |
59 |
75 |
|
|
60 |
76 |
Options options; |
Options options; |