Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
mat4.mul(_TMP_MATPV, camera.getProjection(), camera.getView());
// circle mvp
mat4.scale(this._cacheCircleMVP, _TMP_MAT, vec3.set(_TMP_VEC, worldRadius, worldRadius, worldRadius));
mat4.mul(this._cacheCircleMVP, _TMP_MATPV, this._cacheCircleMVP);
// dot mvp
mat4.scale(this._cacheDotMVP, _TMP_MAT, vec3.set(_TMP_VEC, constRadius, constRadius, constRadius));
mat4.mul(this._cacheDotMVP, _TMP_MATPV, this._cacheDotMVP);
// symmetry mvp
vec3.transformMat4(_TMP_VEC, pickingSym.getIntersectionPoint(), mesh.getMatrix());
mat4.identity(_TMP_MAT);
mat4.translate(_TMP_MAT, _TMP_MAT, _TMP_VEC);
mat4.rotate(_TMP_MAT, _TMP_MAT, rad, _TMP_AXIS);
mat4.scale(_TMP_MAT, _TMP_MAT, vec3.set(_TMP_VEC, constRadius, constRadius, constRadius));
mat4.mul(this._cacheDotSymMVP, _TMP_MATPV, _TMP_MAT);
}
export function J3DCalcYBBoardMtx(dst: mat4, m: mat4, v: vec3 = scratchVec3): void {
// The column vectors lengths here are the scale.
const mx = Math.hypot(m[0], m[1], m[2]);
const mz = Math.hypot(m[8], m[9], m[10]);
vec3.set(v, 0.0, -m[6], m[5]);
vec3.normalize(v, v);
dst[0] = mx;
dst[4] = m[4];
dst[8] = 0;
dst[12] = m[12];
dst[1] = 0;
dst[5] = m[5];
dst[9] = v[1] * mz;
dst[13] = m[13];
dst[2] = 0;
dst[6] = m[6];
dst[10] = v[2] * mz;
dst[14] = m[14];
function aabbLineCheck(p0: vec3, p1: vec3, aabb: AABB): boolean {
// Box center-point
const c = scratchVec3a;
vec3.set(c, (aabb.minX + aabb.maxX)/2, (aabb.minY + aabb.maxY)/2, (aabb.minZ + aabb.maxZ)/2);
// Box halflength extents
const e = scratchVec3b;
vec3.set(e, aabb.maxX - c[0], aabb.maxY - c[1], aabb.maxZ - c[2]);
// Segment midpoint
const m = scratchVec3c;
vec3.add(m, p0, p1);
vec3.scale(m, m, 0.5);
// Segment halflength vector
const d = scratchVec3d;
vec3.sub(d, p1, m);
vec3.sub(m, m, c); // Translate box and segment to origin
// Try world coordinate axes as separating axes
let adx = Math.abs(d[0]);
if (Math.abs(m[0]) > e[0] + adx) return false;
_initTranslate() {
var axis = [0.0, 0.0, 0.0];
this._createArrow(this._transX, vec3.set(axis, 0.0, 0.0, -1.0), COLOR_X);
this._createArrow(this._transY, vec3.set(axis, 0.0, 1.0, 0.0), COLOR_Y);
this._createArrow(this._transZ, vec3.set(axis, 1.0, 0.0, 0.0), COLOR_Z);
var s = ARROW_LENGTH * 0.2;
this._createPlane(this._planeX, COLOR_X, 0.0, s, 0.0, 0.0, 0.0, s);
this._createPlane(this._planeY, COLOR_Y, s, 0.0, 0.0, 0.0, 0.0, s);
this._createPlane(this._planeZ, COLOR_Z, s, 0.0, 0.0, 0.0, s, 0.0);
}
public movement(dst: mat4, time: number) {
const phase = time * this.speed * MathConstants.DEG_TO_RAD;
mat4.fromYRotation(dst, this.baseYaw + Math.sin(phase) * this.amplitudes[0]);
mat4.rotateX(dst, dst, Math.cos(phase) * this.amplitudes[1]);
mat4.rotateZ(dst, dst, this.baseRoll);
if (this.baseScale !== 1) {
vec3.set(movementScratch, this.baseScale, this.baseScale, this.baseScale);
mat4.scale(dst, dst, movementScratch);
}
dst[12] = this.basePos[0];
dst[13] = this.basePos[1] + Math.sin(phase) * this.amplitudes[2];
dst[14] = this.basePos[2];
}
}
var id = this._pickedFace * 4;
var iv1 = fAr[id] * 3;
var iv2 = fAr[id + 1] * 3;
var iv3 = fAr[id + 2] * 3;
var iv4 = fAr[id + 3];
var isQuad = iv4 !== Utils.TRI_INDEX;
if (isQuad) iv4 *= 3;
var len1 = 1.0 / vec3.dist(this._interPoint, vAr.subarray(iv1, iv1 + 3));
var len2 = 1.0 / vec3.dist(this._interPoint, vAr.subarray(iv2, iv2 + 3));
var len3 = 1.0 / vec3.dist(this._interPoint, vAr.subarray(iv3, iv3 + 3));
var len4 = isQuad ? 1.0 / vec3.dist(this._interPoint, vAr.subarray(iv4, iv4 + 3)) : 0.0;
var invSum = 1.0 / (len1 + len2 + len3 + len4);
vec3.set(out, 0.0, 0.0, 0.0);
vec3.scaleAndAdd(out, out, vField.subarray(iv1, iv1 + 3), len1 * invSum);
vec3.scaleAndAdd(out, out, vField.subarray(iv2, iv2 + 3), len2 * invSum);
vec3.scaleAndAdd(out, out, vField.subarray(iv3, iv3 + 3), len3 * invSum);
if (isQuad) vec3.scaleAndAdd(out, out, vField.subarray(iv4, iv4 + 3), len4 * invSum);
return out;
}
}
translate: function (x, y, z) {
var transform = this.state.transform
var translation = vec3.set(scratchVec, x, y, z)
mat4.translate(transform.matrix, transform.matrix, translation)
transform.isIdentity = false
},
_computeVertexNormals() {
// loop through all vertices
let face;
const sumNormal = vec3.create();
const normals = [];
const { vertices } = this;
for(let i = 0; i < vertices.length; i++) {
vec3.set(sumNormal, 0, 0, 0);
for(let j = 0; j < this._faces.length; j++) {
face = this._faces[j];
// if vertex exist in the face, add the normal to sum normal
if(face.indices.indexOf(i) >= 0) {
sumNormal[0] += face.normal[0];
sumNormal[1] += face.normal[1];
sumNormal[2] += face.normal[2];
}
}
vec3.normalize(sumNormal, sumNormal);
function Calc_BILLBOARD_PERSP_STD(m: mat4, nodeMatrix: mat4, parentNodeMatrix: mat4 | null, vx: vec3 = scratchVec3[0], vy: vec3 = scratchVec3[1], vz: vec3 = scratchVec3[2]): void {
vec3.set(vy, m[4], m[5], m[6]);
vec3.set(vz, -m[12], -m[13], -m[14]);
vec3.normalize(vz, vz);
vec3.cross(vx, vy, vz);
vec3.normalize(vx, vx);
vec3.cross(vy, vz, vx);
const scaleX = GetMtx34Scale(nodeMatrix, MtxCol.X);
const scaleY = GetMtx34Scale(nodeMatrix, MtxCol.Y);
const scaleZ = GetMtx34Scale(nodeMatrix, MtxCol.Z);
SetMdlViewMtxSR(m, scaleX, scaleY, scaleZ,
vx[0], vx[1], vx[2],
vy[0], vy[1], vy[2],
vz[0], vz[1], vz[2]);
}
public calcAnim(viewerInput: Viewer.ViewerRenderInput): void {
mat4.copy(this.body0.modelMatrix, this.modelMatrix);
mat4.copy(this.body1.modelMatrix, this.modelMatrix);
mat4.copy(this.body2.modelMatrix, this.modelMatrix);
mat4.copy(this.body3.modelMatrix, this.modelMatrix);
mat4.copy(this.head.modelMatrix, this.modelMatrix);
vec3.set(scratchVec3, 0, 5, 0);
const time = viewerInput.time + (this.animationPhase * 400);
scratchVec3[0] += Math.sin(time / 400) * 4;
scratchVec3[2] += Math.cos(time / 400) * 4;
mat4.translate(this.body0.modelMatrix, this.body0.modelMatrix, scratchVec3);
scratchVec3[1] += 15;
scratchVec3[0] += Math.sin(time / 420) * 3;
scratchVec3[2] += Math.cos(time / 420) * 3;
mat4.translate(this.body1.modelMatrix, this.body1.modelMatrix, scratchVec3);
scratchVec3[1] += 15;
scratchVec3[0] += Math.sin(time / -320) * 2;