# PointCloud intersection raycasting problem

**URL:** <https://discourse.threejs.org/t/pointcloud-intersection-raycasting-problem/8765>\
**Category:** Questions\
**Tags:** points, raycaster\
**Created:** [July 30, 2019, 8:43am UTC](https://discourse.threejs.org/t/pointcloud-intersection-raycasting-problem/8765 "2019-07-30T08:43:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lelouedec](https://avatars.discourse-cdn.com/v4/letter/l/aca169/32.png) [@lelouedec](https://discourse.threejs.org/u/lelouedec)\
**Post date:** [July 30, 2019, 8:43am UTC](https://discourse.threejs.org/t/pointcloud-intersection-raycasting-problem/8765/1 "2019-07-30T08:43:28Z")

</div>

Good morning,  
I am trying to paint over a pointcloud, so I used the PCD loader provided in examples and I am returning a Point object.  
I am following the tutorial to get the intersection with the raycast on the point cloud and display the red sphere there which is fine. However the sphere is always a bit before the points and if I try to use the intersections of the rays with the pointcloud and set the closest ones to the color black using their indices, always half of my point cloud on the same size becomes black but never the points close to where the mouse is.  
I do the intersection as follow:

> raycaster.setFromCamera( mouse, camera );
> 
> ```
> if(pointcloud != null){
> intersects = raycaster.intersectObject(pointcloud);
> intersection = ( intersects.length ) > 0 ? intersects[0] : null;
> if(PAINTING){
> console.log("painting");
> var geometry = pointcloud.geometry;
> var attributes = geometry.attributes;
> // console.log(attributes);
> if ( intersects.length > 0 ) {
> attributes.color.array[intersection.index] = 0.0;
> attributes.color.array[intersection.index+1] = 0.0;
> attributes.color.array[intersection.index+2] = 0.0;
> attributes.color.needsUpdate = true;
> }
> }
> }
> 
> ```

And here what I get after trying to paint points on the right of the strawberry and bottom:

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/2X/3/3404c37cf7a34e01cd02c896c1796ebe466d07be.jpeg)  
Any idea ?

---

<div class="post-metadata">

**Author:** ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)\
**Post date:** [July 30, 2019, 9:05am UTC](https://discourse.threejs.org/t/pointcloud-intersection-raycasting-problem/8765/2 "2019-07-30T09:05:07Z")

</div>

Hi!  
Any chance to provide a working live code example?

---

<div class="post-metadata">

**Author:** ![lelouedec](https://avatars.discourse-cdn.com/v4/letter/l/aca169/32.png) [@lelouedec](https://discourse.threejs.org/u/lelouedec)\
**Post date:** [July 30, 2019, 9:15am UTC](https://discourse.threejs.org/t/pointcloud-intersection-raycasting-problem/8765/3 "2019-07-30T09:15:31Z")

</div>

As I am importing quite a few three js files and the point cloud, I uploaded an archive with the code.  
The html file is in examples/Annotation.html

> **[annotation\_js.zip](https://www.dropbox.com/s/ls4arvqb8c7v6s8/annotation_js.zip?dl=0)**
>
> Shared with Dropbox
