Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
abort: this.quitDrag,
originalEvent: e
}
BindManager.on('press', this.onBindToggle)
BindManager.on('release', this.onBindToggle)
if (this.dragging !== undefined) {
this.$emit('update:dragging', this.dragStarted)
}
this.$emit('dragstart', event)
vec2.copy(this.prev, this.origin)
}
} else {
// Detect drag and emit
this.toSpecifiedCoord(this.current, this.absCurrent)
vec2.sub(this.delta, this.current, this.prev)
vec2.sub(this.offset, this.current, this.origin)
const event: MouseDragEvent = {
current: this.current,
delta: this.delta,
offset: this.offset,
abort: this.quitDrag,
originalEvent: e
}
this.$emit('drag', event)
vec2.copy(this.prev, this.current)
}
}
vec2.copy(this.absPrev, this.absCurrent)
}
let perspective = (cameraZ - z) / cameraZ
p[0] *= perspective
p[1] *= perspective
p[2] = z
vec2.min(min, min, p)
vec2.max(max, max, p)
})
size = vec2.sub([], max, min)
scale = this.standardFace.size / vec2.len(size)
}
// normalize captured feature point coords
{
let center = featurePoint3D[41]
let yAxis = vec2.sub([], featurePoint3D[75], featurePoint3D[7])
let angle = Math.atan2(yAxis[1], yAxis[0]) - Math.PI * 0.5
let mtx = mat3.create()
mat3.rotate(mtx, mtx, -angle)
mat3.scale(mtx, mtx, [scale, scale])
mat3.translate(mtx, mtx, vec2.scale([], center, -1))
this.matrixFeaturePoints = new THREE.Matrix4()
this.matrixFeaturePoints.makeRotationZ(angle)
let s = 1 / scale
this.matrixFeaturePoints.scale(new THREE.Vector3(s, s, s))
this.matrixFeaturePoints.setPosition(new THREE.Vector3(center[0], center[1], center[2]))
this.normalizedFeaturePoints = featurePoint3D.map((p) => {
let q = vec2.transformMat3([], p, mtx)
q[2] = p[2] * scale
// convert to image coord to world coord
let featurePoint3D, size
{
let min = [Number.MAX_VALUE, Number.MAX_VALUE]
let max = [Number.MIN_VALUE, Number.MIN_VALUE]
let mtx = mat3.create()
let scale = planeHeight / imageHeight
mat3.scale(mtx, mtx, [scale, -scale])
mat3.translate(mtx, mtx, [-imageWidth / 2, -imageHeight / 2])
featurePoint3D = featurePoint2D.map((p) => {
let q = vec2.transformMat3([], p, mtx)
vec2.min(min, min, q)
vec2.max(max, max, q)
return q
})
size = vec2.sub([], max, min)
}
// calc z position
let scale = vec2.len(size) / this.standardFace.size
{
let min = [Number.MAX_VALUE, Number.MAX_VALUE]
let max = [Number.MIN_VALUE, Number.MIN_VALUE]
featurePoint3D.forEach((p, i) => {
let z = this.standardFace.getFeatureVertex(i)[2] * scale
if (isNaN(z)) {
return
}
let perspective = (cameraZ - z) / cameraZ
p[0] *= perspective
p[1] *= perspective
p[2] = z
export function rayLineIntersection(ray0: vec2, ray1: vec2, line0: vec2, line1: vec2): [vec2, number] | undefined {
const p = ray0; /* do not write to p (or clone ray0) */
const r = vec2.sub(v2(), ray1, ray0);
const q = line0; /* do not write to q (or clone line0) */
const s = vec2.sub(v2(), line1, line0);
const cross_rs = vec2.cross(v3(), r, s)[2];
if (cross_rs === 0.0) {
return undefined;
}
const qp = vec2.sub(v2(), q, p);
const u = vec2.cross(v3(), qp, vec2.scale(v2(), r, 1.0 / cross_rs))[2];
const t = vec2.cross(v3(), qp, vec2.scale(v2(), s, 1.0 / cross_rs))[2];
if (u < 0.0 || u > 1.0 || t < 0.0) { // } || t > 1.0) { // ray intersects line segment in both directions ...
return undefined;
}
return [vec2.add(v2(), q, vec2.scale(v2(), s, u)), t];
this.featurePoint3D = null
this.normalizedFeaturePoints = null
if (!this.rawFeaturePoints) {
return
}
// add head feature points
{
let faceCenter = vec2.lerp([], this.standardFaceData.getFeatureVertex(14), this.standardFaceData.getFeatureVertex(0), 0.5)
let scale = 1.0 / vec2.sub([], this.standardFaceData.getFeatureVertex(14), faceCenter)[0]
let v0 = this.rawFeaturePoints[0]
let v1 = this.rawFeaturePoints[14]
let center = vec2.lerp(vec2.create(), v0, v1, 0.5)
let xAxis = vec2.sub([], v1, center)
scale *= vec2.len(xAxis)
let rotation = mat3.create()
mat3.rotate(rotation, rotation, Math.atan2(xAxis[1], xAxis[0]))
for (let i = 71; i < 80; i++) {
let p = vec2.sub([], this.standardFaceData.getFeatureVertex(i), faceCenter)
vec2.scale(p, p, scale)
p[1] *= -1
vec2.transformMat3(p, p, rotation)
vec2.add(p, p, center)
this.rawFeaturePoints[i] = p
}
}
// convert to canvas coord to world coord
let size
}
let perspective = (cameraZ - z) / cameraZ
p[0] *= perspective
p[1] *= perspective
p[2] = z
vec2.min(min, min, p)
vec2.max(max, max, p)
})
size = vec2.sub([], max, min)
scale = this.standardFaceData.size / vec2.len(size)
}
// normalize captured feature point coords
{
let center = this.featurePoint3D[41]
let yAxis = vec2.sub([], this.featurePoint3D[75], this.featurePoint3D[7])
let angle = Math.atan2(yAxis[1], yAxis[0]) - Math.PI * 0.5
let mtx = mat3.create()
mat3.rotate(mtx, mtx, -angle)
mat3.scale(mtx, mtx, [scale, scale])
mat3.translate(mtx, mtx, vec2.scale([], center, -1))
this.matrixFeaturePoints.identity()
this.matrixFeaturePoints.makeRotationZ(angle)
let s = 1 / scale
this.matrixFeaturePoints.scale(new THREE.Vector3(s, s, s))
this.matrixFeaturePoints.setPosition(new THREE.Vector3(center[0], center[1], 0))
this.normalizedFeaturePoints = this.featurePoint3D.map((p) => {
let q = vec2.transformMat3([], p, mtx)
q[2] = p[2] * scale
placeEditPoints() {
this.editPoints = []
this.tracker.currentPosition.forEach(this.addEditPoint.bind(this))
let fpCenter = vec2.lerp([], this.face.getFPCoord(14), this.face.getFPCoord(0), 0.5)
let scale = 1.0 / vec2.sub([], this.face.getFPCoord(14), fpCenter)[0]
let v0 = this.tracker.currentPosition[0]
let v1 = this.tracker.currentPosition[14]
let center = vec2.lerp(vec2.create(), v0, v1, 0.5)
let xAxis = vec2.sub([], v1, center)
scale *= vec2.len(xAxis)
let rotation = mat3.create()
mat3.rotate(rotation, rotation, Math.atan2(xAxis[1], xAxis[0]))
for (let i = 71; i < 80; i++) {
let p = vec2.sub([], this.face.getFPCoord(i), fpCenter)
vec2.scale(p, p, scale)
p[1] *= -1
vec2.transformMat3(p, p, rotation)
vec2.add(p, p, center)
this.addEditPoint(p, i)
}
}
get sub(): vec2 {
vec2.sub(this._sub, this.to, this.from)
return this._sub
}
sub(vector) { return vec2.sub(new Vector(), this, vector); }
getBoundsFor(vertices, indices) {
let min = [Number.MAX_VALUE, Number.MAX_VALUE]
let max = [Number.MIN_VALUE, Number.MIN_VALUE]
indices.forEach((index) => {
vec2.min(min, min, vertices[index])
vec2.max(max, max, vertices[index])
})
return {min, max, size: vec2.sub([], max, min), center: vec2.lerp([], min, max, 0.5)}
}