Skip to content

Commit 24658e4

Browse files
mvaligurskyMartin Valigursky
andauthored
Use math.DEG_TO_RAD uinstead of PI / 180 internally (#8111)
Co-authored-by: Martin Valigursky <[email protected]>
1 parent f73b099 commit 24658e4

File tree

6 files changed

+12
-10
lines changed

6 files changed

+12
-10
lines changed

src/extras/exporters/gltf-exporter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ class GltfExporter extends CoreExporter {
325325

326326
camera.type = 'perspective';
327327
camera.perspective = {
328-
yfov: fov * Math.PI / 180,
328+
yfov: fov * math.DEG_TO_RAD,
329329
znear: nearClip,
330330
zfar: farClip
331331
};

src/extras/render-passes/render-pass-ssao.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { BlueNoise } from '../../core/math/blue-noise.js';
22
import { Color } from '../../core/math/color.js';
3+
import { math } from '../../core/math/math.js';
34
import {
45
ADDRESS_CLAMP_TO_EDGE, FILTER_NEAREST, PIXELFORMAT_R8, SEMANTIC_POSITION, SHADERLANGUAGE_GLSL,
56
SHADERLANGUAGE_WGSL
@@ -197,7 +198,7 @@ class RenderPassSsao extends RenderPassShaderQuad {
197198

198199
scope.resolve('uSampleCount').setValue([sampleCount, 1.0 / sampleCount]);
199200

200-
const minAngleSin = Math.sin(minAngle * Math.PI / 180.0);
201+
const minAngleSin = Math.sin(minAngle * math.DEG_TO_RAD);
201202
scope.resolve('uMinHorizonAngleSineSquared').setValue(minAngleSin * minAngleSin);
202203

203204
const spiralTurns = 10.0;

src/scene/camera.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ class Camera {
685685
*/
686686
getFrustumCorners(near = this.nearClip, far = this.farClip) {
687687

688-
const fov = this.fov * Math.PI / 180.0;
688+
const fov = this.fov * math.DEG_TO_RAD;
689689
let x, y;
690690

691691
if (this.projection === PROJECTION_PERSPECTIVE) {

src/scene/gsplat-unified/gsplat-manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ class GSplatManager {
399399
const currentCameraFwd = this.cameraNode.forward;
400400
const dot = Math.min(1, Math.max(-1, this.lastLodCameraFwd.dot(currentCameraFwd)));
401401
const angle = Math.acos(dot);
402-
const rotThreshold = lodUpdateAngleDeg * Math.PI / 180;
402+
const rotThreshold = lodUpdateAngleDeg * math.DEG_TO_RAD;
403403
cameraRotated = angle > rotThreshold;
404404
} else {
405405
// first run, force update to initialize last orientation

src/scene/light.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class Light {
254254

255255
this._position = new Vec3(0, 0, 0);
256256
this._direction = new Vec3(0, 0, 0);
257-
this._innerConeAngleCos = Math.cos(this._innerConeAngle * Math.PI / 180);
257+
this._innerConeAngleCos = Math.cos(this._innerConeAngle * math.DEG_TO_RAD);
258258
this._updateOuterAngle(this._outerConeAngle);
259259

260260
this._usePhysicalUnits = undefined;
@@ -630,7 +630,7 @@ class Light {
630630
}
631631

632632
this._innerConeAngle = value;
633-
this._innerConeAngleCos = Math.cos(value * Math.PI / 180);
633+
this._innerConeAngleCos = Math.cos(value * math.DEG_TO_RAD);
634634
this.updateClusterData(false, true);
635635

636636
if (this._usePhysicalUnits) {
@@ -677,7 +677,7 @@ class Light {
677677
}
678678

679679
_updateOuterAngle(angle) {
680-
const radAngle = angle * Math.PI / 180;
680+
const radAngle = angle * math.DEG_TO_RAD;
681681
this._outerConeAngleCos = Math.cos(radAngle);
682682
this._outerConeAngleSin = Math.sin(radAngle);
683683
this.updateClusterData(false, true);
@@ -1205,13 +1205,13 @@ class Light {
12051205

12061206
// Shrink angles slightly (~1%) to prevent light leaking outside shadow boundaries
12071207
const angleShrinkFactor = 0.99;
1208-
let innerCos = Math.cos(this._innerConeAngle * angleShrinkFactor * Math.PI / 180);
1208+
let innerCos = Math.cos(this._innerConeAngle * angleShrinkFactor * math.DEG_TO_RAD);
12091209
if (innerCos > cosThreshold) {
12101210
innerCos = 1.0 - innerCos;
12111211
flags |= 1; // Use bit 0 for inner angle: 1 = versine, 0 = cosine
12121212
}
12131213

1214-
let outerCos = Math.cos(this._outerConeAngle * angleShrinkFactor * Math.PI / 180);
1214+
let outerCos = Math.cos(this._outerConeAngle * angleShrinkFactor * math.DEG_TO_RAD);
12151215
if (outerCos > cosThreshold) {
12161216
outerCos = 1.0 - outerCos;
12171217
flags |= 2; // Use bit 1 for outer angle: 1 = versine, 0 = cosine

src/scene/renderer/forward-renderer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { now } from '../../core/time.js';
22
import { Debug } from '../../core/debug.js';
3+
import { math } from '../../core/math/math.js';
34
import { Vec3 } from '../../core/math/vec3.js';
45
import { Color } from '../../core/math/color.js';
56
import { DebugGraphics } from '../../platform/graphics/debug-graphics.js';
@@ -425,7 +426,7 @@ class ForwardRenderer extends Renderer {
425426
this.lightShadowIntensity[cnt].setValue(spot.shadowIntensity);
426427

427428
const pixelsPerMeter = spot.penumbraSize / lightRenderData.shadowCamera.renderTarget.width;
428-
const fov = lightRenderData.shadowCamera._fov * Math.PI / 180.0;
429+
const fov = lightRenderData.shadowCamera._fov * math.DEG_TO_RAD;
429430
const fovRatio = 1.0 / Math.tan(fov / 2.0);
430431
this.lightShadowSearchAreaId[cnt].setValue(pixelsPerMeter * fovRatio);
431432

0 commit comments

Comments
 (0)