• 【前端知识】Three 学习日志(十一)—— 高光网格材质Phong


    Three 学习日志(十一)—— 高光网格材质Phong

    一、设置高光亮度属性
    // 模拟镜面反射,产生一个高光效果
    const material = new THREE.MeshPhongMaterial({
        color: 0xff0000,
        shininess: 10, //高光部分的亮度,默认30
    });
    
    • 1
    • 2
    • 3
    • 4
    • 5

    在这里插入图片描述

    // 模拟镜面反射,产生一个高光效果
    const material = new THREE.MeshPhongMaterial({
        color: 0xff0000,
        shininess: 60, //高光部分的亮度,默认30
    });
    
    • 1
    • 2
    • 3
    • 4
    • 5

    在这里插入图片描述

    二、设置高光颜色属性
    // 模拟镜面反射,产生一个高光效果
    const material = new THREE.MeshPhongMaterial({
        color: 0xff0000,
        shininess: 20, //高光部分的亮度,默认30
        specular: 0xffffff, //高光部分的颜色调整为白色
    });
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    在这里插入图片描述

    三、完整代码
    DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Learn Threetitle>
        
        <script src="../build/three.js">script>
        
        <script type="importmap">
            {
                "imports": {
                    "three": "../build/three.module.js",
                    "three/addons/": "../examples/jsm/"
                }
            }
        script>
    head>
    
    <body>
        <script type="module">
            // 引入轨道控制器扩展库OrbitControls.js
            import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
            // 创建3D场景对象Scene
            const scene = new THREE.Scene();
            const axesHelper = new THREE.AxesHelper(150);
            scene.add(axesHelper);
            const geometry = new THREE.BoxGeometry(100, 100, 100);
    
            // 模拟镜面反射,产生一个高光效果
            // const material = new THREE.MeshPhongMaterial({
            //     color: 0xff0000,
            //     shininess: 80, //高光部分的亮度,默认30
            // });
    
            // 模拟镜面反射,产生一个高光效果
            const material = new THREE.MeshPhongMaterial({
                color: 0xff0000,
                shininess: 20, //高光部分的亮度,默认30
                specular: 0xffffff, //高光部分的颜色调整为白色
            });
    
            const pointLight = new THREE.PointLight(0xffffff, 1.0);
            pointLight.position.set(200, 200, 200);
            scene.add(pointLight); //点光源添加到场景中
    
            const mesh = new THREE.Mesh(geometry, material); //网格模型对象Mesh
            mesh.position.set(0, 0, 0);
            scene.add(mesh);
            const camera = new THREE.PerspectiveCamera();
            camera.position.set(600, 600, 600);
            camera.lookAt(0, 0, 0);
            const width = window.innerWidth; // 窗口宽度
            const height = window.innerHeight; // 窗口高度
            const renderer = new THREE.WebGLRenderer();
            renderer.setSize(width, height);
            renderer.render(scene, camera); //执行渲染操作
            document.body.appendChild(renderer.domElement);
    
            // 设置相机控件轨道控制器
            const controls = new OrbitControls(camera, renderer.domElement);
            // 如果OrbitControls改变了相机参数,重新调用渲染器渲染三维场景
            controls.addEventListener('change', function () {
                renderer.render(scene, camera); //执行渲染操作
            });//监听鼠标、键盘事件
    
        script>
    body>
    <style>
        body {
            overflow: hidden;
            margin: 0px;
        }
    style>
    
    html>
    
    • 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
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
  • 相关阅读:
    Std::optional 源码分析
    步进电机接线图
    项目中根据excel文件生成json多语言文件
    [leetcode hot 150]第十五题,三数之和
    springBoot 项目中的静态资源文件夹static和模版文件文件夹templates
    [附源码]java毕业设计水库水面漂浮物WEB系统
    Go语言学习 (一)
    Leetcode 82. Remove Duplicates from Sorted List II
    Flutter GetX的使用
    docker常见问题
  • 原文地址:https://blog.csdn.net/weixin_42919342/article/details/133026805