How to use the three.Geometry function in three

To help you get started, we’ve selected a few 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 wowserhq / wowser / lib / client / pipeline / adt / index.js View on Github external
function ADT(data) {
    var _this = this;

    _classCallCheck(this, ADT);

    this.data = data;
    this.geometry = new THREE.Geometry();
    var faces = this.geometry.faces = [];
    var vertices = this.geometry.vertices = [];

    var size = 33.333333;
    var step = size / 8;

    // See: http://www.pxr.dk/wowdev/wiki/index.php?title=ADT#MCVT_sub-chunk
    for (var cy = 0; cy < 16; ++cy) {
      var _loop = function () {
        var cindex = cy * 16 + cx;
        var chunk = _this.data.MCNKs[cindex];

        chunk.MCVT.heights.forEach(function (height, index) {
          var y = index; // 17
          var x = index % 17;
          if (x > 8) {
github swift502 / Sketchbook / src / sketchbook / objects / object_physics / ConvexPhysics.ts View on Github external
let defaults = {
            mass: 0,
            position: mesh.position,
            friction: 0.3
        };
        options = Utils.setDefaults(options, defaults);
        this.options = options;

        let mat = new CANNON.Material("convMat");
        mat.friction = options.friction;
        // mat.restitution = 0.7;

        if (this.mesh.geometry.isBufferGeometry)
        {
            this.mesh.geometry = new THREE.Geometry().fromBufferGeometry(this.mesh.geometry);
        }

        let cannonPoints = this.mesh.geometry.vertices.map((v) => {
            return new CANNON.Vec3( v.x, v.y, v.z );
        });
        
        let cannonFaces = this.mesh.geometry.faces.map((f) => {
            return [f.a, f.b, f.c];
        });

        let shape = new CANNON.ConvexPolyhedron(cannonPoints, cannonFaces);
        // shape.material = mat;

        // Add phys sphere
        let physBox = new CANNON.Body({
            mass: options.mass,
github gdsestimating / three-dxf / src / index.js View on Github external
function drawPoint(entity, data) {
        var geometry, material, point;

        geometry = new THREE.Geometry();

        geometry.vertices.push(new THREE.Vector3(entity.position.x, entity.position.y, entity.position.z));

        // TODO: could be more efficient. PointCloud per layer?

        var numPoints = 1;

        var color = getColor(entity, data);
        var colors = new Float32Array( numPoints*3 );
        colors[0] = color.r;
        colors[1] = color.g;
        colors[2] = color.b;

        geometry.colors = colors;
        geometry.computeBoundingBox();
github ironbane / ironbane-client / tasks / buildZones.js View on Github external
var postProcessWorld = function (json) {
            var loader = new THREE.ObjectLoader();

            var obj = loader.parse(json);

            var mergedMeshesGeometry = new THREE.Geometry();
            var mergedMaterialsCollection = [];

            var entitiesCollection = new THREE.Object3D(),
                ents = [];

            entitiesCollection.name = 'Entities';

            obj.traverse(function (child) {
                if (child.userData.entity) {
                    if (obj.userData.entity) {
                        // Only if the parent is an entity, we save the uuid
                        // Otherwise it would be no use since the parent will be merged into one world mesh
                        child.parentUuid = obj.uuid;
                    }
                    // store to array for later (don't mess with the tree during traversal)
                    ents.push(child);
github tesseralis / polyhedra-viewer / src / components / viewer / ThreeScene.jsx View on Github external
function getGeometry(solid) {
  const truncated = getTruncated(solid, 0)
  solid = getTruncated(solid, 1)
  console.log(truncated, solid)
  const geometry = new THREE.Geometry()
  solid.vertices.forEach(vertex =>
    geometry.vertices.push(new THREE.Vector3(...vertex)),
  )
  _.flatten(solid.faces.map(toTriangles)).forEach(face =>
    geometry.faces.push(new THREE.Face3(...face)),
  )
  geometry.computeVertexNormals()
  console.log('solid vertices', solid.vertices)
  console.log('geometry vertices', geometry.vertices)
  console.log(
    'truncated vertices',
    truncated.vertices.map(vertex => new THREE.Vector3(...vertex)),
  )
  geometry.morphTargets.push({
    name: 'truncated',
    vertices: truncated.vertices.map(vertex => new THREE.Vector3(...vertex)),
github Voxelum / minecraft-launcher-core-node / docs / site / demo.js View on Github external
scene.add(new THREE.AmbientLight(0xffffff, 0.97));

    const factory = new BlockModelFactory(textReg);
    const o = factory.getObject(grassBlock);
    scene.add(o);

    const control = new THREE.OrbitControls(camera, renderer.domElement);
    control.enableDamping = true;
    control.dampingFactor = 0.2
    control.zoomSpeed = 1.4
    control.rotateSpeed = 0.6
    control.enableKeys = false

    {
        const grid = new THREE.Geometry();
        const gMat = new THREE.LineBasicMaterial({ color: 0xafafaf });
        for (let i = -8; i < 8; ++i) {
            grid.vertices.push(new THREE.Vector3(-8, -8, i));
            grid.vertices.push(new THREE.Vector3(8, -8, i));
            grid.vertices.push(new THREE.Vector3(i, -8, -8));
            grid.vertices.push(new THREE.Vector3(i, -8, 8));
        }
        grid.vertices.push(new THREE.Vector3(-1, -8, 9));
        grid.vertices.push(new THREE.Vector3(1, -8, 9));

        grid.vertices.push(new THREE.Vector3(1, -8, 9));
        grid.vertices.push(new THREE.Vector3(0, -8, 10));

        grid.vertices.push(new THREE.Vector3(0, -8, 10));
        grid.vertices.push(new THREE.Vector3(-1, -8, 9));
github epam / med3web / lib / scripts / graphics2d / mprrenderer.js View on Github external
if (this.m_boundLines[i] !== undefined) {
        this.m_scene.remove(this.m_boundLines[i].getRenderObject());
      }
    }
    for (let i = 0; i < this.m_meshes.length; ++i) {
      if (this.m_meshes[i] !== undefined) {
        this.m_scene.remove(this.m_meshes[i]);
      }
    }
    this.clearControlLines();

    this.m_geo[PROJECTION_X].dispose();
    this.m_geo[PROJECTION_Y].dispose();
    this.m_geo[PROJECTION_Z].dispose();
    this.m_geo[PROJECTION_X] = new THREE.Geometry();
    this.m_geo[PROJECTION_Y] = new THREE.Geometry();
    this.m_geo[PROJECTION_Z] = new THREE.Geometry();

    this.m_material[PROJECTION_X] = null;
    this.m_material[PROJECTION_Y] = null;
    this.m_material[PROJECTION_Z] = null;

    this.m_meshes.fill(undefined);
  }
  /**
github facebook / react-360 / Examples / inputs / 3dof / ThreeDOFRayCaster.js View on Github external
_createController() {
    if (this._mesh) {
      return;
    }
    const beamGeom = new THREE.Geometry();
    beamGeom.vertices.push(
      new THREE.Vector3(-0.01, 0.01, 0),
      new THREE.Vector3(0.01, 0.01, 0),
      new THREE.Vector3(0.01, 0.01, -1),
      new THREE.Vector3(-0.01, 0.01, -1),

      new THREE.Vector3(-0.01, -0.01, 0),
      new THREE.Vector3(0.01, -0.01, 0),
      new THREE.Vector3(0.01, -0.01, -1),
      new THREE.Vector3(-0.01, -0.01, -1),
    );
    beamGeom.faces.push(
      new THREE.Face3(0, 1, 3),
      new THREE.Face3(1, 2, 3),
      new THREE.Face3(1, 5, 2),
      new THREE.Face3(5, 6, 2),
github heremaps / harp.gl / @here / harp-mapview / lib / PolarTileDataSource.ts View on Github external
const step = 360 / subdivisions;

            const cutIndexStart = Math.floor((cutStart.longitude + 180) / step);
            const cutIndexEnd = Math.ceil((cutEnd.longitude + 180) / step);

            for (let i = cutIndexStart + 1; i < cutIndexEnd; i++) {
                points.push(new GeoCoordinates(poleLat, i * step - 180, 0));
            }

            points.push(cutEnd);
            if (inPointD) {
                points.push(d);
            }
        }

        const g = new THREE.Geometry();

        for (const point of points) {
            const projected = dstProjection.projectPoint(point, new THREE.Vector3());
            g.vertices.push(projected.sub(tile.center));
        }

        for (let i = 1; i < points.length - 1; i++) {
            g.faces.push(isNorthPole ? new THREE.Face3(0, i, i + 1) : new THREE.Face3(0, i + 1, i));
        }

        const geometry = new THREE.BufferGeometry();
        geometry.fromGeometry(g);
        g.dispose();

        const mesh = new THREE.Mesh(geometry, material);
        mesh.userData = {
github lucascassiano / reViz3d / reViz3d-R2a / src / viewer / grid.js View on Github external
_drawGrid() {
        var gridGeometry, gridMaterial, mainGridZ, planeFragmentShader, planeGeometry, planeMaterial, subGridGeometry, subGridMaterial, subGridZ;

        //offset to avoid z fighting
        mainGridZ = -0.05;
        gridGeometry = new THREE.Geometry();
        gridMaterial = new THREE.LineBasicMaterial({
            color: new THREE.Color().setHex(this.color),
            opacity: this.opacity,
            linewidth: 2,
            transparent: true
        });

        subGridZ = -0.05;
        subGridGeometry = new THREE.Geometry();
        subGridMaterial = new THREE.LineBasicMaterial({
            color: new THREE.Color().setHex(this.color),
            opacity: this.opacity / 2,
            transparent: true
        });

        var step = this.step;