• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

210
Vistas
Changing the way three.js projects a texture onto a halfsphere

I am currently trying to project an image onto the inside of a halfsphere in a three.js project. The half sphere is created via

const geometry = new THREE.SphereGeometry(Component.radius, this.resolution, this.resolution,
        Math.PI, Math.PI, 0, Math.PI);
this.material = new THREE.MeshStandardMaterial({color: 0xffffff});
this.material.side = THREE.DoubleSide;

this.sphere = new THREE.Mesh(geometry, this.material);

// The image of the texture is set later dynamically via 
// this.material.map = textureLoader.load(...); 

With radius and resolution being constants. This works fine, except for one issue: The image becomes distorted around the "top" and "bottom" of the sphere, like this: Simple example of distorted texture:

enter image description here

The texture originally had the value "0,0" in the bottom left and "0,1" in the bottom right, and with the camera facing down from the center of the demisphere the bottom left and bottom right corner are squished onto the "bottom" point of the sphere.

I want to change this behavior so the texture corners are instead on where they would be if you place the square texture into a sphere, with the corners touching the circle, then stretching the lines between the corners to match the circle. Simple mock of what i mean:

enter image description here

I have tried playing with the mapping Attribute of my texture, but that doesn't change the behaviour from my understanding.

about 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

After changing the UV coordinates, my half sphere texture is't stretching on border as well:

Texture issue visualised

this.sphereGeometry = new THREE.SphereGeometry(
  10,
  32,
  24,
  0,
  Math.PI,
  0,
  Math.PI
);

const {
  uv: uvAttribute,
  normal
} = this.sphereGeometry.attributes;

for (let i = 0; i < normal.count; i += 1) {
  let u = normal.getX(i);
  let v = normal.getY(i);

  u = u / 2 + 0.5;
  v = v / 2 + 0.5;

  uvAttribute.setXY(i, u, v);
}

const texture = new THREE.TextureLoader().load(
  'https://i.imgur.com/CslEXIS.jpg'
);

texture.flipY = false;
texture.mapping = THREE.CubeUVRefractionMapping;
texture.needsUpdate = true;

const basicMaterial = new THREE.MeshBasicMaterial({
  map: texture,
  side: THREE.DoubleSide,
});

this.sphere = new THREE.Mesh(this.sphereGeometry, basicMaterial);
this.scene.add(this.sphere);
about 3 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda