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

src/lights: move to es6 classes #20018

Conversation

DefinitelyMaybe
Copy link
Contributor

@DefinitelyMaybe DefinitelyMaybe commented Aug 5, 2020

the unit tests are currently failing because there are properties that havent made it to the json outputs. Will investigate.

@DefinitelyMaybe DefinitelyMaybe marked this pull request as draft August 5, 2020 07:52
@DefinitelyMaybe DefinitelyMaybe mentioned this pull request Aug 5, 2020
43 tasks
@DefinitelyMaybe
Copy link
Contributor Author

I tell a lie.

test/unit/build/three.source.unit.js

...
// Compare keys.
var keys1 = Object.keys( val1 );
var keys2 = Object.keys( val2 );

for ( var i = 0, l = keys1.length; i < l; i ++ ) {

  if ( keys2.indexOf( keys1[ i ] ) < 0 ) {

    return makeFail( 'Property "' + keys1[ i ] + '" is unexpected.' );

  }

}

for ( var i = 0, l = keys2.length; i < l; i ++ ) {

  if ( keys1.indexOf( keys2[ i ] ) < 0 ) {

    return makeFail( 'Property "' + keys2[ i ] + '" is missing.' );

  }

}
...

It looks like this PR is failing because of the way objects are compared. Having moved properties into the constructors has broken that logic.

@DefinitelyMaybe
Copy link
Contributor Author

DefinitelyMaybe commented Aug 15, 2020

Whoop, whoop! ready for review here 👍

wait, what do we make of one e-2-e test round passing, one failing and one cancelled?

@DefinitelyMaybe DefinitelyMaybe marked this pull request as ready for review August 15, 2020 01:17
@DefinitelyMaybe DefinitelyMaybe changed the title Draft: src/lights: move to es6 classes src/lights: move to es6 classes Aug 15, 2020
@mrdoob mrdoob added this to the r120 milestone Aug 18, 2020
@mrdoob mrdoob modified the milestones: r120, r121 Aug 23, 2020
@mrdoob mrdoob modified the milestones: r121, r122 Sep 29, 2020
@mrdoob mrdoob modified the milestones: r122, r123 Oct 28, 2020
@DefinitelyMaybe
Copy link
Contributor Author

conflicts resolved

@mrdoob mrdoob modified the milestones: r123, r124 Nov 25, 2020
@mrdoob mrdoob modified the milestones: r124, r125 Dec 24, 2020
@mrdoob mrdoob modified the milestones: r125, r126 Jan 27, 2021

constructor: Light,
this.receiveShadow = undefined;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did this come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are from old code that was there when I originally did the change.
This commit was the change.
I can take then out.

@mrdoob
Copy link
Owner

mrdoob commented Feb 3, 2021

I'm noticing that we're moving a bunch of objects from the prototype to the constructor.

For example:
https://github.com/mrdoob/three.js/pull/20018/files#diff-f68165aa546b3399e537b30554e49440c6aac4c2ab53da315877742cb9d1ec85L37-R46

Is not possible to keep them in the prototype somehow? We'll use more memory otherwise.

@DefinitelyMaybe
Copy link
Contributor Author

Anyone got any figures regarding this?

@marcofugaro
Copy link
Contributor

@mrdoob @DefinitelyMaybe for private variables that need to be shared across al instances, this is the pattern to use:

const _position = /*@__PURE__*/ new Vector3();
const _quaternion = /*@__PURE__*/ new Quaternion();
const _scale = /*@__PURE__*/ new Vector3();
const _orientation = /*@__PURE__*/ new Vector3();

@mrdoob
Copy link
Owner

mrdoob commented Feb 5, 2021

@DefinitelyMaybe Do you mind updating this PR with that pattern?

@DefinitelyMaybe DefinitelyMaybe marked this pull request as draft February 6, 2021 07:53
Comment on lines +31 to +45
this._viewportCount = 1;

];
this._viewports = [

}
new Vector4( 0, 0, 1, 1 )

];

Object.assign( LightShadow.prototype, {
this._projScreenMatrix = new Matrix4();

_projScreenMatrix: new Matrix4(),
this._lightPositionWorld = new Vector3();

_lightPositionWorld: new Vector3(),
this._lookTarget = new Vector3();

_lookTarget: new Vector3(),
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which should be updated? is it these ones?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is hard to work with / review.

Do you mind splitting this PR in multiple ones? (One per file)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we would have made single PR per file from the start we would have been done with this transition.
Right now a single file is blocking many others.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

Comment on lines +19 to +53
this._viewportCount = 6;
this._viewports = [
// These viewports map a cube-map onto a 2D texture with the
// following orientation:
//
// xzXZ
// y Y
//
// X - Positive x direction
// x - Negative x direction
// Y - Positive y direction
// y - Negative y direction
// Z - Positive z direction
// z - Negative z direction

// positive X
new Vector4( 2, 1, 1, 1 ),
// negative X
new Vector4( 0, 1, 1, 1 ),
// positive Z
new Vector4( 3, 1, 1, 1 ),
// negative Z
new Vector4( 1, 1, 1, 1 ),
// positive Y
new Vector4( 3, 0, 1, 1 ),
// negative Y
new Vector4( 1, 0, 1, 1 )
];
this._cubeUps = [
new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
];
this._frameExtents = new Vector2( 4, 2 );

}

PointLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {

constructor: PointLightShadow,

isPointLightShadow: true,
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and these ones?

@mrdoob
Copy link
Owner

mrdoob commented Feb 9, 2021

#21231

@mrdoob mrdoob closed this Feb 9, 2021
@mrdoob mrdoob removed this from the r126 milestone Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants