当前位置: 首页 > news >正文

潍坊 餐饮网站建设学装修设计

潍坊 餐饮网站建设,学装修设计,做网站的论坛,网站侧边栏菜单本文 我们来说法向 法向 又叫 法向量 就是 我们一个三维物体 顶点垂直于面 的方向 向量 他的作用 用来做光反射 根据光照的方向 根据面进行反射 我们上文写的这个代码 import ./style.css import * as THREE from three; import { OrbitControls } from …本文 我们来说法向 法向 又叫 法向量 就是 我们一个三维物体 顶点垂直于面 的方向 向量 他的作用 用来做光反射 根据光照的方向 根据面进行反射 我们上文写的这个代码 import ./style.css import * as THREE from three; import { OrbitControls } from three/examples/jsm/controls/OrbitControls.js;//创建相机 const camera new THREE.PerspectiveCamera(45, //视角 视角越大 能看到的范围就越大window.innerWidth / window.innerHeight,//相机的宽高比 一般和画布一样大最好0.1, //近平面 相机能看到最近的距离1000 //远平面 相机能看到最远的距离 ); const scene new THREE.Scene(); let uvTexture new THREE.TextureLoader().load(/textUv.jpg);const planeGeometry new THREE .PlaneGeometry(1, 1); console.log(planeGeometry); const planeMaterial new THREE.MeshBasicMaterial({map: uvTexture }) const planeMesh new THREE.Mesh(planeGeometry, planeMaterial); scene.add(planeMesh);const geometry new THREE.BufferGeometry(); console.log(geometry); // 创建顶点数据 const vertices new Float32Array([-1.0 ,-1.0 ,0.0,1.0 ,-1.0, 0.0,1.0 ,1.0 ,0.0,-1.0 ,1.0, 0.0 ]) geometry.setAttribute(position, new THREE.BufferAttribute(vertices, 3)); const indices new Uint16Array([0 ,1 ,2, 0, 3, 2]); const material new THREE.MeshBasicMaterial({map: uvTexture,side: THREE.DoubleSide }) const uv new Float32Array([0, 0, 1, 0, 1, 1, 0, 1 ]) geometry.setAttribute(uv, new THREE.BufferAttribute(uv, 2)); geometry.setIndex(new THREE.BufferAttribute(indices, 1)); const cube new THREE.Mesh(geometry, material); cube.position.x - 3 scene.add(cube)//c创建一个canvas容器 并追加到 body上 const renderer new THREE.WebGLRenderer(0); renderer.setSize(window.innerWidth, window.innerHeight); document.body.appendChild(renderer.domElement);//设置相机位置 这里 我们设置Z轴 大家可以试试 S Y 和 Z 都是可以的 camera.position.z 5; //设置相机默认看向哪里 三个 0 代表 默认看向原点 camera.lookAt(0, 0, 0); //将内容渲染到元素上 renderer.render(scene, camera); const controls new OrbitControls(camera, renderer.domElement);function animate() {controls.update();requestAnimationFrame(animate);/*cube.rotation.x 0.01;cube.rotation.y 0.01;*/renderer.render(scene, camera); } animate();运行起来 然后打开控制台 会发现 我们通过 PlaneGeometry 创建的几何体 它是自带法向量的 但我们自己创建的这个平面 它是没有的 我们将代码更改如下 import ./style.css import * as THREE from three; import { OrbitControls } from three/examples/jsm/controls/OrbitControls.js; import { RGBELoader } from three/examples/jsm/loaders/RGBELoader.js;//创建相机 const camera new THREE.PerspectiveCamera(45, //视角 视角越大 能看到的范围就越大window.innerWidth / window.innerHeight,//相机的宽高比 一般和画布一样大最好0.1, //近平面 相机能看到最近的距离1000 //远平面 相机能看到最远的距离 ); const scene new THREE.Scene(); let uvTexture new THREE.TextureLoader().load(/textUv.jpg);const planeGeometry new THREE .PlaneGeometry(1, 1); console.log(planeGeometry); const planeMaterial new THREE.MeshBasicMaterial({map: uvTexture,side: THREE.DoubleSide }) const planeMesh new THREE.Mesh(planeGeometry, planeMaterial); scene.add(planeMesh);const geometry new THREE.BufferGeometry(); console.log(geometry); // 创建顶点数据 const vertices new Float32Array([-1.0 ,-1.0 ,0.0,1.0 ,-1.0, 0.0,1.0 ,1.0 ,0.0,-1.0 ,1.0, 0.0 ]) geometry.setAttribute(position, new THREE.BufferAttribute(vertices, 3)); const indices new Uint16Array([0 ,1 ,2, 0, 3, 2]); const material new THREE.MeshBasicMaterial({map: uvTexture,side: THREE.DoubleSide }) const uv new Float32Array([0, 0, 1, 0, 1, 1, 0, 1 ]) geometry.setAttribute(uv, new THREE.BufferAttribute(uv, 2)); geometry.setIndex(new THREE.BufferAttribute(indices, 1)); const cube new THREE.Mesh(geometry, material); cube.position.x - 3 scene.add(cube)//c创建一个canvas容器 并追加到 body上 const renderer new THREE.WebGLRenderer(0); renderer.setSize(window.innerWidth, window.innerHeight); document.body.appendChild(renderer.domElement);//设置相机位置 这里 我们设置Z轴 大家可以试试 S Y 和 Z 都是可以的 camera.position.z 5; //设置相机默认看向哪里 三个 0 代表 默认看向原点 camera.lookAt(0, 0, 0); //将内容渲染到元素上 renderer.render(scene, camera); const controls new OrbitControls(camera, renderer.domElement);let rgbeloader new RGBELoader(); rgbeloader.load(/xhdr/Alex_Hart-Snow_Pano_2k.hdr,(texture) {scene.background texture;texture.mapping THREE.EquirectangularReflectionMapping;planeMaterial.envMap texture;material.envMap texture; })function animate() {controls.update();requestAnimationFrame(animate);/*cube.rotation.x 0.01;cube.rotation.y 0.01;*/renderer.render(scene, camera); } animate();这里 我们 RGBELoader引入环境贴图 然后 将我们两个材质都设置 envMap 为当前场景贴图 但明显 我们用PlaneGeometry创建的 有法向的几何体就可以反光 但我们自己写的这个几何体 并没有反射的一个效果 这边 问题就出在 我们自己创建的没有法向向量 这里 我们将代码改成这样 const geometry new THREE.BufferGeometry(); // 创建顶点数据 const vertices new Float32Array([-1.0 ,-1.0 ,0.0,1.0 ,-1.0, 0.0,1.0 ,1.0 ,0.0,-1.0 ,1.0, 0.0 ]) geometry.setAttribute(position, new THREE.BufferAttribute(vertices, 3)); const indices new Uint16Array([0 ,1 ,2, 0, 3, 2]); const material new THREE.MeshBasicMaterial({map: uvTexture,side: THREE.DoubleSide }) const uv new Float32Array([0, 0, 1, 0, 1, 1, 0, 1 ]) geometry.setAttribute(uv, new THREE.BufferAttribute(uv, 2)); geometry.computeVertexNormals(); geometry.setIndex(new THREE.BufferAttribute(indices, 1)); console.log(geometry); const cube new THREE.Mesh(geometry, material); cube.position.x - 3 scene.add(cube)因为执行顺序的问题 换了一些代码的位置 主要还是 用几何体对象执行了 computeVertexNormals 这样 我们在运行代码 我们自己创建的这个几何体 它就有法向向量了 我们两个板就都有效果了 但好像只出来了一半 没事 除了computeVertexNormals 我们还可以自己去定义 normal的值 参考代码如下 const geometry new THREE.BufferGeometry(); // 创建顶点数据 const vertices new Float32Array([-1.0 ,-1.0 ,0.0,1.0 ,-1.0, 0.0,1.0 ,1.0 ,0.0,-1.0 ,1.0, 0.0 ]) geometry.setAttribute(position, new THREE.BufferAttribute(vertices, 3)); const indices new Uint16Array([0 ,1 ,2, 0, 3, 2]); const material new THREE.MeshBasicMaterial({map: uvTexture,side: THREE.DoubleSide }) const uv new Float32Array([0, 0, 1, 0, 1, 1, 0, 1 ]) geometry.setAttribute(uv, new THREE.BufferAttribute(uv, 2)); const normals new Float32Array([0, 0, 1,0, 0, 1,0, 0, 1,0, 0, 1 ]) geometry.setAttribute(normal, new THREE.BufferAttribute(normals, 3)); geometry.setIndex(new THREE.BufferAttribute(indices, 1)); console.log(geometry); const cube new THREE.Mesh(geometry, material); cube.position.x - 3 scene.add(cube)这里 我们定义了一个数组 normals 对应四个角 我们都是 x和y都不管 面对x y的两个方向 反射不需要 就设置 z 就可以了 因为z是面对我们的方向 只要我们相机看得到这个反射效果就好了 然后将数组写入 normal 属性 运行结果如下 然后 为了我们能够更方便的调试 法向量 我们可以这样做 首先 我们需要在代码中导入 //导入顶点法向量辅助器 import { VertexNormalsHelper } from three/examples/jsm/helpers/VertexNormalsHelper.js;然后 我们可以随便找个地方这样写 const helper new VertexNormalsHelper(cube, 8.2, 0xff0000); scene.add(helper);接受三个参数 第一个 你要看哪个几何体的法向量就给他传进去 第二个 辅助线的长度 第三个 辅助线的颜色 运行之后 我们的效果就出来了 x y 都没有 只有y轴一条真线 它能够帮助我们更直观的看到法向量效果
http://www.zqtcl.cn/news/466859/

