How to use the expo-three.THREE.Vector3 function in expo-three

To help you get started, we’ve selected a few expo-three examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github expo / expo-three / example / ThreeAR.js View on Github external
export function hitTestFromOrigin(origin: Vector, direction: Vector) {
  const { rawFeaturePoints } = AR.getCurrentFrame({ rawFeaturePoints: true });

  if (rawFeaturePoints.length === 0) {
    return [];
  }

  // Determine the point from the whole point cloud which is closest to the hit test ray.
  var closestFeaturePoint = origin;
  var minDistance = 99999999999;

  for (let feature of rawFeaturePoints) {
    const { x, y, z, id } = feature;
    let featurePos = new THREE.Vector3(x, y, z);

    let originVector = origin.clone().sub(featurePos);
    let crossProduct = originVector.clone().cross(direction);
    let featureDistanceFromResult = crossProduct.length();

    if (featureDistanceFromResult < minDistance) {
      closestFeaturePoint = featurePos;
      minDistance = featureDistanceFromResult;
    }
  }

  // Compute the point along the ray that is closest to the selected feature.
  let originToFeature = closestFeaturePoint.clone().sub(origin);
  let hitTestResult = origin
    .clone()
    .add(direction.clone().multiply(direction.clone().dot(originToFeature)));
github expo / expo-three / example / ThreeAR.js View on Github external
export function hitTestRayFromScreenPos(camera, point: Point) {
  let cameraPos = positionFromTransform(camera.matrix);

  // Note: z: 1.0 will unproject() the screen position to the far clipping plane.
  let positionVec = new THREE.Vector3(point.x, point.y, 1.0);
  let screenPosOnFarClippingPlane = unprojectPoint(camera, positionVec);

  let rayDirection = screenPosOnFarClippingPlane.clone().sub(cameraPos);
  rayDirection.normalize();

  const hitTest = new HitTestRay();
  hitTest.origin = cameraPos;
  hitTest.direction = rayDirection;
  return hitTest;
}
//-> FeatureHitTestResult?
github expo / expo-three / example / screens / AR / Measure / index.js View on Github external
setupLine = () => {
    const geometry = new THREE.Geometry();
    geometry.vertices.push(new THREE.Vector3());
    geometry.vertices.push(new THREE.Vector3(1, 1, 1));
    geometry.verticesNeedUpdate = true;
    geometry.dynamic = true;

    this.line = new THREE.Line(
      geometry,
      new THREE.LineBasicMaterial({
        color: 0x00ff00,
        opacity: 1,
        linewidth: 7,
        side: THREE.DoubleSide,
        linecap: 'round',
      })
    );
    /// https://stackoverflow.com/questions/36497763/three-js-line-disappears-if-one-point-is-outside-of-the-cameras-view
    this.line.frustumCulled = false; // Avoid flicker
github EvanBacon / Expo-Voxel / js / lib / voxel-engine.js View on Github external
Game.prototype.showChunk = function(chunk) {
  const chunkIndex = chunk.position.join('|');
  if (chunkIndex !== '0|0|0') {
    return;
  }
  console.log('show chunk', chunkIndex);
  var bounds = this.voxels.getBounds.apply(this.voxels, chunk.position);
  var scale = new THREE.Vector3(1, 1, 1);
  var mesh = new VoxelMesh(chunk, this.mesher, scale);
  this.voxels.chunks[chunkIndex] = chunk;
  if (this.voxels.meshes[chunkIndex]) {
    if (this.voxels.meshes[chunkIndex].surfaceMesh)
      this.scene.remove(this.voxels.meshes[chunkIndex].surfaceMesh);
    if (this.voxels.meshes[chunkIndex].wireMesh)
      this.scene.remove(this.voxels.meshes[chunkIndex].wireMesh);
  }
  this.voxels.meshes[chunkIndex] = mesh;
  if (this.meshType === 'wireMesh') mesh.createWireMesh();
  else mesh.createSurfaceMesh(this.materials.material);
  this.materials.paint(mesh);

  mesh.setPosition(bounds[0][0], bounds[0][1], bounds[0][2]);
  mesh.addToScene(this.scene);
  this.emitter.emit('renderChunk', chunk);
github expo / expo-three / example / ThreeAR.js View on Github external
export const scaleLongestSideToSize = (mesh, size) => {
  let sizedVector = new THREE.Vector3();
  new THREE.Box3().setFromObject(mesh).getSize(sizedVector);

  const { x: width, y: height, z: depth } = sizedVector;

  const longest = Math.max(width, Math.max(height, depth));
  const scale = size / longest;
  mesh.scale.set(scale, scale, scale);
};
github expo / expo-three / example / screens / Effects / VignetteExample.js View on Github external
setupCamera({ width, height }) {
    this.camera = new THREE.PerspectiveCamera(70, width / height, 1, 5000);
    this.camera.position.z = 400;
    this.camera.lookAt(new THREE.Vector3());
  }
github expo / expo-three / example / screens / Effects / VignetteExample.js View on Github external
require('three/examples/js/shaders/ColorCorrectionShader');
    require('three/examples/js/shaders/VignetteShader');
    require('three/examples/js/shaders/DigitalGlitch');

    this.effect = new THREE.EffectComposer(this.renderer);

    const renderPass = new THREE.RenderPass(this.scene, this.camera);
    const copyPass = new THREE.ShaderPass(THREE.CopyShader);
    this.effect.addPass(renderPass);

    const vh = 1.4;
    const vl = 1.2;
    const colorCorrectionPass = new THREE.ShaderPass(
      THREE.ColorCorrectionShader
    );
    colorCorrectionPass.uniforms['powRGB'].value = new THREE.Vector3(
      vh,
      vh,
      vh
    );
    colorCorrectionPass.uniforms['mulRGB'].value = new THREE.Vector3(
      vl,
      vl,
      vl
    );
    this.effect.addPass(colorCorrectionPass);
    const vignettePass = new THREE.ShaderPass(THREE.VignetteShader);
    vignettePass.uniforms['darkness'].value = 1.0;
    this.effect.addPass(vignettePass);
    this.effect.addPass(copyPass);
    copyPass.renderToScreen = true;