three实现三维发光粒子宇宙银河系星体旋转动画效果代码
代码语言:html
所属分类:三维
代码描述:three实现三维发光粒子宇宙银河系星体旋转动画效果代码,结合lil-gui科修改参数呈现不同的效果。
代码标签: three 三维 发光 粒子 宇宙 银河 星体 旋转 动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta name="viewport" content="width=device-width,initial-scale=1"> <meta charset="UTF-8"> <style> html, body { margin: 0; overflow: hidden; } .webgl { position: fixed; outline: none; width: 100%; height: 100%; } </style> </head> <body > <canvas class="webgl"></canvas> <script type="importmap">{ "imports": { "three": "//repo.bfw.wiki/bfwrepo/js/module/three/build/three.module.js" } }</script> <script type="module"> import GUI from '//repo.bfw.wiki/bfwrepo/js/lil-gui.esm.js'; import { Clock } from "three"; import { OrbitControls } from '//repo.bfw.wiki/bfwrepo/js/module/three/examples/jsm/controls/OrbitControls.js'; import * as THREE from "three"; import { Perlin } from "//repo.bfw.wiki/bfwrepo/js/module/three-noise.js"; const gui = new GUI(); gui.close(); const scene = new THREE.Scene(); /** * Galaxy */ const parameters = { branchCount: 25000, size: 0.01, galaxyRadius: 20, branches: 40, noiseScale: 0.2, turnTheta: Math.PI * 0.75, randomness: 2, randomnessPower: 4.8, insideColor: '#14ffd8', outsideColor: '#ff00f7' }; let geometry = null; let material = null; let points = null; const generateGalaxy = () => { /** * Destroy previous galaxy */ if (points !== null) { geometry.dispose(); material.dispose(); scene.remove(points); } /** * Geometry */ geometry = new THREE.BufferGeometry(); const positions = new Float32Array(parameters.branchCount * 3 * parameters.branches); const colors = new Float32Array(parameters.branchCount * 3 * parameters.branches); const colorInside = new THREE.Color(parameters.insideColor); const outsideColor = new THREE.Color(parameters.outsideColor); const perlin = new Perlin(Math.random()); for (let branch = 0; branch < parameters.branches; branch++) { const theta = branch * ((Math.PI * 2.0) / parameters.branches); let point = new THREE.Vector2(Math.cos(theta) * 0.01, Math.sin(theta) * 0.01); for (let index = .........完整代码请登录后点击上方下载按钮下载查看
网友评论0