Wrong normal with raycaster

Hi guys.
I want to get position and normal through raycaster. It works fine when the box was not rotated.

QQ%E5%9B%BE%E7%89%8720181226223417
When the box was rotated, raycaster get wrong normals.
QQ%E5%9B%BE%E7%89%8720181226223440
How can I fixed this?!

Hi!
Could you provide the code of what and how you do with raycaster and given normal?

function onMouseDown(event) {
            mouse.x = (event.clientX / renderer.domElement.clientWidth) * 2 - 1;
            mouse.y = - (event.clientY / renderer.domElement.clientHeight) * 2 + 1;
            raycaster.setFromCamera(mouse, camera);
            // See if the ray from the camera into the world hits one of our meshes
            var intersects = raycaster.intersectObjects(objectList);
            // Toggle rotation bool for meshes that we clicked
            if (intersects.length > 0) {
                helper.position.set(0, 0, 0);
                helper.lookAt(intersects[0].face.normal);
                helper.position.copy(intersects[0].point);
            }
        }

I use transformControls to rotate the box

        transformControl = new THREE.TransformControls(camera, renderer.domElement);
        transformControl.addEventListener('change', render);
        transformControl.addEventListener('dragging-changed', function (event) {
            orbitControl.enabled = !event.value;
        });
        renderScene.add(transformControl);

Have a look at this example:
https://threejs.org/examples/?q=decals#webgl_decals
and its source code:

1 Like

A working example, based on the example with decals:

1 Like

thank you all ! It works:grin:

You’re welcome :slight_smile: :beers: