Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function subdivideMeshes (mesh) {
const planeNormal = rand.onSphere(1)
const planePt = rand.insideSphere(5)
const [mesh1, mesh2] = clipMeshWithPlane(mesh, planeNormal, planePt)
const offset1 = vec3.scale([], planeNormal, settings.offset)
const offset2 = vec3.scale([], planeNormal, -settings.offset)
// const rotation = mat4.fromRotation([], rand.range(0, Math.PI * 0.5), planeNormal)
return [
mesh1.map(points => points.map(pt => vec3.add([], pt, offset1))),
mesh2.map(points => points.map(pt => vec3.add([], pt, offset2)))
// mesh1.map(points => points.map(pt => vec3.transformMat4([], pt, rotation))),
// mesh2
]
}
function subdivideMeshes (mesh) {
const planeNormal = rand.onSphere(1)
const planePt = rand.insideSphere(5)
const [mesh1, mesh2] = clipMeshWithPlane(mesh, planeNormal, planePt)
const offset1 = vec3.scale([], planeNormal, settings.offset)
const offset2 = vec3.scale([], planeNormal, -settings.offset)
// const rotation = mat4.fromRotation([], rand.range(0, Math.PI * 0.5), planeNormal)
return [
mesh1.map(points => points.map(pt => vec3.add([], pt, offset1))),
mesh2.map(points => points.map(pt => vec3.add([], pt, offset2)))
// mesh1.map(points => points.map(pt => vec3.transformMat4([], pt, rotation))),
// mesh2
]
}
function getLinePlaneIntersection (line, planeNormal, pointOnPlane) {
const [p0, p1] = line
const dir = vec3.subtract([], p1, p0)
const t = vec3.dot(vec3.subtract([], pointOnPlane, p0), planeNormal) / vec3.dot(dir, planeNormal)
return t >= 0 && t <= 1 ? vec3.add([], vec3.scale([], dir, t), p0) : null
}
function getLinePlaneIntersection (line, planeNormal, pointOnPlane) {
const [p0, p1] = line
const dir = vec3.subtract([], p1, p0)
const t = vec3.dot(vec3.subtract([], pointOnPlane, p0), planeNormal) / vec3.dot(dir, planeNormal)
return t >= 0 && t <= 1 ? vec3.add([], vec3.scale([], dir, t), p0) : null
}
function getLinePlaneIntersection (line, planeNormal, pointOnPlane) {
const [p0, p1] = line
const dir = vec3.subtract([], p1, p0)
const t = vec3.dot(vec3.subtract([], pointOnPlane, p0), planeNormal) / vec3.dot(dir, planeNormal)
return t >= 0 && t <= 1 ? vec3.add([], vec3.scale([], dir, t), p0) : null
}
function getLinePlaneIntersection (line, planeNormal, pointOnPlane) {
const [p0, p1] = line
const dir = vec3.subtract([], p1, p0)
const t = vec3.dot(vec3.subtract([], pointOnPlane, p0), planeNormal) / vec3.dot(dir, planeNormal)
return t >= 0 && t <= 1 ? vec3.add([], vec3.scale([], dir, t), p0) : null
}
function getLinePlaneIntersection (line, planeNormal, pointOnPlane) {
const [p0, p1] = line
const dir = vec3.subtract([], p1, p0)
const t = vec3.dot(vec3.subtract([], pointOnPlane, p0), planeNormal) / vec3.dot(dir, planeNormal)
return t >= 0 && t <= 1 ? vec3.add([], vec3.scale([], dir, t), p0) : null
}
function tick () {
let velocity = vec3.subtract([], curPosition, lastPosition)
const delta = vec3.subtract([], destination, curPosition)
const acceleration = vec3.scale([], delta, 0.001)
velocity = vec3.add(velocity, acceleration, velocity)
if (vec3.length(velocity) > 0.005) {
velocity = vec3.normalize(velocity, velocity)
velocity = vec3.scale(velocity, velocity, 0.005)
}
const nextPosition = vec3.add([], velocity, curPosition)
lastPosition = curPosition
curPosition = nextPosition
return curPosition
}
}
function normalise(vec) {
const out = [];
vec3.normalize(out, vec);
return out;
}
function normalise(vec) {
var out = [];
vec3.normalize(out, vec);
return out;
}