• Box.js

  • ¶

    Like cube but not subdivided and continuous on edges

  • ¶

    Parent class : geom.Geometry

  • ¶

    Example use

     var g = new Box(1, 1, 1);
     var mesh = new Mesh(g, new materials.SolidColor());
    
    var geom = require('pex-geom');
    var Vec2 = geom.Vec2;
    var Vec3 = geom.Vec3;
    var Geometry = geom.Geometry;
  • ¶

    Box ( sx, sy, sz )

    sx - size x / width { Number = 1 }
    sy - size y / height { Number = 1 }
    sz - size z / depth { Number = 1 }

    function Box(sx, sy, sz) {
      sx = sx != null ? sx : 1;
      sy = sy != null ? sy : sx != null ? sx : 1;
      sz = sz != null ? sz : sx != null ? sx : 1;
    
      Geometry.call(this, { vertices: true, faces: true });
    
      var vertices = this.vertices;
      var faces = this.faces;
    
      var x = sx/2;
      var y = sy/2;
      var z = sz/2;
  • ¶

    bottom

      vertices.push(new Vec3(-x, -y, -z));
      vertices.push(new Vec3(-x, -y,  z));
      vertices.push(new Vec3( x, -y,  z));
      vertices.push(new Vec3( x, -y, -z));
  • ¶

    top

      vertices.push(new Vec3(-x,  y, -z));
      vertices.push(new Vec3(-x,  y,  z));
      vertices.push(new Vec3( x,  y,  z));
      vertices.push(new Vec3( x,  y, -z));
  • ¶
    4----7
    

    /: /| 5——6 | | 0..|.3 |, |/ 1——2

      faces.push([0, 3, 2, 1]); //bottom
      faces.push([4, 5, 6, 7]); //top
      faces.push([0, 1, 5, 4]); //left
      faces.push([2, 3, 7, 6]); //right
      faces.push([1, 2, 6, 5]); //front
      faces.push([3, 0, 4, 7]); //back
    
      this.computeNormals();
    }
    
    Box.prototype = Object.create(Geometry.prototype);
    
    module.exports = Box;