cannon+three实现设定点数三维掷骰子效果代码
代码语言:html
所属分类:三维
代码描述:cannon+three实现设定点数三维掷骰子效果代码,两个骰子会根据你设定好的点数落地呈现预定点数。
代码标签: cannon three 设定 点数 三维 掷骰子
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> html, body { padding: 0; margin: 0; } body { height: 100vh; display: flex; align-items: end; justify-content: center; } .container { width: 100%; height: 100%; background-image: linear-gradient(#6DD5FA, #2980B9); } .lil-gui { --width: 450px; max-width: 90%; --widget-height: 20px; font-size: 15px; --input-font-size: 15px; --padding: 10px; --spacing: 10px; --slider-knob-width: 5px; --background-color: rgba(5, 0, 15, .8); --widget-color: rgba(255, 255, 255, .3); --focus-color: rgba(255, 255, 255, .4); --hover-color: rgba(255, 255, 255, .5); --font-family: monospace; } </style> </head> <body translate="no"> <div class="container"> <canvas id="canvas"></canvas> </div> <script type="importmap">{ "imports": { "three": "//repo.bfw.wiki/bfwrepo/js/module/three/build/164/three.module.js", "three/addons/": "//repo.bfw.wiki/bfwrepo/js/module/three/examples/164/jsm/" } } </script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/es-module-shims.1.6.3.js"></script> <script type="module"> import * as CANNON from "//repo.bfw.wiki/bfwrepo/js/module/cannon-es.0.20.0.js"; import * as THREE from "three"; import * as BufferGeometryUtils from "three/addons/utils/BufferGeometryUtils.js"; import GUI from "//repo.bfw.wiki/bfwrepo/js/lil-gui.esm.js"; const containerEl = document.querySelector(".container"); const canvasEl = document.querySelector("#canvas"); let renderer, scene, camera, diceMesh, physicsRender, simulation; let simulationOn = true; let currentResult = [0, 0]; const params = { // dice segments: 40, edgeRadius: .08, notchRadius: .15, notchDepth: .17, // physics restitution: .3, friction: .1, // ux desiredResult: 7, throw: throwMe }; function throwMe() { simulationOn = true; throwDice(); } const diceArray = []; const floorPlanesArray = []; let throwBtn; initPhysics(); initScene(); createFloor().........完整代码请登录后点击上方下载按钮下载查看
网友评论0