Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
publicAPI.computeMatrix = () => {
// check whether or not need to rebuild the matrix
if (publicAPI.getMTime() > model.matrixMTime.getMTime()) {
mat4.identity(model.matrix);
if (model.userMatrix) {
mat4.multiply(model.matrix, model.matrix, model.userMatrix);
}
mat4.translate(model.matrix, model.matrix, model.origin);
mat4.translate(model.matrix, model.matrix, model.position);
mat4.multiply(model.matrix, model.matrix, model.rotation);
mat4.scale(model.matrix, model.matrix, model.scale);
mat4.translate(model.matrix, model.matrix, [
-model.origin[0],
-model.origin[1],
-model.origin[2],
]);
mat4.transpose(model.matrix, model.matrix);
// check for identity
model.isIdentity = true;
break;
case TexMtxMapMode.ViewProjmapBasic:
case TexMtxMapMode.ViewProjmap:
mat4.copy(dst, modelViewMatrix);
break;
case 0x05:
case TexMtxMapMode.EnvmapOldEffectMtx:
case TexMtxMapMode.EnvmapEffectMtx:
computeNormalMatrix(dst, modelMatrix, true);
break;
default:
// No mapping.
mat4.identity(dst);
break;
}
}
import createREGL from 'regl'
import { mat4 } from 'gl-matrix'
import Stats from '@jpweeks/rstats'
import { LineBuilder } from '../index'
const regl = createREGL()
const setupCamera = regl({
uniforms: {
view: mat4.identity([]),
projection: ({ viewportWidth, viewportHeight }) => {
const w = viewportWidth / 2
const h = viewportHeight / 2
return mat4.ortho([], -w, w, -h, h, 0, 10)
}
}
})
const stats = new Stats()
const lines = LineBuilder.create(regl, {
bufferSize: 300
})
const ctx = lines.getContext()
ctx.globalAlpha = 0.5
ctx.strokeStyle = '#ffeeee'
render(scene) {
mat4.identity(this.lightViewMatrix);
mat4.translate(
this.lightViewMatrix,
this.lightViewMatrix,
this.light.position.v
);
mat4.lookAt(this.lightViewMatrix, this.light.position.v, this.center, UP);
this.renderTarget.render(scene, this.camera);
}
}
export function calcTexMtx_Basic(dst: mat4, scaleS: number, scaleT: number, rotation: number, translationS: number, translationT: number, centerS: number, centerT: number, centerQ: number): void {
const theta = rotation * Math.PI;
const sinR = Math.sin(theta);
const cosR = Math.cos(theta);
mat4.identity(dst);
dst[0] = scaleS * cosR;
dst[4] = scaleS * -sinR;
dst[12] = translationS + centerS + scaleS * (sinR * centerT - cosR * centerS);
dst[1] = scaleT * sinR;
dst[5] = scaleT * cosR;
dst[13] = translationT + centerT + -scaleT * (-sinR * centerS + cosR * centerT);
}
lookAt(aEye, aCenter, aUp = [0, 1, 0])
{
this.position.x = aEye[0];
this.position.y = aEye[1];
this.position.z = aEye[2];
this.pp = aEye;
mat4.identity(this._view);
mat4.lookAt(this._view, aEye, aCenter, aUp);
}
updateProjectionMatrix()
export function calcTexMtx_Maya(dst: mat4, scaleS: number, scaleT: number, rotation: number, translationS: number, translationT: number): void {
const theta = rotation * Math.PI;
const sinR = Math.sin(theta);
const cosR = Math.cos(theta);
mat4.identity(dst);
dst[0] = scaleS * cosR;
dst[1] = scaleT * -sinR;
dst[12] = scaleS * ((-0.5 * cosR) - (0.5 * sinR - 0.5) - translationS);
dst[4] = scaleS * sinR;
dst[5] = scaleT * cosR;
dst[13] = scaleT * ((-0.5 * cosR) + (0.5 * sinR - 0.5) + translationT) + 1;
}
updateMatrices(matrix) {
mat4.identity(matrices.modelView);
mat4.copy(matrices.modelView, matrix);
mat4.invert(matrices.inversedModelView, matrices.modelView);
mat4.transpose(matrices.inversedModelView, matrices.inversedModelView);
mat4.identity(matrices.normal);
mat4.copy(matrices.normal, matrices.inversedModelView);
}
publicAPI.roll = (angle) => {
const eye = model.position;
const at = model.focalPoint;
const up = model.viewUp;
const viewUpVec4 = vec4.fromValues(up[0], up[1], up[2], 0.0);
mat4.identity(rotateMatrix);
const viewDir = vec3.fromValues(
at[0] - eye[0],
at[1] - eye[1],
at[2] - eye[2]
);
mat4.rotate(
rotateMatrix,
rotateMatrix,
vtkMath.radiansFromDegrees(angle),
viewDir
);
vec4.transformMat4(viewUpVec4, viewUpVec4, rotateMatrix);
model.viewUp[0] = viewUpVec4[0];
model.viewUp[1] = viewUpVec4[1];
model.viewUp[2] = viewUpVec4[2];
public calcAndSetBaseMtx(viewerInput: Viewer.ViewerRenderInput): void {
const hasAnyMapFunction = (
(this.rotator !== null && this.rotator.isWorking())
);
if (hasAnyMapFunction) {
const m = this.modelInstance!.modelMatrix;
mat4.identity(m);
if (this.rotator !== null && this.rotator.isWorking())
mat4.mul(m, m, this.rotator.rotateMtx);
m[12] = this.translation[0];
m[13] = this.translation[1];
m[14] = this.translation[2];
} else {
super.calcAndSetBaseMtx(viewerInput);
}
}
}