Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

367
Visualizações
How to project only part of a texture to a face threejs?

I want to make portals with threejs by drawing an ellipse and then texture mapping a WebGlRenderTarget to its face. I have that function sort of working, but it tries to stretch the large rectangular buffer from the render target to the ellipse. What I want is to project the texture in its original dimensions onto the ellipse and just cut out anything that doesn't hit the ellipse like so:

Before Projection:

After projection:

enter image description here

How can this be done with threejs? I've looked into texture coordinates, but don't understand how to use them, and even saw a projection light PR in threejs that might work?

Edit: I also watched a Sebastian Lague video on portals and saw he does this with “screen space coordinates”. Any advice on using those?

Thanks for your help!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Made a codepen available here:
https://codepen.io/cdeep/pen/JjyjOqY

UV mapping lets us specify which parts of the texture correspond to which vertices of the geometry. More details here: https://www.spiria.com/en/blog/desktop-software/understanding-uv-mapping-and-textures/

You could loop through the vertices and set the corresponding UV value.

const vertices = ellipseGeometry.attributes.position.array;
for(let i = 0; i < numPoints; i++) {
  const [x, y] = [vertices[3*i], vertices[3*i + 1]];
  uvPositions.push(0.5 + x * imageHeight / ((2 * yRadius) * imageWidth));
  uvPositions.push(0.5 + y / (2 * yRadius));
}
ellipseGeometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvPositions, 2 ));

UV coordinates increase from (0, 0) to (1, 1) from bottom left to top right. The above code works because the ellipse is on the x-y plane. Or else, you'll need to get the x,y values in the plane of the ellipse.

More info on texture mapping in three.js here:
https://discoverthreejs.com/book/first-steps/textures-intro/

Edit: Do note that the demo doesn't really look like a portal. For that, you'll need to move the texture based on the camera view which isn't that simple

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda