rayzee 6.2.0 → 6.4.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,173 @@
1
+ /**
2
+ * Minimal 4x4 matrix math for the pbrt CTM stack.
3
+ *
4
+ * Matrices are flat 16-element arrays in COLUMN-MAJOR order, identical to
5
+ * THREE.Matrix4.elements (element index = col*4 + row). This lets the scene
6
+ * builder do `new Matrix4().fromArray(ctm)` with no conversion.
7
+ *
8
+ * pbrt's `Transform [16]` directive supplies values that, after pbrt's internal
9
+ * transpose, are exactly column-major — so they map straight onto this layout.
10
+ *
11
+ * Pure JS so the parser stays Three.js-free and unit-testable.
12
+ */
13
+
14
+ export function identity() {
15
+
16
+ return [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ];
17
+
18
+ }
19
+
20
+ /** Matrix product a*b (applies b first, then a, to a column vector). */
21
+ export function multiply( a, b ) {
22
+
23
+ const a11 = a[ 0 ], a21 = a[ 1 ], a31 = a[ 2 ], a41 = a[ 3 ];
24
+ const a12 = a[ 4 ], a22 = a[ 5 ], a32 = a[ 6 ], a42 = a[ 7 ];
25
+ const a13 = a[ 8 ], a23 = a[ 9 ], a33 = a[ 10 ], a43 = a[ 11 ];
26
+ const a14 = a[ 12 ], a24 = a[ 13 ], a34 = a[ 14 ], a44 = a[ 15 ];
27
+
28
+ const b11 = b[ 0 ], b21 = b[ 1 ], b31 = b[ 2 ], b41 = b[ 3 ];
29
+ const b12 = b[ 4 ], b22 = b[ 5 ], b32 = b[ 6 ], b42 = b[ 7 ];
30
+ const b13 = b[ 8 ], b23 = b[ 9 ], b33 = b[ 10 ], b43 = b[ 11 ];
31
+ const b14 = b[ 12 ], b24 = b[ 13 ], b34 = b[ 14 ], b44 = b[ 15 ];
32
+
33
+ return [
34
+ a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41,
35
+ a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41,
36
+ a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41,
37
+ a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41,
38
+
39
+ a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42,
40
+ a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42,
41
+ a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42,
42
+ a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42,
43
+
44
+ a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43,
45
+ a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43,
46
+ a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43,
47
+ a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43,
48
+
49
+ a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44,
50
+ a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44,
51
+ a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44,
52
+ a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44
53
+ ];
54
+
55
+ }
56
+
57
+ export function translate( x, y, z ) {
58
+
59
+ return [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1 ];
60
+
61
+ }
62
+
63
+ export function scale( x, y, z ) {
64
+
65
+ return [ x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1 ];
66
+
67
+ }
68
+
69
+ /** Axis-angle rotation. `angle` is in DEGREES (pbrt convention). */
70
+ export function rotate( angle, x, y, z ) {
71
+
72
+ const len = Math.hypot( x, y, z ) || 1;
73
+ x /= len; y /= len; z /= len;
74
+
75
+ const rad = angle * Math.PI / 180;
76
+ const c = Math.cos( rad ), s = Math.sin( rad ), t = 1 - c;
77
+
78
+ const m00 = t * x * x + c, m01 = t * x * y - s * z, m02 = t * x * z + s * y;
79
+ const m10 = t * x * y + s * z, m11 = t * y * y + c, m12 = t * y * z - s * x;
80
+ const m20 = t * x * z - s * y, m21 = t * y * z + s * x, m22 = t * z * z + c;
81
+
82
+ return [
83
+ m00, m10, m20, 0,
84
+ m01, m11, m21, 0,
85
+ m02, m12, m22, 0,
86
+ 0, 0, 0, 1
87
+ ];
88
+
89
+ }
90
+
91
+ function sub( a, b ) {
92
+
93
+ return [ a[ 0 ] - b[ 0 ], a[ 1 ] - b[ 1 ], a[ 2 ] - b[ 2 ] ];
94
+
95
+ }
96
+
97
+ function cross( a, b ) {
98
+
99
+ return [
100
+ a[ 1 ] * b[ 2 ] - a[ 2 ] * b[ 1 ],
101
+ a[ 2 ] * b[ 0 ] - a[ 0 ] * b[ 2 ],
102
+ a[ 0 ] * b[ 1 ] - a[ 1 ] * b[ 0 ]
103
+ ];
104
+
105
+ }
106
+
107
+ function normalize( a ) {
108
+
109
+ const len = Math.hypot( a[ 0 ], a[ 1 ], a[ 2 ] ) || 1;
110
+ return [ a[ 0 ] / len, a[ 1 ] / len, a[ 2 ] / len ];
111
+
112
+ }
113
+
114
+ /**
115
+ * Builds the camera-to-world matrix from a pbrt LookAt (eye, look, up).
116
+ * pbrt uses a left-handed camera basis: +z is the viewing direction.
117
+ * Columns: [ right, newUp, dir, eye ].
118
+ */
119
+ export function lookAtCameraToWorld( eye, look, up ) {
120
+
121
+ const dir = normalize( sub( look, eye ) );
122
+ const right = normalize( cross( normalize( up ), dir ) );
123
+ const newUp = cross( dir, right );
124
+
125
+ return [
126
+ right[ 0 ], right[ 1 ], right[ 2 ], 0,
127
+ newUp[ 0 ], newUp[ 1 ], newUp[ 2 ], 0,
128
+ dir[ 0 ], dir[ 1 ], dir[ 2 ], 0,
129
+ eye[ 0 ], eye[ 1 ], eye[ 2 ], 1
130
+ ];
131
+
132
+ }
133
+
134
+ /** General 4x4 inverse (column-major in/out). Returns identity if singular. */
135
+ export function invert( m ) {
136
+
137
+ const n11 = m[ 0 ], n21 = m[ 1 ], n31 = m[ 2 ], n41 = m[ 3 ];
138
+ const n12 = m[ 4 ], n22 = m[ 5 ], n32 = m[ 6 ], n42 = m[ 7 ];
139
+ const n13 = m[ 8 ], n23 = m[ 9 ], n33 = m[ 10 ], n43 = m[ 11 ];
140
+ const n14 = m[ 12 ], n24 = m[ 13 ], n34 = m[ 14 ], n44 = m[ 15 ];
141
+
142
+ const t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44;
143
+ const t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44;
144
+ const t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44;
145
+ const t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
146
+
147
+ const det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
148
+ if ( det === 0 ) return identity();
149
+ const idet = 1 / det;
150
+
151
+ return [
152
+ t11 * idet,
153
+ ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * idet,
154
+ ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * idet,
155
+ ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * idet,
156
+
157
+ t12 * idet,
158
+ ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * idet,
159
+ ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * idet,
160
+ ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * idet,
161
+
162
+ t13 * idet,
163
+ ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * idet,
164
+ ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * idet,
165
+ ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * idet,
166
+
167
+ t14 * idet,
168
+ ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * idet,
169
+ ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * idet,
170
+ ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * idet
171
+ ];
172
+
173
+ }