티스토리 뷰
728x90
반응형
https://threejs.org/docs/index.html?q=gltf#examples/en/loaders/GLTFLoader
three.js docs
threejs.org
해보자.
1. 스케치팹 에서 gltf 파일을 받는다.
Log in to your Sketchfab account
sketchfab.com
01. 이전 orbitControls 에서처럼 GLTFLoader를 불러온다
import { GLTFLoader } from '../node_modules/three/examples/jsm/loaders/GLTFLoader.js'
02. gltf코드 추가
//gltfloader
const gltfloader = new GLTFLoader()
const url = '../donny/scene.gltf'
gltfloader.load(
url,
(gltf) => {
const root = gltf.scene
scene.add(root)
}
)
>app.js 전체
import * as THREE from 'three'
import { Scene } from 'three'
import { WEBGL } from './webgl'
import { OrbitControls } from '../node_modules/three/examples/jsm/controls/OrbitControls.js'
import { GLTFLoader } from '../node_modules/three/examples/jsm/loaders/GLTFLoader.js'
if (WEBGL.isWebGLAvailable()) {
//장면
const scene = new THREE.Scene();
//배경색 바꾸기
scene.background = new THREE.Color(0x004fff)
//카메라
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000)
camera.position.z =3
//캔버스
// const canvas = document.querySelector('#c')
//렌더러
const renderer = new THREE.WebGLRenderer({
alpha : true,
antialias : true
})
renderer.setSize(window.innerWidth, window.innerHeight)
document.body.appendChild(renderer.domElement)
//controls
const controls = new OrbitControls( camera, renderer.domElement )
//Light
const pointLight = new THREE.PointLight(0xffffff, 1)
pointLight.position.set(0,2,12)
scene.add(pointLight)
//gltfloader
const gltfloader = new GLTFLoader()
const url = '../donny/scene.gltf'
gltfloader.load(
url,
(gltf) => {
const root = gltf.scene
scene.add(root)
}
)
//render
function render(time) {
time *= 0.001; // convert time to seconds
renderer.render(scene, camera);
requestAnimationFrame(render);
}
requestAnimationFrame(render);
//반응형 처리
function onWindowResize(){
camera.aspect = window.innerWidth/window.innerHeight
camera.updateProjectionMatrix()
renderer.setSize(window.innerWidth, window.innerHeight)
}
window.addEventListener('resize', onWindowResize)
} else {
var warning = WEBGL.getWebGLErrorMessage()
document.body.appendChild(warning)
}
npm run serve
음 .. 빛과 카메라 다시 수정
//카메라
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000)
camera.position.z =3
scene.add(camera)
//Light
const pointLight = new THREE.PointLight(0xffffff, 1)
pointLight.position.set(0,2,12)
// scene.add(pointLight)
camera.add(pointLight)
728x90
반응형
'Web > WebGL' 카테고리의 다른 글
웹 Vue + Three.js : FBX load (0) | 2022.10.14 |
---|---|
Three.js_05 마우스 오브제 회전 OrbitControls (0) | 2022.06.08 |
Three.js_ 04 재질 (0) | 2022.06.07 |
Three.js_ 03 3D 도형 추가 + 반응형 (0) | 2022.06.07 |
Three.js_ 02 구조 알아보기 (0) | 2022.06.07 |
250x250
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- sequelize
- 유니티
- three.js
- VR
- Express
- google ai studio
- ai film
- Arduino
- RNN
- houdini
- 라즈베리파이
- CNC
- opencv
- oculuspro
- Java
- MQTT
- 후디니
- Python
- node.js
- Unity
- ai image generator
- imgtoimg
- DeepLeaning
- docker
- colab
- TouchDesigner
- krea
- AI
- Midjourney
- runwayai
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함
반응형