Three.js: [Feature Request]: Add Helper base class

Created on 30 Jan 2019  路  6Comments  路  Source: mrdoob/three.js

The different helper classes really come in handy when developing, especially for non-visible objects like planes and lights.

I wonder if it makes sense to let all the current helpers extend a base class called "Helper" or so. This would make it easy to traverse through all the helpers in an object with a .isHelper property and e.g. change their visibility.

Most helpful comment

This can be handled at the app level.

var myHelpers = [];
myHelpers.push( gridHelper );

All 6 comments

The thing is that helpers have different super classes right now e.g. Object3D, LineSegments, Line or Mesh. I think you need some refactoring in order to change this situation. Not sure it's worth to do so just for introducing a .isHelper property...

Yep that's a good point... They do all have Object3D as a super class, it would be possible to add a super class between Object3D and the next (super) class. Just for an .isHelper that does sound over the top though.

Has something like this been discussed before? i can't seem to find anything in the direction

Has something like this been discussed before?

Not to my knowledge.

I would vote for such a change if the Helper class would do a bit more than just defining .isHelper. Unfortunately, helpers work differently and don't share a common interface.

I know this is a long shot, but I'd suggest mixin pattern for helper class.
For example:

export const Helper = ( superclass ) => class extends superclass {
constructor() {
this.isHelper = true;
}
}

And then you define your custom helper...

export class MyHelper extends Helper(MeshOrWhatever) {
}

This can be handled at the app level.

var myHelpers = [];
myHelpers.push( gridHelper );
Was this page helpful?
0 / 5 - 0 ratings

Related issues

zsitro picture zsitro  路  3Comments

yqrashawn picture yqrashawn  路  3Comments

fuzihaofzh picture fuzihaofzh  路  3Comments

jlaquinte picture jlaquinte  路  3Comments

makc picture makc  路  3Comments