[Plugin] MaterialConsolidator
-
###########################################################################
TIG (c) 2010-2019
All Rights Reserved.
THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES,INCLUDING,WITHOUT LIMITATION,THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
###########################################################################
materialconsolidator.rb
###########################################################################
Type 'TIG::MaterialConsolidator.new' in the Ruby Console.
OR
'Menu' > 'Tools' > 'Material Consolidator'
All materials with the same 'properties' are consolidated into one, and the
rest are purged... [the progress is reported in the Console/Command-line]
It is one step undoable.
The Status Bar and/or Ruby Console reports progress.
The Ruby Console also lists the names of any purged materials.
###########################################################################
Two materials are only considered duplicates if they have exactly matching 'properties'.
These are:-
materialType
color RGB
transparency [alpha]If 'material.texture', then also:-
texture.filename
texture.image_width
texture.image_height
texture.width
texture.heightThe materials are all compared with each other.
If ANY one of their properties don't match then the compared materials are NOT duplicates and therefore they are NOT consolidated.
However, if ALL of the properties do match then the first 'duplicated material' in the list is 'kept'... all objects using these 'duplicated materials' will have them replaced with the 'kept' material [i.e. they are 'consolidated']...
On completion any now unused 'duplicated materials' are purged...With v2.0 the exactness [tolerance] of the matches is also optional.
When you start the tool a dialog asks you if you want to specify a tolerance,
If you answer Yes a second dialog asks you to specify them...
Its options are:RGB Red 0=exact ..255 variance range
RGB Green 0=exact ..255 variance range
RGB Blue 0=exact ..255 variance range
Alpha 0=exact ..100 variance rangeLeaving everything set to the default 0 forces exact matches only...
So if a material's Red is 127, 0 matches 127 exactly, and 10 matches 117 to 137,
255 matches all values of Red 0 to 255, although in this case 128 would have
sufficed, because 0 to 255 are the outermost limits.
The Alpha range of 100 reflects the possible 0 to 100 values allowed.
Use with thought, undo if results are unexpected - e.g. you manage to wipe all
transparent materials or make everything 'black' !
###########################################################################
Version:
1.0 20101218 First issue.
1.1 20101218 Menu added.
1.2 20101219 Listing/Sorting optimized, command-line prompts added.
1.3 20110116 Wrapped into a class 'MaterialConsolidator'.
2.0 20190722 Module wrapped, 'tolerances' added.
3.0 20190722 Tolerance rules tweaked.
Get the latest version from the PluginStore:
https://sketchucation.com/pluginstore?pln=materialconsolidator -
@tig said:
All materials with the same 'properties' are consolidated into one
What do you mean by "properties"?
-
@gaieus said:
@tig said:
All materials with the same 'properties' are consolidated into one
What do you mean by "properties"?
Two materials are only considered duplicates if they have exactly matching 'properties'.
These are:-materialType
color RGB
transparency [alpha] If 'material.texture' then also:-texture.filename
texture.image_width
texture.image_height
texture.width
texture.height
The materials are all compared with each other.
If ANY one of their properties don't match then the compared materials are NOT duplicates and therefore they are NOT consolidated.
However, if ALL of the properties do match then the first 'duplicated material' in the list is 'kept'... all objects using these 'duplicated materials' will have them replaced with the 'kept' material [i.e. they are 'consolidated']...
On completion any now unused 'duplicated materials' are purged... -
Whoow TIG ! are you my Santa? Yesterday I was thinking that I could use something like that... and today here it is!
Dear Santa, Thanks for this mighty plugin and if you don't mind I would like in completion a bike, some tricky soap (the kind which colors hands in black), for my dear sister :imp: and a candy ! :smile:
-
Thanks TIG for the explanation, it makes sense now.
Ah, and before I forget; many thanks for the plugin, too!
-
thank you so much TIG! this is a blessing. i can't tell you how many times i've downloaded models from the 3d warehouse which seem to exponentially multiply the list of materials already in my model.
-
Hi TIG,
Are the faces that were painted with a "removed" material repainted with the consolidated one ?
I mean suppose you have 2 faces, one is painted with material m1 and the other with material m2.
If the materials have matching properties, one of them is purged, say m2.
Does the face painted with m2 repainted with the remaining m1 material ?
Thanks for all your work, -
@didier bur said:
Hi TIG,
Are the faces that were painted with a "removed" material repainted with the consolidated one ?
I mean suppose you have 2 faces, one is painted with material m1 and the other with material m2.
If the materials have matching properties, one of them is purged, say m2.
Does the face painted with m2 repainted with the remaining m1 material ?
Thanks for all your work,Yes!
It ensures that only one material of the exact same 'properties' is used - this means that if m1==m2 then everything*** that used m2 now has m1 and m2 is purged if m1==m2==m3 etc m2 and m3 go and everything is m1...
---'everything' means all faces, edges, groups and component-instances etc... in the model and inside definitions too... -
Excellent!
-
Another awesome and needed tool, any possibility to have it available in the 'tools' drop down menu? as typing into ruby consol everytime will require me to remember the command and I have already forgotten it.
-
Awesome! It's time to clean those Augean stables.
-
Sweet! Thanks, TIG!
@solo said:
Another awesome and needed tool, any possibility to have it available in the 'tools' drop down menu? as typing into ruby consol everytime will require me to remember the command and I have already forgotten it.
+1
-
Here's v1.1 http://forums.sketchucation.com/viewtopic.php?p=295290#p295290
It now has 'Material Consolidator' under the 'Tools' menu... -
Oh, YES!!
Thank you, TIG
-
Hi TIG!
I have some important suggestion. The majority of people working in the 3D field use some prefixes in the mats\layers\camera names. It's extremely helpful to differ my stuff from the others.I for example name all my assets in this way: zzz_blahblah. And everything is inserted in the initial template file.
So what I'm asking for is ability to set the default nameprioty directly in the ruby file
itself (just to set up it once and forget). In my case zzz_* formula would be dominant.
What do you think? -
rv1974
At the moment the first material in the database is used in preference to any other matches [the names are not considered just the position in the list], so if you have 'zzz_Material', 'zzz_Material1' and 'xxx_Material99' that are all exact matching 'clones' and 'zzz_Material' is the first one then everything becomes 'zzz_Material' and the others are purged...
I can't see how we would use 'prefixes' to sort materials [at the moment, as I said, the name is ignored and its 'order of being created' is used] -
Here's v1.2 http://forums.sketchucation.com/viewtopic.php?p=295290#p295290
The listing and sorting algorithms have been optimized for speed and command-line/console progress messages added... -
@tig said:
rv1974
At the moment the first material in the database is used in preference to any other matches [the names are not considered just the position in the list], so if you have 'zzz_Material', 'zzz_Material1' and 'xxx_Material99' that are all exact matching 'clones' and 'zzz_Material' is the first one then everything becomes 'zzz_Material' and the others are purged...
I can't see how we would use 'prefixes' to sort materials [at the moment, as I said, the name is ignored and its 'order of being created' is used]
order of being created is already a nice thing. The workaround is to embed a simple planes matrix with user common used materials applied into initial template.
Thank you. -
-
@rocorona said:
@tig said:
@gaieus said:
@tig said:
These are:-
materialType
color RGB
transparency [alpha]What is a material "type"?
I feel I'm missing something basilar, but I can't find this in the "modify material" window.The
materialType
is accessible via the API - it returns values [0/1/2] depending on if the material is simply a 'plain-color', has a 'texture' or it has a texture and it has been 'colorized'... that's all... http://code.google.com/apis/sketchup/docs/ourdoc/material.html#materialType
Advertisement