@playcanvas/splat-transform
Version:
Library and CLI tool for 3D Gaussian splat format conversion and transformation
15 lines (14 loc) • 1.31 kB
TypeScript
/**
* Quaternion → 3×3 rotation matrix, with early-out on zero-length quat.
*
* Reads: rotW, rotX, rotY, rotZ (raw input quat components from the
* splat decode)
* Defines: r00..r22 (rotation matrix entries, row-major)
* Returns: early via writeInvalid + return if the quaternion has zero
* length (degenerate splat)
*
* Normalises the quaternion first so the rotation matrix is orthonormal
* even if the upstream data stored an unnormalised quat.
*/
declare const quatRotation = "\n let qlen2 = rotW * rotW + rotX * rotX + rotY * rotY + rotZ * rotZ;\n if (qlen2 == 0.0) { writeInvalid(i); return; }\n let invQ = inverseSqrt(qlen2);\n let qw = rotW * invQ;\n let qx = rotX * invQ;\n let qy = rotY * invQ;\n let qz = rotZ * invQ;\n\n let xx = qx * qx; let yy = qy * qy; let zz = qz * qz;\n let xy = qx * qy; let xzq = qx * qz; let yz = qy * qz;\n let wxq = qw * qx; let wy_ = qw * qy; let wzq = qw * qz;\n let r00 = 1.0 - 2.0 * (yy + zz);\n let r01 = 2.0 * (xy - wzq);\n let r02 = 2.0 * (xzq + wy_);\n let r10 = 2.0 * (xy + wzq);\n let r11 = 1.0 - 2.0 * (xx + zz);\n let r12 = 2.0 * (yz - wxq);\n let r20 = 2.0 * (xzq - wy_);\n let r21 = 2.0 * (yz + wxq);\n let r22 = 1.0 - 2.0 * (xx + yy);\n";
export { quatRotation };