@geastack/gea3d 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,53 @@
1
+ // SPDX-License-Identifier: GPL-3.0-only
2
+ // Enumerations shared by the native engine and its TS faces (api.ts,
3
+ // api.web.ts); they mirror the enums in gea3d_native.h.
4
+
5
+ export const NODE_GROUP = 0
6
+ export const NODE_MESH = 1
7
+ export const NODE_LINE_SEGMENTS = 2
8
+ export const NODE_LINE = 3
9
+ export const NODE_POINTS = 4
10
+ export const NODE_SPRITE = 5
11
+ export const NODE_CAMERA = 6
12
+ export const NODE_LIGHT = 7
13
+
14
+ export const LIGHT_AMBIENT = 1
15
+ export const LIGHT_DIRECTIONAL = 2
16
+ export const LIGHT_HEMISPHERE = 3
17
+ export const LIGHT_POINT = 4
18
+
19
+ export const MATERIAL_VERTEX_COLORS = 1
20
+ export const MATERIAL_TRANSPARENT = 2
21
+ export const MATERIAL_FOG = 4
22
+ export const MATERIAL_FLAT_SHADING = 8
23
+ export const MATERIAL_WIREFRAME = 16
24
+ export const MATERIAL_DEPTH_TEST = 32
25
+ export const MATERIAL_DEPTH_WRITE = 64
26
+ export const MATERIAL_SIZE_ATTENUATION = 128
27
+ export const MATERIAL_VISIBLE = 256
28
+ export const MATERIAL_ADDITIVE = 512
29
+
30
+ export const BACKGROUND_NONE = 0
31
+ export const BACKGROUND_FLAT = 1
32
+ export const BACKGROUND_GRADIENT = 2
33
+
34
+ export const FOG_NONE = 0
35
+ export const FOG_LINEAR = 1
36
+ export const FOG_EXP2 = 2
37
+
38
+ export const STAT_SUBMITTED = 0
39
+ export const STAT_NEAR_REJECTED = 1
40
+ export const STAT_CULLED = 2
41
+ export const STAT_CLIP_DROPPED = 3
42
+ export const STAT_DROPPED = 4
43
+ export const STAT_MESHES_DRAWN = 5
44
+ export const STAT_MESHES_CULLED = 6
45
+ export const STAT_PRIMITIVES = 7
46
+ export const STAT_COMPOSITED = 8
47
+
48
+ export const RAY_DISTANCE = 0
49
+ export const RAY_POINT_X = 1
50
+ export const RAY_POINT_Y = 2
51
+ export const RAY_POINT_Z = 3
52
+ export const RAY_FACE = 4
53
+ export const RAY_INSTANCE = 5
@@ -0,0 +1,185 @@
1
+ // SPDX-License-Identifier: GPL-3.0-only
2
+ #pragma once
3
+
4
+ // Single-precision matrix helpers for the native scene graph. Matrices are
5
+ // column-major float[16] in three.js element order (m[column * 4 + row]).
6
+
7
+ #include <cmath>
8
+ #include <cstring>
9
+
10
+ namespace gea::host::gea3d::math {
11
+
12
+ inline void identity(float *m)
13
+ {
14
+ std::memset(m, 0, sizeof(float) * 16);
15
+ m[0] = 1.0f;
16
+ m[5] = 1.0f;
17
+ m[10] = 1.0f;
18
+ m[15] = 1.0f;
19
+ }
20
+
21
+ // out = a * b. `out` may alias neither input.
22
+ inline void multiply(float *out, const float *a, const float *b)
23
+ {
24
+ for (int col = 0; col < 4; col++) {
25
+ const float b0 = b[col * 4];
26
+ const float b1 = b[col * 4 + 1];
27
+ const float b2 = b[col * 4 + 2];
28
+ const float b3 = b[col * 4 + 3];
29
+ for (int row = 0; row < 4; row++) {
30
+ out[col * 4 + row] = a[row] * b0 + a[4 + row] * b1 + a[8 + row] * b2 + a[12 + row] * b3;
31
+ }
32
+ }
33
+ }
34
+
35
+ // Affine multiply: both inputs have a (0, 0, 0, 1) bottom row.
36
+ inline void multiplyAffine(float *out, const float *a, const float *b)
37
+ {
38
+ for (int col = 0; col < 4; col++) {
39
+ const float b0 = b[col * 4];
40
+ const float b1 = b[col * 4 + 1];
41
+ const float b2 = b[col * 4 + 2];
42
+ for (int row = 0; row < 3; row++) {
43
+ out[col * 4 + row] = a[row] * b0 + a[4 + row] * b1 + a[8 + row] * b2;
44
+ }
45
+ out[col * 4 + 3] = 0.0f;
46
+ }
47
+ out[12] += a[12];
48
+ out[13] += a[13];
49
+ out[14] += a[14];
50
+ out[15] = 1.0f;
51
+ }
52
+
53
+ // Matrix4.compose(position, quaternion, scale).
54
+ inline void compose(float *m, const float *p, const float *q, const float *s)
55
+ {
56
+ const float x = q[0], y = q[1], z = q[2], w = q[3];
57
+ const float x2 = x + x, y2 = y + y, z2 = z + z;
58
+ const float xx = x * x2, xy = x * y2, xz = x * z2;
59
+ const float yy = y * y2, yz = y * z2, zz = z * z2;
60
+ const float wx = w * x2, wy = w * y2, wz = w * z2;
61
+ m[0] = (1.0f - (yy + zz)) * s[0];
62
+ m[1] = (xy + wz) * s[0];
63
+ m[2] = (xz - wy) * s[0];
64
+ m[3] = 0.0f;
65
+ m[4] = (xy - wz) * s[1];
66
+ m[5] = (1.0f - (xx + zz)) * s[1];
67
+ m[6] = (yz + wx) * s[1];
68
+ m[7] = 0.0f;
69
+ m[8] = (xz + wy) * s[2];
70
+ m[9] = (yz - wx) * s[2];
71
+ m[10] = (1.0f - (xx + yy)) * s[2];
72
+ m[11] = 0.0f;
73
+ m[12] = p[0];
74
+ m[13] = p[1];
75
+ m[14] = p[2];
76
+ m[15] = 1.0f;
77
+ }
78
+
79
+ // Inverse of an affine matrix through its 3x3 cofactors. Returns false (and
80
+ // writes identity) when the matrix is singular.
81
+ inline bool invertAffine(float *out, const float *m)
82
+ {
83
+ const float a00 = m[0], a01 = m[4], a02 = m[8];
84
+ const float a10 = m[1], a11 = m[5], a12 = m[9];
85
+ const float a20 = m[2], a21 = m[6], a22 = m[10];
86
+ const float c00 = a11 * a22 - a12 * a21;
87
+ const float c01 = a12 * a20 - a10 * a22;
88
+ const float c02 = a10 * a21 - a11 * a20;
89
+ const float det = a00 * c00 + a01 * c01 + a02 * c02;
90
+ if (det == 0.0f) {
91
+ identity(out);
92
+ return false;
93
+ }
94
+
95
+ const float inv = 1.0f / det;
96
+ out[0] = c00 * inv;
97
+ out[1] = c01 * inv;
98
+ out[2] = c02 * inv;
99
+ out[3] = 0.0f;
100
+ out[4] = (a02 * a21 - a01 * a22) * inv;
101
+ out[5] = (a00 * a22 - a02 * a20) * inv;
102
+ out[6] = (a01 * a20 - a00 * a21) * inv;
103
+ out[7] = 0.0f;
104
+ out[8] = (a01 * a12 - a02 * a11) * inv;
105
+ out[9] = (a02 * a10 - a00 * a12) * inv;
106
+ out[10] = (a00 * a11 - a01 * a10) * inv;
107
+ out[11] = 0.0f;
108
+ const float tx = m[12], ty = m[13], tz = m[14];
109
+ out[12] = -(out[0] * tx + out[4] * ty + out[8] * tz);
110
+ out[13] = -(out[1] * tx + out[5] * ty + out[9] * tz);
111
+ out[14] = -(out[2] * tx + out[6] * ty + out[10] * tz);
112
+ out[15] = 1.0f;
113
+ return true;
114
+ }
115
+
116
+ inline void transformPoint(const float *m, float x, float y, float z, float *out)
117
+ {
118
+ out[0] = m[0] * x + m[4] * y + m[8] * z + m[12];
119
+ out[1] = m[1] * x + m[5] * y + m[9] * z + m[13];
120
+ out[2] = m[2] * x + m[6] * y + m[10] * z + m[14];
121
+ }
122
+
123
+ inline void transformDirection(const float *m, float x, float y, float z, float *out)
124
+ {
125
+ out[0] = m[0] * x + m[4] * y + m[8] * z;
126
+ out[1] = m[1] * x + m[5] * y + m[9] * z;
127
+ out[2] = m[2] * x + m[6] * y + m[10] * z;
128
+ }
129
+
130
+ inline float maxScaleOnAxis(const float *m)
131
+ {
132
+ const float sx = m[0] * m[0] + m[1] * m[1] + m[2] * m[2];
133
+ const float sy = m[4] * m[4] + m[5] * m[5] + m[6] * m[6];
134
+ const float sz = m[8] * m[8] + m[9] * m[9] + m[10] * m[10];
135
+ float s = sx > sy ? sx : sy;
136
+ if (sz > s) s = sz;
137
+ return std::sqrt(s);
138
+ }
139
+
140
+ inline bool normalize3(float *v)
141
+ {
142
+ const float lenSq = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
143
+ if (lenSq <= 0.0f) return false;
144
+ const float inv = 1.0f / std::sqrt(lenSq);
145
+ v[0] *= inv;
146
+ v[1] *= inv;
147
+ v[2] *= inv;
148
+ return true;
149
+ }
150
+
151
+ // Six clip-space planes (a, b, c, d; inside when a*x + b*y + c*z + d >= 0) of
152
+ // a combined projection * view matrix, normalized so d measures distance.
153
+ inline void frustumPlanes(const float *m, float planes[6][4])
154
+ {
155
+ const float rows[4][4] = {
156
+ {m[0], m[4], m[8], m[12]},
157
+ {m[1], m[5], m[9], m[13]},
158
+ {m[2], m[6], m[10], m[14]},
159
+ {m[3], m[7], m[11], m[15]},
160
+ };
161
+ for (int i = 0; i < 3; i++) {
162
+ for (int k = 0; k < 4; k++) {
163
+ planes[i * 2][k] = rows[3][k] + rows[i][k];
164
+ planes[i * 2 + 1][k] = rows[3][k] - rows[i][k];
165
+ }
166
+ }
167
+ for (int i = 0; i < 6; i++) {
168
+ float *plane = planes[i];
169
+ const float len = std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
170
+ if (len <= 0.0f) continue;
171
+ const float inv = 1.0f / len;
172
+ for (int k = 0; k < 4; k++) plane[k] *= inv;
173
+ }
174
+ }
175
+
176
+ inline bool sphereInFrustum(const float planes[6][4], const float *center, float radius)
177
+ {
178
+ for (int i = 0; i < 6; i++) {
179
+ const float *p = planes[i];
180
+ if (p[0] * center[0] + p[1] * center[1] + p[2] * center[2] + p[3] < -radius) return false;
181
+ }
182
+ return true;
183
+ }
184
+
185
+ } // namespace gea::host::gea3d::math