How to use the aframe/src.THREE.BufferGeometry function in aframe

To help you get started, we’ve selected a few aframe 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 kabbi / zanzarah-tools / src / three / BSPLoader.js View on Github external
const { textureCoords } = data;
    const uvLayer = geometry.faceVertexUvs[0] = [];
    // eslint-disable-next-line no-unused-vars
    for (const [ _, a, b, c ] of indices) {
      const uvs = [a, b, c].map(index => {
        const [ u, v ] = textureCoords[index];
        return new THREE.Vector2(u, 1 - v);
      });
      uvLayer.push(uvs);
    }

    geometry.dynamic = false;
    geometry.computeFaceNormals();
    geometry.computeBoundingSphere();
    return new THREE.BufferGeometry()
      .fromGeometry(geometry);
  }
github kabbi / zanzarah-tools / src / three / DFFExporter.js View on Github external
_generateRwGeometry(mesh) {
    let geometry = null;
    if (mesh.geometry.isGeometry) {
      geometry = new THREE.BufferGeometry().fromGeometry(mesh.geometry);
    } else if (mesh.geometry.isBufferGeometry) {
      geometry = mesh.geometry;
    } else {
      throw new Error('Geometry type not supported');
    }

    const positionBuffer = geometry.getAttribute('position');
    const normalBuffer = geometry.getAttribute('normal');
    // const colorBuffer = geometry.getAttribute('color');
    const uvBuffer = geometry.getAttribute('uv');

    const data = {
      vertices: [],
      indices: [],
      vertexColors: [],
    };
github kabbi / zanzarah-tools / src / three / TransformControls.js View on Github external
THREE.TransformGizmo.call(this);

  const arrowGeometry = new THREE.Geometry();
  const mesh = new THREE.Mesh(new THREE.BoxGeometry(0.125, 0.125, 0.125));
  mesh.position.y = 0.5;
  mesh.updateMatrix();

  arrowGeometry.merge(mesh.geometry, mesh.matrix);

  const lineXGeometry = new THREE.BufferGeometry();
  lineXGeometry.addAttribute('position', new THREE.Float32BufferAttribute([ 0, 0, 0, 1, 0, 0 ], 3));

  const lineYGeometry = new THREE.BufferGeometry();
  lineYGeometry.addAttribute('position', new THREE.Float32BufferAttribute([ 0, 0, 0, 0, 1, 0 ], 3));

  const lineZGeometry = new THREE.BufferGeometry();
  lineZGeometry.addAttribute('position', new THREE.Float32BufferAttribute([ 0, 0, 0, 0, 0, 1 ], 3));

  this.handleGizmos = {

    X: [
      [ new THREE.Mesh(arrowGeometry, new GizmoMaterial({ color: 0xff0000 })), [ 0.5, 0, 0 ], [ 0, 0, -Math.PI / 2 ] ],
      [ new THREE.Line(lineXGeometry, new GizmoLineMaterial({ color: 0xff0000 })) ],
    ],

    Y: [
      [ new THREE.Mesh(arrowGeometry, new GizmoMaterial({ color: 0x00ff00 })), [ 0, 0.5, 0 ] ],
      [ new THREE.Line(lineYGeometry, new GizmoLineMaterial({ color: 0x00ff00 })) ],
    ],

    Z: [
      [ new THREE.Mesh(arrowGeometry, new GizmoMaterial({ color: 0x0000ff })), [ 0, 0, 0.5 ], [ Math.PI / 2, 0, 0 ] ],
github kabbi / zanzarah-tools / src / three / TransformControls.js View on Github external
const CircleGeometry = function (radius, facing, arc) {
    const geometry = new THREE.BufferGeometry();
    const vertices = [];
    arc = arc ? arc : 1;

    for (let i = 0; i <= 64 * arc; ++i) {
      if (facing === 'x') {
        vertices.push(0, Math.cos(i / 32 * Math.PI) * radius, Math.sin(i / 32 * Math.PI) * radius);
      }
      if (facing === 'y') {
        vertices.push(Math.cos(i / 32 * Math.PI) * radius, 0, Math.sin(i / 32 * Math.PI) * radius);
      }
      if (facing === 'z') {
        vertices.push(Math.sin(i / 32 * Math.PI) * radius, Math.cos(i / 32 * Math.PI) * radius, 0);
      }
    }

    geometry.addAttribute('position', new THREE.Float32BufferAttribute(vertices, 3));
github kabbi / zanzarah-tools / src / three / TransformControls.js View on Github external
THREE.TransformGizmoTranslate = function () {
  THREE.TransformGizmo.call(this);

  const arrowGeometry = new THREE.Geometry();
  const mesh = new THREE.Mesh(new THREE.CylinderGeometry(0, 0.05, 0.2, 12, 1, false));
  mesh.position.y = 0.5;
  mesh.updateMatrix();

  arrowGeometry.merge(mesh.geometry, mesh.matrix);

  const lineXGeometry = new THREE.BufferGeometry();
  lineXGeometry.addAttribute('position', new THREE.Float32BufferAttribute([ 0, 0, 0, 1, 0, 0 ], 3));

  const lineYGeometry = new THREE.BufferGeometry();
  lineYGeometry.addAttribute('position', new THREE.Float32BufferAttribute([ 0, 0, 0, 0, 1, 0 ], 3));

  const lineZGeometry = new THREE.BufferGeometry();
  lineZGeometry.addAttribute('position', new THREE.Float32BufferAttribute([ 0, 0, 0, 0, 0, 1 ], 3));

  this.handleGizmos = {

    X: [
      [ new THREE.Mesh(arrowGeometry, new GizmoMaterial({ color: 0xff0000 })), [ 0.5, 0, 0 ], [ 0, 0, -Math.PI / 2 ] ],
      [ new THREE.Line(lineXGeometry, new GizmoLineMaterial({ color: 0xff0000 })) ],
    ],

    Y: [
github kabbi / zanzarah-tools / src / three / DFFLoader.js View on Github external
_parseGeometry(section) {
    const { vertices, normals, vertexColors, textureCoords} = this._getData(section);
    const geometry = new THREE.BufferGeometry();

    const triangleGroups = this._getTriangleGroups(section);
    const triangleCount = Object.keys(triangleGroups).reduce((sum, key) => (
      sum + triangleGroups[key].length
    ), 0);

    const positionBuffer = new THREE.BufferAttribute(
      new Float32Array(triangleCount * 3 * 3), 3
    );
    const normalBuffer = normals && new THREE.BufferAttribute(
      new Float32Array(triangleCount * 3 * 3), 3, true
    );
    const colorBuffer = vertexColors && new THREE.BufferAttribute(
      new Uint8Array(triangleCount * 3 * 3), 3, true
    );
    const uvBuffer = textureCoords && new THREE.BufferAttribute(
github kabbi / zanzarah-tools / src / three / TransformControls.js View on Github external
THREE.TransformGizmoScale = function () {
  THREE.TransformGizmo.call(this);

  const arrowGeometry = new THREE.Geometry();
  const mesh = new THREE.Mesh(new THREE.BoxGeometry(0.125, 0.125, 0.125));
  mesh.position.y = 0.5;
  mesh.updateMatrix();

  arrowGeometry.merge(mesh.geometry, mesh.matrix);

  const lineXGeometry = new THREE.BufferGeometry();
  lineXGeometry.addAttribute('position', new THREE.Float32BufferAttribute([ 0, 0, 0, 1, 0, 0 ], 3));

  const lineYGeometry = new THREE.BufferGeometry();
  lineYGeometry.addAttribute('position', new THREE.Float32BufferAttribute([ 0, 0, 0, 0, 1, 0 ], 3));

  const lineZGeometry = new THREE.BufferGeometry();
  lineZGeometry.addAttribute('position', new THREE.Float32BufferAttribute([ 0, 0, 0, 0, 0, 1 ], 3));

  this.handleGizmos = {

    X: [
      [ new THREE.Mesh(arrowGeometry, new GizmoMaterial({ color: 0xff0000 })), [ 0.5, 0, 0 ], [ 0, 0, -Math.PI / 2 ] ],
      [ new THREE.Line(lineXGeometry, new GizmoLineMaterial({ color: 0xff0000 })) ],
    ],

    Y: [
      [ new THREE.Mesh(arrowGeometry, new GizmoMaterial({ color: 0x00ff00 })), [ 0, 0.5, 0 ] ],
      [ new THREE.Line(lineYGeometry, new GizmoLineMaterial({ color: 0x00ff00 })) ],
    ],