BlendLuxCore
BlendLuxCore copied to clipboard
LOL: .blend file bloated with preview thumbnails
Issue
When packing all external data into .blend file, all the preview thumbnails will get packed as well. I noticed, when I used one BlendLuxCore-saved file on another computer, it then complained about missing images, when toggling "Automatically pack into .blend" off and on.
Besides all the thumbnails, this is isn't pretty either:

OS:
Blender version: 2.83 LuxCore version: BlendLuxCore-latest-win64
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
This is a drawback of using Blender's image datablocks.
Instead, we should load the images ourselves. For example, we could save them in PFM format, where we already have a loader: https://github.com/LuxCoreRender/BlendLuxCore/blob/master/utils/pfm.py
We would then store the image pixel data in a bgl.Buffer and load it into OpenGL:
buffer_size = width * height * channel_count
buffer = bgl.Buffer(bgl.GL_BYTE, [buffer_size])
# Transfer pixel data into the buffer here
...
# Load into OpenGL
gl_format = bgl.GL_RGBA
internal_format = bgl.GL_RGBA8
texture = bgl.Buffer(bgl.GL_INT, 1)
bgl.glGenTextures(1, texture)
texture_id = texture[0]
bgl.glActiveTexture(bgl.GL_TEXTURE0)
bgl.glBindTexture(bgl.GL_TEXTURE_2D, texture_id)
bgl.glTexImage2D(bgl.GL_TEXTURE_2D, 0, internal_format, width, height,
0, gl_format, bgl.GL_BYTE, buffer)
edge_mode = bgl.GL_CLAMP_TO_EDGE
bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_WRAP_S, edge_mode)
bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_WRAP_T, edge_mode)
interpolation_mode = bgl.GL_LINEAR
bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, interpolation_mode)
bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, interpolation_mode)
NULL = 0
bgl.glBindTexture(bgl.GL_TEXTURE_2D, NULL)
We can then draw the texture using the generated texture_id.
Just one more question: Where (in which material.blend) are those textures scratched_painted_metal_01_2k_Height.png and Smudges_01_2k.png stored?
Is Blender really storing all the hidden images on packing? Doesn't Blenderkit has the same problem then since the initial code comes from that addon? The rework of the code will require a lot of work. I am currently writing an addon for Sharlybg which can manage the assets on the server which is integrated into Blender and Blender doesn't support PFM files, IIRC.
Not that it matters much, but there are 379 additional files (images), a total of just over 2 MB, stored in a .blend file. Carry that blend file to another computer (with another username logged in) and toggle "Automatically pack into .blend" off and back on - you'll get the whole list of missing files at each and every save.
Just one more question: Where (in which material.blend) are those textures
scratched_painted_metal_01_2k_Height.pngandSmudges_01_2k.pngstored?
Both textures are in the 'Textured Dark Chrome' material blend file but only one is used. I have to investigate what is going on and why they are not available on your side.
Doesn't Blenderkit has the same problem then since the initial code comes from that addon?
Yes.
About the file format, we can stick to JPG, we just need a function that reads the JPG into memory and gives us the pixel data. I can add such a function to pyluxcore for blender and write a proof-of-concept that shows how to use it.
About the file format, we can stick to JPG, we just need a function that reads the JPG into memory and gives us the pixel data. I can add such a function to pyluxcore for blender and write a proof-of-concept that shows how to use it.
That would be great. I will have only little time to work on the library in the next weeks. Today is the calculated birth date of our daughter and we are expecting the baby in the next days.
Congratulations!
I can add such a function to pyluxcore for blender and write a proof-of-concept that shows how to use it.
I have done this a while ago, but then I tried to integrate it into the LOL part of the addon and got nowhere. I'll push the LuxCore code to a branch sometime or link it as a diff.