Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
case geometryTypes.sphere:
// sphere pos
let position = vec3.fromValues(
geometryData[geoTexturePackedBlockDataSize * i + 0],
geometryData[geoTexturePackedBlockDataSize * i + 1],
geometryData[geoTexturePackedBlockDataSize * i + 2]
);
let radius = vec3.fromValues(
geometryData[geoTexturePackedBlockDataSize * i + 3],
geometryData[geoTexturePackedBlockDataSize * i + 3],
geometryData[geoTexturePackedBlockDataSize * i + 3]
);
vec3.sub(geoBoundBoxMin, position, radius);
vec3.add(geoBoundBoxMax, position, radius);
geoBoundBoxCentroid = position;
break;
case geometryTypes.volumeAabb:
geoBoundBoxMin = vec3.fromValues(
geometryData[geoTexturePackedBlockDataSize * i + 0],
geometryData[geoTexturePackedBlockDataSize * i + 1],
geometryData[geoTexturePackedBlockDataSize * i + 2]
);
geoBoundBoxMax = vec3.fromValues(
geometryData[geoTexturePackedBlockDataSize * i + 3],
geometryData[geoTexturePackedBlockDataSize * i + 4],
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;
let ady = Math.abs(d[1]);
if (Math.abs(m[1]) > e[1] + ady) return false;
let adz = Math.abs(d[2]);
if (Math.abs(m[2]) > e[2] + adz) return false;
// Add in an epsilon term to counteract arithmetic errors when segment is
// (near) parallel to a coordinate axis (see text for detail)
adx += epsilon; ady += epsilon; adz += epsilon;
// Try cross products of segment direction vector with coordinate axes
if (Math.abs(m[1] * d[2] - m[2] * d[1]) > e[1] * adz + e[2] * ady) return false;
if (Math.abs(m[2] * d[0] - m[0] * d[2]) > e[0] * adz + e[2] * adx) return false;
let px = worldLocation[0];
let py = worldLocation[1];
let pz = worldLocation[2];
if (modelObject.xYQuad) {
let vx = vec3Heap[4], vy = vec3Heap[5];
vx[0] = velocity[0];
vx[1] = velocity[1];
vx[2] = 0;
vec3.normalize(vx, vx);
vy[0] = -vx[1];
vy[1] = vx[0];
vy[2] = 0;
vec3.add(vec3Heap[2], vx, vy);
vec3.sub(vec3Heap[1], vy, vx);
vec3.negate(vec3Heap[0], vec3Heap[2]);
vec3.negate(vec3Heap[3], vec3Heap[1]);
vectors = vec3Heap;
}
let pv1 = vectors[0];
let pv2 = vectors[1];
let pv3 = vectors[2];
let pv4 = vectors[3];
vertices[0] = px + pv1[0] * scalex;
vertices[1] = py + pv1[1] * scaley;
vertices[2] = pz + pv1[2] * scalez;
vertices[3] = px + pv2[0] * scalex;
vertices[4] = py + pv2[1] * scaley;
vertices[5] = pz + pv2[2] * scalez;
triangleArea(a, b, c) {
vec3.sub(this._v1, b, a)
vec3.sub(this._v2, c, a)
vec3.cross(this._v1, this._v1, this._v2)
return 0.5 * vec3.len(this._v1)
}
pan(angle: number) {
const n = vec3.create();
vec3.normalize(n, vec3.sub(n, this.eye, this.center));
const u = vec3.create();
vec3.cross(u, this.up, n);
vec3.normalize(u, u);
let v = vec3.create();
vec3.cross(v, n, u);
vec3.normalize(v, v);
const panmat4 = mat4.create();
mat4.fromRotation(panmat4, angle, v);
let newCenter = vec3.create();
vec3.sub(newCenter, this.center, this.eye);
vec3.transformMat4(newCenter, newCenter, panmat4);
vec3.add(this.center, newCenter, this.eye);
this.units.forEach(ent => {
let {instance, location, radius} = ent;
vec3.set(eMid, 0, 0, radius / 2);
vec3.set(eSize, radius, radius, radius);
vec3.add(eMid, eMid, location);
vec3.sub(eMid, eMid, ray);
vec3.div(eMid, eMid, eSize);
vec3.div(rDir, dir, eSize);
let dlen = vec3.sqrLen(rDir);
let dp = Math.max(0, vec3.dot(rDir, eMid)) / dlen;
if (dp > entDist) return;
vec3.scale(rDir, rDir, dp);
if (vec3.sqrDist(rDir, eMid) < 1.0) {
entity = ent;
entDist = dp;
}
});
let sel = [];
triangleArea(a, b, c) {
vec3.sub(this._v1, b, a)
vec3.sub(this._v2, c, a)
vec3.cross(this._v1, this._v1, this._v2)
return 0.5 * vec3.len(this._v1)
}
return function (point, v1, v2, v3) {
vec3.sub(vec1, v1, v2);
vec3.sub(vec2, v1, v3);
vec3.sub(vecP1, point, v2);
vec3.sub(vecP2, point, v3);
var total = vec3.len(vec3.cross(temp, vec1, vec2));
var area1 = vec3.len(vec3.cross(temp, vec1, vecP1));
var area2 = vec3.len(vec3.cross(temp, vec2, vecP2));
var area3 = vec3.len(vec3.cross(temp, vecP1, vecP2));
return Math.abs(total - (area1 + area2 + area3)) < 1E-20;
};
})();
function getExtendsFromAccessor(accessor, worldTransform, outMin, outMax)
{
const boxMin = vec3.create();
vec3.transformMat4(boxMin, jsToGl(accessor.min), worldTransform);
const boxMax = vec3.create();
vec3.transformMat4(boxMax, jsToGl(accessor.max), worldTransform);
const center = vec3.create();
vec3.add(center, boxMax, boxMin);
vec3.scale(center, center, 0.5);
const centerToSurface = vec3.create();
vec3.sub(centerToSurface, boxMax, center);
const radius = vec3.length(centerToSurface);
for (const i of [1, 2, 3])
{
outMin[i] = center[i] - radius;
outMax[i] = center[i] + radius;
}
}