Materials Library

First, I was not talking about the user interface, which I think is excellent. Nor would I remove functionality, as I feel you have done a good job in organizing the interface in such a way that it is easy use.

I published some days ago, my materials.blend with over 100 categorized materials, but the point is that the addon “should never be used into the database”. materials.blend is meant to be just a container for all those materials. not a file to work with this addon.
I realize that materials.blend is simply a container. But I would argue that, because the script cannot run without it, it should be a part of the standard distribution rather than requiring a user to create one or download one separately. Yes, I realize it is really easy to create the file, just tying to think of any and every little detail that can be done to simplify the life of a user, especially a less technically inclined user, without detracting from the functionality. Some ideas on ways that you could make it a part of the standard distribution would be to either generate the file automatically if it is missing (this could be a simple try-except block) or include one with the script download. The same would be true of the categories.xml file.

I think the script is portable in the way that you can copy the database, categories.xml and matlibvx.py to another computer and will work the same. [I’m] providing instruction into the web site. Change the first 2 variables, matlibpath and catspath on the new machine and its done. [Emphasis mine]

A folder would make things a bit easier, [that’s] right. and you can change the script to point to a specific folder instead the binary path, if u like, just make sure that path is absolute.
This is very trivial for you and for myself, but again, do you really want a less tech savy user to have to figure this out? I would argue no, you don’t. The code snippet I throw out might be a cleaner solution for a less technical user. What it does is it gets path to the source file for the code that is running, similar to how bpy.app.binary_path provides the path to the Blender binary. This would allow you to have the material.blend and categories.xml files in the same directory as the actual python script. The user would not need to modify the path regardless of their platform. It would “just work”. Additionally for distribution on your end you can have the trio in a zip file the a user downloads, all files are extracted to the same location, and then the user can just have a single folder they can move from machine to machine (increased portability and increased ease of use).

Merge materials is a cool thing that you can do, if you think about it materials.blend is a blend file. So you can append straight to the library all the materials you want. Just make sure those materials are using a fake user to avoid that they are flushed after saving.

I guess im providing the code to change all fake users at once. After the appending run this:

for mat in bpy.data.materials:
mat.use_fake_user=True

save the file and its done, 50 more materials added to the database.
I’m just wondering if there is a way to automate this. Something like at the bottom of your current interface you have a path field and a button that say’s “Merge”. To use it you would specify the path to some material.blend file and then press “Merge”. The add-on would then do the work of scanning for every material in the specified .blend and add it to the current .blend, complete with fake users. A quick mockup of how the interface might look is attached.

I run out of ideas, i dont know what can i do to improve it further
If I think of anything, I’ll let you know :wink:

Attachments


That suggestions are all great BrikBot. Ill study them and I agree that users shouldnt be python skilled in order to use the addon. I just didnt figure it out how to implement all of this without having to do little setup.

One thing that i got in mind when i did the addon was to try to use the minimum amount of space for all those controls. For example i could have drawn two filepath finders, the same as your picture for mats.blend and cats.xml so you can configure where they are, or even point to another library. But i discarded that because it would take a lot of unusued space once they are configured. Materials properties is a large section so i thought this was important.

However a solution could be to add a setup button that shows and hides “extra” options. Such the merge feature you suggested. That could work.

The inspect works good. Removing the script name instead the excutable solves the crossplatform problems. It didnt know about that module. Ill see how can i setup it. I like the folder idea. and ill try that too.

Last, Creating the database. Hmm this could be a tricky one, basically what you do when you create materials.blend is making a copy of the startup.blend. But different users could set the startup.blend the same as their current project, so the database could contain a lot of unnecesary geometry. Thats why i told the user to manually create the database.
A solution could be to remove all the unwanted objects once the file is copied.

I will check all those options in time, im developing the curve tools right now but i will take a look at your suggestions, they are all welcome.

Cheers.

However a solution could be to add a setup button that shows and hides “extra” options. Such the merge feature you suggested. That could work.
So your thinking something like the attached mockups?

Also, I see what you mean with creating a database. That one will be tricky, but I think it will be feasible.

Attachments



Yes, thats exactly what i thought in first place. Its looks good for the merge feature but i was thinking about source and xml.

First, I cant see any advantage for having multiple databases, this also could lead to potential mistakes if the option is “hidden” and you are saving materials into a wrong file. The only case that i thought it could be useful was for network share.

The xml should be tied togheter with the source so its not a good thing to let the user change the categories path. If i consider to make a Source finder the xml shall be automated.

As i said it looks good but i have to consider all of these. Its still valid for merge or other operations that would come in mind.

Im studying to implement thumbnails generation, ill know soon if this is possible.

Hai, As you know there is a script called material utilities. It is having options like select by material, assign material to selection etc. If you can merge those options with your script with some icons I think it will be very useful

Hi swathi.
Blender already have that functions without the need of an addon. Select by material is Shift+L. Assign material to several objects is called make links by materials on Ctrl+L and you also have copy/paste materials right below to add/remove object’s material.

These type secrets are the problem with blender. Normally people can see it if there is an icon some where near material editor

Thanks for the quick replay

I am willing to bet you’ve already thought through most of this, but thinking about thumbnails, I keep coming to two primary methods for them. I’ve listed them below with the pros and cons that I can think of off the top of my head for each:

Realtime Rendering
Would render a preview for the material when and every time it is requested.+ No disk usage

  • Could be very slow with complex materials
  • Could be very slow with a large preview
  • Relies on the Blender internal render; might not be suitable for non-Blender materialsCached Images
    Would render a preview for a material either on creation or the first time a preview for the material is requested if it does not exist. Then for the preview it would simply show the cached image.+ Can be very fast
  • Can be stored inside the .blend file
  • Requires additional disk space to store the images
  • Rendering preview image may cause what the user sees to be odd lock-ups as the image is rendered
  • May have to rely on the Blender internal render; might not be suitable for non-Blender materials
    I tinkered around with the scripting the second and I can see how to create a new image and render the current one, but cannot seem to get the image data from the rendered image to the new image within Blender. It looks like you might have to have the render save to disk, then import the saved image as a new image and pack it.

That is really cool, Brikbot.

I didnt thought about realtime preview and it can be an interesting solution. It could be done using the bgl module and a bit of shading language.
For complex materials the preview can be clamped, i mean you dont have to preview all the material settings such sub surface scattering. Very interesting but difficult to program. I could give a try.

My first thought was screen capturing the material preview panel on creation. With a new redesign with some of your ideas (that im willing to do) such the inspect and create its own addon folder this is very possible. Screen capture has some advantages, that is you dont have to wait for render, and blender’s material preview supports external renders.

Images can be stored inside the blend file but i think it would be faster to store them outside, so you dont have to make calls to the database, neither make a new image datablock. Yep, aditional disk space but theres nothing much we can do here. Thumbnails are going to be really small sized so not much of a problem.

create a new image and render the current one, but cannot seem to get the image data from the rendered image to the new image

I guess that the rendered image is an image called “Render Result” that you can save to disk directly, so you dont have to create a new one. Render to disk its also possible or even use a temporary scene to do the renders. (i dont like the render idea but its something to consider if the other options fails)

Another subject that can be a problem is adding or modifying materials straight into the database. But its all a matter to try and experiment.

Thanks again for your very valuable ideas, Brikbot. Ill come back if i do any progress.

My first thought was screen capturing the material preview panel on creation. . . . Screen capture has some advantages, that is you dont have to wait for render, and blender’s material preview supports external renders.
That sounds like it would be ideal since it does support external renders. My question would be how you would reliably capture the preview? Especially since there is no guarantee on the location of the preview window on the screen. I wonder if there is a way to access the preview image within Blender. . . .

Another subject that can be a problem is adding or modifying materials straight into the database. But its all a matter to try and experiment.
It would slow start up time but you could scan the materials on start up and see if there is a corresponding image and if not, generate one. Or if the image does not exist when you try to show the preview, generate it then. That might have less of an impact on overall script performance. I feel like the ideal would be to have it check and generate in the background while the add-on is not being used . . . maybe as a separate thread? Python’s GIL would prevent the thread from running while the main thread is active helping minimize its impact. It could be very tricky to get the handle passed around correctly though. Oh, and it might cause a problem if the user tries to preview the material and the preview image has not been generated yet, which I feel like brings it back to generating the preview if it is absent. Anyway, just some thoughts.

Ive update the script with some of Brikbots suggestions.Update list is published at the main thread.

Hope you like them and see ya soon.

Hi Alfonso,

Thanks for your “Matlib VX 5.3” addon. I love it!

But i have had a bug with: If you have a space in the name of one folder to your matlib folder, you don’t register your new material. The script try to execute a bad address to the materials.blend because the address is cut where is the space. Try to mind at this, please.

I have a error when I reload too…(windows Blender 2.59 Rev39725)
Traceback (most recent call last):
File “C:…\addons_extern\matlib_init_.py”, line 808, in invoke
self.report(msgtype, msg)
TypeError: MATLIB_OT_add_remove_matlib.report(): error with argument 1, “type” - ,
Function.type expected a set, not a str

Byby

Ok didnt notice about that. Ill try to fix it soon.
Thanks for the feedback.

Actually I am working on this and much , much more :wink:

getting an error with this one, on ubuntu 11.04 here is the error



- Traceback (most recent call last):
-   File "/home/exloupis/blender/2.59/scripts/addons_extern/matlib/__init__.py", line 806, in invoke
-     self.report(msgtype, msg)
- TypeError: MATLIB_OT_add_remove_matlib.report(): error with argument 1, "type" - , Function.type expected a set, not a str
-  
- location:<unknown location>:-1
-  
- location:<unknown location>:-1
- Can't open file C:/Users/Dad/AppData/Local/Temp/14981.blend@ for writing: No such file or directory.
- 


first one is self explanatory. The second error is because :
a) you assume i use windows
b) you assume c: is the partition where blender is run

The script doesnt assume it uses windows, its makes use of the inspect module to detect the appropiate path.

Having an error on the report function, should indicate an api change. The last time that i tested the script was on 2.59 rev39307 and it worked. Maybe on earlier builds it doesnt.

A known bug that i havent fixed yet is that if the path to library has any spaces the script fails on saving and load materials.
for example:
Wrong paths:
X:\Blender Foundation\2.59\scripts\addons\matlib(matlib files)
X:\Program Files\Blender\2.59\scripts\addons\matlib(matlib files) it has an space

Valid Path:
X:\Blender\2.59\scripts\addons\matlib(matlib files)

This doesnt seem to be your problem, so i guess it could be due a change on the api. I dont have many time to check this out, but ill see what i can do.

Thanks for the feedback kilon.

Regards.

This is weird, I keep getting the second error even if I deactivate your script, which means one thing. That your script is not to blame .Must be a blender bug.

By the way I use Blender 2.59 r 40555 on ubuntu 11.04 just for your information. Take your time, I am not in any hurry.

EDIT: Not even a blender bug apparently the blend file was to blame it pointed to a windows temp folder. All is good.

Hello Mackraken, first of all thank you very much for your add-on which is really useful. I would like to know if in the meantime you had the chance to fix the reporting error which is still there. Hopefully, being now almost close to Blender’s release 2.61 could you tell us if your addon will work also with Cycles materials?

Good life and kind regards,

Harvester

Hey Harvester.

I dont know what you mean about the report error.
The only error that i havent fixed yet is having spaces at the blenders binary route.
For example:
You have installed blender at:
C:\Blender Foundation\Blender\2.xx\blender.exe (it has space, matlib doesnt work)
or C:\Program files\Blender\2.59\blender.exe

It works well if you have a path like:
X:\Blender\2.59\blender.exe
or
X:\SomeFolderWithoutSpaces\Blender\2.59\blender.exe

Its tricky to fix and you can solve it by fixing the path. so this is not in my list at the moment.

I havent tested cycles yet but it should work well. I will do it as soon as i finish some scripts that i have in hands.
If this is not the error that are you talkin pls let me know.

Thanks for the feedback

This one for cycles materials would made my day!
MAckraken this is so needed for the cycles render engine…
I hate to build nodes agagain and again…