• 티스토리 홈
  • 프로필사진
    KIMJAVAN
  • 방명록
  • 공지사항
  • 태그
  • 블로그 관리
  • 글 작성
KIMJAVAN
  • 프로필사진
    KIMJAVAN
    • 개발 (160)
      • 마크업 언어 (19)
        • HTML (7)
        • CSS (12)
      • 자바스크립트 (85)
        • JavaScript (34)
        • JS Library (6)
        • React (13)
        • threeJS (6)
        • TypeScript (2)
        • Next js (5)
        • Node JS (18)
        • webGL (1)
      • AI (4)
        • chat-gpt (4)
      • flutter (17)
        • dart (11)
        • flutter (6)
      • Sql (3)
      • PHP (4)
      • Python (2)
      • Git (4)
      • vscode (1)
      • 개발 도움 사이트 (7)
      • 작업기록 (1)
      • 오류 모음 (3)
      • 메모장 (7)
  • 방문자 수
    • 전체:
    • 오늘:
    • 어제:
  • 최근 댓글
      등록된 댓글이 없습니다.
    • 최근 공지
        등록된 공지가 없습니다.
      # Home
      # 공지사항
      #
      # 태그
      # 검색결과
      # 방명록
      • [threejs] 환경 맵 만들기 / 유리 질감 구현하기
        2023년 08월 23일
        • KIMJAVAN
        • 작성자
        • 2023.08.23.오후01:55
        728x90
        import * as THREE from "./three.module.js";
        import { OrbitControls } from './three/examples/jsm/controls/OrbitControls.js';

        export default function example() {
            // Create a scene, camera, and renderer
            const 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 transparency
            const 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 camera
            camera.position.z = 3;

            // Add lights and controls
            const light = new THREE.DirectionalLight(0xffffff, 1);
            light.position.set(0, 1, 2);
            scene.add(light);

            const controls = new OrbitControls(camera, renderer.domElement);

            // Render loop
            const animate = () => {
                requestAnimationFrame(animate);
                renderer.render(scene, camera);
            };

            // Start the rendering loop
            animate();
        }

        // Call the example function to start rendering
        example();

        '자바스크립트 > 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일 동안 최신 버전이 감지되어도 모달 창이 표시되지 않습니다.)
      목차
      표시할 목차가 없습니다.
        • 안녕하세요
        • 감사해요
        • 잘있어요

        티스토리툴바

        단축키

        내 블로그

        내 블로그 - 관리자 홈 전환
        Q
        Q
        새 글 쓰기
        W
        W

        블로그 게시글

        글 수정 (권한 있는 경우)
        E
        E
        댓글 영역으로 이동
        C
        C

        모든 영역

        이 페이지의 URL 복사
        S
        S
        맨 위로 이동
        T
        T
        티스토리 홈 이동
        H
        H
        단축키 안내
        Shift + /
        ⇧ + /

        * 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.