【前端知识】Three 学习日志(五)—— 点光源辅助观察

Three 学习日志(五)------ 点光源辅助观察

一、引入点光源辅助观察

javascript 复制代码
// 光源辅助观察
const pointLightHelper = new THREE.PointLightHelper(pointLight, 10);
scene.add(pointLightHelper);

二、改变点光源位置

javascript 复制代码
// 点光源位置
pointLight.position.set(200, 200, 200);
// 改变点光源位置
pointLight.position.set(-100, -100, -100);
scene.add(pointLight); //点光源添加到场景中

三、完整代码

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Learn Three</title>
    <!-- 引入three,下载地址参考:http://www.webgl3d.cn/pages/aac9ab/#%E7%89%B9%E5%AE%9A%E7%89%88%E6%9C%ACthree-js%E6%96%87%E4%BB%B6%E5%8C%85%E4%B8%8B%E8%BD%BD -->
    <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.MeshLambertMaterial();
        const pointLight = new THREE.PointLight(0xffffff, 1.0);

        // 点光源位置
        pointLight.position.set(200, 200, 200);
        // 改变点光源位置
        pointLight.position.set(-100, -100, -100);
        scene.add(pointLight); //点光源添加到场景中
        // 光源辅助观察
        const pointLightHelper = new THREE.PointLightHelper(pointLight, 10);
        scene.add(pointLightHelper);

        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(200, 200, 200);
        camera.lookAt(0, 0, 0);
        const width = 800; //宽度
        const height = 500; //高度
        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>

</html>
相关推荐
浩星12 小时前
iframe引入界面有el-date-picker日期框,点击出现闪退问题处理
前端·vue.js·elementui
技术钱12 小时前
element plus 多个form校验
前端
yume_sibai12 小时前
HTML HTML基础(3)
前端·html
米花丶12 小时前
JSBridge安全通信:iOS/Android桥对象差异与最佳实践
前端·webview
萌萌哒草头将军13 小时前
🚀🚀🚀 Oxc 恶意扩展警告;Rolldown 放弃 CJS 支持;Vite 发布两个漏洞补丁版本;Rslib v0.13 支持 ts-go
前端·javascript·vue.js
接着奏乐接着舞。13 小时前
3D地球可视化教程 - 第1篇:基础地球渲染系统
前端·javascript·vue.js·3d·three.js
龙傲天66613 小时前
Scala的面向对象和函数式编程特性 Idea环境搭建和输入输出
前端
蓝色海岛13 小时前
element-ui表格嵌套表格,鼠标移入时样式错乱-问题调研及处理办法
前端
薄雾晚晴13 小时前
Rspack 实战:用 SWC Loader 搞定 JS 兼容(支持 IE 11 + 现代浏览器,兼顾构建速度)
前端·vue.js
恋猫de小郭13 小时前
Flutter 官方 LLM 动态 UI 库 flutter_genui 发布,让 App UI 自己生成 UI
android·前端·flutter