-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
GLTFExporter: decompress compressed textures using render targets instead of canvas #26666
Conversation
…inity in GLTFExporter
Do you mind sharing such a glTF asset in this PR? In this way, we can import the asset and then try the export with |
Or if the input is not a glTF file, it would be helpful to have some other way to reproduce the problem here. I don't think either of these issues are expected, so we just need to be sure we understand the problems for which we would be maintaining the code in this fix. :) |
https://threejs.org/examples/?q=export#misc_exporter_gltf go here and click export coffeemat three times, you will experience context loss. my PR seems to sometimes work, and sometimes i still get context losses unfortunately. |
been having tons of issues with package linking which made me run incorrect/"random" versions, so was a bit confused. still haven't found a proper way to deep link three -> engine -> application for development so working with three fixes is insanely slow. forcecontextloss works every time for me to prevent context leak (which in turn causes real context loss) |
I haven't had the time to look for a repro case for count=Infinity note that the failed deepscan check is not related to these changes |
Could you please split these two fixes into two separate PRs? |
@LeviPesin Please let the collaborators do this kind of issue and PR management. The first thing that was required here is to be able to reproduce what's going wrong. |
@Dadibom Let's focus on this issue first. It would be good to know when and why |
@Mugen87 I am not quite sure and unfortunately i can't share the project
|
Note that its not BufferAttribute.count that is Infinity |
Does your geometries hold group data? AFAICS, this is the only way |
Hmm yes I am finding this:
I don't know exactly why this is done, will investigate further. |
Using Regarding your particular use case with |
Do you mind removing all changes to The fix in the exporter looks good, imo! |
I think there was some reason to use customDepthMaterial but i don't remember, however the group is added because we use multiple materials/layers |
A single group does not add multi material support. You would need something like this: child.geometry.addGroup(0, Infinity, 0);
child.geometry.addGroup(0, Infinity, 1); |
Yes, the other materials (and groups) are added in later stages :) |
|
||
const readableTexture = new Texture( renderer.domElement ); | ||
const readableTexture = renderTarget.texture; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using the texture of the render target, do you mind creating a new instance of Texture
instead?
I'm not sure who else is going to use the decompress()
in the future and it seems more safe to use a fresh texture object instead of a render target texture.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why create a new texture? WebGLRenderTarget is not reused and I'm gussing it already does new Texture
internally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why create a new texture?
Textures of render targets have a flag that indicate they belong to render targets. When using these textures for rendering, they are treated differently by the renderer. Instead of setting the flag to a different value, it's more clear to just create a new instance.
Also note these lines:
this works because the exporter doesnt actually check the texture data, only texture.image. if you tried to render the texture it wouldn't be visible as it is already disposed. however the exporter itself does not dispose textures it creates with decompress so for now this is required |
|
||
const renderTarget = new WebGLRenderTarget( width, height, { | ||
stencilBuffer: true, | ||
colorSpace: IS_SRGB ? SRGBColorSpace : LinearSRGBColorSpace, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
colorSpace: IS_SRGB ? SRGBColorSpace : LinearSRGBColorSpace, | |
colorSpace: texture.colorSpace, |
Wouldn't this be simpler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, if it works! If not we should probably include a comment explaining why texture.colorSpace
is not used...
The texture for conversion may be non-color, using NoColorspace. Somewhat related:
@WestLangley should we consider NoColorSpace a valid color space for a render target? I think the answer is probably yes, but I'm not sure whether it's fully supported now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@donmccurdy I think this is an issue to be debated elsewhere, but FWIW...
-
One can render non-color data to a render target.
-
I don't think we should "honor" the color space of a render target when rendering to it. The color space is relevant only when reading from the render target.
Description
Old texture decompress function left dangling contexts. Since the browser can only have a certain number of contexts, your application will eventually break.
This new approach does not leak contexts.
https://threejs.org/examples/?q=export#misc_exporter_gltf
go here and click export coffeemat three or so times, you will experience context loss