Search code examples
aframe

Aframe Image with Depth one side only


I want to show an image with a frame. Using <a-image> gives me a plane with the image. <a-box src="path/to/img.jpg> however gives me the image but it's giving me the image 6 times. Is it possible to get the box with am image at the front and any color at all other sides?


Solution

  • I don't know if you can do this with Aframe (I don't think so), but you can do it with Threejs, by making an array of materials that contain a material for each box face, and applying that to the box mesh.

    const loadManager = new THREE.LoadingManager();
    const loader = new THREE.TextureLoader(loadManager);
    
    const materials = [
      new THREE.MeshBasicMaterial({map: loader.load('resources/images/flower-1.jpg')}),
      new THREE.MeshBasicMaterial({map: loader.load('resources/images/flower-2.jpg')}),
      new THREE.MeshBasicMaterial({map: loader.load('resources/images/flower-3.jpg')}),
      new THREE.MeshBasicMaterial({map: loader.load('resources/images/flower-4.jpg')}),
      new THREE.MeshBasicMaterial({map: loader.load('resources/images/flower-5.jpg')}),
      new THREE.MeshBasicMaterial({map: loader.load('resources/images/flower-6.jpg')}),
    ];
    
    loadManager.onLoad = () => {
      const cube = new THREE.Mesh(geometry, materials);
      scene.add(cube);
      cubes.push(cube);  // add to our list of cubes to rotate
    };
    

    you can place this code inside of a custom component that is attached the cube geometry. Here is the tutorial that the above code was taken from, on threejsfundamentals.