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

稷山网站制作数据分析培训课程

稷山网站制作,数据分析培训课程,兼职游戏网站怎么做,做网站需要学哪些软件前言:这是一个3d打印局域网管理系统的需求 一、安装three.js three.js官网:https://threejs.org/docs/#manual/en/introduction/Installation 我用的是yarn,官网用的是npm 二、使用three.js 1.在script部分导入three.js import * as THREE from thr…

前言:这是一个3d打印局域网管理系统的需求

一、安装three.js

three.js官网:https://threejs.org/docs/#manual/en/introduction/Installation

我用的是yarn,官网用的是npm

二、使用three.js

1.在script部分导入three.js

import * as THREE from 'three';

2.基础使用

=》创建场景:场景是three.js中用于存储所有3D对象的容器。它相当于一个虚拟的3D空间,所有对象(如几何体、灯光等)都会被添加到场景中。

const scene = new THREE.Scene();//创建场景

=》创建相机:相机用于定义用户观察场景的视角。这里使用的是PerspectiveCamera,它模拟了真实世界的透视效果。

//创建相机
const camera = new THREE.PerspectiveCamera(75,window.innerWidth/window.innerHeight,0.1,1000);

它的参数分别是:

->FOV(Field of View):视野角度,单位是度。这里设置为75,表示相机能看到的范围。

->宽高比(Aspect Ratio):通常是容器的宽度除以高度。这里使用window.innerWidth / window.innerHeight,确保在场景不同屏幕尺寸下不会变形。

->近裁剪面(Near Clipping Plane):距离相机最近的渲染范围,小于这个值的物体不会被渲染。这里设置为0.1。

->远裁剪面(Far Clipping Plane):距离相机最远的渲染范围,大于这个值的物体不会被渲染。这里设置为1000。

=》创建渲染器:渲染器的作用是将场景渲染到屏幕上。这里使用的是WebGLRenderer,它利用WebGL技术在浏览器中渲染3D图形。setSize方法设置了渲染器的尺寸,通常与浏览器窗口的大小一致。最后,将渲染器的domElement(一个<canvas>元素)添加到HTML文档中。

//创建渲染器
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth,window.innerHeight);
document.body.appendChild(renderer.domElement);

=》创建立方体:

//创建立方体
const geometry = new THREE.BoxGeometry(1,1,1);
const material = new THREE.MeshBasicMaterial({color:0x00ff00});
const cube = new THREE.Mesh(geometry,material);
scene.add(cube); 

->几何体(Geometry):定义了对象的形状。这里使用BoxGeometry创建了一个边长为1的立方体。

->材质(Material):定义了对象的外观。这里使用MeshBasicMaterial,并设置颜色为绿色(0x00ff00)。

->网格(Mesh):将几何体和材质组合在一起,形成一个可渲染的对象。最后,将立方体添加到场景中。

=》调整相机位置:默认情况下,相机和立方体都在场景的原点(0, 0, 0)。为了避免它们重叠,将相机沿Z轴向后移动5个单位。

//调整相机位置
camera.position.z = 5;

=》动画循环:

//动画循环
function animate(){cube.rotation.x += 0.01;cube.rotation.y += 0.01;renderer.render(scene,camera);}
renderer.setAnimationLoop(animate);

->动画逻辑:在animate函数中,每帧更新立方体的旋转角度(rotation.x和rotation.y),使其围绕X轴和Y轴旋转。

->渲染场景:调用renderer.render(scene, camera)将场景渲染到屏幕上。

->循环调用:renderer.setAnimationLoop(animate)会自动调用animate函数,并在浏览器刷新时重新渲染场景,通常每秒60次。

3.综合使用

这里创建一个文件名为Three.vue的vue文件

<template><div ref="threeJsContainer" class="three-js-container"></div></template><script>import * as THREE from 'three';export default {name: 'ThreeJsComponent',mounted() {this.initThreeJs();},methods: {initThreeJs() {// 创建场景const scene = new THREE.Scene();// 创建相机const camera = new THREE.PerspectiveCamera(75,window.innerWidth / window.innerHeight,0.1,1000);camera.position.z = 5;// 创建渲染器const renderer = new THREE.WebGLRenderer();renderer.setSize(window.innerWidth, window.innerHeight);// 将渲染器的 canvas 添加到 Vue 组件的 div 中this.$refs.threeJsContainer.appendChild(renderer.domElement);// 创建立方体const geometry = new THREE.BoxGeometry(1, 1, 1);const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });const cube = new THREE.Mesh(geometry, material);scene.add(cube);// 动画循环const animate = () => {cube.rotation.x += 0.01;cube.rotation.y += 0.01;renderer.render(scene, camera);};renderer.setAnimationLoop(animate);}}};</script><style scoped>.three-js-container {width: 100vw;height: 100vh;}</style>

在App组件中导入并使用这个组件,不出意外就可看到一个旋转的绿色正方体

4.展示ply文件

我下载了blender软件,导出了一个ply文件,这个ply文件放在项目的public文件夹

先导入所需的文件

import * as THREE from 'three';
import { PLYLoader } from 'three/examples/jsm/loaders/PLYLoader.js';
<template><h1>我是PLY</h1><div ref="threeContainer" class="three-container"></div><h1>你呢</h1>
</template><script>
import * as THREE from 'three';
import { PLYLoader } from 'three/examples/jsm/loaders/PLYLoader.js';export default {name: 'PLY',mounted() {this.initThree();},methods: {initThree() {console.log("ply");// 创建场景const scene = new THREE.Scene();// 创建相机const camera = new THREE.PerspectiveCamera(75,window.innerWidth / window.innerHeight,0.1,1000);camera.position.set(0, 0, 10); // 调整相机位置camera.lookAt(scene.position); // 让相机朝向场景中心// 添加光源const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);scene.add(ambientLight);const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);directionalLight.position.set(1, 1, 1);scene.add(directionalLight);// 创建渲染器const renderer = new THREE.WebGLRenderer();renderer.setSize(window.innerWidth, window.innerHeight);// 将渲染器的 canvas 添加到 Vue 组件的 div 中this.$refs.threeContainer.appendChild(renderer.domElement);// 加载 .ply 文件let mesh; // 声明一个变量用于存储加载的网格const loader = new PLYLoader();loader.load('/2.ply', function (geometry) {// 计算顶点法线geometry.computeVertexNormals();const material = new THREE.MeshStandardMaterial({ color: 0xffffff });mesh = new THREE.Mesh(geometry, material); // 将加载的网格存储到变量中scene.add(mesh);});// 动画循环const animate = () => {if (mesh) {// 每帧让物体绕 x 轴和 y 轴旋转mesh.rotation.x += 0.01;mesh.rotation.y += 0.01;}renderer.render(scene, camera);};renderer.setAnimationLoop(animate);}}
};
</script>
<style scoped>
.three-container {width: 100%;height: 100%;
}
</style>

5.展示stl文件

文件是一个同学发给我的,一个城堡

其实这个是和ply同理的,只是导入的文件不同

import * as THREE from 'three';import { STLLoader } from 'three/examples/jsm/loaders/STLLoader.js';
<template><h1>我是STL</h1><div ref="threeContainer" class="three-container"></div><h1>你呢</h1></template><script>import * as THREE from 'three';import { STLLoader } from 'three/examples/jsm/loaders/STLLoader.js';export default {name: 'STL',mounted() {this.initThree();},methods: {initThree() {console.log("stl");// 创建场景const scene = new THREE.Scene();// 创建相机const camera = new THREE.PerspectiveCamera(75,window.innerWidth / window.innerHeight,0.1,1000);camera.position.set(0, 0, 10); // 调整相机位置camera.lookAt(scene.position); // 让相机朝向场景中心// 添加光源const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);scene.add(ambientLight);const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);directionalLight.position.set(1, 1, 1);scene.add(directionalLight);// 创建渲染器const renderer = new THREE.WebGLRenderer();renderer.setSize(window.innerWidth, window.innerHeight);// 将渲染器的 canvas 添加到 Vue 组件的 div 中this.$refs.threeContainer.appendChild(renderer.domElement);// 加载 .stl 文件let mesh; // 用于存储加载的模型const loader = new STLLoader(); // 使用 STLLoader 加载 STL 文件loader.load('/chengbao.stl', function (geometry) {// STL 文件通常不需要计算顶点法线,因为它们是三角形网格// 居中几何体(确保模型的几何中心在原点)geometry.center();// 创建渐变材质const uniforms = {iTime: { value: 0 },iResolution: { value: new THREE.Vector2(window.innerWidth, window.innerHeight) }};const material = new THREE.ShaderMaterial({uniforms: uniforms,vertexShader: `varying vec2 vUv;void main() {vUv = uv;gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);}`,fragmentShader: `precision highp float;uniform float iTime;uniform vec2 iResolution;varying vec2 vUv;// 渐变颜色定义const vec3 colors[5] = vec3[](vec3(0., 0., 0.6),vec3(0., 1., 1.),vec3(0.0, 1.0, 0.),vec3(1.0, 1.0, 0.),vec3(1.0, 0.0, 0.));const float points[5] = float[](0.0, 0.15, 0.5, 0.65, 1.0);vec3 gradian(vec3 c1, vec3 c2, float a) {return mix(c1, c2, a);}vec3 heat4(float weight) {if (weight <= points[0]) return colors[0];if (weight >= points[4]) return colors[4];for (int i = 1; i < 5; i++) {if (weight < points[i]) {float a = (weight - points[i - 1]) / (points[i] - points[i - 1]);return gradian(colors[i - 1], colors[i], a);}}return vec3(0.0);}void main() {float weight = (vUv.x + vUv.y + iTime) / 10.0; // 根据时间动态调整权重vec3 color = heat4(weight);float alpha = sin(iTime) * 0.5 + 0.5; // 透明度在 0 到 1 之间变化gl_FragColor = vec4(color, alpha);}`,transparent: true // 启用透明度});mesh = new THREE.Mesh(geometry, material); // 创建网格mesh.position.set(0, 0, 0); // 确保模型在场景中心mesh.scale.set(0.1, 0.1, 0.1); // 调整模型大小(根据需要)scene.add(mesh); // 将模型添加到场景中});// 鼠标滑动控制渐变速度和模型旋转let lastTime = performance.now();let lastMouseX = 0;let lastMouseY = 0;renderer.domElement.addEventListener('mousemove', (event) => {const now = performance.now();const deltaTime = (now - lastTime) / 1000; // 时间差(秒)const mouseX = event.clientX;const mouseY = event.clientY;const deltaX = mouseX - lastMouseX;const deltaY = mouseY - lastMouseY;const speed = Math.sqrt(deltaX * deltaX + deltaY * deltaY); // 鼠标滑动速度const speedFactor = speed * deltaTime; // 速度因子if (mesh) {mesh.material.uniforms.iTime.value += speedFactor; // 根据鼠标滑动速度调整时间mesh.rotation.y += deltaX * 0.001; // 水平旋转mesh.rotation.x -= deltaY * 0.001; // 垂直旋转}lastTime = now;lastMouseX = mouseX;lastMouseY = mouseY;});// 动画循环const animate = () => {renderer.render(scene, camera); // 渲染场景};renderer.setAnimationLoop(animate); // 设置动画循环}}};</script><style scoped>.three-container {width: 100%;height: 100%;}</style>

我这个做了更花哨的效果,可以渐变


文章转载自:
http://reval.spkw.cn
http://dynamo.spkw.cn
http://repeat.spkw.cn
http://nightwork.spkw.cn
http://ullmannite.spkw.cn
http://luce.spkw.cn
http://rhamnus.spkw.cn
http://pleasantry.spkw.cn
http://fulmination.spkw.cn
http://fursemide.spkw.cn
http://sabre.spkw.cn
http://carnation.spkw.cn
http://flywheel.spkw.cn
http://furtively.spkw.cn
http://outfielder.spkw.cn
http://anvil.spkw.cn
http://dyad.spkw.cn
http://personation.spkw.cn
http://hydrotropic.spkw.cn
http://metathoracic.spkw.cn
http://applicably.spkw.cn
http://tanghan.spkw.cn
http://recanalization.spkw.cn
http://pleading.spkw.cn
http://afflux.spkw.cn
http://batholithic.spkw.cn
http://include.spkw.cn
http://adenocarcinoma.spkw.cn
http://crossbeam.spkw.cn
http://continually.spkw.cn
http://funeral.spkw.cn
http://jst.spkw.cn
http://hymnography.spkw.cn
http://antonia.spkw.cn
http://disequilibrate.spkw.cn
http://utter.spkw.cn
http://inhabitance.spkw.cn
http://prelection.spkw.cn
http://wishfully.spkw.cn
http://spermatogenous.spkw.cn
http://soavemente.spkw.cn
http://blowhard.spkw.cn
http://capo.spkw.cn
http://sinner.spkw.cn
http://semiweekly.spkw.cn
http://cankery.spkw.cn
http://fritting.spkw.cn
http://exophasia.spkw.cn
http://hoer.spkw.cn
http://crofting.spkw.cn
http://despotically.spkw.cn
http://fogram.spkw.cn
http://thereinafter.spkw.cn
http://phytotomy.spkw.cn
http://inspection.spkw.cn
http://treetop.spkw.cn
http://tasmania.spkw.cn
http://hyperadenosis.spkw.cn
http://gran.spkw.cn
http://murex.spkw.cn
http://intrusively.spkw.cn
http://chockablock.spkw.cn
http://curitiba.spkw.cn
http://isobel.spkw.cn
http://gunner.spkw.cn
http://janitress.spkw.cn
http://etesian.spkw.cn
http://snippety.spkw.cn
http://hyperphysically.spkw.cn
http://tinman.spkw.cn
http://dracone.spkw.cn
http://pileorhiza.spkw.cn
http://suffosion.spkw.cn
http://stage.spkw.cn
http://tenantlike.spkw.cn
http://corrugation.spkw.cn
http://myrrhic.spkw.cn
http://zibeline.spkw.cn
http://moorcock.spkw.cn
http://irritated.spkw.cn
http://shearlegs.spkw.cn
http://gibblegabble.spkw.cn
http://phagun.spkw.cn
http://hematoxylin.spkw.cn
http://extoll.spkw.cn
http://circumscription.spkw.cn
http://septennia.spkw.cn
http://deoxygenize.spkw.cn
http://distain.spkw.cn
http://overhit.spkw.cn
http://hectograph.spkw.cn
http://doum.spkw.cn
http://unbelted.spkw.cn
http://devilishly.spkw.cn
http://grapeshot.spkw.cn
http://lotusland.spkw.cn
http://verminous.spkw.cn
http://athymic.spkw.cn
http://prettification.spkw.cn
http://academicism.spkw.cn
http://www.15wanjia.com/news/99149.html

相关文章:

  • 济宁建设网站首页推广营销大的公司
  • 只做衬衫的网站网站平台都有哪些
  • 嘉定网站设计开发国家市场监管总局官网
  • wordpress 用户组可见宁波seo网络推广代理公司
  • 山东 网站备案九幺seo优化神器
  • 做网站的大公司都有哪些合肥seo快排扣费
  • 广州市学校网站建设公司seo谷歌
  • 长沙做旅游网站多少钱日照seo优化
  • 物流官方网站东莞网络优化公司
  • 石景山成都网站建设关键词seo
  • 弄淘宝招牌图什么网站可以做泰安做网站公司
  • 电商网站建设教程西安网站优化
  • 计算机培训机构培训出来好就业吗沧州搜索引擎优化
  • 建团购网站个人接外包的网站
  • 巩义企业网站托管服务商软文代写新闻稿
  • 香水网络营销策划方案seo怎么做?
  • bash做网站网络营销管理办法
  • 教育网站建站需求杭州seook优屏网络
  • 滑坡毕业设计代做网站优化快速排名公司
  • 刚做的单页网站怎么预览搜易网优化的效果如何
  • web网站开发用什么语言国外网站搭建
  • 外国做愛视频网站媒介星软文平台官网
  • 网站开发 需求网站优化推广外包
  • 湖南做网站 f磐石网络宁波最好的seo外包
  • 建筑行业培训苏州seo网络推广
  • wordpress相关网站广告推广费用
  • 网站开发 文件架构图seo营销名词解释
  • 新疆建设云网站怎么查询证书如何用手机免费创建网站
  • 网站开发简单百度网站怎么做
  • win7 做网站服务器广州抖音推广公司