相关文章:

  • 建设 互动 网站 模式网络营销模式不是孤立存在的
  • 怡梦姗网站做么上海21世纪人才网官网登录
  • 家政网站建设方案分析哈尔滨做网站找哪家好
  • 如何建设论坛网站营销宣传策划方案
  • 企业网站推广排名技术网
  • 网站建设网页设计培训学校延边网站建设
  • 自己做网站需要的技术个人简历表格下载
  • 做网站建设小程序ukidc做电影网站
  • 网站内容分析软文范例100字
  • 网站建站策划用vs做网站
  • 如何建自己的网站做农村电子商务的网站有哪些内容
  • 手机销售网站设计怎么推广软件让别人下载
  • 贵州三蒲建设工程有限公司网站莱阳网站制作
  • 外贸买家网站适合初学者模仿的网站
  • 安徽蚌埠怀远县建设局网站米卓网站建设
  • 网站框架怎么建设微信旧版本下载
  • 速贝网站友情链接怎么做企业网站开发的设计流程
  • 网站建设 安庆网站开发免责合同
  • 天津深圳网站开发定制网络工程考研方向
  • 做app网站的公司哪家好济南网站建设市场
  • 自己做网站页面网站国内空间和国外空间
  • 桂城网站制作公司asp.net jsp 网站
  • 太原免费静态网页制作网站如何搭建钓鱼网站
  • 英语门户网站织梦源码修改wordpress登录页面
  • 网络建设和网站建设网站快速收录提交
  • 免费的建设网站软件北京电力交易中心谢开
  • 建设一个网站需要提供什么手续好看的美食网站设计
  • 西宁网站seo公司网站建设和维护释义
  • 建站平台有哪些免费一键搭建网站wordpress ent 主题
  • 国内比较大的源码网站营销型网站与普通网站的区别