【发布时间】:2015-08-17 01:26:23
【问题描述】:
我带着一个 GeoJSON :
(country.json -> https://github.com/johan/world.geo.json/blob/master/countries.geo.json)
在名为 data 的变量中包含全球坐标。然后我应用一个.mesh。我想将大纲添加到国家/地区的数字中,即放置一个新的 THREE.Line,但不是如何。我很困惑,因为我没有驱动太多 d3.js,然后不怎么驱动。非常感谢。
var countries = [];
var i, j;
// convert to threejs meshes
for (i = 0 ; i < data.features.length ; i++) {
var geoFeature = data.features[i];
var properties = geoFeature.properties;
var feature = path(geoFeature);
// we only need to convert it to a three.js path
var mesh = transformSVGPathExposed(feature);
// add to array
for (j = 0 ; j < mesh.length ; j++) {
countries.push({"data": properties, "mesh": mesh[j]});
}
}
// extrude paths and add color
for (i = 0 ; i < countries.length ; i++) {
// create material color based on average
var material = new THREE.MeshPhongMaterial({
color: "#000000",
opacity:0.5
});
console.log(mesh)
// extrude mesh
var shape3d = countries[i].mesh.extrude({
amount: 1,
bevelEnabled: false
});
// create a mesh based on material and extruded shape
var toAdd = new THREE.Mesh(shape3d, material);
//set name of mesh
toAdd.name = countries[i].data.name;
// rotate and position the elements
toAdd.rotation.x = Math.PI/2;
toAdd.translateX(-490);
toAdd.translateZ(50);
toAdd.translateY(20);
// add to scene
scene.add(toAdd);
}
我有地图上所有国家的数字,我放了轮廓,即在上面放一条线: http://postimg.org/image/3v9mc2jet/
我想要像示例中一样的轮廓线(新的三行..):
【问题讨论】:
-
你想要的是
EdgesHelper吗?见this post。 -
@WestLangley 不,我需要图形的轮廓(新的三行 ..)。黑线勾勒出各个国家的颜色如下图。postimg.org/image/qo5bqaon7
-
@WestLangley 在我的代码中我想知道如何添加坐标以生成每个国家/地区的线(新 THREE.Line ..)
-
每个国家都是单独的挤压形状吗?如果是,那么
EdgesHelper会做你想做的事。试试看。 -
如果您只想要图形前面的线条,则使用
geo = shape.createPointsGeometry(); var line = new THREE.Line( geo, material ); line.position.set( x, y, z );将线条添加为拉伸网格的子项。另见threejs.org/examples/webgl_geometry_extrude_shapes2.html。
标签: javascript d3.js three.js