gpt4 book ai didi

javascript - 将 d3.js 与 THREE.js earth 同步

转载 作者:行者123 更新时间:2023-11-29 15:25:36 25 4
gpt4 key购买 nike

我正在尝试将 WebGL earth 与 d3.geo.satellite 投影相结合。

我已经设法将 2 个投影相互叠加并同步旋转,但我无法同步缩放。当我同步它们以匹配大小时,WebGL 投影会变形,但 d3.geo.satellite 保持不变。我尝试了 projection.scale、projection.distance 的不同组合,但没有成功。

这是 JS fiddle(加载资源需要一点时间)。您可以拖动它进行旋转(效果很好)。但如果你放大(使用鼠标滚轮),你就会看到问题。

https://jsfiddle.net/nxtwrld/7x7dLj4n/2/

重要的代码在脚本的底部——缩放函数。

function scale(){
var scale = d3.event.scale;
var ratio = scale/scale0;

// scale projection
projection.scale(scale);

// scale Three.js earth
earth.scale.x = earth.scale.y = earth.scale.z = ratio;
}

最佳答案

我也不使用 WebGL earth,检查你的 jsfiddle 不再工作,我假设你的问题是你想将 D3.js 与 Threejs 集成作为 3d globe 的解决方案。

我可以建议你试试earthjs作为您的解决方案。在引擎盖下它使用 D3.js v4 和 Threejs 修订版 8x 都是最新的,它可以在 Svg、canvas 和 threejs(WebGL) 之间结合。

    const g = earthjs({padding:60})
.register(earthjs.plugins.mousePlugin())
.register(earthjs.plugins.threejsPlugin())
.register(earthjs.plugins.autorotatePlugin())
.register(earthjs.plugins.dropShadowSvg(),'dropshadow')
.register(earthjs.plugins.worldSvg('../d/world-110m.json'))
.register(earthjs.plugins.globeThreejs('../globe/world.jpg'))
g._.options.showLakes = false;
g.ready(function(){
g.create();
})

上面的代码片段你可以从 here 运行它.

关于javascript - 将 d3.js 与 THREE.js earth 同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39434107/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com