Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c6a253c

Browse files
committed
refactor(soba): extract THREE.REVISION to a constant
1 parent f3bbd0c commit c6a253c

File tree

12 files changed

+32
-18
lines changed

12 files changed

+32
-18
lines changed

libs/soba/loaders/src/texture-loader/texture-loader.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ export function injectNgtsTextureLoader<TInput extends string[] | string | Recor
2121
effect(() => {
2222
const textures = result();
2323
if (!textures) return;
24-
const array = Array.isArray(textures)
25-
? textures
26-
: textures instanceof THREE.Texture
27-
? [textures]
28-
: Object.values(textures);
29-
if (onLoad) onLoad(array);
30-
array.forEach(store.get('gl').initTexture);
24+
const gl = store.get('gl');
25+
if ('initTexture' in gl) {
26+
const array = Array.isArray(textures)
27+
? textures
28+
: textures instanceof THREE.Texture
29+
? [textures]
30+
: Object.values(textures);
31+
if (onLoad) onLoad(array);
32+
array.forEach(store.get('gl').initTexture);
33+
}
3134
});
3235

3336
return result;

libs/soba/shaders/src/caustics/caustics-projection-material.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { revision } from 'angular-three-soba/utils';
12
import * as THREE from 'three';
23
import { shaderMaterial } from '../shader-material/shader-material';
34

@@ -30,6 +31,6 @@ export const CausticsProjectionMaterial = shaderMaterial(
3031
vec3 back = texture2D(causticsTextureB, lightSpacePos.xy).rgb;
3132
gl_FragColor = vec4((front + back) * color, 1.0);
3233
#include <tonemapping_fragment>
33-
#include <${parseInt(THREE.REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
34+
#include <${revision >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
3435
}`,
3536
);

libs/soba/shaders/src/convolution-material/convolution-material.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { revision } from 'angular-three-soba/utils';
12
import { NoBlending, ShaderMaterial, Uniform, Vector2 } from 'three';
23

34
export class ConvolutionMaterial extends ShaderMaterial {
@@ -53,7 +54,7 @@ export class ConvolutionMaterial extends ShaderMaterial {
5354
5455
#include <dithering_fragment>
5556
#include <tonemapping_fragment>
56-
#include <encodings_fragment>
57+
#include <${revision >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
5758
}`,
5859
vertexShader: `uniform vec2 texelSize;
5960
uniform vec2 halfTexelSize;

libs/soba/shaders/src/grid-material/grid-material.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { NgtShaderMaterial } from 'angular-three';
2+
import { revision } from 'angular-three-soba/utils';
23
import * as THREE from 'three';
34
import { shaderMaterial } from '../shader-material/shader-material';
45

@@ -74,7 +75,7 @@ export const GridMaterial = shaderMaterial(
7475
if (gl_FragColor.a <= 0.0) discard;
7576
7677
#include <tonemapping_fragment>
77-
#include <${parseInt(THREE.REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
78+
#include <${revision >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
7879
}
7980
`,
8081
);

libs/soba/shaders/src/mesh-refraction-material/mesh-refraction-material.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Author: N8Programs
22
// https://github.com/N8python/diamonds
33

4+
import { revision } from 'angular-three-soba/utils';
45
import * as THREE from 'three';
56
// @ts-expect-error: shaderIntersectFunction is available but typescript complains
67
import { MeshBVHUniformStruct, shaderIntersectFunction, shaderStructs } from 'three-mesh-bvh';
@@ -168,6 +169,6 @@ export const MeshRefractionMaterial = shaderMaterial(
168169
float nFresnel = fresnelFunc(viewDirection, normal) * fresnel;
169170
gl_FragColor = vec4(mix(finalColor, vec3(1.0), nFresnel), 1.0);
170171
#include <tonemapping_fragment>
171-
#include <${parseInt(THREE.REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
172+
#include <${revision >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
172173
}`,
173174
);

libs/soba/shaders/src/soft-shadow-material/soft-shadow-material.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { NgtShaderMaterial } from 'angular-three';
2+
import { revision } from 'angular-three-soba/utils';
23
import * as THREE from 'three';
34
import { shaderMaterial } from '../shader-material/shader-material';
45

@@ -25,7 +26,7 @@ export const SoftShadowMaterial = shaderMaterial(
2526
vec4 sampledDiffuseColor = texture2D(map, vUv);
2627
gl_FragColor = vec4(color * sampledDiffuseColor.r * blend, max(0.0, (1.0 - (sampledDiffuseColor.r + sampledDiffuseColor.g + sampledDiffuseColor.b) / alphaTest)) * opacity);
2728
#include <tonemapping_fragment>
28-
#include <${parseInt(THREE.REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
29+
#include <${revision >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
2930
}`,
3031
);
3132

