Quellcode durchsuchen

feat: 增加hrd配置, hdr文件未上传

sunxiao vor 8 Monaten
Ursprung
Commit
1a25a75bd2
1 geänderte Dateien mit 31 neuen und 7 gelöschten Zeilen
  1. 31 7
      src/views/screen/3d/renderModel.js

+ 31 - 7
src/views/screen/3d/renderModel.js

@@ -3,6 +3,7 @@ import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls' //导
 import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader'
 import { MTLLoader } from 'three/examples/jsm/loaders/MTLLoader'
 import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'
+import { RGBELoader } from 'three/examples/jsm/loaders/RGBELoader';
 
 class motor3d {
   constructor(selector) {
@@ -74,6 +75,8 @@ class motor3d {
 
   initRender() {
     this.renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true })//设置抗锯齿
+    // this.renderer.toneMapping = THREE.ACESFilmicToneMapping;
+    // this.renderer.toneMappingExposure = 1; 
     //设置屏幕像素比
     this.renderer.setPixelRatio(window.devicePixelRatio)
     //渲染的尺寸大小
@@ -118,6 +121,22 @@ class motor3d {
         console.log(error);
       })
 
+      const rgbeLoader = new RGBELoader();
+      rgbeLoader.load('/clarens_night_02_8k.hdr', (texture) => {
+        texture.mapping = THREE.EquirectangularReflectionMapping;
+        texture.minFilter = THREE.LinearFilter;
+        texture.magFilter = THREE.LineasrFilter;
+        // texture.format = THREE.RGBEFormat;
+
+        this.scene.environment = texture;
+
+        // texture.mapping = THREE.EquirectangularReflectionMapping;
+        // texture.encoding = THREE.LinearEncoding;
+        // this.scene.environment = texture;
+      }, undefined, (error) => {
+          console.error('An error happened.', error);
+      });
+
       // mtlLoader.load('./texture.mtl', (mtl) => {
       //   mtl.preload();
 
@@ -125,14 +144,19 @@ class motor3d {
 
       //   objLoader.load('./factory.obj', (obj) => {
       //     obj.position.set(0, 10, 0);
+      //     var material = new THREE.MeshStandardMaterial({ color: '#fff' });
       //     obj.traverse(function (child) {
-      //       console.log(child);
-      //       if (child instanceof THREE.Mesh) {
-      //         if (child.material instanceof THREE.MeshStandardMaterial ||
-      //           child.material instanceof THREE.MeshPhongMaterial) {
-      //             child.material.color.set('ffffff');
-      //         }
-      //       }
+      //       console.log(child.name);
+      //     //   if (child instanceof THREE.Mesh) {
+      //     //     for (let i = 0; i < child.material.length; i++) {
+      //     //       child.material[i].color.set(0xffffff); // 设置材质颜色为白色
+      //     //   }
+      //         // child.material = material;
+      //         // if (child.material instanceof THREE.MeshStandardMaterial ||
+      //         //   child.material instanceof THREE.MeshPhongMaterial) {
+      //         //     child.material.color.set('#fff');
+      //         // }
+      //     // }
       //     })
       //     this.scene.add(obj)
       //     resolve('模型添加成功')