Treant Posted November 23, 2016 Share Posted November 23, 2016 Hi, I want to create city map with 3D buildings. I have GeoJSON with building data. I'm using this data to make 2D polygonal mesh (building shape). http://www.babylonjs-playground.com/#10IOII#14 (I've used example values) Is there way to add 3'rd dimension to it? I want to use my 2D mesh as base for 3D Object. Is it possible to store this 3D object as Vector3? I want to map all verticles and keep them around for future use. (I'm starting with babylon.js, i don't know is this proper way to do it.) { "type":"FeatureCollection", "features":[ { "id":"w26358613", "properties":{ "levels":8 }, "geometry":{ "type":"Polygon", "coordinates":[ [ [ 13.426143, 52.51832 ], [ 13.426195, 52.518392 ], [ 13.426155, 52.518423 ], [ 13.426192, 52.518479 ], [ 13.426252, 52.518476 ], [ 13.426296, 52.51854 ], [ 13.426473, 52.518496 ], [ 13.426319, 52.518275 ], [ 13.426143, 52.51832 ] ] ] }, "type":"Feature" } ] } Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 24, 2016 Share Posted November 24, 2016 Hi @Treant, welcome to the forum. What you speak-of is a bit over my head, but maybe this playground demo would help. Extrusion, breakfast of champions. Maybe others will comment. I'm not overly experienced with these things. Again, welcome. I'll be nearby. Quote Link to comment Share on other sites More sharing options...
Klaas Posted November 25, 2016 Share Posted November 25, 2016 Hi, maybe you are searching for a way to extrude 2d shapes into 3d objects. Have a look here:http://doc.babylonjs.com/tutorials/Parametric_Shapes#extrusion and here http://doc.babylonjs.com/classes/2.4/Mesh#static-extrudeshape-name-shape-path-scale-rotation-cap-scene-updatable-sideorientation-instance-rarr-mesh-classes-2-4-mesh- Quote Link to comment Share on other sites More sharing options...
Treant Posted December 2, 2016 Author Share Posted December 2, 2016 I will give you guys update on this. I managed to parse geoJSON data and made Vector3 shapes out of it. (pic 1) Then I extruded building shapes: All i need now is outline like in pic related: From what I read you can't use renderOutline() method on extruded shapes. I've seen this demo http://www.babylonjs-playground.com/#E51MJ#11 as an example of outline, but i can't apply it to my extruded shapes. Should I construct my 3D mesh in some other way? I only have Vector3 outlines of buildings. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 2, 2016 Share Posted December 2, 2016 I see no reason why renderOutline shoud not work on your mesh. You can also think about using a more advanced option: highlights: http://www.babylonjs-playground.com/#1KUJ0A#0 (http://doc.babylonjs.com/tutorials/Highlight_Layer) Quote Link to comment Share on other sites More sharing options...
Treant Posted December 4, 2016 Author Share Posted December 4, 2016 Sorry for noobish questions. My renderOutine is not displaying properly when mesh's material is transparent.Example: http://www.babylonjs-playground.com/#ULLTW#3 It also has these weird corners: Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 5, 2016 Share Posted December 5, 2016 The outline is done by scaling meshes but they need to have their pivot at their center I would highly recommend using highlights instead in your case Quote Link to comment Share on other sites More sharing options...
Nabroski Posted December 17, 2016 Share Posted December 17, 2016 @Treant i found something interessting trough experimenting. maybe its usefull. i leave it herehttp://www.babylonjs-playground.com/#ULLTW#5 Quote Link to comment Share on other sites More sharing options...
TimT77 Posted July 25, 2018 Share Posted July 25, 2018 On 12/2/2016 at 9:25 AM, Treant said: I will give you guys update on this. I managed to parse geoJSON data and made Vector3 shapes out of it. (pic 1) Hey Treant! Could you explain me how did you "convert" the geoJSON data into Vector3? Thx in advance! Tim Quote Link to comment Share on other sites More sharing options...
pichou Posted October 14, 2018 Share Posted October 14, 2018 Most of the time geoJSON are made of latitude/longitude coordinates which you can easily translate to babylonJS Vector3 with this function : let getVectorFromLatlng = (lat:number, lng:number, radius) => { var phi = (90-lat)*(Math.PI/180), theta = (lng+180)*(Math.PI/180), x = (radius) * Math.sin(phi)*Math.cos(theta), z = (radius) * Math.sin(phi)*Math.sin(theta), y = (radius) * Math.cos(phi); return new BABYLON.Vector3(x/3, y/3, z/3); } Lokamidou 1 Quote Link to comment Share on other sites More sharing options...
Lokamidou Posted January 29, 2019 Share Posted January 29, 2019 On 10/14/2018 at 3:30 PM, pichou said: Most of the time geoJSON are made of latitude/longitude coordinates which you can easily translate to babylonJS Vector3 with this function : let getVectorFromLatlng = (lat:number, lng:number, radius) => { var phi = (90-lat)*(Math.PI/180), theta = (lng+180)*(Math.PI/180), x = (radius) * Math.sin(phi)*Math.cos(theta), z = (radius) * Math.sin(phi)*Math.sin(theta), y = (radius) * Math.cos(phi); return new BABYLON.Vector3(x/3, y/3, z/3); } Hey could you advise me how to load and render a geojson data file (this one for example https://a.data.osmbuildings.org/0.2/anonymous/tile/16/35210/21492.json ) Quote Link to comment Share on other sites More sharing options...
pichou Posted January 30, 2019 Share Posted January 30, 2019 Here is the functions I created to draw world border lines from a geojson file around a 3D sphere in https://wazana.io : addWorldLines () { $.getJSON("yougeojsonfileurl", (data) => { let features = data.features; for (let i = 0; i < features.length; i++) { let geo = features[ i ].geometry; let coord = geo.coordinates; if (geo.type == 'Polygon') { this.buildLine(coord); } else { for (let j = 0; j < coord.length; j++) { this.buildLine(coord[j]); } } } this.setStyle(); }); } worldLines = []; buildLine (coord:Array<any>) { let gradient = BABYLON.Color3.FromHexString(Colors.gradient); for (let i = 0; i < coord.length; i++) { let poly = coord; let babylonGeo = []; for (let i = 0; i < poly.length; i++) { let pos =this. getVectorFromLatlng(poly[1], poly[0], this.radius); babylonGeo.push(pos); } let line = BABYLON.Mesh.CreateLines('sbline'+i, babylonGeo, this.scene); line.parent = this.sphere; line.isPickable = false; line.color = gradient; this.worldLines.push(line); } } Lokamidou 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.