libs/soba/shaders/src/sparkles-material/sparkles-material.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { NgtShaderMaterial } from 'angular-three';
2-
import * as THREE from 'three';
2+
import { revision } from 'angular-three-soba/utils';
33
import { shaderMaterial } from '../shader-material/shader-material';
44

55
export const SparklesMaterial = shaderMaterial(
@@ -33,7 +33,7 @@ export const SparklesMaterial = shaderMaterial(
3333
float strength = 0.05 / distanceToCenter - 0.1;
3434
gl_FragColor = vec4(vColor, strength * vOpacity);
3535
#include <tonemapping_fragment>
36-
#include <${parseInt(THREE.REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
36+
#include <${revision >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
3737
}`,
3838
);
3939

libs/soba/shaders/src/spot-light-material/spot-light-material.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { NgtShaderMaterial } from 'angular-three';
2+
import { revision } from 'angular-three-soba/utils';
23
import * as THREE from 'three';
34

45
export class SpotLightMaterial extends THREE.ShaderMaterial {
@@ -80,7 +81,7 @@ export class SpotLightMaterial extends THREE.ShaderMaterial {
8081
gl_FragColor = vec4(lightColor, intensity * opacity);
8182
8283
#include <tonemapping_fragment>
83-
#include <${parseInt(THREE.REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
84+
#include <${revision >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
8485
}`,
8586
});
8687
}

libs/soba/shaders/src/star-field-material/star-field-material.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { NgtShaderMaterial } from 'angular-three';
2-
import * as THREE from 'three';
2+
import { revision } from 'angular-three-soba/utils';
33
import { shaderMaterial } from '../shader-material/shader-material';
44

55
export const StarFieldMaterial = shaderMaterial(
@@ -30,7 +30,7 @@ void main() {
3030
gl_FragColor = vec4(vColor, opacity);
3131
3232
#include <tonemapping_fragment>
33-
#include <${parseInt(THREE.REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
33+
#include <${revision >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
3434
}
3535
`,
3636
);

libs/soba/staging/src/accumulative-shadows/randomized-lights.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { CUSTOM_ELEMENTS_SCHEMA, Component, Input, computed, effect } from '@angular/core';
22
import { NgtArgs, extend, injectNgtRef, signalStore, type NgtGroup } from 'angular-three';
3+
import { revision } from 'angular-three-soba/utils';
34
import { Repeat } from 'ngxtension/repeat';
45
import * as THREE from 'three';
56
import { DirectionalLight, Group, OrthographicCamera, Vector2 } from 'three';
@@ -76,7 +77,7 @@ export class NgtsRandomizedLights {
7677
position: [0, 0, 0],
7778
radius: 1,
7879
amount: 8,
79-
intensity: parseInt(THREE.REVISION.replace(/\D+/g, '')) >= 155 ? Math.PI : 1,
80+
intensity: revision >= 155 ? Math.PI : 1,
8081
ambient: 0.5,
8182
});
8283
Math = Math;

libs/soba/utils/src/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { REVISION } from 'three';
2+
3+
export const revision = parseInt(REVISION.replace(/\D+/g, ''));

libs/soba/utils/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export { revision } from './constants';
12
export * from './content/content';

0 commit comments

Comments
 (0)