您现在的位置是:首页 > 数码 > 

Three.js

2025-07-27 12:46:11
Three.js 法向贴图保存的不是每个像素的高度,而是像素的法向量,通过很晒的点和面就可以创建出细节非常丰富的模型。 1、示例 示例 .html 效果 2、normalMap属性 normalMap: RGB值影响每个像素片段的表面法线,并改变颜的颜,法线贴图不会改变表面的实际形状,只有对灯光产生

Three.js

法向贴图保存的不是每个像素的高度,而是像素的法向量,通过很晒的点和面就可以创建出细节非常丰富的模型。

1、示例

示例
.html
效果

2、normalMap属性

normalMapRGB值影响每个像素片段的表面法线,并改变颜的颜,法线贴图不会改变表面的实际形状,只有对灯光产生反应。
normalScale:影响的程度。

2.1、创建实例
let loader = new THREE.TextureLoader();
let texture = loader.load(	../../textures/general/	  imageUrl);
let normal = loader.load(	../../textures/general/	  normalMap);
 = texture;
 = normal;

、示例代码

<!DOCTYPE html>
<html lang=en>
<head><meta charset=UTF-8><link rel=icon href=../../../three.png><title>使用 法向贴图 创建更加细致的皱纹</title><style>body {margin: 0;overflow: hidden; /* 溢出隐藏 */}#loading {position: fixed;top: 50%;left: 50%;color: #FFFFFF;font-size: 20px;margin-top: -0px;margin-left: -40px;}</style><script src=../../libs/build/three-r9.js></script><script src=../../libs/examples/js/Detector.js></script><script src=../../libs/examples/js/libs/dat.js></script><script src=../../libs/examples/js/libs/js></script><script src=../../libs/examples/js/controls/OrbitControls.js></script>
</head>
<body>
<p id=loading>loading......</p>
<script>let scene, camera, renderer, controls, guiControls;let stats = initStats();/* 场景 */function initScene() {scene = new THREE.Scene();scene.background = new THREE.Color(0x050505);}/* 相机 */function initCamera() {camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 10000);camera.position.set(0, 0, -50);camera.lookAt(new THREE.Vector(0, 0, 0));}/* 渲染器 */function initRender() {renderer = new THREE.WebGLRenderer({antialias: true});renderer.setSize(window.innerWidth, window.innerHeight);document.body.appendChild(renderer.domElement);}/* 灯光 */function initLight() {scene.add(new THREE.AmbientLight(0x0c0c0c));let spotLight1 = new THREE.SpotLight(0xffffff);spotLight1.position.set(-400, -400, -400);let spotLight2 = new THREE.SpotLight(0xffffff);spotLight2.position.set(400, 400, 400);scene.add(spotLight1);scene.add(spotLight2);}/* 控制器 */function initControls() {/* 地图控件 */controls = new THREE.OrbitControls(camera, renderer.domElement);/* 属性参数 */}/* 调试插件 */function initGui() {guiControls = new function () { = 1;};let gui = new dat.GUI();gui.add(guiControls, 	normalScale	, -2, 2).onChange(function (e) {set(e, e);});}/* 场景中的内容 */let box1;let box2;function initContent() {box1 = createMesh(new THREE.BoxGeometry(10, 10, 10), 	plaster.jpg	, 	plaster-normal.jpg	);box2 = createMesh(new THREE.BoxGeometry(10, 10, 10), 	plaster.jpg	);(10);(-10);scene.add(box1);scene.add(box2);removeLoading();}/* 移除加载元素 */function removeLoading() {document.getElementById(	loading	).style.display = 	none	;}/* 创建带有纹理的网格 */function createMesh(geometry, imageUrl, normalMap) {let loader = new THREE.TextureLoader();let texture = loader.load(	../../textures/general/	  imageUrl);let material = new THREE.MeshPhongMaterial(); = texture;if (normalMap !== undefined) {let normal = loader.load(	../../textures/general/	  normalMap); = normal;}let mesh = new THREE.Mesh(geometry, material);return mesh;}/* 性能插件 */function initStats() {let stats = new Stats();document.body.appendChild(stats.domElement);return stats;}/* 窗口变动触发 */function onWindowResize() {camera.aspect = window.innerWidth / window.innerHeight;camera.updateProjectionMatrix();renderer.setSize(window.innerWidth, window.innerHeight);}/* 数据更新 */function update() {stats.update();controls.update();if (box1 && box2) {box1.rotateY(0.01);box2.rotateY(0.01);}}/* 初始化 */function init() {if (!Detector.webgl) Detector.addGetWebGLMessage();initScene();initCamera();initRender();initLight();initControls();initContent();initGui();/* 监听事件 */window.addEventListener(	resize	, onWindowResize, false);}/* 循环渲染 */function animate() {requestAnimationFrame(animate);renderer.render(scene, camera);update();}/* 初始加载 */(function () {cole.log(three init start...);init();animate();cole.log(three init end...);})();</script>
</body>
</html>

#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格

本文地址:http://www.dnpztj.cn/shuma/707530.html

相关标签:无
上传时间: 2023-11-21 22:19:33

上一篇:星梦缘陈彦妃

下一篇:易观千帆

留言与评论(共有 16 条评论)
本站网友 海拉细胞
6分钟前 发表
guiControls;let stats = initStats();/* 场景 */function initScene() {scene = new THREE.Scene();scene.background = new THREE.Color(0x050505);}/* 相机 */function initCamera() {camera = new THREE.PerspectiveCamera(45
本站网友 伊犁租房
24分钟前 发表
onWindowResize
本站网友 英雄联盟加速器
3分钟前 发表
400);scene.add(spotLight1);scene.add(spotLight2);}/* 控制器 */function initControls() {/* 地图控件 */controls = new THREE.OrbitControls(camera
本站网友 围攻淘宝
23分钟前 发表
10)
本站网友 齐怀
12分钟前 发表
-400);let spotLight2 = new THREE.SpotLight(0xffffff);spotLight2.position.set(400
本站网友 审时度势
24分钟前 发表
-0px;margin-left
本站网友 偷原味丝袜
16分钟前 发表
window.innerHeight);}/* 数据更新 */function update() {stats.update();controls.update();if (box1 && box2) {box1.rotateY(0.01);box2.rotateY(0.01);}}/* 初始化 */function init() {if (!Detector.webgl) Detector.addGetWebGLMessage();initScene();initCamera();initRender();initLight();initControls();initContent();initGui();/* 监听事件 */window.addEventListener( resize
本站网友 硅橡胶产品
28分钟前 发表
10)
本站网友 累不累睡不睡
25分钟前 发表
10)
本站网友 太平船务有限公司
22分钟前 发表
material);return mesh;}/* 性能插件 */function initStats() {let stats = new Stats();document.body.appendChild(stats.domElement);return stats;}/* 窗口变动触发 */function onWindowResize() {camera.aspect = window.innerWidth / window.innerHeight;camera.updateProjectionMatrix();renderer.setSize(window.innerWidth
本站网友 瑟瑟发抖的意思
15分钟前 发表
400
本站网友 莴苣子
3分钟前 发表
e);});}/* 场景中的内容 */let box1;let box2;function initContent() {box1 = createMesh(new THREE.BoxGeometry(10
本站网友 怎样使皮肤美白
5分钟前 发表
plaster.jpg
本站网友 祛痘小偏方
22分钟前 发表
-40px;}</style><script src=../../libs/build/three-r9.js></script><script src=../../libs/examples/js/Detector.js></script><script src=../../libs/examples/js/libs/dat.js></script><script src=../../libs/examples/js/libs/js></script><script src=../../libs/examples/js/controls/OrbitControls.js></script> </head> <body> <p id=loading>loading......</p> <script>let scene
本站网友 debian源
4分钟前 发表
示例 示例 .html 效果 2