【问题标题】:contour figure working with d3.js and Three.js使用 d3.js 和 Three.js 的轮廓图
【发布时间】: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/

我想要像示例中一样的轮廓线(新的三行..):

http://postimg.org/image/qo5bqaon7/

【问题讨论】:

  • 你想要的是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


【解决方案1】:

如果你有一个THREE.Shape,并且你想创建一个大纲,那么要遵循的模式是这样的:

var material = new THREE.LineBasicMaterial( { color: 0xffffff, linewidth: 2 } );

var geometry = shape.createPointsGeometry();

var line = new THREE.Line( geometry, material );

line.position.set( x, y, z );

scene.add( line );

如果您正在渲染形状和轮廓,如果您设置renderOrder 以便最后渲染线条,这可能会更好看:

line.renderOrder = 2; // the default renderOrder for all objects is 0

在当前版本的three.js中,如果形状有孔,这将无法正常工作。

three.js r.71

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-19
    • 2014-11-21
    • 2021-07-20
    • 2022-01-19
    • 1970-01-01
    • 2021-01-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多