-
-
Notifications
You must be signed in to change notification settings - Fork 35.6k
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
WebGLRenderer is not extendable #19305
Comments
Related comment: #19304 (comment) |
@Mugen87 I agree that exposing internal helpers to public API would make them unchangeable. Do you think we could do some kind of gray area? i.e. make it possible to swap helpers in WebGLRenderer but "on your own risk", without guarantee that it will work same way in future versions. |
I personally would not go down this way and keep the renderer internals closed. I'm okay with having interfaces like However, this design decision is up to @mrdoob. |
Forking requires alot of management, most teams not willing to do. This leads to most threejs based projects to be stuck with some r57 prehistoric versions, making it hard for one developer to participate in multiple projects. Making functionality extendable atleast semi-publicly would help the community. |
For the same reason many modern languages provide some kind of reflection API, which allows to access library internals. JavaScript allows for some parts to be completely "sealed", not accessible in any way, but doing so do no good for library users. |
You are about to hit something that is set in stone :) Mugen outlined the two basic opposing directions. I lie somewhere in between. These hooks mentioned are not very consistent, the same javascript code you write in I still like these hooks, i'd like there to be more of them, and i'd like some of them to be less buggy. However, just to better explain the situation even I think the best way for the time being is to actually modify the code. To explain this situation better, if you look at some ancient version, you'll see that all of these renderer methods were accessible either on the instance or the prototype. So with ancient javascript you could "just" replace these at runtime. Since, methods and state has been made private, and having typescript on top of everything may complicate things a little bit. Having said this, i think PRs that break the renderer even further are probably going to be an easier sell than a large attempt to make the renderer customizable. This may come naturally later. Ie. more areas need to be identified that would allow for more hooks. I feel compassion for this:
It's sometimes not even the management, but the issue of trust/risk. It's much easier to ship some code with a hook, than modify a library. |
Do you know the reason for making them private? To disallow library users to depend on them? |
I think encapsulation coupled with the language we have to use. It's not easy to make safe javascript.
But for experimenting, some temporary hacks and such, it'd be nice. Likewise, Now, something like this:
I think that this is a neat pattern, but would probably work better with some things and not much sense with others. Something as complex as |
Agree, this is a strange feature of JS. Though es6+ class declaration allows to do the same, means soon all modern js code will allow such hacks. Probably it does not make sense to fight the language. (I mean to hide private functions, using tricks)
This would open up alot of possibilities and algorithms to be implemented without forking. Currently some cool features can not be added to project examples, just because they require library code change. |
es6 declaration is just syntactic sugar, the prototype is still accessible. I wouldn't exactly refer to these patterns as tricks, they are features of the language. The overrides are worth discussing though, in general. It'd be amazing if certain things could be overridden . |
right? |
Maybe not relevant at all but maybe you use proxy to replace a specific method if the change is well localized? |
@NicolasRannou thanx for the link. Unfortunately Proxy is not enough. |
Do you mind elaborating on that statement? What projects have you seen that are stuck in prehistoric versions? |
Yes, it's easier to not break user code that way. I've personally seen more people having good experiences upgrading to new versions than not. But I guess that's not what you have seen. |
ah. good to hear. perhaps y'all are hanging out for support of private fields across browser's? |
I think autodesk's forge is on 78 or something like that. |
Autodesk web viewer is using r71, I think |
I think that this would be great to collect some data for. The products I worked on were also stuck at older versions. |
@mrdoob As far as I see it, there are 2 types of projects using threejs
The strategy of sealing functionality might help projects of type 1. not to "shoot them selves in the foot", but at the same time it is doing the opposite for projects of type 2. making customization and library upgrades harder. |
Just upgraded from r115 to r117. Was pain in the ass, as I have a copy of WebGLRenderer with modifications, which is not compatible with r117 renderer anymore :( |
Closing in favor of #19554. |
Description of the problem
It is impossible to extend functionality of WebGLRenderer without changing library code or copy-pasting thousands of lines of code.
For example, I would like to change a single line of code in one of renderer helpers, i.e. WebGLRendererLists.
Currently my best choice is to copy WebGLRendererLists, change one line, copy WebGLRenderer and change single line of renderLists initialization. This basically makes library non-upgradable. Most projects, I have seen, dont bother to copy, they just change code in place and never upgrade threejs.
Suggestion
WebGLRendererParameters could include custom helpers, same as it includes WebGLRenderingContext object. This would make it possible to replace helpers without creating a copy of WebGLRenderer.
The text was updated successfully, but these errors were encountered: