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

three粒子飘动效果

1、总结

<template> <div id="box"></div> </template> <script setup> import * as three from 'three'; import { onMounted } from 'vue'; import { OrbitControls } from 'three/addons/controls/OrbitControls.js'; import ring from "../assets/ring_a.png" onMounted(() => { const box = document.querySelector("#box") const scene = new three.Scene() const textLoader = new three.TextureLoader() const ringMap = textLoader.load(ring) let count = 6000 //点的个数 const particleGeometry = new three.BufferGeometry() const positions = new Float32Array(count * 3) const colors = new Float32Array(count * 3) for (let i = 0; i < count * 3; i++) { positions[i] = (Math.random() - 0.5) * 20 //-5 - 5 //*后面的数表示的是范围 colors[i] = Math.random()// 0-1 } particleGeometry.setAttribute('position', new three.BufferAttribute(positions, 3)) particleGeometry.setAttribute('color', new three.BufferAttribute(colors, 3)) const particleMaterial = new three.PointsMaterial({ size: 0.1, transparent: true, sizeAttenuation: true//大小进行衰减 }) particleMaterial.map = ringMap // particleMaterial.depthTest=false//第一种方案,设置为false就可以看到后面的元素了 particleMaterial.depthWrite = false//第二种方案,设置为false就可以看到后面的元素了 particleMaterial.blending = three.AdditiveBlending //开启混合,就是颜色会混合 particleMaterial.vertexColors = true//开启后:粒子颜色 = 几何体顶点上设置的 colors 数组 const particle = new three.Points(particleGeometry, particleMaterial) scene.add(particle) // 聚光灯 const spotLight = new three.SpotLight(0xffffff, 200); spotLight.position.set(0, 0, 10); spotLight.castShadow = true spotLight.shadow.camera.near = 1 spotLight.shadow.camera.far = 300 spotLight.shadow.camera.fov = 20 scene.add(spotLight) const sizes = { width: window.innerWidth, height: window.innerHeight } const camera = new three.PerspectiveCamera(75, sizes.width / sizes.height) camera.position.set(-10, 0.5, 5) camera.lookAt(0, 0, 0) scene.add(camera) // const axesHelper = new three.AxesHelper(100) // scene.add(axesHelper) const renderer = new three.WebGLRenderer() renderer.setSize(sizes.width, sizes.height) renderer.shadowMap.enabled = true // 2. 必须开启渲染器阴影 const controls = new OrbitControls(camera, renderer.domElement) controls.addEventListener("change", () => { renderer.render(scene, camera) }) renderer.render(scene, camera) box.appendChild(renderer.domElement) const clock = new three.Clock() animation() function animation() { renderer.render(scene, camera) const time = clock.getElapsedTime() // particle.rotation.y = time * 0.2//旋转 for (let i = 0; i < count; i++) { const i3 = i * 3 const x = particleGeometry.attributes.position.array[i3] //particleGeometry.attributes.position.array获取的是1维数组 particleGeometry.attributes.position.array[i3 + 1] = Math.sin(time + x) } particleGeometry.attributes.position.needsUpdate = true // controls.update() requestAnimationFrame(animation) } }) </script>

http://www.jsqmd.com/news/786507/

相关文章:

  • CANN/cannbot-skills:KVCache Offload 异步搬运流案例
  • 电源管理设计:能效优化与同步整流技术实践
  • 使用 Taotoken 聚合多模型 API 为创业项目构建智能客服原型
  • 解锁以太坊交易效率:PBS 与棘刺雕猴的深度实践
  • 深度定制Linux内核:为特定硬件优化CPU调度与电源管理
  • IncreRTL框架:基于LLM的精准增量RTL代码生成技术
  • 大模型智能体框架big-brain:从原理到生产部署的工程实践
  • 构建AI增强的网状思维工作流:从MCP协议到多智能体协同的实践
  • AI编程助手防忽悠指南:用文件契约与自动化验证提升协作效率
  • 大路灯什么品牌好用又亮?揭秘护眼大路灯综合榜十强,优质健康光
  • 力反馈差分量化技术:提升机器人布料操作稳定性
  • 多模态AI如何重塑教育:从理论到实践的课堂革命
  • 3个步骤搞定SD-WebUI-Inpaint-Anything自定义修复模型:告别“找不到模型“的烦恼
  • PostGIS实现多波段栅格数据转单波段灰度图【ST_Grayscale】
  • 初次使用 Taotoken 模型广场进行选型与试用的感受
  • 拿PMP证书到底值不值?从薪资影响看清晖这类机构的价值
  • 大模型应用可观测性实战:从黑盒调试到成本优化
  • 内容创作团队如何通过Taotoken调度不同模型完成多样化文案生成
  • 边缘LLM自适应混合精度量化技术APreQEL解析
  • Python 爬虫高级实战:Playwright 动态渲染爬虫开发
  • 物联网 MQTT 安全:风险分析与实战防御策略深度解析
  • AI Agent成本优化实战:智能模型路由与上下文压缩技术解析
  • localtime和gmtime获取的时间不可靠
  • 从简单夹爪到灵巧手的运动映射:原理、实现与机器人抓取技能迁移
  • 助睿ETL入门实验指导
  • 跨境电商提效必看:6款指纹浏览器RPA功能深度对比
  • OpenClaw(小龙虾 AI)完整安装使用教程
  • 用专业微光,吸引技术实习生主动奔赴
  • Portage开源项目:构建跨平台AI技能市场,实现技能一次编写处处运行
  • 如何获取最完整的 AVC 日志?