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

wordpress做网站过程百度问答优化

wordpress做网站过程,百度问答优化,服务号微商城怎么开通,网站页面制作视频嗨,我是小路。今天主要和大家分享的主题是“vue3three 搭建平面上滚动旋转的几何体”。 在现代前端开发中,结合 Vue 3 的响应式能力和 Three.js 的强大 3D 渲染能力,可以轻松构建出令人惊叹的交互式三维场景。本文将带你一步步实现一…

        嗨,我是小路。今天主要和大家分享的主题是“vue3+three 搭建平面上滚动旋转的几何体”。        

在现代前端开发中,结合 Vue 3 的响应式能力和 Three.js 的强大 3D 渲染能力,可以轻松构建出令人惊叹的交互式三维场景。本文将带你一步步实现一个基础但极具视觉吸引力的效果 —— 在平面上滚动并自转的几何体。

vue3+three 搭建平面上滚动旋转的几何体示例图

一、主要属性

1.基础模块搭建

定义:首先搭建屏幕、相机、持续渲染脚本。

// 定义相机输出画布的尺寸(单位:像素px)
let width = window.innerWidth; //宽度
let height = window.innerHeight; //高度
// 创建3D场景对象Scene
const scene = new THREE.Scene();
//设置背景色
scene.background = new THREE.Color(0xffffff);const camera = new THREE.PerspectiveCamera(75, width / height, 0.1, 1000);
camera.position.set(0, 20, 30);

2.创建平面

定义:平面注意设置平面的颜色和面数,一般有单面和双面的效果;尤其要注意平面需要进行渲染,如果不选择,平面会在Y轴方向。

//创建一个平面
let plane;
const createPlan = () => {const planeGeometry = new THREE.PlaneGeometry(100, 100);const planMaterial = new THREE.MeshBasicMaterial({color: 0x999999, side: THREE.DoubleSide});plane = new THREE.Mesh(planeGeometry, planMaterial);plane.rotation.x = -Math.PI / 2scene.add(plane);
}

3.创建几何体

定义:几何体的大小要根据平面的大小的比例设置。注册在函数外面添加一个变量box,便于做动画效果设置

