Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public _initArtoolkit(onCompleted: () => any) {
// set this._artoolkitProjectionAxisTransformMatrix to change artoolkit
// projection matrix axis to match usual` webgl one
this._artoolkitProjectionAxisTransformMatrix = new THREE.Matrix4();
this._artoolkitProjectionAxisTransformMatrix.multiply(
new THREE.Matrix4().makeRotationY(Math.PI)
);
this._artoolkitProjectionAxisTransformMatrix.multiply(
new THREE.Matrix4().makeRotationZ(Math.PI)
);
// get cameraParameters
const cameraParameters = new ARToolKitCameraParam(
this.parameters.cameraParametersUrl,
() => {
// init controller
const arController = new ARToolKitController(
this.parameters.canvasWidth,
this.parameters.canvasHeight,
cameraParameters
);
// Skip center point if it already exists
if (Math.sqrt(trueProbePoint.x * trueProbePoint.x + trueProbePoint.y * trueProbePoint.y) < pointTolerance) {
if (centerPointGenerated) {
continue;
}
centerPointGenerated = true;
}
// If we have a close point, create a new indicator
if (!isNaN(trueProbePoint.z)) {
const radius = (numPoints > 64) ? smallIndicatorRadius
: (numPoints > 9) ? mediumIndicatorRadius
: bigIndicatorRadius;
const sphereGeometry = new SphereGeometry(radius);
sphereGeometry.applyMatrix(new Matrix4().makeTranslation(x, y, z));
const material = new MeshBasicMaterial({ color, opacity, transparent: true });
const sphere = new Mesh(sphereGeometry, material);
sphere.coords = trueProbePoint;
indicators.push(sphere);
}
}
return indicators;
}
Processor.prototype.process = function(lot) {
this.depth = 0;
if (lot.faces[0].a !== 0) throw "I assume the first face uses the first vertex!"; // TODO
lot.computeFaceNormals();
var world = new THREE.Matrix4();
world.makeRotationFromQuaternion(quat_from_first_face(lot.vertices[lot.faces[0].a], lot.vertices[lot.faces[0].b], null));
world.setPosition( lot.vertices[0].clone() );
var inverse_world = new THREE.Matrix4();
inverse_world.getInverse(world, true);
lot.applyMatrix(inverse_world);
lot.pivot = new THREE.Vector3(0,0,0);
lot.pivotRotate = new THREE.Quaternion();
lot.pivotTransform = new THREE.Matrix4();
lot.pivotTransformInverse = new THREE.Matrix4();
lot.computeFaceNormals();
this.stack = [lot];
this.res = [];
this.applyRule(this.rules.Lot);
awake () {
super.awake()
if (this.gameObject.isStatic) {
const renderEngine = this.gameEngine.renderEngine as ThreeRenderEngine
if (renderEngine.mergedStatic) {
renderEngine.mergedStatic.meshes.add(
this.url,
new Matrix4().fromArray(this.transform.localToWorldMatrix),
)
return
}
}
this.getProperty("url").onValue(url => {
this._urlRemover()
this.objectValue.update(undefined)
this._urlRemover = loadGLTFWithBoundingBox(this.gameEngine.loader, url).onValue(gltf => {
this.objectValue.update(SkeletonUtils.clone(gltf.scene) as Object3D)
this._boundsValid = false
})
})
}
static createMatrixToPlaceStreetRight(depth) {
return new THREE.Matrix4().makeTranslation(0, 0, -depth);
}
maybeEval(this.options.sizeY, dp),
maybeEval(this.options.sizeZ, dp))];
break;
case 'sphere':
geos = [new THREE.SphereGeometry(maybeEval(this.options.sizeR, dp), 16, 16)];
break;
case 'ellipsoid':
geos = [new THREE.SphereGeometry(1.0, 16, 16)];
geos[0].applyMatrix(new THREE.Matrix4().makeScale(
maybeEval(this.options.sizeX, dp),
maybeEval(this.options.sizeY, dp),
maybeEval(this.options.sizeZ, dp)));
break;
case 'tetrahedron':
geos = [new THREE.TetrahedronGeometry(1.0)];
geos[0].applyMatrix(new THREE.Matrix4().makeScale(
maybeEval(this.options.sizeX, dp),
maybeEval(this.options.sizeY, dp),
maybeEval(this.options.sizeZ, dp)));
break;
case 'octahedron':
geos = [new THREE.OctahedronGeometry(1.0)];
geos[0].applyMatrix(new THREE.Matrix4().makeScale(
maybeEval(this.options.sizeX, dp),
maybeEval(this.options.sizeY, dp),
maybeEval(this.options.sizeZ, dp)));
break;
case 'cube':
default:
geos = [new THREE.BoxGeometry(
maybeEval(this.options.sizeX, dp),
maybeEval(this.options.sizeX, dp),
ThreeBSP.prototype.toGeometry = function() {
var i, j,
matrix = new THREE.Matrix4().getInverse( this.matrix ),
geometry = new THREE.Geometry(),
polygons = this.tree.allPolygons(),
polygon_count = polygons.length,
polygon, polygon_vertice_count,
vertice_dict = {},
vertex_idx_a, vertex_idx_b, vertex_idx_c,
vertex, face,
verticeUvs;
for ( i = 0; i < polygon_count; i++ ) {
polygon = polygons[i];
polygon_vertice_count = polygon.vertices.length;
for ( j = 2; j < polygon_vertice_count; j++ ) {
verticeUvs = [];
THREE.TransformGizmo.prototype.update = function (rotation, eye) {
var vec1 = new THREE.Vector3(0, 0, 0);
var vec2 = new THREE.Vector3(0, 1, 0);
var lookAtMatrix = new THREE.Matrix4();
this.traverse(function (child) {
if (child.name.search("E") !== - 1) {
child.quaternion.setFromRotationMatrix(lookAtMatrix.lookAt(eye, vec1, vec2));
} else if (child.name.search("X") !== - 1 || child.name.search("Y") !== - 1 || child.name.search("Z") !== - 1) {
child.quaternion.setFromEuler(rotation);
}
});
};
point() {
if (!this.orientation || !this.eye) return;
let euler = this.orientation.getScreenAdjustedEuler();
let a = THREE.Math.degToRad(euler.alpha);
let b = THREE.Math.degToRad(euler.beta);
let g = THREE.Math.degToRad(euler.gamma);
let ra = new THREE.Matrix4();
let rb = new THREE.Matrix4();
let rg = new THREE.Matrix4();
ra.makeRotationZ(a);
rb.makeRotationX(b);
rg.makeRotationY(g);
let r = this.eye.clone();
r.multiply(ra);
r.multiply(rb);
r.multiply(rg);
this.context.camera.quaternion.setFromRotationMatrix(r);
$('#debug2').text(euler.alpha);
}
lineVertices.push(lineDestination.x, lineDestination.y, lineDestination.z);
coneGeometry.faces.forEach(function (face) {
face.vertexColors.push(headColor, headColor, headColor);
});
if (direction.y > 0.99999) {
quaternion.set(0, 0, 0, 1);
} else if (direction.y < -0.99999) {
quaternion.set(1, 0, 0, 0);
} else {
axis.set(direction.z, 0, -direction.x).normalize();
quaternion = new THREE.Quaternion().setFromAxisAngle(axis, Math.acos(direction.y));
}
coneGeometry.applyMatrix(new THREE.Matrix4().makeRotationFromQuaternion(quaternion));
coneGeometry.translate(destination.x, destination.y, destination.z);
if (!heads) {
heads = coneGeometry;
} else {
heads.merge(coneGeometry);
}
} else {
lineVertices.push(destination.x, destination.y, destination.z);
}
return heads;
},