three实现立方体爬上楼梯堆叠动画效果代码
代码语言:html
所属分类:三维
代码描述:three实现立方体爬上楼梯堆叠动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> @import url(https://fonts.googleapis.com/css?family=Open+Sans:800); body{ margin: 0; padding: 0; overflow: hidden; } footer{ position: absolute; padding: 15px; bottom: 0; } footer a{ font-family:'Open Sans', sans-serif; font-size: 14px; color: #212121; text-decoration: underline; } </style> </head> <body> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/TweenMax.min.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.72.js"></script> <script> var that; var StairwayCubes = function () { this.scene = new THREE.Scene(); that = this; }; StairwayCubes.prototype.init = function () { this.createCamera(); this.createRenderer(); this.createBoxes(); this.createFloor(); this.createLights(); this.animateBoxes(); this.render(); }; StairwayCubes.prototype.createCamera = function () { this.camera = new THREE.OrthographicCamera(window.innerWidth / -2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / -2, -1000, 1000); this.camera.position.x = 100; this.camera.position.y = 100; this.camera.position.z = 100; this.camera.lookAt(new THREE.Vector3(0, 0, 0)); this.camera.zoom = 1.1; this.camera.updateProjectionMatrix(); //Adjust the scene to center the stairs this.scene.position.z = 150; this.scene.position.y = -50; }; StairwayCubes.prototype.createRenderer = function () { this.renderer = new THREE.WebGLRenderer({ antialias: true }); this.renderer.setSize(window.innerWidth, window.innerHeight); this.renderer.setClearColor(0xf2f2f2); this.renderer.shadowMapEnabled = true; this.renderer.shadowMapType = THREE.PCFSoftShadowMap; this.renderer.shadowMapSoft = true; document.body.appendChild(this.renderer.domElement); //window.addEventListener('resize', this.onWindowResize, false); }; StairwayCubes.prototype.createBoxes = function () { this.numberOfStairs = 4; this.repeatBoxeAnimation = this.numberOfStairs - 1; this.stairs = []; var positionZStart = -25; //start position of the stairs on their Z axis var geometry = new THREE.BoxGeometry(50, 50, 50); var material = new THREE.MeshLambertMaterial({ color: 0xf2f2f2, shading: THREE.FlatShading }); //boxe container is usefull to rotate the boxe around his edge this.boxeContainer = new THREE.Object3D(); this.boxeContainer.rotation.x = -2 * Math.PI; this.boxeContainer.position.y = 50; this.boxeContainer.position.z = -50; this.boxe = new THREE.Mesh(geometry, material); this.boxe.position.x = 0; this.boxe.position.y = -25; this.boxe.position.z = 25; this.boxe.castShadow = true; this.boxeContainer.add(this.boxe); this.scene.add(this.boxeContainer); //We create the stairs var geometryStair = new THREE.BoxGeometry(50, 51, 50); geometryStair.applyMatrix(new THREE.Matrix4().makeTranslation(0, 25, 0)); //permit to change the origin point to the box floor for (var i = 1; i <= this.numberOfStairs; i++) { this.stairs[i] = new THREE.Mesh(geometryStair, material); this.stairs[i].position.y = -1; this.stairs[i].position.z = positionZStart - 50; this.stairs[i].scale.y = 0; this.stairs[i].castShadow = true; positionZStart -= 50; this.scene.add(this.stairs[i]); } }; StairwayCubes.prototype.createFl.........完整代码请登录后点击上方下载按钮下载查看
网友评论0