-
Notifications
You must be signed in to change notification settings - Fork 27
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
Texture problem with detached DOM elements #26
Comments
Can you provide your patch. I'll have to take a look at it. |
Patch proposal to fix thothbot#26 When DOM elements are detached from the document, offsetWidth/Height are always 0: whereas the element may have proper size set in width/height attributes. This patch adds a fallback on width/height properties when offsetWidth/Height are 0. It allows to use a canvas as a texture without having to attach it first.
Here is my texture generation code:
Example usage: |
This is very nice solution. I suppose we should create TextTexture class in Parallax for this. What do you think? |
I think it would be a nice addition, as rendering text is easy with canvas and well supported by browsers, but not everybody will have the idea to use it.
I'm a WebGL beginner and I wouldn't be able to tell what are the most common use cases for text textures, but the class should be easy to extends to cover custom use cases. |
When you create a texture from a DOM element, for example a canvas, if this element is not attached to the document, the texture will not work.
The reason is texture size is read from the element's offsetWidth/offsetHeight properties, and these properties are always 0 for DOM detached elements; hence texture size will be (0,0).
(NB: I pasted these few lines of code but same problem in others methods.)
Three.js read width/height properties instead, which is nice because you must fill these properties when you create a canvas to use it as a texture; thus you dont need to attach the canvas to the document.
One possible solution would be to first read width/height properties, then having a fallback on offsetWidth/Height (I can provide a patch if you wish and if you agree on this solution).
The text was updated successfully, but these errors were encountered: