Skip to content

deyihu/poly-extrude

Repository files navigation

poly-extrude

Extrude polygons/polylines. Born in maptalks.three project

Examples












Install

NPM

npm i poly-extrude

CDN

<script type="text/javascript" src="https://unpkg.com/poly-extrude/dist/poly-extrude.js"></script>

Use

  import {
      extrudePolygons,
      extrudePolylines,
      cylinder,
      expandPaths,
      extrudeSlopes,
      expandTubes,
      plane
  } from 'poly-extrude';

  //if you use cdn,the namespace is polyextrude

  //   const {
  //       extrudePolygons,
  //       extrudePolylines
  //   } = window.polyextrude;

  const polygons = [
      //polygon
      [
          //outring
          [
              [x, y],
              [x, y],
              ...........
          ],
          //holes
          [
              [x, y],
              [x, y], ...........
          ],
          ........

      ],
      //other polygons
      ......
  ];

  const polylines = [
      // polyline
      [
          [x, y],
          [x, y],
          ...........
      ],
      //polyline
      [
          [x, y],
          [x, y],
          ...........
      ],
  ];

  const result = extrudePolygons(polygons, {
      depth: 2
  });
  const {
      positon,
      normal,
      uv,
      indices
  } = result;
  //do something

API

extrudePolygons(polygons, options)

  • polygons
  • options.depth
  • options.top Whether to display the top
  const result = extrudePolygons(polygons, {
      depth: 2
  });
  const {
      positon,
      normal,
      uv,
      indices
  } = result;
  //do something

extrudePolylines(lines, options)

  • lines
  • options.depth
  • options.lineWidth
  • options.bottomStickGround Is the bottom attached to the ground
  • options.pathUV generate Path UV

extrudePolylines pathUV demo

   const result = extrudePolylines(polylines, {
       depth: 2,
       lineWidth: 2
   });
   const {
       positon,
       normal,
       uv,
       indices
   } = result;
   //do something

cylinder(center, options)

  • center
  • options.radius
  • options.height
  • options.radialSegments
const center = [0, 0];
const result = cylinder(center, {

    radius: 1,
    height: 2,
    radialSegments: 6

});
const {
    positon,
    normal,
    uv,
    indices

} = result;
//do something

expandPaths(lines, options)

  • lines
  • options.lineWidth
const result = expandPaths(polylines, {

    cornerRadius: 0.5,
    lineWidth: 2

});
const {

    positon,
    normal,
    uv,
    indices

} = result;
//do something

extrudeSlopes(lines, options)

  • lines
  • options.depth
  • options.lineWidth
  • options.side Which side serves as the slope, 'left' or 'right'
  • options.sideDepth slope depth
  • options.bottomStickGround Is the bottom attached to the ground
  • options.pathUV generate Path UV

extrudeSlopes pathUV demo

const result = extrudeSlopes(polylines, {

    depth: 1,
    side: 'left',
    sideDepth: 0,
    lineWidth: 2

});
const {

    positon,
    normal,
    uv,
    indices

} = result;
//do something

expandTubes(lines, options)

  • lines
  • options.radius
  • options.radialSegments
const result = expandTubes(polylines, {

    radius: 1,
    radialSegments: 8

});
const {

    positon,
    normal,
    uv,
    indices

} = result;
//do something

plane(width, height,devideW,devideH)

  • width
  • height
  • devideW
  • devideH

plane demo
custom terrain demo

const result = plane(100, 100, 10, 10);
const {

    positon,
    normal,
    uv,
    indices

} = result;
//do something