본문 바로가기
3Js

OBJLoader(), MTLLoader(). 블렌더에서 파일 가져오기

by 영감은어디에 2024. 7. 19.

블렌더에서 -> 형태인 obj 와 재질인 mtl 파일로 export 하여 가져옴. 
처음에 아무것도 안보여서 다른 개체를 다 삭제함.
그래도 안보여서 스케일을 1000배 키웠더니 검게 형태만 보임.
빛을 추가하고 세기를 키웠더니 그제서야 보임 

// OBJ Loader
const OBJloader = new OBJLoader() // MTLLoader에서 로드한 materials 파일을 설정합니다.
let ObjGroup = new THREE.Object3D()
// MTL Loader
const mtlLoader = new MTLLoader()

mtlLoader.load('../static/img/lemon.mtl', (mtl) => {
mtl.preload()
OBJloader.setMaterials(mtl);

OBJloader.load( '../static/img/lemon.obj',function (object) {
    ObjGroup.add(object);
    ObjGroup.scale.set(1000, 1000, 1000);
    scene.add(ObjGroup);
    },
    function (xhr) {
    const progress = (xhr.loaded / xhr.total) * 100 + '%'
    console.log(progress)
    },
    function (error) {
    console.log('An error happened')
    }
)
})
const ambientLight = new THREE.AmbientLight(0xffffff, 1.8)
scene.add(ambientLight)
// OBJ 끝