three+cannon实现三维小球搅拌重力模拟效果代码
代码语言:html
所属分类:三维
代码描述:three+cannon实现三维小球搅拌重力模拟效果代码
代码标签: three cannon 三维 小球 搅拌 重力 模拟
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> html { font-family: "Ropa Sans", Arial, sans-serif; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; } *, *::after, *::before { box-sizing: border-box; } body { padding: 0; margin: 0; background-color: #333333; overflow: hidden; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } a { font-size: 22px; color: #fff; text-decoration: none; padding: 10px; transition: background-color 0.3s, color 0.3s; } a:hover { color: #390fff; background-color: #fff; } section { margin: 10px; position: absolute; z-index: 1; bottom: 0; width: 100%; } #stats { position: absolute; } </style> </head> <body > <div id="stats"></div> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/Stats-16.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.144.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/OrbitControls.144.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/TransformControls.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/tweakpane.3.02.js"></script> <script type="module"> import * as CANNON from "//repo.bfw.wiki/bfwrepo/js/module/cannon-es.0.20.0.js"; const hexToRgb = hex => { const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); return result ? { r: parseInt(result[1], 16) / 255, g: parseInt(result[2], 16) / 255, b: parseInt(result[3], 16) / 255 } : null; }; const rgbToHex = (s) => s.match(/[0-9]+/g).reduce((a, b) => a + (b | 256).toString(16).slice(1), "#"); class App { constructor() { this.settings = { velocity: 0.015, width: window.innerWidth, height: window.innerHeight, debug: false, colors: { background: rgbToHex( window.getComputedStyle(document.body).backgroundColor), floor: rgbToHex(window.getComputedStyle(document.body).backgroundColor), box: "#390fff", spheres: { left: "#390fff", right: "#ffffff" }, ambientLight: "#ffffff", directionalLight: "#ffffff", pointLight: "#390fff" } }; } init() { this.setup(); this.createScene(); this.createCamera(); this.addCameraControls(); this.addAmbientLight(); this.addDirectionalLight(); this.addPhysicsWorld(); this.addPointLight(); this.addFloor(); this.addBox(); this.addPropeller(); this.addInnerBoudaries(); this.addWindowListeners(); this.addGuiControls(); this.addInitialSpheres(); this.addStatsMonitor(); this.animate(); } addGuiControls() { this.pane = new Tweakpane.Pane(); this.guiSettings = this.pane.addFolder({ title: "Colors", expanded: false }); this.guiSettings. addInput(this.settings.colors, "background"). on("change", evt => { this.floor.material.color = hexToRgb(evt.value); document.body.........完整代码请登录后点击上方下载按钮下载查看
网友评论0