#!BPY """ Name: 'Refractor' Blender: 2.46 Group: 'Materials' Tooltip: 'Set a Material's IOR value to a preset value' """ __author__ = "Kevin Morgan" __version__ = "1.5 3/6/2008" __url__ = ["http://gamulabs.freepgs.com"] __email__ = ["Please PM user forTe on BA.org for questions"] __bpydoc__ = """ This script will pop up a series of menus:
The first menu will allow the user to select a material in there file.
The second menu has IOR values organized by type (Solid, Liquid, Gas, Organic). The user just selects one.

COMPATABILITY NOTICE: This script will not work in versions prior 2.46, because it uses the PupTreeMenu feature, added in 2.46. For an older version of the script, see my site. """ # Copyright 2008, Kevin Morgan # -------------------------------------------------------------------------- # ***** BEGIN GPL LICENSE BLOCK ***** # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # ***** END GPL LICENCE BLOCK ***** # -------------------------------------------------------------------------- import Blender.Draw as D import bpy # IOR Value Dictionaries, Organized by relative states of matter IORDictGas = { 'Vacuum': 1.000, 'Air': 1.000} IORDictLiq = { 'Benzene (20 C)': 1.501, 'Water (20 C)': 1.333, 'Ethanol (20 C)': 1.361, 'Carbon Tetrachloride (20 C)': 1.461, 'Carbon Disulfide (20 C)': 1.628, 'Acetone': 1.36, 'Glycerol': 1.473, 'Bromine': 1.661, 'Sugar Solution': 1.49} IORDictSol = { 'Diamond': 2.419, 'Strontium Titanite': 2.41, 'Amber': 1.55, 'Fused Silica': 1.458, 'Sodium Chloride (Salt)': 1.50, 'Pyrex': 1.470, 'Ruby': 1.760, 'Ice': 1.31, 'Cryolite': 1.338, 'Acrylic': 1.491, 'Rock Salt': 1.516, 'Crown Glass': 1.52, 'Polycarbonate': 1.585, 'PET': 1.575, 'Flint Glass': 1.6, 'Fused Quartz': 1.46, 'Cubic Zirconia': 2.165, 'Moissanite': 2.67, 'Sapphire': 1.77} IORDictOrg = { 'Cornea': 1.38, 'Eye Lens': 1.41, 'Vitreous Humor': 1.34, 'Aqueous Humor': 1.33} def setIORValue(matName, value): bpy.data.materials[matName].setIOR(value) return gasOffset = 1 liqOffset = 100 solOffset = 200 orgOffset = 300 scriptOffset = 500 def drawMaterialMenu(): men = 'REFRACTOR: Select Material%t|' matNames = [m.name for m in bpy.data.materials] m = [m + '%x' + str(i) + '|' for i,m in enumerate(matNames)] men += ''.join(m) men += '%l|QUIT SCRIPT%x'+str(len(matNames)) rval = D.PupMenu(men) if rval == len(matNames): return -1, -1 else: return rval, matNames def drawIORMenu(matName): GasNames = [k for k in IORDictGas.keys()] LiqNames = [k for k in IORDictLiq.keys()] SolNames = [k for k in IORDictSol.keys()] OrgNames = [k for k in IORDictOrg.keys()] # Zip returns a list: [(Vacuum, 1), (Air, 2)] gas = zip(GasNames, xrange(gasOffset, gasOffset + len(GasNames))) gasMen = ("Gases", gas) # Zip Return list: [(Water, 1.333), ...] liq = zip(LiqNames, xrange(liqOffset, liqOffset+len(LiqNames))) liqMen = ("Liquids", liq) sol = zip(SolNames, xrange(solOffset, solOffset+len(SolNames))) solMen = ("Solids", sol) org = zip(OrgNames, xrange(orgOffset, orgOffset+len(OrgNames))) orgMen = ("Organics", org) # Options for Script scriptMen = ("Options", [("Current Material: " + matName, scriptOffset), ("Change Material", scriptOffset + 1), ("Quit", scriptOffset + 2)]) # Need to return result as well as how the menus currently are return D.PupTreeMenu([gasMen, liqMen, solMen, orgMen, scriptMen]), gas, liq, sol, org def main(): while 1: mId, matNames = drawMaterialMenu() # Get the index into matNames if mId < 0: #Exit if -1 break matName = matNames[mId] iorId, gasMen, liqMen, solMen, orgMen = drawIORMenu(matName) if iorId == scriptOffset: # Select Current Material iorId = drawIORMenu(matName) if iorId == scriptOffset + 1: # Change Material continue if iorId == scriptOffset + 2: # Quit break iorValue = 1.000 # Values stored in gasMen are stored as ('Name', id), we pull out Name and use it as a key # for the appropriate dictionary based off the offsets we've already set. if iorId < liqOffset: iorValue = IORDictGas[gasMen[iorId - gasOffset][0]] if iorId >= liqOffset and iorId < solOffset: iorValue = IORDictLiq[liqMen[iorId - liqOffset][0]] if iorId >= solOffset and iorId < orgOffset: iorValue = IORDictSol[solMen[iorId - solOffset][0]] if iorId >= orgOffset and iorId < scriptOffset: iorValue = IORDictOrg[orgMen[iorId - orgOffset][0]] setIORValue(matName, iorValue) break return main()