Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

three.js draw geojson #125

Closed
skypan opened this issue Dec 4, 2020 · 5 comments
Closed

three.js draw geojson #125

skypan opened this issue Dec 4, 2020 · 5 comments
Assignees
Labels
❓ question Further information is requested 🏃 example
Milestone

Comments

@skypan
Copy link

skypan commented Dec 4, 2020

Can the examples provides : draw buildings and loads with three.js and geojson, so that i can draw then with threejs's ability

i try to draw then by the ExtrudeBufferGeometry, but the result is bad , my code is

` addBuildings(data, info, height) {
height = height ? height : 1;

for (let i = 0; i < data.length; i++) {
  let el = data[i];

  // 二维的点
  let shape = this.genShape(el);
  let geometry = this.genGeometry(shape, {
    curveSegments: 1,
    depth:  0.5 * height,
    bevelEnabled: false,
  });
  let mesh = new THREE.Mesh(geometry, this.meshMaterial);
  
  let coords = getCenter(el);
  let cube = tb.Object3D({ obj: mesh}).setCoords([coords.longitude, coords.latitude, 1]);
  this.buildings.push(cube);
}

}

genShape(points) {
let shape = new THREE.Shape();

for (let i = 0; i < points.length; i++) {
  let elp = points[i];
  let pos = tb.projectToWorld([elp[0], elp[1], 0]);
  if (i == 0) {
    shape.moveTo(-pos.x, pos.y);
  } else {
    shape.lineTo(-pos.x, pos.y);
  }
}

return shape;

}

genGeometry(shape, settings) {
// 2d 拉伸到 3d
let geometry = new THREE.ExtrudeBufferGeometry(shape, settings);
geometry.computeBoundingBox();
return geometry;
}`

now the way of draw buildings is that mapbox's fill-extrusion, but i can not add the special effects, such as Sweep light

@jscastro76
Copy link
Owner

Can you share 1 or 2 items from your geoJson file?

@jscastro76 jscastro76 added ❓ question Further information is requested 🏃 example labels Dec 4, 2020
@jscastro76 jscastro76 self-assigned this Dec 4, 2020
@jscastro76 jscastro76 added this to the v.2.1.2. milestone Dec 4, 2020
@jscastro76
Copy link
Owner

jscastro76 commented Dec 4, 2020

Hi @skypan, I found what’s the problem you’re having... the buildings shake, aren’t they?
That’s an well known issue from Mapbox with the precision of long decimal numbers. I’m preparing an example on how to create Threebox extrusions with a geoJson standard file with solid buildings and not shaking at all. I’ll be back to you when it’s ready.

jscastro76 added a commit that referenced this issue Dec 4, 2020
… standard geoJson #127 Added a new example [17-extrusions.html](https://github.com/jscastro76/threebox/blob/master/examples/17-extrusions.html)

- [#126](#126) add options.rotate and options.scale for Objects3D #126
- [#125](#125) three.js draw geojson #125
@jscastro76
Copy link
Owner

I have uploaded a new example with extrusions read from a geojson file with real complex features from the composite layer. I have created a new method tb.extrusion to demonstrate it's functionality in 2 ways, one passing an array of THREE.Vector(2) objects, and the other one reading from the geoJson. The result is very cool... Thanks for the question, it pushed me to create extrusions that it was a pending task.
image

jscastro76 added a commit that referenced this issue Dec 6, 2020
- add options.rotate and options.scale for Objects3D #126
- Create a new example with Three.js extrusions based on standard geoJson #127 Added a new example [17-extrusions.html](https://github.com/jscastro76/threebox/blob/master/examples/17-extrusions.html)
- Convert internal variables (`selectedObject`, `draggedObject`, ...) into instance variables #130
- Deprecate `tb.setLayerZoomVisibility`, overlaps with `tb.toggleLayer` #134
- when an object is wireframed, all its clones are too #124
- Error when wireframing all the objects #131
- While dragging an object if mouse overs a label it stops dragging #132
- A layer shouldn't be shown explicitely if it's not in the right zoom range #133
@skypan
Copy link
Author

skypan commented Dec 7, 2020

@jscastro76 thanks your anwser, I try it and it works good, before that my local's case is shake indeed,after that I will try it with the shadermaterial and show the special effects

@jscastro76
Copy link
Owner

@jscastro76 thanks your anwser, I try it and it works good, before that my local's case is shake indeed,after that I will try it with the shadermaterial and show the special effects

@skypan glad to hear it worked well in your scenario. Don’t forget to share the result when you add the shader and those effects, I’d love to see it!

jscastro76 added a commit that referenced this issue Dec 9, 2020
Minor version by [@jscastro76](https://github.com/jscastro76), some enhancements and bugs.

#### ✨ Enhancements

- #125 three.js draw geojson.
- #126 add options.rotate and options.scale for Objects3D.
- #127 Create a new example with Three.js extrusions based on standard geoJson. Added a new example [17-extrusions.html](https://github.com/jscastro76/threebox/blob/master/examples/17-extrusions.html)
- #130 Convert internal variables (`selectedObject`, `draggedObject`, ...) into instance variables .
- #134 Deprecate `tb.setLayerZoomVisibility`, overlaps with `tb.toggleLayer`.
- #138 expose `SunCalc.toJulian`

#### 🪲 Bug fixes

- #124 when an object is wireframed, all its clones are too.
- #131 Error when wireframing all the objects.
- #132 While dragging an object if mouse overs a label it stops dragging.
- #133 A layer shouldn't be shown explicitely if it's not in the right zoom range.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓ question Further information is requested 🏃 example
Projects
None yet
Development

No branches or pull requests

2 participants