Last active
May 1, 2024 21:15
-
-
Save toto-castaldi/269b4f3b515355f8e2ef to your computer and use it in GitHub Desktop.
three.js mesh sphere scaling with Tweens
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <body></body> | |
| <script src="http://gamingJS.com/Three.js"></script> | |
| <script src="http://gamingJS.com/ChromeFixes.js"></script> | |
| <script src="http://gamingJS.com/Tween.js"></script> | |
| <script> | |
| var scene = new THREE.Scene(); | |
| var width = window.innerWidth - 20; | |
| var height = window.innerHeight - 20; | |
| var aspect_ratio = width / height; | |
| var camera = new THREE.PerspectiveCamera(75, aspect_ratio, 1, 10000); | |
| camera.position.z = 500; | |
| scene.add(camera); | |
| var renderer = new THREE.WebGLRenderer(); | |
| renderer.shadowMapEnabled = true; | |
| renderer.setSize(width, height); | |
| document.body.appendChild(renderer.domElement); | |
| //############################################## | |
| var cover = new THREE.MeshNormalMaterial(); | |
| var sphereShape = new THREE.SphereGeometry(100, 20, 15); | |
| var sphereMesh = new THREE.Mesh(sphereShape, cover); | |
| scene.add(sphereMesh); | |
| var clock = new THREE.Clock(); | |
| function animate() { | |
| requestAnimationFrame(animate); | |
| var t = clock.getElapsedTime(); | |
| TWEEN.update(); | |
| renderer.render(scene, camera); | |
| } | |
| var buildUp = function () { | |
| return new TWEEN.Tween({ | |
| scale: 1 | |
| }).to ({ | |
| scale : 3 | |
| }, 2000).onUpdate(function () { | |
| sphereMesh.scale.x = this.scale; | |
| }).onComplete(function () { | |
| buildDown().start(); | |
| }); | |
| }; | |
| var buildDown = function () { | |
| return new TWEEN.Tween({ | |
| scale: 3 | |
| }).to ({ | |
| scale : 1 | |
| }, 2000).onUpdate(function () { | |
| sphereMesh.scale.x = this.scale; | |
| }).onComplete(function () { | |
| buildUp().start(); | |
| }); | |
| }; | |
| buildUp().start(); | |
| animate(); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment