Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Material: Use pseudo private variables. #22443

Merged
merged 3 commits into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/materials/Material.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ let materialId = 0;

class Material extends EventDispatcher {

#alphaTest = 0;

constructor() {

super();
Expand Down Expand Up @@ -76,23 +74,25 @@ class Material extends EventDispatcher {

this.version = 0;

this._alphaTest = 0;

}

get alphaTest() {

return this.#alphaTest;
return this._alphaTest;

}

set alphaTest( value ) {

if ( this.#alphaTest > 0 !== value > 0 ) {
if ( this._alphaTest > 0 !== value > 0 ) {

this.version ++;

}

this.#alphaTest = value;
this._alphaTest = value;

}

Expand Down
19 changes: 10 additions & 9 deletions src/materials/MeshPhysicalMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ import * as MathUtils from '../math/MathUtils.js';

class MeshPhysicalMaterial extends MeshStandardMaterial {

#clearcoat = 0;
#transmission = 0;

constructor( parameters ) {

super();
Expand Down Expand Up @@ -86,43 +83,47 @@ class MeshPhysicalMaterial extends MeshStandardMaterial {
this.specularTint = new Color( 1, 1, 1 );
this.specularTintMap = null;

this._clearcoat = 0;
this._transmission = 0;


this.setValues( parameters );

}

get clearcoat() {

return this.#clearcoat;
return this._clearcoat;

}

set clearcoat( value ) {

if ( this.#clearcoat > 0 !== value > 0 ) {
if ( this._clearcoat > 0 !== value > 0 ) {

this.version ++;

}

this.#clearcoat = value;
this._clearcoat = value;

}

get transmission() {

return this.#transmission;
return this._transmission;

}

set transmission( value ) {

if ( this.#transmission > 0 !== value > 0 ) {
if ( this._transmission > 0 !== value > 0 ) {

this.version ++;

}

this.#transmission = value;
this._transmission = value;

}

Expand Down
33 changes: 0 additions & 33 deletions utils/build/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,44 +277,13 @@ ${ code }`;

}

// Transform #properties to _properties until they're supported in bundlers
// https://github.com/mrdoob/three.js/issues/22437
function privateProperties() {

return {

transform( code, id ) {

if ( /\.glsl.js$/.test( id ) === true ) return;

// replace `#property =` with `_property =`
code = code.replace( /#(\w+) =/g, ( match, p1 ) => `_${p1} =` );

// replace `#property;` with `_property;`
code = code.replace( /#(\w+);/g, ( match, p1 ) => `_${p1};` );

// replace `this.#property` with `this._property`
code = code.replace( /this\.#(\w+)/g, ( match, p1 ) => `this._${p1}` );

return {
code: code,
map: null
};

}

};

}

let builds = [
{
input: 'src/Three.js',
plugins: [
addons(),
glconstants(),
glsl(),
privateProperties(),
header()
],
output: [
Expand All @@ -329,7 +298,6 @@ let builds = [
plugins: [
addons(),
glsl(),
privateProperties(),
babel( {
babelHelpers: 'bundled',
compact: false,
Expand All @@ -354,7 +322,6 @@ let builds = [
addons(),
glconstants(),
glsl(),
privateProperties(),
babel( {
babelHelpers: 'bundled',
babelrc: false,
Expand Down