I am trying to create country polygons and color them.
Successful at creating the polygons based on the border coordinates data that i have.
So now problem is with coloring this ‘INDIA’ polygon
The piece of code i used for generating the above images in the scene:
var shape = new window.THREE.Shape(points);
var colorLineGeometry = new window.THREE.ShapeBufferGeometry(shape);
countryMaterial = new window.THREE.MeshBasicMaterial({
color: 0x00ff00,
opacity: 1,
transparent: true
});
countryMesh = new window.THREE.Mesh(colorLineGeometry, countryMaterial);
So i understood internally buffer geometry triangulates to generate faces and color them. But the triangulation is making india geometry to shape out and coloring is not happening as expected.
Please, help me to finish this task
Do you mind sharing your code as a fiddle? https://jsfiddle.net/gzw7u9cv/
If this is a triangulation problem, it’s necessary to debug in order to find out what’s going wrong.
@Mugen87 you need the working example or just the code is fine??
@Mugen87 i cannot provide you any working example, as this the country border coordinates data is in json format…and couldnot load my json data file into jsfiddle
If you have JSON data, there is no need to load them into the fiddle. You can embed them as a simple JSON object.
A live example would be indeed more helpful than just code.
The below code generates the coloured india map:
‘points’ passed as an arguement to THREE.Shape is the array of Vector3’s which contains the polygon boundary coordinates.
var shape = new window.THREE.Shape(points);
var colorLineGeometry = new window.THREE.ShapeBufferGeometry(shape);
countryMaterial = new window.THREE.MeshBasicMaterial({
color: 0x00ff00,
opacity: 1,
transparent: true
});
countryMesh = new window.THREE.Mesh(colorLineGeometry, countryMaterial);
And i used ShapeBufferGeometry to create the india geometry, but when i create mesh for this geometry, the material.color of the geometry is not in sync with the geometry!
Sorry, this is not more informative than your first post. Please share a live example or your a GitHub repo with your code.
Somehow it reminded me about this:
Yeah I tried this and used earcut to generate the faces for the country geometry. But still the coloring is similar to the above shared image. I need to color the irregular geometries e.g. india map perfectly. Please help me out. Thanks in advance
@prisoner849 yes i have read it. and i tried earcut on a single poygon. The above shown image with india border is a single polygon.
Well, you’d better somehow break it in several polygons (if possible), and process each separately.
@prisoner849 yeah that will make the process static…and suppose if i could make this work for ‘india’ what about other countries? That would be time consuming sir
It starts from the point of where from and how you obtain the data for your polygons. Is it possible to get it already splitted into separate groups of points for polygons?
@prisoner849 @Mugen87 Is there is any function in three.js or any implemented algorithm to convert a concave polygon into convex subpolygons. If i could convert my concave polyogon into convex sets i could fix the issue. Thanks in advance.