-
-
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
Texture: Added Source class. #22846
Texture: Added Source class. #22846
Conversation
@Mugen87 Do you want to give this a try this month, or should move it to next month? |
I would prefer to put this in |
I think now would be a good time to merge this PR 😇 . |
Aaaand it's merged. Yay! |
I have very low confidence about this commit... See: mrdoob/three.js#22846 See: mrdoob/three.js#23419
* feature (Texture): Add Source class I have very low confidence about this commit... See: mrdoob/three.js#22846 See: mrdoob/three.js#23419 * fix: forgot to export `Source` I added in the previous commit * test: add a test code, texture-source.ts * fix: Source.data can be ImageData * fix: make `source.data` be `any` * fix (Texutre): Texture variantes, make `.image` an accessor
* Texture: Added Source class. * WebGLTextures: Rebase. * WebGLTextures: Clean up.
Does this PR also decrease the memory usage? |
I don't think this was true before, see https://jsfiddle.net/6hbsov02/1/. The redundant upload did appear when cloning an existing texture, see https://jsfiddle.net/p93ca80j/. This is now fixed with latest versions: https://jsfiddle.net/p93ca80j/2/ |
Hello, in the new version (140) when creating a clone of a texture after using it, a warning appears: |
Thanks for reporting. This is actually a bug in |
Sorry but, what is const source = new THREE.Source( image ); // source.data = image
const material = new THREE.MeshBasicMaterial();
material.map = new THREE.Texture();
material.map.source = source;
material.map.offset.x = 0.5; |
Usually something that you load via |
Is it possible to set the source after being loaded like we usually do with function LoadTexture(url) {
const TextureLoader = new THREE.TextureLoader()
const texture = TextureLoader.load(url)
return texture
} To something like this: function LoadTexture(url) {
const texture = new THREE.Texture()
const loader = new THREE.ImageLoader()
loader.load(url, (image) => {
texture.source = new THREE.Source(image)
})
return texture
} |
Yes, but you have to set the |
Is there a way to know when this task is done? texture.source = mysource
texture.needsUpdate = true I am using expo-three for react-native. But after a lot of hours of testing I had to use a setTimeout just to apply the same source to different textures. Does not work if I apply them in a regular for/loop. The texture does not show up. My setTimeout solution feels very dirty. Just wondering if there is another aproach for this. |
@Josema the texture will upload to the GPU synchronously, the next time a material using it renders. If you'd like to force that to happen at a particular time, you can upload the texture in advance: renderer.initTexture(texture); https://threejs.org/docs/?q=renderer#api/en/renderers/WebGLRenderer.initTexture |
Related issue: see #17949
Description
This PR adds a new class
Source
which represents the data source for a texture. This approach allows to identify unique data sources and avoid duplicate texture uploads.The code represents the minimal implementation which is necessary to introduce this feature. It should be 100% backwards compatible. It's possible to enhance the implementation with specific data source classes per texture (e.g.
DataSource
,CompressedSource
etc.) but it's not really necessary for the first step.Note: Assigning an instance of
THREE.Source
to a texture constructor is problematic since textures do not have a common signature for their data definitions. Meaning this quickly breaks if you want to assign a source object to a data texture because this class describes its image data with three parameters. So instead of doing:you would expect:
which obviously breaks the signature. At least it is a bit messy to process this use case in code.
The PR does not support this pattern right now so the code example from #17949 (comment) looks like so: