Code Monkey home page Code Monkey logo

three-conic-polygon-geometry's Introduction

ThreeJS Conic Polygon Geometry

NPM package Build Size NPM Downloads

A ThreeJS geometry class for drawing polygons on a sphere using cones.

Examples:

Quick start

import { ConicPolygonGeometry } from 'three-conic-polygon-geometry';

or using a script tag

<script src="//unpkg.com/three-conic-polygon-geometry"></script>

then

const myMesh = new THREE.Mesh(
  new THREE.ConicPolygonGeometry(polygonGeoJson),
  new THREE.MeshBasicMaterial({ color: 'blue' })
);

API reference

Constructor

ConicPolygonGeometry(polygonGeoJson: GeoJson polygon coordinates, bottomHeight: Float, topHeight: Float, closedBottom: Boolean, closedTop: Boolean, includeSides: Boolean, curvatureResolution: Float)

  • polygonGeoJson: Coordinates array as specified in GeoJson geometry.coordinates for type: Polygon. The first item is the polygon contour, additional items are the inner holes. It's recommended to split the geometries at the anti-meridian.
  • bottomHeight: Starting height of the cone. Default is 0.
  • topHeight: Ending height of the cone. Default is 1.
  • closedBottom: Whether to add a cap surface on the cone bottom. Default is true.
  • closedTop: Whether to add a cap surface on the cone top. Default is true.
  • includeSides: Whether to include the side surfaces of the cone. Default is true.
  • curvatureResolution: The resolution in angular degrees of the sphere curvature. The finer the resolution, the more the polygon is fragmented into smaller faces to approximate the spheric surface, at the cost of performance. Default is 5.

Properties

.parameters: Object

An object with a property for each of the constructor parameters. Any modification after instantiation does not change the geometry.

Groups

The geometry supports three distinct groups to which different materials can be applied.

  • 0: The side surface of the cone.
  • 1: The bottom surface of the cone.
  • 2: The top surface of the cone.

three-conic-polygon-geometry's People

Contributors

ptgreg avatar vasturiano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

three-conic-polygon-geometry's Issues

Error when creating a Hexagon in React-three globe

I'm experiencing this bug a couple repos up from here, but I'm pretty sure its a bug since the other repos just call this one.

I'm getting this GEOJSON feature from uber's h3ToGeoJson function.
when I plug it into geojson.io it appears normally.
however when I put it on the globe it renders the polygon feature as everything except the hexagon.
image

{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "id": "8159bffffffffff",
            "properties": {},
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -4.866872026589571,
                            15.219885219398503
                        ],
                        [
                            -4.01399844347046,
                            11.545295975414758
                        ],
                        [
                            -4.01399844347047,
                            11.545295975414751
                        ],
                        [
                            -0.3191827268566136,
                            9.731836670975918
                        ],
                        [
                            2.888107601500233,
                            11.881770859938978
                        ],
                        [
                            2.302842809205857,
                            16.098688642959498
                        ],
                        [
                            -1.711309903977913,
                            17.93540458181741
                        ],
                        [
                            -3.2925648296836454,
                            16.71898040589194
                        ],
                        [
                            -4.866872026589571,
                            15.219885219398503
                        ]
                    ]
                ]
            },
            "__id": "755664730"
        }
    ]
}

Let me know if there is a fix I can do to transform the hexagon, or a setting in the three conic polygon geometry to fix this

[Feature request] change of spheric resolution or bend polygon around sphere

The conic-polygon-geometry only uses border coords, it works fine for small regions. But for big regions, it makes large flat areas which will be blocked by the sphere surface:

with 0 altitude, only borders are visible for most regions
Screen Shot 2020-07-15 at 20 18 06
with 0.1 altitude, more visible regions, but still holes for big countries
Screen Shot 2020-07-15 at 20 18 48

The idea would be adding vertices in the middle of regions, especially for big regions, then bend around the globe, finally something like:

It will be very nice if the vertices/triangulated map can be done automatically!

Inaccurate Polygons

Hello there,

Many thanks for making this awesome package!

I have noticed that some country polygons from the Natural Earth data don't render correctly. This can be seen by removing the wireframe: true from this line in the Countries example and rotating/zooming to Iceland:

image

You can see that the triangles aren't correct. Now, I notice that raising the curvatureResolution parameter in the THREE.ConicPolygonGeometry constructor to 5 seems to fix that:

image

But this breaks other country polygons, such as the nearby Greenland.

Is it possible to configure the ConicPolygonGeometry to get the polygons perfect?

Cheers

Seb

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.