1 module sbylib.wrapper.assimp.functions;
2 
3 import bindbc.assimp.types;
4 import sbylib.math : vec2, vec3, vec4, quat, mat4;
5 
6 string toRegularString(aiString str) {
7     import std.conv : to;
8 
9     return str.data[0..str.length].to!string;
10 }
11 
12 vec2 toSbylibVector(aiVector2D v) {
13     return vec2(v.x, v.y);
14 }
15 
16 vec3 toSbylibVector(aiVector3D v) {
17     return vec3(v.x, v.y, v.z);
18 }
19 
20 vec3 toSbylibVector(aiColor3D c) {
21     return vec3(c.r, c.g, c.b);
22 }
23 
24 vec4 toSbylibVector(aiColor4D c) {
25     return vec4(c.r, c.g, c.b, c.a);
26 }
27 
28 quat toSbylibQuaternion(aiQuaternion q) {
29     return quat(q.x, q.y, q.z, q.w);
30 }
31 
32 mat4 toSbylibMatrix(aiMatrix4x4 m) {
33     return mat4(m.a1, m.a2, m.a3, m.a4,
34             m.b1, m.b2, m.b3, m.b4,
35             m.c1, m.c2, m.c3, m.c4,
36             m.d1, m.d2, m.d3, m.d4);
37 }
38 
39 auto toArray(alias postProcess, T)(uint len, T* data) {
40     struct Result {
41         size_t length;
42         T* data;
43 
44         auto front() { return postProcess(data[0]); }
45 
46         void popFront() { data++; length--; }
47 
48         bool empty() { return length == 0; }
49 
50         Result save() { return Result(length, data); }
51 
52         auto back() { return postProcess(data[length-1]); }
53 
54         void popBack() { length--; }
55 
56         auto opIndex(size_t idx) { return postProcess(data[idx]); }
57     }
58 
59     return Result(len, data);
60 }
61 
62 E toEnum(E, O)(O o) {
63     import std : asOriginalType, to;
64     return o.asOriginalType.to!E;
65 }
66 
67 string indent(string str) {
68     import std.algorithm : map;
69     import std..string : split, join;
70     return str.split("\n").map!(line => "    " ~ line).join("\n");
71 }
72 
73 string tree(string title, string[] components) {
74     import std.algorithm : map;
75     import std.range : enumerate;
76     import std..string : join, split;
77     import std.array : array;
78     import std.format : format;
79     import sbylib.wrapper.assimp.functions : indent;
80 
81     return (title
82             ~ components.enumerate.map!(component =>
83                 component.value.split("\n").enumerate.map!(line =>
84                     (component.index+1 == components.length ?
85                      (line.index == 0 ? "L---" : "    ") : (line.index == 0 ? "|---" : "|    ")) ~ line.value
86                     ).join("\n")).array).join("\n");
87 }
88