babylon实现宇宙戴森球三维模型动画代码
代码语言:html
所属分类:三维
代码描述:babylon实现宇宙戴森球三维模型动画代码,可以缩放旋转进入能量球内部。
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <style> #renderCanvas { position: absolute; width: 100%; height: 100%; touch-action: none; left: 0%; right: 0%; bottom:0%; top: 0%; } html, body { overflow: hidden; width: 100%; height: 100%; margin: 0; padding: 0; font-family: 'Rajdhani', sans-serif; color: white; font-size: large; } a:link, a:visited { background-color: #f44336; color: white; padding: 14px 25px; text-align: center; text-decoration: none; display: inline-block; } .container { position: relative; height: 100%; width: 100%; } .header { position: absolute; left:0; right:0; top:0; padding-left:10px; text-align: center; } .footer { position: absolute; right:0; bottom:0; margin:5px; padding:5px; } a:hover, a:active { background-color: red; } .center { position: absolute; background-color: #00bfa5; left: 0%; right: 0%; bottom:0%; top: 0%; margin:10px; padding:10px; } #fps { position: absolute; background-color: black; border: 2px solid red; text-align: center; font-size: 16px; color: white; top: 15px; right: 10px; width: 60px; height: 20px; } </style> <link href="https://fonts.googleapis.com/css2?family=Rajdhani:wght@500&display=swap" rel="stylesheet"> <!-- Babylon.js --> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/dat.gui-min.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/ammo.min.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/cannon.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/Oimo.min.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/earcut.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/babylon.5.2.0.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/babylonjs.materials.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/babylonjs.proceduralTextures.min.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/babylonjs.postProcess.min.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/babylonjs.loaders.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/babylonjs.serializers.min.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/babylon.gui.min.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/babylon.inspector.bundle.js"></script> </head> <body> <div class="container"> <div class="container"><canvas id="renderCanvas" class="container" /></div> </div> <div id="fps">0</div> <script> const TEXTURE_FOLDER = "https://www.babylonjs-playground.com/textures/"; const GROUND_SIZE = 50; const SKYBOX_SIZE = GROUND_SIZE * 5.0; var quality = 10; const FUR_TEXTURE = "//repo.bfw.wiki/bfwrepo/image/625b6bbc5f411.png"; const DOME_TEXTURE = "//repo.bfw.wiki/bfwrepo/image/625b6becbac74.png"; const SKYBOX = "//repo.bfw.wiki/bfwrepo/image/625b6c41d20a5.jpeg"; // States var g_timer = null; var animateCamera = true; var shouldAnimate = false; createHemisphere = (scene, outerRadi = 10, innerRadi = 8) => { let detail = 16; let outerSphere = BABYLON.MeshBuilder.CreateSphere("outerSphere", { diameter: outerRadi * 2, segments: detail }); let innerSphere = BABYLON.MeshBuilder.CreateSphere("innerSphere", { diameter: innerRadi * 2, segments: detail }); let box = BABYLON.MeshBuilder.CreateBox( "box", { size: outerRadi * 2 }, scene); box.position.y = outerRadi; let hole1 = BABYLON.CSG.FromMesh(outerSphere); let hole2 = BABYLON.CSG.FromMesh(innerSphere); let hole3 = BABYLON.CSG.FromMesh(box); let newHolePlate = hole1.subtract(hole2).subtract(hole3); box.dispose(); innerSphere.dispose(); outerSphere.dispose(); let hemiSphere = newHolePlate.toMesh("hemiSphere", null, scene); return hemiSphere; }; // Views const divFps = document.getElementById("fps"); const canvas = document.getElementById("renderCanvas"); // Essential const engine = new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: true, stencil: true }); const scene = new BABYLON.Scene(engine); scene.enablePhysics(new BABYLON.Vector3(0, -10, 0)); scene.clearColor = new BABYLON.Color3.Black(); var ambientLight = new BABYLON.HemisphericLight("ambientLight", .........完整代码请登录后点击上方下载按钮下载查看
网友评论0