three实现一个三维圆球笼子旋转动画效果代码
代码语言:html
所属分类:三维
代码描述:three实现一个三维圆球笼子旋转动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { overflow: hidden; } .canvas-container { height: 100%; width: 100%; } </style> </head> <body> <div class='canvas-container'></div> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.92.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/OrbitControls.js"></script> <script> let SCENE; let CAMERA; let RENDERER; let CONTROLS; main(); function main() { init(); animate(); } function init() { initScene(); initCamera(); initRenderer(); initControls(); initEventListeners(); createObjects(); document.querySelector('.canvas-container').appendChild(RENDERER.domElement); } function initScene() { SCENE = new THREE.Scene(); initLights(); } function initLights() { const point = new THREE.PointLight(0x079fff, 2.5, 300, 1); point.position.set(0, 100, 50); SCENE.add(point); const ambient = new THREE.AmbientLight(0x000510); SCENE.add(ambient); } function initCamera() { CAMERA = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 2000); CAMERA.position.y = 100; CAMERA.position.z = 100; } function initRenderer() { RENDERER = new THREE.WebGLRenderer({ alpha: true }); RENDERER.setPixelRatio(window.devicePixelRatio); RENDERER.setSize(window.innerWidth, window.innerHeight); RENDERER.shadowMap.enabled = true; RENDERER.shadowMapSort = true; RENDERER.setClearColor(0x000510, 1); RENDERER.sortObjects = false; } function initControls() { CONTROLS = new THREE.OrbitControls(CAMERA); CONTROLS.enableZoom = false; CONTROLS.minPolarAngle = 0; CONTROLS.maxPolarAngle = Math.PI * 3 / 4; CONTROLS.update(); } function initEventListeners() { window.addEventListener('resize', onWindowResize); onWindowResize(); } function onWindowResize() { CAMERA.aspect = window.innerWidth / window.innerHeight; CAMERA.updateProjectionMatrix(); RENDERER.setSize(window.innerWidth, window.innerHeight); } function animate() { requestAnimationFrame(animate); CONTROLS.update(); SCENE.traverse(child => { if (child.isMesh) { .........完整代码请登录后点击上方下载按钮下载查看
网友评论0