<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="de">
	<id>https://wiki.stephanschlegel.de/index.php?action=history&amp;feed=atom&amp;title=Three.js_-_Animation</id>
	<title>Three.js - Animation - Versionsgeschichte</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.stephanschlegel.de/index.php?action=history&amp;feed=atom&amp;title=Three.js_-_Animation"/>
	<link rel="alternate" type="text/html" href="https://wiki.stephanschlegel.de/index.php?title=Three.js_-_Animation&amp;action=history"/>
	<updated>2026-05-06T16:13:12Z</updated>
	<subtitle>Versionsgeschichte dieser Seite in Wikizone</subtitle>
	<generator>MediaWiki 1.35.14</generator>
	<entry>
		<id>https://wiki.stephanschlegel.de/index.php?title=Three.js_-_Animation&amp;diff=25677&amp;oldid=prev</id>
		<title>Steff: Die Seite wurde neu angelegt: „== Links ==  ThreeJS - Snippets == Techniques == === Timebased Tick / Loop Function === Für Animationen können wir in einem Loop die Szene Rendern, Objek…“</title>
		<link rel="alternate" type="text/html" href="https://wiki.stephanschlegel.de/index.php?title=Three.js_-_Animation&amp;diff=25677&amp;oldid=prev"/>
		<updated>2021-12-30T20:11:51Z</updated>

		<summary type="html">&lt;p&gt;Die Seite wurde neu angelegt: „== Links ==  &lt;a href=&quot;/index.php?title=ThreeJS_-_Snippets&quot; title=&quot;ThreeJS - Snippets&quot;&gt;ThreeJS - Snippets&lt;/a&gt; == Techniques == === Timebased Tick / Loop Function === Für Animationen können wir in einem Loop die Szene Rendern, Objek…“&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Neue Seite&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Links ==&lt;br /&gt;
 [[ThreeJS - Snippets]]&lt;br /&gt;
== Techniques ==&lt;br /&gt;
=== Timebased Tick / Loop Function ===&lt;br /&gt;
Für Animationen können wir in einem Loop die Szene Rendern, Objekte verändern, Szene erneut Rendern usw. In JavaScript kann man dazu die window.requestAnimationFrame Funktion nutzen. Damit die zeitlichen Abläufe nicht von der Rechnerleistung sondern rein von der Zeit abhängen gibt es einige Möglichkeiten diesen Loop umzusetzen.&lt;br /&gt;
&lt;br /&gt;
Die Beispiele setzen eine Setup mit einem Camera Object &amp;#039;camera&amp;#039;, einer Szene scene, und einem Renderer &amp;#039;renderer&amp;#039; voraus. Du kannst z.B. das Beispiel auf der Hauptseite nutzen.&lt;br /&gt;
==== Pure JavaScript calculation ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
let time = Date.now() &lt;br /&gt;
const tick = () =&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    // JS based time calculation&lt;br /&gt;
    const currentTime = Date.now()&lt;br /&gt;
    const deltaTime = currentTime - time&lt;br /&gt;
    time = currentTime&lt;br /&gt;
    //console.log(deltaTime)&lt;br /&gt;
    // Update objects&lt;br /&gt;
    mesh.rotation.y += 0.001 * deltaTime&lt;br /&gt;
    renderer.render(scene, camera)&lt;br /&gt;
    // tell JS to call tick on the next frame&lt;br /&gt;
    window.requestAnimationFrame(tick) &lt;br /&gt;
}&lt;br /&gt;
// go...&lt;br /&gt;
tick()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ThreeJS Clock Object ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
const clock = new THREE.Clock()&lt;br /&gt;
const tick = () =&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    // Hint: do NOT use clock.getDelta() - it can cause problems (buggy in end of 2021)&lt;br /&gt;
    const elapsedTime = clock.getElapsedTime()&lt;br /&gt;
    //console.log(elapsedTime)&lt;br /&gt;
    mesh.rotation.y = elapsedTime * Math.PI * 2 // one revolution / s&lt;br /&gt;
    camera.lookAt(mesh.position)&lt;br /&gt;
    camera.position.z = Math.sin(elapsedTime) // back and forth&lt;br /&gt;
    // Render&lt;br /&gt;
    renderer.render(scene, camera)&lt;br /&gt;
    window.requestAnimationFrame(tick) &lt;br /&gt;
}&lt;br /&gt;
tick()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== GSAP Animation ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// GSAP has it&amp;#039;s own requestAnimationFrame, thus no time calculation needed&lt;br /&gt;
// we just let gsap update our values and tick does render each frame&lt;br /&gt;
gsap.to(mesh.position,{ duration: 1, delay: 1, x: 2 })&lt;br /&gt;
gsap.to(mesh.position,{ duration: 1, delay: 1, x: 0 })&lt;br /&gt;
const tick = () =&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    // Render on each frame&lt;br /&gt;
    renderer.render(scene, camera)&lt;br /&gt;
    window.requestAnimationFrame(tick) &lt;br /&gt;
}&lt;br /&gt;
// GO...&lt;br /&gt;
tick()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Steff</name></author>
	</entry>
</feed>