Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

354
Views
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 4 years ago · Juan Pablo Isaza
1 answers
Answer question

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 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!