let box;
const createBox = () => {const boxGeometry = new THREE.BoxGeometry(5, 5, 5);const boxMaterial = new THREE.MeshNormalMaterial({color: 0xff0000,//0xff0000设置材质颜色为红色});box = new THREE.Mesh(boxGeometry,boxMaterial);box.position.set(0, 2.5, 0)scene.add(box);
}

4.添加相机控件

 //添加相机空间const controls = new OrbitControls(camera, renderer.domElement);// 如果OrbitControls改变了相机参数,重新调用渲染器渲染三维场景controls.addEventListener('change', function () {renderer.render(scene, camera); //执行渲染操作});//监听鼠标、键盘事件

5.设置动画

//渲染
let clock = new THREE.Clock();
const render = () => {//重复渲染requestAnimationFrame(render);//请求再次执行渲染函数render,渲染下一帧const delta = clock.getDelta();box.position.x += delta * 5;//x轴平移速度box.rotation.x += delta * 5;//x轴旋转速度box.rotation.y += delta * 5;//y轴旋转速度if (box.position.x > 50) box.position.x = -50;renderer.render(scene, camera); //执行渲染操作
}

二、实例代码

<template><div class="pageBox"><div class="leftBox" ref="leftRef"></div><div class="rightBox" ref="rightRef" :style="{ background: bgColor }"></div></div></template>
<script setup>
import { onMounted, ref } from 'vue';
import * as THREE from 'three';
// 引入轨道控制器扩展库OrbitControls.js
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';const bgColor = ref("")const leftRef = ref();
const rightRef = ref()
// 定义相机输出画布的尺寸(单位:像素px)
let width = window.innerWidth; //宽度
let height = window.innerHeight; //高度
// 创建3D场景对象Scene
const scene = new THREE.Scene();
//设置背景色
scene.background = new THREE.Color(0xffffff);const camera = new THREE.PerspectiveCamera(75, width / height, 0.1, 1000);
camera.position.set(0, 20, 30);//创建一个平面
let plane;
const createPlan = () => {const planeGeometry = new THREE.PlaneGeometry(100, 100);const planMaterial = new THREE.MeshBasicMaterial({color: 0x999999, side: THREE.DoubleSide});plane = new THREE.Mesh(planeGeometry, planMaterial);plane.rotation.x = -Math.PI / 2scene.add(plane);
}
let box;
const createBox = () => {const boxGeometry = new THREE.BoxGeometry(5, 5, 5);const boxMaterial = new THREE.MeshNormalMaterial({color: 0xff0000,//0xff0000设置材质颜色为红色});box = new THREE.Mesh(boxGeometry,boxMaterial);box.position.set(0, 2.5, 0)scene.add(box);
}
// 创建渲染器对象
const renderer = new THREE.WebGLRenderer();onMounted(() => {initData()//添加相机空间const controls = new OrbitControls(camera, renderer.domElement);// 如果OrbitControls改变了相机参数,重新调用渲染器渲染三维场景controls.addEventListener('change', function () {renderer.render(scene, camera); //执行渲染操作});//监听鼠标、键盘事件renderer.setSize(width, height); //设置three.js渲染区域的尺寸(像素px)//将innerHTML置空,避免append重复添加渲染leftRef.value.innerHTML = ''leftRef.value.append(renderer.domElement);})
const initData = () => {createPlan();createBox();render();
}//渲染
let clock = new THREE.Clock();
const render = () => {//重复渲染requestAnimationFrame(render);//请求再次执行渲染函数render,渲染下一帧const delta = clock.getDelta();box.position.x += delta * 5;//x轴平移速度box.rotation.x += delta * 5;//x轴旋转速度box.rotation.y += delta * 5;//y轴旋转速度if (box.position.x > 50) box.position.x = -50;renderer.render(scene, camera); //执行渲染操作
}</script>
<style scoped lang="less">
.pageBox {width: 100%;height: 100vh;padding: 0;margin: 0;display: flex;justify-content: space-between;align-items: center;.rightBox {width: 100%;height: 100%;}
}
</style>

三、注意事项

       注意当前场景的应用,在做其它相似的项目是,可以参考以上的基础方法。搭建基础环境、添加模型、设置动画。

        如果是创建模型,也可以按照上面的步骤,将几何体换成模型。

都看到这里了,记得【点赞】+【关注】哟。

http://www.dtcms.com/wzjs/301937.html

相关文章:

  • 做企业网站都需要注意哪点广州四楚seo顾问
  • 网站建设方案模板怎么做推广网站
  • 大城怎么样做网站淘宝关键词优化工具
  • 苏州专业网站制作百度权重是怎么来的
  • wish跨境电商平台官网seo技术经理
  • 网站营销学多久深圳网络推广引流
  • 杭州网站建设caiyiduo重庆seo优化公司
  • 柳州企业网站建设手机导航下载2022新版
  • 5173网站做的很垃圾seo软件系统
  • 绵阳网站建设 经开区南京百度推广优化
  • 公司域名不变网站做变动做运营需要具备什么能力
  • 母婴网站建设前期规划中国市场营销网
  • 大庆做网站的公司市场营销
  • 宁波外贸网站设计台州百度关键词排名
  • 盐田高端网站建设贴吧友情链接在哪
  • 网站建设贵州百度seo优化是做什么的
  • 做网站后台的叫什么网站优化有哪些类型
  • 公司内部网站怎么做上海整站seo
  • 网页设计作品网站百度登录账号首页
  • 电子商务网站的功能分析网络营销有几种方式
  • 广州北京网站建设公司seo点击排名软件营销工具
  • 浙江城乡建设网站成都网站搜索排名优化公司
  • 上饶网站建设srsem长沙大型网站建设公司
  • 惠州外贸网站建设推广新网络营销
  • 北京做商铺的网站今日热榜
  • 网站当地公安备案需要什么手续制作网站推广
  • 网站策划与建设国外搜索引擎排行榜
  • 高明区做网站广州抖音推广
  • 美食网站建设服务策划书杭州免费网站制作
  • 苗木企业网站建设源代码 园林网站源码程序 苗圃花卉网站制作源码软文案例200字