src/api/primitives/polyhedron.js
function (options) {
  options = options || {}
  if (('points' in options) !== ('faces' in options)) {
    throw new Error("polyhedron needs 'points' and 'faces' arrays")
  }
  let vertices = parseOptionAs3DVectorList(options, 'points', [
            [1, 1, 0],
            [1, -1, 0],
            [-1, -1, 0],
            [-1, 1, 0],
            [0, 0, 1]
  ])
        .map(function (pt) {
          return new Vertex3(pt)
        })
  let faces = parseOption(options, 'faces', [
            [0, 1, 4],
            [1, 2, 4],
            [2, 3, 4],
            [3, 0, 4],
            [1, 0, 3],
            [2, 1, 3]
  ])
    // Openscad convention defines inward normals - so we have to invert here
  faces.forEach(function (face) {
    face.reverse()
  })
  let polygons = faces.map(function (face) {
    return new Polygon3(face.map(function (idx) {
      return vertices[idx]
    }))
  })

    // TODO: facecenters as connectors? probably overkill. Maybe centroid
    // the re-tesselation here happens because it's so easy for a user to
    // create parametrized polyhedrons that end up with 1-2 dimensional polygons.
    // These will create infinite loops at CSG.Tree()
  return fromPolygons(polygons).reTesselated()
}
function (options) {
  options = options || {}
  if (('points' in options) !== ('faces' in options)) {
    throw new Error("polyhedron needs 'points' and 'faces' arrays")
  }
  let vertices = parseOptionAs3DVectorList(options, 'points', [
            [1, 1, 0],
            [1, -1, 0],
            [-1, -1, 0],
            [-1, 1, 0],
            [0, 0, 1]
  ])
        .map(function (pt) {
          return new Vertex3(pt)
        })
  let faces = parseOption(options, 'faces', [
            [0, 1, 4],
            [1, 2, 4],
            [2, 3, 4],
            [3, 0, 4],
            [1, 0, 3],
            [2, 1, 3]
  ])
    // Openscad convention defines inward normals - so we have to invert here
  faces.forEach(function (face) {
    face.reverse()
  })
  let polygons = faces.map(function (face) {
    return new Polygon3(face.map(function (idx) {
      return vertices[idx]
    }))
  })

    // TODO: facecenters as connectors? probably overkill. Maybe centroid
    // the re-tesselation here happens because it's so easy for a user to
    // create parametrized polyhedrons that end up with 1-2 dimensional polygons.
    // These will create infinite loops at CSG.Tree()
  return fromPolygons(polygons).reTesselated()
}
function ( options ) { options = options || { } if ( ( 'points' in options ) !== ( 'faces' in options ) ) { throw new Error ( "polyhedron needs 'points' and 'faces' arrays" ) } let vertices = parseOptionAs3DVectorList ( options , 'points' , [ [ 1 , 1 , 0 ] , [ 1 , - 1 , 0 ] , [ - 1 , - 1 , 0 ] , [ - 1 , 1 , 0 ] , [ 0 , 0 , 1 ] ] ) . map ( function ( pt ) { return new Vertex3 ( pt ) } ) let faces = parseOption ( options , 'faces' , [ [ 0 , 1 , 4 ] , [ 1 , 2 , 4 ] , [ 2 , 3 , 4 ] , [ 3 , 0 , 4 ] , [ 1 , 0 , 3 ] , [ 2 , 1 , 3 ] ] ) // Openscad convention defines inward normals - so we have to invert here faces . forEach ( function ( face ) { face . reverse ( ) } ) let polygons = faces . map ( function ( face ) { return new Polygon3 ( face . map ( function ( idx ) { return vertices [ idx ] } ) ) } ) // TODO: facecenters as connectors? probably overkill. Maybe centroid // the re-tesselation here happens because it's so easy for a user to // create parametrized polyhedrons that end up with 1-2 dimensional polygons. // These will create infinite loops at CSG.Tree() return fromPolygons ( polygons ) . reTesselated ( ) }
it is defined twice ??? Create a polyhedron using Openscad style arguments. NON API !
Define face vertices clockwise looking from outside.
@param {Object} [options] - options for construction
@returns {CSG} new 3D solid
it is defined twice ??? Create a polyhedron using Openscad style arguments . NON API ! Define face vertices clockwise looking from outside .