Skip to content

Commit

Permalink
refactor: annotate revision checks, static fields, add automatic anno…
Browse files Browse the repository at this point in the history
…tations
  • Loading branch information
CodyJasonBennett committed Sep 23, 2023
1 parent 3bd54df commit 0f273ac
Show file tree
Hide file tree
Showing 9 changed files with 733 additions and 268 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
},
"sideEffects": false,
"devDependencies": {
"@babel/core": "^7.22.20",
"@types/babel__core": "^7.20.2",
"@types/node": "^20.6.3",
"@types/three": "^0.128.0",
"copyfiles": "^2.4.1",
Expand Down
3 changes: 1 addition & 2 deletions src/controls/OrbitControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import {
Vector3,
Ray,
Plane,
MathUtils,
} from 'three'

const _ray = /* @__PURE__ */ new Ray()
const _plane = /* @__PURE__ */ new Plane()
const TILT_LIMIT = Math.cos(70 * MathUtils.DEG2RAD)
const TILT_LIMIT = Math.cos(70 * (Math.PI / 180))

// This set of controls performs orbiting, dollying (zooming), and panning.
// Unlike TrackballControls, it maintains the "up" direction object.up (+Y by default).
Expand Down
4 changes: 3 additions & 1 deletion src/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1634,14 +1634,16 @@ const WEBGL_TYPE_SIZES = {
MAT4: 16,
}

const _version = /* @__PURE__ */ REVISION.replace(/\D+/g, '')

const ATTRIBUTES = {
POSITION: 'position',
NORMAL: 'normal',
TANGENT: 'tangent',
// uv => uv1, 4 uv channels
// https://github.com/mrdoob/three.js/pull/25943
// https://github.com/mrdoob/three.js/pull/25788
.../* @__PURE__ */ (REVISION.replace(/\D+/g, '') >= 152
...(_version >= 152
? {
TEXCOORD_0: 'uv',
TEXCOORD_1: 'uv1',
Expand Down
133 changes: 69 additions & 64 deletions src/objects/Reflector.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,70 +15,6 @@ import {
} from 'three'

class Reflector extends Mesh {
static ReflectorShader = {
uniforms: {
color: {
value: null,
},

tDiffuse: {
value: null,
},

textureMatrix: {
value: null,
},
},

vertexShader: /* glsl */ `
uniform mat4 textureMatrix;
varying vec4 vUv;
#include <common>
#include <logdepthbuf_pars_vertex>
void main() {
vUv = textureMatrix * vec4( position, 1.0 );
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
#include <logdepthbuf_vertex>
}`,

fragmentShader: /* glsl */ `
uniform vec3 color;
uniform sampler2D tDiffuse;
varying vec4 vUv;
#include <logdepthbuf_pars_fragment>
float blendOverlay( float base, float blend ) {
return( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );
}
vec3 blendOverlay( vec3 base, vec3 blend ) {
return vec3( blendOverlay( base.r, blend.r ), blendOverlay( base.g, blend.g ), blendOverlay( base.b, blend.b ) );
}
void main() {
#include <logdepthbuf_fragment>
vec4 base = texture2DProj( tDiffuse, vUv );
gl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );
#include <tonemapping_fragment>
#include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
}`,
}

constructor(geometry, options = {}) {
super(geometry)

Expand Down Expand Up @@ -255,4 +191,73 @@ class Reflector extends Mesh {
}
}

let _version = /* @__PURE__ */ REVISION.replace(/\D+/g, '')
_version = /* @__PURE__ */ parseInt(_version)

/* @__PURE__ */ Object.assign(Reflector, {
ReflectorShader: {
uniforms: {
color: {
value: null,
},

tDiffuse: {
value: null,
},

textureMatrix: {
value: null,
},
},

vertexShader: /* glsl */ `
uniform mat4 textureMatrix;
varying vec4 vUv;
#include <common>
#include <logdepthbuf_pars_vertex>
void main() {
vUv = textureMatrix * vec4( position, 1.0 );
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
#include <logdepthbuf_vertex>
}`,

fragmentShader: /* glsl */ `
uniform vec3 color;
uniform sampler2D tDiffuse;
varying vec4 vUv;
#include <logdepthbuf_pars_fragment>
float blendOverlay( float base, float blend ) {
return( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );
}
vec3 blendOverlay( vec3 base, vec3 blend ) {
return vec3( blendOverlay( base.r, blend.r ), blendOverlay( base.g, blend.g ), blendOverlay( base.b, blend.b ) );
}
void main() {
#include <logdepthbuf_fragment>
vec4 base = texture2DProj( tDiffuse, vUv );
gl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );
#include <tonemapping_fragment>
#include <${_version >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
}`,
},
})

export { Reflector }
121 changes: 63 additions & 58 deletions src/objects/Refractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,64 +16,6 @@ import {
} from 'three'

class Refractor extends Mesh {
static RefractorShader = {
uniforms: {
color: {
value: null,
},

tDiffuse: {
value: null,
},

textureMatrix: {
value: null,
},
},

vertexShader: /* glsl */ `
uniform mat4 textureMatrix;
varying vec4 vUv;
void main() {
vUv = textureMatrix * vec4( position, 1.0 );
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}`,

fragmentShader: /* glsl */ `
uniform vec3 color;
uniform sampler2D tDiffuse;
varying vec4 vUv;
float blendOverlay( float base, float blend ) {
return( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );
}
vec3 blendOverlay( vec3 base, vec3 blend ) {
return vec3( blendOverlay( base.r, blend.r ), blendOverlay( base.g, blend.g ), blendOverlay( base.b, blend.b ) );
}
void main() {
vec4 base = texture2DProj( tDiffuse, vUv );
gl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );
#include <tonemapping_fragment>
#include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
}`,
}

constructor(geometry, options = {}) {
super(geometry)

Expand Down Expand Up @@ -301,4 +243,67 @@ class Refractor extends Mesh {
}
}

let _version = /* @__PURE__ */ REVISION.replace(/\D+/g, '')
_version = /* @__PURE__ */ parseInt(_version)

/* @__PURE__ */ Object.assign(Refractor, {
RefractorShader: {
uniforms: {
color: {
value: null,
},

tDiffuse: {
value: null,
},

textureMatrix: {
value: null,
},
},

vertexShader: /* glsl */ `
uniform mat4 textureMatrix;
varying vec4 vUv;
void main() {
vUv = textureMatrix * vec4( position, 1.0 );
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}`,

fragmentShader: /* glsl */ `
uniform vec3 color;
uniform sampler2D tDiffuse;
varying vec4 vUv;
float blendOverlay( float base, float blend ) {
return( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );
}
vec3 blendOverlay( vec3 base, vec3 blend ) {
return vec3( blendOverlay( base.r, blend.r ), blendOverlay( base.g, blend.g ), blendOverlay( base.b, blend.b ) );
}
void main() {
vec4 base = texture2DProj( tDiffuse, vUv );
gl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );
#include <tonemapping_fragment>
#include <${_version >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
}`,
},
})

export { Refractor }
11 changes: 8 additions & 3 deletions src/objects/Sky.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { BackSide, BoxGeometry, Mesh, ShaderMaterial, UniformsUtils, Vector3, REVISION } from 'three'

let _version: any = /* @__PURE__ */ REVISION.replace(/\D+/g, '')
_version = /* @__PURE__ */ parseInt(_version)

const SkyShader = {
uniforms: {
turbidity: { value: 2 },
Expand Down Expand Up @@ -166,7 +169,7 @@ const SkyShader = {
gl_FragColor = vec4( retColor, 1.0 );
#include <tonemapping_fragment>
#include <${parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
#include <${_version >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
}
`,
Expand Down Expand Up @@ -199,8 +202,10 @@ class Sky extends Mesh {
super(new BoxGeometry(1, 1, 1), material)
}

static SkyShader = SkyShader
public static material = material
static SkyShader: typeof SkyShader
static material: typeof material
}

/* @__PURE__ */ Object.assign(Sky, { SkyShader, material })

export { Sky }
Loading

0 comments on commit 0f273ac

Please sign in to comment.