- [threejs] 환경 맵 만들기 / 유리 질감 구현하기2023년 08월 23일
- KIMJAVAN
- 작성자
- 2023.08.23.:55
728x90import * as THREE from "./three.module.js";import { OrbitControls } from './three/examples/jsm/controls/OrbitControls.js';
export default function example() {// Create a scene, camera, and rendererconst scene = new THREE.Scene();const camera = new THREE.PerspectiveCamera(75,window.innerWidth / window.innerHeight,0.1,1000);const renderer = new THREE.WebGLRenderer();renderer.setSize(window.innerWidth, window.innerHeight);document.body.appendChild(renderer.domElement);
// Create a sphere geometry (instead of box geometry)const sphereGeometry = new THREE.SphereGeometry(1, 32, 32);
// Load a cube map texture (for environment mapping)const cubeTextureLoader = new THREE.CubeTextureLoader();const cubeMapTexture = cubeTextureLoader.load(['./assets/images/album-three-d-section/humble_ft.jpg','./assets/images/album-three-d-section/humble_bk.jpg','./assets/images/album-three-d-section/humble_up.jpg','./assets/images/album-three-d-section/humble_dn.jpg','./assets/images/album-three-d-section/humble_rt.jpg','./assets/images/album-three-d-section/humble_lf.jpg',]);
scene.background = cubeMapTexture;
// Create a material with environment mapping and transparencyconst sphereMaterial = new THREE.MeshStandardMaterial({color: 0xffffff,envMap: cubeMapTexture,transparent: true,opacity: 0.5,metalness: 1,roughness: 0.1,side: THREE.DoubleSide});
// Create a sphere mesh (instead of cube mesh)const sphereMesh = new THREE.Mesh(sphereGeometry, sphereMaterial);scene.add(sphereMesh);
// Position the cameracamera.position.z = 3;
// Add lights and controlsconst light = new THREE.DirectionalLight(0xffffff, 1);light.position.set(0, 1, 2);scene.add(light);
const controls = new OrbitControls(camera, renderer.domElement);
// Render loopconst animate = () => {requestAnimationFrame(animate);renderer.render(scene, camera);};
// Start the rendering loopanimate();}
// Call the example function to start renderingexample();'자바스크립트 > threeJS' 카테고리의 다른 글
[R3F] material 잘 정리되어있는 블로그 (0) 2024.08.21 [R3F] Ambient Occlusion Map / alpha map (0) 2024.08.21 [three.js] camera.position.set() / camera.rotation.set() (0) 2023.08.11 [threeJS] cos, sin, tan 함수를 사용해서 배치하기 (0) 2023.08.07 [threeJS] 최적화 (0) 2023.08.07 다음글이전글이전 글이 없습니다.댓글
스킨 업데이트 안내
현재 이용하고 계신 스킨의 버전보다 더 높은 최신 버전이 감지 되었습니다. 최신버전 스킨 파일을 다운로드 받을 수 있는 페이지로 이동하시겠습니까?
("아니오" 를 선택할 시 30일 동안 최신 버전이 감지되어도 모달 창이 표시되지 않습니다.)