@predy-js/math 0.1.88-beta.2 → 0.1.88-beta.5
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.
- package/dist/index.js +56 -0
- package/dist/index.mjs +56 -1
- package/dist/mat4.d.ts +1 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -184,6 +184,61 @@ function mat4fromRotationTranslationScale(out, q, v, s) {
|
|
|
184
184
|
out[15] = 1;
|
|
185
185
|
return out;
|
|
186
186
|
}
|
|
187
|
+
function mat4fromRotationTranslationScaleAnchor(out, q, v, s, anchor) {
|
|
188
|
+
const x = q[0];
|
|
189
|
+
const y = q[1];
|
|
190
|
+
const z = q[2];
|
|
191
|
+
const w = q[3];
|
|
192
|
+
const x2 = x + x;
|
|
193
|
+
const y2 = y + y;
|
|
194
|
+
const z2 = z + z;
|
|
195
|
+
const xx = x * x2;
|
|
196
|
+
const xy = x * y2;
|
|
197
|
+
const xz = x * z2;
|
|
198
|
+
const yy = y * y2;
|
|
199
|
+
const yz = y * z2;
|
|
200
|
+
const zz = z * z2;
|
|
201
|
+
const wx = w * x2;
|
|
202
|
+
const wy = w * y2;
|
|
203
|
+
const wz = w * z2;
|
|
204
|
+
const sx = s[0];
|
|
205
|
+
const sy = s[1];
|
|
206
|
+
const sz = s[2];
|
|
207
|
+
// Initialize the matrix to identity
|
|
208
|
+
for (let i = 0; i < 16; i++) {
|
|
209
|
+
out[i] = (i % 5 === 0) ? 1 : 0;
|
|
210
|
+
}
|
|
211
|
+
// Translate to anchor
|
|
212
|
+
out[0] = (1 - (yy + zz)) * sx;
|
|
213
|
+
out[1] = (xy + wz) * sx;
|
|
214
|
+
out[2] = (xz - wy) * sx;
|
|
215
|
+
out[3] = 0;
|
|
216
|
+
out[4] = (xy - wz) * sy;
|
|
217
|
+
out[5] = (1 - (xx + zz)) * sy;
|
|
218
|
+
out[6] = (yz + wx) * sy;
|
|
219
|
+
out[7] = 0;
|
|
220
|
+
out[8] = (xz + wy) * sz;
|
|
221
|
+
out[9] = (yz - wx) * sz;
|
|
222
|
+
out[10] = (1 - (xx + yy)) * sz;
|
|
223
|
+
out[11] = 0;
|
|
224
|
+
// out[12] = v[0];
|
|
225
|
+
// out[13] = v[1];
|
|
226
|
+
// out[14] = v[2];
|
|
227
|
+
out[15] = 1;
|
|
228
|
+
// Apply rotation
|
|
229
|
+
const rotMat = [
|
|
230
|
+
1 - (yy + zz), xy + wz, xz - wy, 0,
|
|
231
|
+
xy - wz, 1 - (xx + zz), yz + wx, 0,
|
|
232
|
+
xz + wy, yz - wx, 1 - (xx + yy), 0,
|
|
233
|
+
0, 0, 0, 1,
|
|
234
|
+
];
|
|
235
|
+
const aw = (rotMat[3] * x + rotMat[7] * y + rotMat[11] * z + rotMat[15]) || 1;
|
|
236
|
+
const ax = -anchor[0] * sx, ay = -anchor[1] * sy, az = -anchor[2] * sz;
|
|
237
|
+
out[12] = (rotMat[0] * ax + rotMat[4] * ay + rotMat[8] * az + rotMat[12]) / aw + v[0];
|
|
238
|
+
out[13] = (rotMat[1] * ax + rotMat[5] * ay + rotMat[9] * az + rotMat[13]) / aw + v[1];
|
|
239
|
+
out[14] = (rotMat[2] * ax + rotMat[6] * ay + rotMat[10] * az + rotMat[14]) / aw + v[2];
|
|
240
|
+
return out;
|
|
241
|
+
}
|
|
187
242
|
function invertMat4(out, a) {
|
|
188
243
|
const a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
|
|
189
244
|
const a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
|
|
@@ -940,6 +995,7 @@ exports.mat4Clone = mat4Clone;
|
|
|
940
995
|
exports.mat4Determinate = mat4Determinate;
|
|
941
996
|
exports.mat4create = mat4create;
|
|
942
997
|
exports.mat4fromRotationTranslationScale = mat4fromRotationTranslationScale;
|
|
998
|
+
exports.mat4fromRotationTranslationScaleAnchor = mat4fromRotationTranslationScaleAnchor;
|
|
943
999
|
exports.mat4identity = mat4identity;
|
|
944
1000
|
exports.mat4invert = mat4invert;
|
|
945
1001
|
exports.mat4multiply = mat4multiply;
|
package/dist/index.mjs
CHANGED
|
@@ -180,6 +180,61 @@ function mat4fromRotationTranslationScale(out, q, v, s) {
|
|
|
180
180
|
out[15] = 1;
|
|
181
181
|
return out;
|
|
182
182
|
}
|
|
183
|
+
function mat4fromRotationTranslationScaleAnchor(out, q, v, s, anchor) {
|
|
184
|
+
const x = q[0];
|
|
185
|
+
const y = q[1];
|
|
186
|
+
const z = q[2];
|
|
187
|
+
const w = q[3];
|
|
188
|
+
const x2 = x + x;
|
|
189
|
+
const y2 = y + y;
|
|
190
|
+
const z2 = z + z;
|
|
191
|
+
const xx = x * x2;
|
|
192
|
+
const xy = x * y2;
|
|
193
|
+
const xz = x * z2;
|
|
194
|
+
const yy = y * y2;
|
|
195
|
+
const yz = y * z2;
|
|
196
|
+
const zz = z * z2;
|
|
197
|
+
const wx = w * x2;
|
|
198
|
+
const wy = w * y2;
|
|
199
|
+
const wz = w * z2;
|
|
200
|
+
const sx = s[0];
|
|
201
|
+
const sy = s[1];
|
|
202
|
+
const sz = s[2];
|
|
203
|
+
// Initialize the matrix to identity
|
|
204
|
+
for (let i = 0; i < 16; i++) {
|
|
205
|
+
out[i] = (i % 5 === 0) ? 1 : 0;
|
|
206
|
+
}
|
|
207
|
+
// Translate to anchor
|
|
208
|
+
out[0] = (1 - (yy + zz)) * sx;
|
|
209
|
+
out[1] = (xy + wz) * sx;
|
|
210
|
+
out[2] = (xz - wy) * sx;
|
|
211
|
+
out[3] = 0;
|
|
212
|
+
out[4] = (xy - wz) * sy;
|
|
213
|
+
out[5] = (1 - (xx + zz)) * sy;
|
|
214
|
+
out[6] = (yz + wx) * sy;
|
|
215
|
+
out[7] = 0;
|
|
216
|
+
out[8] = (xz + wy) * sz;
|
|
217
|
+
out[9] = (yz - wx) * sz;
|
|
218
|
+
out[10] = (1 - (xx + yy)) * sz;
|
|
219
|
+
out[11] = 0;
|
|
220
|
+
// out[12] = v[0];
|
|
221
|
+
// out[13] = v[1];
|
|
222
|
+
// out[14] = v[2];
|
|
223
|
+
out[15] = 1;
|
|
224
|
+
// Apply rotation
|
|
225
|
+
const rotMat = [
|
|
226
|
+
1 - (yy + zz), xy + wz, xz - wy, 0,
|
|
227
|
+
xy - wz, 1 - (xx + zz), yz + wx, 0,
|
|
228
|
+
xz + wy, yz - wx, 1 - (xx + yy), 0,
|
|
229
|
+
0, 0, 0, 1,
|
|
230
|
+
];
|
|
231
|
+
const aw = (rotMat[3] * x + rotMat[7] * y + rotMat[11] * z + rotMat[15]) || 1;
|
|
232
|
+
const ax = -anchor[0] * sx, ay = -anchor[1] * sy, az = -anchor[2] * sz;
|
|
233
|
+
out[12] = (rotMat[0] * ax + rotMat[4] * ay + rotMat[8] * az + rotMat[12]) / aw + v[0];
|
|
234
|
+
out[13] = (rotMat[1] * ax + rotMat[5] * ay + rotMat[9] * az + rotMat[13]) / aw + v[1];
|
|
235
|
+
out[14] = (rotMat[2] * ax + rotMat[6] * ay + rotMat[10] * az + rotMat[14]) / aw + v[2];
|
|
236
|
+
return out;
|
|
237
|
+
}
|
|
183
238
|
function invertMat4(out, a) {
|
|
184
239
|
const a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
|
|
185
240
|
const a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
|
|
@@ -916,4 +971,4 @@ function quatStar(out, quat) {
|
|
|
916
971
|
return out;
|
|
917
972
|
}
|
|
918
973
|
|
|
919
|
-
export { NumberEpsilon, clamp, ensureVec3, getMat4TR, getMat4TRS, invertMat4, isZeroVec, mat3FromQuat, mat3FromRotation, mat3FromRotationZ, mat3MulMat3, mat3NormalFromMat4, mat3Rotate, mat3Scale, mat3Translate, mat3create, mat4Clone, mat4Determinate, mat4create, mat4fromRotationTranslationScale, mat4identity, mat4invert, mat4multiply, mat4perspective, mat4rotate, mat4scale, mat4translate, quatCreate, quatEquals, quatFromRotation, quatMultiply, quatStar, rotateVec2, rotationFromMat3, vec2TransformByMat3, vec3AddVec3, vec3Create, vec3Cross, vec3MulMat3, vec3MulMat4, vec3MulNum, vec3MulVec3, vec3RotateByMat4, vec3RotateByQuat, vec3TranslateByMat4, vecAdd, vecAddCombine, vecAssign, vecDot, vecFill, vecMinus, vecMulCombine, vecMulScalar, vecNormalize, vecSquareDistance };
|
|
974
|
+
export { NumberEpsilon, clamp, ensureVec3, getMat4TR, getMat4TRS, invertMat4, isZeroVec, mat3FromQuat, mat3FromRotation, mat3FromRotationZ, mat3MulMat3, mat3NormalFromMat4, mat3Rotate, mat3Scale, mat3Translate, mat3create, mat4Clone, mat4Determinate, mat4create, mat4fromRotationTranslationScale, mat4fromRotationTranslationScaleAnchor, mat4identity, mat4invert, mat4multiply, mat4perspective, mat4rotate, mat4scale, mat4translate, quatCreate, quatEquals, quatFromRotation, quatMultiply, quatStar, rotateVec2, rotationFromMat3, vec2TransformByMat3, vec3AddVec3, vec3Create, vec3Cross, vec3MulMat3, vec3MulMat4, vec3MulNum, vec3MulVec3, vec3RotateByMat4, vec3RotateByQuat, vec3TranslateByMat4, vecAdd, vecAddCombine, vecAssign, vecDot, vecFill, vecMinus, vecMulCombine, vecMulScalar, vecNormalize, vecSquareDistance };
|
package/dist/mat4.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { mat4 } from '@predy-js/render-interface';
|
|
|
2
2
|
import type { vec3, vec4 } from '@predy-js/render-interface';
|
|
3
3
|
export declare function mat4create(): mat4;
|
|
4
4
|
export declare function mat4fromRotationTranslationScale(out: mat4 | number[], q: vec4, v: vec3, s: vec3): mat4;
|
|
5
|
+
export declare function mat4fromRotationTranslationScaleAnchor(out: mat4 | number[], q: vec4, v: vec3, s: vec3, anchor: vec3): mat4;
|
|
5
6
|
export declare function invertMat4(out: mat4 | number[], a: mat4): mat4;
|
|
6
7
|
export declare function mat4Determinate(a: mat4): number;
|
|
7
8
|
export declare function getMat4TR(mat4: mat4 | number[], translate?: vec3, quat?: vec4, scaling?: vec3): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@predy-js/math",
|
|
3
|
-
"version": "0.1.88-beta.
|
|
3
|
+
"version": "0.1.88-beta.5",
|
|
4
4
|
"description": "Mars JSON Specification",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"prepublishOnly": "npm run build"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@predy-js/render-interface": "0.1.88-beta.
|
|
31
|
+
"@predy-js/render-interface": "0.1.88-beta.5",
|
|
32
32
|
"@commitlint/cli": "^13.2.1",
|
|
33
33
|
"@commitlint/config-conventional": "^13.2.0",
|
|
34
34
|
"@rollup/plugin-commonjs": "^21.0.3",
|