我是 Three.js 的新手,我找到了一些关于该主题的答案,但没有一个使用缓冲区几何形状。我正在 React 上制作欧洲的 3D 地形项目,我希望能够根据某些值更改水位。为了做到这一点,我的着色必须逐个顶点完成,而不是从图像中添加纹理,如果我更改顶点的值,着色将不会改变。因此,根据顶点的“高度”,我想分配不同的颜色。
这是我的 componentDidMount 函数:
const SIZE_AMPLIFIER = 15;
var container = document.getElementById("main_map");
var scene, camera, renderer, controls;
var data, plane;
//load map data from bin file
function loadTerrain(file) {
var xhr = new XMLHttpRequest();
xhr.responseType = 'arraybuffer';
xhr.open('GET', file, true);
xhr.onload = function (evt) {
if (xhr.response) {
data = new Uint16Array(xhr.response)
init()
}
};
xhr.send(null);
}
loadTerrain('stats.bin');
function init() {
// initialize camera
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, .1, 100000);
camera.position.set(10000, …Run Code Online (Sandbox Code Playgroud)