Skip to content

feat: adds customizable colors to CameraHelper#23829

Closed
gsimone wants to merge 1 commit into
mrdoob:devfrom
gsimone:feat/camera-helper-colors
Closed

feat: adds customizable colors to CameraHelper#23829
gsimone wants to merge 1 commit into
mrdoob:devfrom
gsimone:feat/camera-helper-colors

Conversation

@gsimone

@gsimone gsimone commented Apr 1, 2022

Copy link
Copy Markdown
Contributor

Found myself needing to color-code camera helpers and wanting to use toned-down colors in other occasions.

This PR wouldn't let users change the colors after construction, but it could be a good middle ground - as helpers are cheap to rebuild anyway

Usage:

const helper = new CameraHelper( camera, 0xffffff ) // white frustum
...

image

TODO

  • Add docs

Comment on lines -33 to +37
const colorFrustum = new Color( 0xffaa00 );
const colorCone = new Color( 0xff0000 );
const colorUp = new Color( 0x00aaff );
const colorTarget = new Color( 0xffffff );
const colorCross = new Color( 0x333333 );
const _colorFrustum = new Color( colorFrustum );
const _colorCone = new Color( colorCone );
const _colorUp = new Color( colorUp );
const _colorTarget = new Color( colorTarget );
const _colorCross = new Color( colorCross );

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This naming convention here is ugly, but I'd rather the arguments have the nice names - as they are user-facing

class CameraHelper extends LineSegments {

constructor( camera ) {
constructor( camera, colorFrustum = 0xffaa00, colorCone = 0xff0000, colorUp = 0x00aaff, colorTarget = 0xffffff, colorCross = 0x333333 ) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

An alternative API would be passing an object with all colors as

{
   frustum: 0xff0000,
   cone: 0xff00ff,
  // ...etc
}

But I can't recall objects that also use this pattern, so this felt more appropriate

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think that the object is a better approach. And it will also solve the naming problem.

@mrdoob

mrdoob commented Apr 2, 2022

Copy link
Copy Markdown
Owner

How about...

const helper = new THREE.CameraHelper( camera ).setColors( frustum, cone, up, target, cross );

@mrdoob mrdoob added this to the r140 milestone Apr 2, 2022
@gsimone

gsimone commented Apr 2, 2022

Copy link
Copy Markdown
Contributor Author

@mrdoob that API would be nice indeed, but it would require require rebuilding the vertices and colors attributes OR a possibly signifcant refactor of the class to just update the colors buffer - moving the two buffers creation to a method. Think it's worth pursuing? 🤔

@Mugen87

Mugen87 commented Apr 4, 2022

Copy link
Copy Markdown
Collaborator

In the past we have agreed to no introduce larger ctor signatures nor options parameters again. The idea is the usage of methods which tends to be a less error prone API. Hence, the PR in ist current form is problematic.

CameraHelper.setColors() would nicely map to AxesHelper.setColors(). As mentioned above, it's probably best to implement the color buffer setup in a separate function and reuse it in the ctor and setColors().

@gsimone

gsimone commented Apr 4, 2022

Copy link
Copy Markdown
Contributor Author

I'll give that a shot 👍
Think it's ok to also rebuild the position buffer? That would require the smallest possible code change - as I'd just take the current constructor to a method.

@Mugen87

Mugen87 commented Apr 4, 2022

Copy link
Copy Markdown
Collaborator

I think it's more clear if setColors() only changes the color buffer. Even if that means more things in the class have to be changed.

@Mugen87

Mugen87 commented Jun 14, 2022

Copy link
Copy Markdown
Collaborator

Closing in favor of #24235.

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