Просмотр исходного кода

Global: Replace `Clock` with `Timer`. (#32793)

Michael Herzog 1 месяц назад
Родитель
Сommit
b776aef251

+ 4 - 2
editor/js/Viewport.js

@@ -777,12 +777,14 @@ function Viewport( editor ) {
 
 
 	let prevActionsInUse = 0;
 	let prevActionsInUse = 0;
 
 
-	const clock = new THREE.Clock(); // only used for animations
+	const timer = new THREE.Timer(); // only used for animations
 
 
 	function animate() {
 	function animate() {
 
 
+		timer.update();
+
 		const mixer = editor.mixer;
 		const mixer = editor.mixer;
-		const delta = clock.getDelta();
+		const delta = timer.getDelta();
 
 
 		let needsUpdate = false;
 		let needsUpdate = false;
 
 

+ 5 - 3
examples/jsm/objects/Water2.js

@@ -1,5 +1,5 @@
 import {
 import {
-	Clock,
+	Timer,
 	Color,
 	Color,
 	Matrix4,
 	Matrix4,
 	Mesh,
 	Mesh,
@@ -74,7 +74,7 @@ class Water extends Mesh {
 		const cycle = 0.15; // a cycle of a flow map phase
 		const cycle = 0.15; // a cycle of a flow map phase
 		const halfCycle = cycle * 0.5;
 		const halfCycle = cycle * 0.5;
 		const textureMatrix = new Matrix4();
 		const textureMatrix = new Matrix4();
-		const clock = new Clock();
+		const timer = new Timer();
 
 
 		// internal components
 		// internal components
 
 
@@ -180,7 +180,7 @@ class Water extends Mesh {
 
 
 		function updateFlow() {
 		function updateFlow() {
 
 
-			const delta = clock.getDelta();
+			const delta = timer.getDelta();
 			const config = scope.material.uniforms[ 'config' ];
 			const config = scope.material.uniforms[ 'config' ];
 
 
 			config.value.x += flowSpeed * delta; // flowMapOffset0
 			config.value.x += flowSpeed * delta; // flowMapOffset0
@@ -207,6 +207,8 @@ class Water extends Mesh {
 
 
 		this.onBeforeRender = function ( renderer, scene, camera ) {
 		this.onBeforeRender = function ( renderer, scene, camera ) {
 
 
+			timer.update();
+
 			updateTextureMatrix( camera );
 			updateTextureMatrix( camera );
 			updateFlow();
 			updateFlow();
 
 

+ 5 - 3
examples/jsm/physics/JoltPhysics.js

@@ -1,4 +1,4 @@
-import { Clock, Vector3, Quaternion, Matrix4 } from 'three';
+import { Timer, Vector3, Quaternion, Matrix4 } from 'three';
 
 
 const JOLT_PATH = 'https://cdn.jsdelivr.net/npm/jolt-physics@1.0.0/dist/jolt-physics.wasm-compat.js';
 const JOLT_PATH = 'https://cdn.jsdelivr.net/npm/jolt-physics@1.0.0/dist/jolt-physics.wasm-compat.js';
 
 
@@ -222,11 +222,13 @@ async function JoltPhysics() {
 
 
 	//
 	//
 
 
-	const clock = new Clock();
+	const timer = new Timer();
 
 
 	function step() {
 	function step() {
 
 
-		let deltaTime = clock.getDelta();
+		timer.update();
+
+		let deltaTime = timer.getDelta();
 
 
 		// Don't go below 30 Hz to prevent spiral of death
 		// Don't go below 30 Hz to prevent spiral of death
 		deltaTime = Math.min( deltaTime, 1.0 / 30.0 );
 		deltaTime = Math.min( deltaTime, 1.0 / 30.0 );

+ 5 - 3
examples/jsm/physics/RapierPhysics.js

@@ -1,4 +1,4 @@
-import { Clock, Vector3, Quaternion, Matrix4 } from 'three';
+import { Timer, Vector3, Quaternion, Matrix4 } from 'three';
 
 
 const RAPIER_PATH = 'https://cdn.skypack.dev/@dimforge/rapier3d-compat@0.17.3';
 const RAPIER_PATH = 'https://cdn.skypack.dev/@dimforge/rapier3d-compat@0.17.3';
 
 
@@ -301,11 +301,13 @@ async function RapierPhysics() {
 
 
 	//
 	//
 
 
-	const clock = new Clock();
+	const timer = new Timer();
 
 
 	function step() {
 	function step() {
 
 
-		world.timestep = clock.getDelta();
+		timer.update();
+
+		world.timestep = timer.getDelta();
 		world.step();
 		world.step();
 
 
 		//
 		//

+ 7 - 5
examples/jsm/postprocessing/EffectComposer.js

@@ -1,7 +1,7 @@
 import {
 import {
-	Clock,
 	HalfFloatType,
 	HalfFloatType,
 	NoBlending,
 	NoBlending,
+	Timer,
 	Vector2,
 	Vector2,
 	WebGLRenderTarget
 	WebGLRenderTarget
 } from 'three';
 } from 'three';
@@ -121,12 +121,12 @@ class EffectComposer {
 		this.copyPass.material.blending = NoBlending;
 		this.copyPass.material.blending = NoBlending;
 
 
 		/**
 		/**
-		 * The internal clock for managing time data.
+		 * The internal timer for managing time data.
 		 *
 		 *
 		 * @private
 		 * @private
-		 * @type {Clock}
+		 * @type {Timer}
 		 */
 		 */
-		this.clock = new Clock();
+		this.timer = new Timer();
 
 
 	}
 	}
 
 
@@ -215,9 +215,11 @@ class EffectComposer {
 
 
 		// deltaTime value is in seconds
 		// deltaTime value is in seconds
 
 
+		this.timer.update();
+
 		if ( deltaTime === undefined ) {
 		if ( deltaTime === undefined ) {
 
 
-			deltaTime = this.clock.getDelta();
+			deltaTime = this.timer.getDelta();
 
 
 		}
 		}
 
 

粤ICP备19079148号