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

192
Visualizações
Three.js different texture on each side

This is my cube with texture:

const textureLoader: TextureLoader = new TextureLoader();
const textureArray: MeshBasicMaterial[] = [
  new MeshBasicMaterial({ map: textureLoader.load("./model/front.jpeg") }),
  new MeshBasicMaterial({ map: textureLoader.load("./model/back.jpeg") }),
  new MeshBasicMaterial({ map: textureLoader.load("./model/top.jpeg") }),
  new MeshBasicMaterial({ map: textureLoader.load("./model/bottom.jpeg") }),
  new MeshBasicMaterial({ map: textureLoader.load("./model/left.jpeg") }),
  new MeshBasicMaterial({ map: textureLoader.load("./model/right.jpeg") }),
];

textureArray.forEach((_, index) => {
  textureArray[index].side = BackSide;
});

const cubeGeometry: BoxGeometry = new BoxGeometry(5, 5, 5);
const cube: Mesh = new Mesh(cubeGeometry, textureArray);
scene.add(cube);

I got no errors and the screen is black. what's wrong?

My bundler is parcel

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

0

Try it like so:

let camera, scene, renderer;
let mesh;

init();
animate();

function init() {

  camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.01, 10);
  camera.position.z = 4;

  scene = new THREE.Scene();

  const textureLoader = new THREE.TextureLoader().setPath('https://threejs.org/examples/textures/cube/Bridge2/');
  const materials = [
    new THREE.MeshBasicMaterial({
      map: textureLoader.load("negx.jpg")
    }),
    new THREE.MeshBasicMaterial({
      map: textureLoader.load("negy.jpg")
    }),
    new THREE.MeshBasicMaterial({
      map: textureLoader.load("negz.jpg")
    }),
    new THREE.MeshBasicMaterial({
      map: textureLoader.load("posx.jpg")
    }),
    new THREE.MeshBasicMaterial({
      map: textureLoader.load("posy.jpg")
    }),
    new THREE.MeshBasicMaterial({
      map: textureLoader.load("posz.jpg")
    }),
  ];

  materials.forEach((_, index) => {
    materials[index].side = THREE.BackSide;
  });

  const cubeGeometry = new THREE.BoxGeometry();
  mesh = new THREE.Mesh(cubeGeometry, materials);
  scene.add(mesh);

  //

  renderer = new THREE.WebGLRenderer({
    antialias: true
  });
  renderer.setSize(window.innerWidth, window.innerHeight);
  document.body.appendChild(renderer.domElement);

}

function animate() {

  requestAnimationFrame(animate);

  mesh.rotation.x += 0.01;
  mesh.rotation.y += 0.02;

  renderer.render(scene, camera);

}
body {
      margin: 0;
}
<script src="https://cdn.jsdelivr.net/npm/three@0.139.2/build/three.min.js"></script>

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