Learning
레슨 4 / 8·2개 토픽

에셋 관리와 텍스처

에셋 시스템으로 리소스 사전 로딩하기

A-Frame의 시스템은 이미지, 오디오, 비디오, 3D 모델 등 외부 리소스를 장면 렌더링 전에 미리 로딩합니다. 에셋을 사전 로딩하면 텍스처가 깜빡이거나 모델이 늦게 나타나는 현상을 방지할 수 있습니다. 안에 ,

html
<a-scene>
  <!-- 에셋 사전 로딩 -->
  <a-assets>
    <!-- 이미지 텍스처 -->
    <img id="sky-img" src="sky.jpg" />
    <img id="floor-img" src="floor.png" />
    <img id="wall-img" src="bricks.jpg" />

    <!-- 오디오 -->
    <audio id="bgm" src="background.mp3" preload="auto"></audio>

    <!-- 3D 모델 (GLTF) -->
    <a-asset-item id="tree-model" src="tree.glb"></a-asset-item>
    <a-asset-item id="chair-model" src="chair.gltf"></a-asset-item>
  </a-assets>

  <!-- 360도 하늘 배경 — 이미지 텍스처 적용 -->
  <a-sky src="#sky-img"></a-sky>

  <!-- 바닥 — 텍스처 반복 적용 -->
  <a-plane
    src="#floor-img"
    rotation="-90 0 0"
    width="20"
    height="20"
    repeat="10 10"
  ></a-plane>

  <!-- 벽면 — 텍스처 적용 -->
  <a-box
    src="#wall-img"
    position="0 1.5 -5"
    width="6"
    height="3"
    depth="0.2"
  ></a-box>
</a-scene>

텍스처 매핑과 재질 속성

html
<a-scene>
  <a-assets>
    <img id="wood-tex" src="wood.jpg" />
    <img id="metal-tex" src="metal.jpg" />
    <img id="normal-map" src="wood-normal.jpg" />
  </a-assets>

  <!-- 기본 텍스처 매핑 -->
  <a-box
    src="#wood-tex"
    position="-2 1 -4"
    width="2"
    height="2"
    depth="2"
  ></a-box>

  <!-- material 컴포넌트로 세밀한 제어 -->
  <a-sphere
    position="2 1.5 -4"
    radius="1"
    material="
      src: #metal-tex;
      metalness: 0.9;
      roughness: 0.1;
      normalMap: #normal-map;
      normalTextureRepeat: 2 2;
    "
  ></a-sphere>

  <!-- 투명 텍스처 -->
  <a-plane
    src="#wood-tex"
    position="0 2 -5"
    width="3"
    height="2"
    material="
      transparent: true;
      opacity: 0.7;
      side: double;
    "
  ></a-plane>
</a-scene>
  • — 장면 시작 전 모든 리소스를 미리 로딩하는 컨테이너
  • — GLTF/OBJ 등 3D 모델 파일 사전 로딩
  • src="#id" — 에셋의 id를 참조하여 텍스처/모델 적용
  • repeat="x y" — 텍스처를 타일처럼 반복 (바닥, 벽 등에 유용)
  • normalMap — 표면의 요철감을 표현하는 노멀 맵 텍스처
  • metalness / roughness — PBR 재질의 금속성과 거칠기
  • transparent: true + opacity — 반투명 재질 구현
  • side: double — 양면 렌더링 (뒷면도 보이게)
💡

에 timeout="10000" 속성을 추가하면 에셋 로딩 타임아웃을 조절할 수 있습니다(기본 3초). 대용량 모델이나 고해상도 텍스처가 많으면 타임아웃을 늘리세요. 로딩이 완료되기 전에 장면이 렌더링되면 텍스처 없이 표시될 수 있습니다.