Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Player.prototype.tick = function(td) {
vec3.add(this.velocity, vec3.scale(this.acceleration, td, auxv3));
if(this.hadContact) {
// assume a constant normal force of .1 COF ~.5
var friction = 0.05,
speed = vec3.length(this.velocity);
friction = Math.min(speed, friction);
vec3.scale(this.velocity, 1-friction/speed);
}
vec3.add(this.position, vec3.scale(this.velocity, td, auxv3));
var world = this.world,
scale = world.scale,
aabb = this.aabb,
voxel;
// prepare AABB
this.shape.setPosition(this.position[0], this.position[1], this.position[2]);
this.shape.updateAABB(aabb);
fitAABBtoGrid(aabb, scale);
var voxels = [];
for(var x = aabb.x0; x < aabb.x1; x+=scale) {
for(var y = aabb.y0; y < aabb.y1; y+=scale) {
for(var z = aabb.z0; z < aabb.z1; z+=scale) {
if(world.voxel([x, y, z]) > 0){
function drawPlateVectors(u_projection, mesh, {r_xyz, r_plate, plate_vec}) {
let line_xyz = [], line_rgba = [];
for (let r = 0; r < mesh.numRegions; r++) {
line_xyz.push(r_xyz.slice(3 * r, 3 * r + 3));
line_rgba.push([1, 1, 1, 1]);
line_xyz.push(vec3.add([], r_xyz.slice(3 * r, 3 * r + 3),
vec3.scale([], plate_vec[r_plate[r]], 2 / Math.sqrt(N))));
line_rgba.push([1, 0, 0, 0]);
}
renderLines({
u_projection,
u_multiply_rgba: [1, 1, 1, 1],
u_add_rgba: [0, 0, 0, 0],
a_xyz: line_xyz,
a_rgba: line_rgba,
count: line_xyz.length,
});
}
zoom(df) {
var delta = [0.0, 0.0, 0.0];
vec3.sub(delta, this._offset, this._trans);
vec3.scale(delta, delta, df * this._speed / 54);
if (df < 0.0)
delta[0] = delta[1] = 0.0;
this.setTrans(vec3.add(this._trans, this._trans, delta));
vec3.scale(delta, delta, 5);
this.translateDelay(delta, DELAY_TRANSLATE);
}
_computeCenterGizmo(center = [0.0, 0.0, 0.0]) {
var meshes = this._main.getSelectedMeshes();
var acc = [0.0, 0.0, 0.0];
var icenter = [0.0, 0.0, 0.0];
for (var i = 0; i < meshes.length; ++i) {
var mesh = meshes[i];
vec3.transformMat4(icenter, mesh.getCenter(), mesh.getEditMatrix());
vec3.transformMat4(icenter, icenter, mesh.getMatrix());
vec3.add(acc, acc, icenter);
}
vec3.scale(center, acc, 1.0 / meshes.length);
return center;
}
vec3.sub(delta, this.pairedWarpPod.translation, this.translation);
const mag = vec3.length(delta);
const upVec = vec3.create();
calcUpVec(upVec, this);
const negUpVec = vec3.create();
vec3.negate(negUpVec, upVec);
const crossA = vec3.create(), crossB = vec3.create();
vec3.cross(crossA, delta, negUpVec);
vec3.normalize(crossA, crossA);
vec3.cross(crossB, crossA, delta);
vec3.normalize(crossB, crossB);
const halfway = vec3.create();
vec3.scale(halfway, delta, 0.5);
vec3.add(halfway, this.translation, halfway);
const mag2 = 0.5 * mag;
const b = mag2 / Math.sin(MathConstants.TAU / 8);
let a = (b * b) - (mag2 * mag2);
if (a >= 0) {
const norm = 1 / Math.sqrt(a);
const anorm = a * norm;
const cubic = (anorm * norm) - 3.0;
a = -cubic * anorm * 0.5;
}
const ca = vec3.create(), cb = vec3.create();
vec3.scaleAndAdd(ca, halfway, crossB, a);
vec3.scale(cb, crossB, -b);
vec3.scale(halfway, delta, 0.5);
vec3.add(halfway, this.translation, halfway);
const mag2 = 0.5 * mag;
const b = mag2 / Math.sin(MathConstants.TAU / 8);
let a = (b * b) - (mag2 * mag2);
if (a >= 0) {
const norm = 1 / Math.sqrt(a);
const anorm = a * norm;
const cubic = (anorm * norm) - 3.0;
a = -cubic * anorm * 0.5;
}
const ca = vec3.create(), cb = vec3.create();
vec3.scaleAndAdd(ca, halfway, crossB, a);
vec3.scale(cb, crossB, -b);
for (let i = 0; i < numPoints; i++) {
const v = vec3.create();
const ha = 1.0 - ((i - numPoints / 2) / numPoints);
const c = (Math.sin(Math.PI * ha) + 1.0) * 0.5;
const rad = lerp(-MathConstants.TAU / 8, MathConstants.TAU / 8, c);
mat4.fromRotation(scratchMatrix, rad, crossA);
vec3.transformMat4(v, cb, scratchMatrix);
vec3.add(v, v, ca);
vec3.scaleAndAdd(v, v, upVec, 200);
this.warpPathPoints.push(v);
}
this.pathDrawer = new WarpPodPathDrawer(sceneObjHolder, this.resourceHolder.arc, this.warpPathPoints, this.color);
const move = (direction, dirSign) => {
vec3.scale(moveDir, direction, dirSign * this.moveVelocity);
vec3.add(this.lookFrom, this.lookFrom, moveDir);
vec3.add(this.lookAt, this.lookAt, moveDir);
}
deform(featurePoints) {
let displacement = featurePoints.map((p, i) => {
let fp = this.standardFaceData.getFeatureVertex(i)
return vec3.sub([], p, fp)
})
let attribute = this.geometry.getAttribute('position')
let n = attribute.array.length / 3
for (let i = 0; i < n; i++) {
let p = vec3.create()
let b = 0
this.standardFaceData.data.face.weight[i].forEach((w) => {
vec3.add(p, p, vec3.scale(vec3.create(), displacement[w[0]], w[1]))
b += w[1]
})
vec3.scale(p, p, 1 / b)
vec3.add(p, p, this.standardFaceData.getVertex(i))
attribute.array[i * 3 + 0] = p[0]
attribute.array[i * 3 + 1] = p[1]
attribute.array[i * 3 + 2] = p[2]
}
attribute.needsUpdate = true
}
getLightViewMatrix: function (mat) {
var manager = this.light.scene.lights;
var entry = manager.getModelEntry(this.id);
var p_dir = entry.parameters["direction"];
var p_pos = entry.parameters["position"];
var bb = new XML3D.Box();
this.light.scene.getBoundingBox(bb);
var off = vec3.create();
var bbCenter = bb.center();
var bbSize = bb.size();
var d = bbSize.length(); //diameter of bounding sphere of the scene
vec3.scale(off, p_dir, -0.55 * d); //enlarge a bit on the radius of the scene
p_pos = vec3.add(p_pos, bbCenter.data, off);
entry.parameters["position"] = p_pos;
//create new transformation matrix depending on the updated parameters
mat4.identity(mat);
var lookat_mat = mat4.create();
var top_vec = vec3.fromValues(0.0, 1.0, 0.0);
if ((p_dir[0] == 0.0) && (p_dir[2] == 0.0)) //check if top_vec colinear with direction
top_vec = vec3.fromValues(0.0, 0.0, 1.0);
var up_vec = vec3.create();
var dir_len = vec3.len(p_dir);
vec3.scale(up_vec, p_dir, -vec3.dot(top_vec, p_dir) / (dir_len * dir_len));
vec3.add(up_vec, up_vec, top_vec);
vec3.normalize(up_vec, up_vec);
mat4.lookAt(lookat_mat, vec3.fromValues(0.0, 0.0, 0.0), p_dir, up_vec);
const prev = idx - 1;
const twoPrev = idx > 1 ? idx - 2 : posPathLength - 1;
posKeyframe(vecs[0], this.spline, twoPrev);
posKeyframe(vecs[1], this.spline, prev);
posKeyframe(vecs[2], this.spline, idx);
posKeyframe(vecs[3], this.spline, nxt);
const tangentScale = 512 * Math.abs(this.spline.xTrack[idx].time - this.spline.xTrack[prev].time) / 100;
vec3.sub(vecs[1], vecs[1], vecs[0]);
vec3.normalize(vecs[1], vecs[1]);
vec3.scale(vecs[1], vecs[1], tangentScale);
vec3.sub(vecs[3], vecs[3], vecs[2]);
vec3.normalize(vecs[3], vecs[3]);
vec3.scale(vecs[3], vecs[3], tangentScale);
const t0 = vecs[1];
const t1 = vecs[3];
this.pos[0] = sampleFloatAnimationTrackSimple(this.spline.xTrack, cyclePhase, t0[0], t1[0])
this.pos[1] = sampleFloatAnimationTrackSimple(this.spline.yTrack, cyclePhase, t0[1], t1[1])
this.pos[2] = sampleFloatAnimationTrackSimple(this.spline.zTrack, cyclePhase, t0[2], t1[2])
vec3.scale(this.pos, this.pos, this.translationScale);
const heading = sampleFloatAnimationTrackSimple(this.spline.hTrack, cyclePhase, 1, -1);
const pitch = sampleFloatAnimationTrackSimple(this.spline.pTrack, cyclePhase, 1, -1);
const roll = sampleFloatAnimationTrackSimple(this.spline.rTrack, cyclePhase, 1, -1);
mat4.fromTranslation(dst, this.pos);
mat4.rotateZ(dst, dst, heading * MathConstants.DEG_TO_RAD);
mat4.rotateX(dst, dst, pitch * MathConstants.DEG_TO_RAD);