简体   繁体   English

三个点中的可点击粒子PointCloud

[英]Clickable particles in three.js PointCloud

I am visualizing 3d data points (which I read in via a csv-file) with the help of three.js. 我在three.js的帮助下可视化3d数据点(我通过csv文件读入)。 I want to click on points in that PointCloud to show other measurement data for those specific points. 我想点击PointCloud中的点来显示这些特定点的其他测量数据。 According to examples I found this is possible apparently but I don't get it working. 根据实例我发现这显然是可能的,但我没有让它工作。 I have the following code (basically from those examples): 我有以下代码(基本上来自这些示例):

function onDocumentMouseMove(e) {       
    mouseVector.x = 2 * (e.clientX / containerWidth) - 1;
    mouseVector.y = 1 - 2 * (e.clientY / containerHeight);
    var vector = new THREE.Vector3(mouseVector.x, mouseVector.y, 0.5).unproject(camera);
    raycaster.ray.set(camera.position, vector.sub(camera.position).normalize());
    scene.updateMatrixWorld();
    intersects = raycaster.intersectObject(particles);
    console.log(intersects);
}

But intersects always is an empty array no matter which point I move over. 但是无论我移动到哪一点,相交总是一个空数组。

Regarding the particles Object I wrote the following: 关于粒子对象,我写了以下内容:

geometry = new THREE.Geometry();        

for (var i = 0; i < howmany; i++) {
    var vector = new THREE.Vector3(data[i][0], data[i][2], data[i][1] );
    geometry.vertices.push(vector);
}

attributes = {
     size: { type: 'f', value: [] },
     customColor: { type: 'c', value: [] }
};

uniforms = {
    color: { type: "c", value: new THREE.Color( 0xFFFFFF ) },
    texture: { type: "t", value: THREE.ImageUtils.loadTexture( "js/threejs/examples/textures/sprites/disc.png" ) }
};

var shaderMaterial = new THREE.ShaderMaterial( {
    uniforms: uniforms,
    attributes: attributes,
    vertexShader: document.getElementById( 'vertexshader' ).textContent,
    fragmentShader: document.getElementById( 'fragmentshader' ).textContent,
    alphaTest: 0.9,
} );

particles = new THREE.PointCloud( geometry, shaderMaterial );

for (var i = 0; i < howmany; i++) {
    colors[i] = new THREE.Color(RainBowColor(data[i][3], 4));
    sizes[i] = PARTICLE_SIZE * 0.5;
}
scene.add(particles);

where all the the variables are initialized previously, PARTICLE_SIZE is 20 and particles are about 10.000 in number with values between (0,0,0) and (10000,10000,10000). 其中所有变量都是先前初始化的,PARTICLE_SIZE为20,粒子数约为10.000,其值在(0,0,0)和(10000,10000,10000)之间。 For rotating and zooming I use THREE.OrbitControls. 对于旋转和缩放,我使用THREE.OrbitControls。

Does anyone see the mistake or is raycasting with particles not possible in this case? 在这种情况下,是否有人看到错误或使用粒子进行光线投射?

Many thanks, Mika. 非常感谢,米卡。

When using Raycaster with Points (formerly PointCloud ), you need to be aware that in the Raycaster constructor, 当使用Raycaster with Points (以前称为PointCloud )时,您需要注意在Raycaster构造函数中,

params.Points.threshold = 1

You may have to change that value, depending on the scale of your scene. 您可能需要更改该值,具体取决于场景的比例。 The units of threshold are in world units. threshold单位是世界单位。

Also, the click area will only be approximate, because the code does not take into consideration any transparency in Points.material.map . 此外,点击区域只是近似值,因为代码没有考虑Points.material.map任何透明度。

three.js r.72 three.js r.72

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM