Why is my decal stretched and deformed on some surfaces of the model?

Hello, everyone! The following is an example

As shown in the picture above.The decal of the coffee logo is intact on some surfaces. However, on some surfaces (such as the top surface), deformation or stretching may occur.

The following is my code:

 const handlePointerDown = (event) => {
    
    const { x, y } = event;
    mouse.x = (x / gl.domElement.clientWidth) * 2 - 1;
    mouse.y = -(y / gl.domElement.clientHeight) * 2 + 1;

    
    raycaster.setFromCamera(mouse, camera);
    const intersects = raycaster.intersectObject(nodes.Main, true);

    //create a decal
    if (intersects.length > 0) {
      const intersection = intersects[0];
      console.log('3D World Coordinates:', intersection.point);

      // texture.colorSpace = THREE.SRGBColorSpace
      const decalPosition = intersection.point;
      const decalOrientation = new Vector3(0, 0, 0);
      const decalSize = new Vector3(0.2, 0.2, 0.2);
      const geometry = new DecalGeometry(nodes.Main, decalPosition, decalOrientation, decalSize)

      // const material = new THREE.MeshBasicMaterial({ map: texture });
      const material = new THREE.MeshPhongMaterial({
        map: texture,
        transparent: true,
        shininess: 30,
        depthTest: true,
        depthWrite: false, 
        polygonOffset: true,
        polygonOffsetFactor: - 4,
        wireframe: false,
      });
      applyProps(materials, { needsUpdate: true })
      
      const mesh = new THREE.Mesh(geometry, material);
      mesh.updateMatrix();
      scene.add(mesh)

      // setIntersections([...intersections, intersection.point]);
    }
  };

Thank you very much

Decals are not wrapped along the object surface like a paper sticker. Decals act like torches that project light. When they are perpendicular to the surface, the shape looks proportional. When they are applied to slanting surfaces, the shape is stretched.

2 Likes

@BOON_DRAGON You’re not calculating the decalOrientation.

Ctrl-F decalOrientation in this sample to see how they handle it:

Sorry, I only saw the answer now. I have solved it! Thank you!

1 Like