properties_texture.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  1. # ##### BEGIN GPL LICENSE BLOCK #####
  2. #
  3. # This program is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU General Public License
  5. # as published by the Free Software Foundation; either version 2
  6. # of the License, or (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software Foundation,
  15. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. #
  17. # ##### END GPL LICENSE BLOCK #####
  18. # <pep8 compliant>
  19. import bpy
  20. from bpy.types import (
  21. Menu,
  22. Panel,
  23. UIList,
  24. )
  25. from bpy.types import (
  26. Brush,
  27. FreestyleLineStyle,
  28. ParticleSettings,
  29. Texture,
  30. )
  31. from rna_prop_ui import PropertyPanel
  32. from bl_ui.properties_paint_common import brush_texture_settings
  33. class TEXTURE_MT_context_menu(Menu):
  34. bl_label = "Texture Specials"
  35. COMPAT_ENGINES = {'BLENDER_RENDER'}
  36. def draw(self, _context):
  37. layout = self.layout
  38. layout.operator("texture.slot_copy", icon='COPYDOWN')
  39. layout.operator("texture.slot_paste", icon='PASTEDOWN')
  40. class TEXTURE_UL_texslots(UIList):
  41. def draw_item(self, _context, layout, _data, item, icon, _active_data, _active_propname, _index):
  42. slot = item
  43. tex = slot.texture if slot else None
  44. if self.layout_type in {'DEFAULT', 'COMPACT'}:
  45. if tex:
  46. layout.prop(tex, "name", text="", emboss=False, icon_value=icon)
  47. else:
  48. layout.label(text="", icon_value=icon)
  49. elif self.layout_type == 'GRID':
  50. layout.alignment = 'CENTER'
  51. layout.label(text="", icon_value=icon)
  52. def context_tex_datablock(context):
  53. idblock = context.brush
  54. if idblock:
  55. return idblock
  56. idblock = context.line_style
  57. if idblock:
  58. return idblock
  59. if context.particle_system:
  60. idblock = context.particle_system.settings
  61. return idblock
  62. class TextureButtonsPanel:
  63. bl_space_type = 'PROPERTIES'
  64. bl_region_type = 'WINDOW'
  65. bl_context = "texture"
  66. class TEXTURE_PT_preview(TextureButtonsPanel, Panel):
  67. bl_label = "Preview"
  68. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  69. @classmethod
  70. def poll(cls, context):
  71. tex = context.texture
  72. return tex and (tex.type != 'NONE' or tex.use_nodes) and (context.engine in cls.COMPAT_ENGINES)
  73. def draw(self, context):
  74. layout = self.layout
  75. tex = context.texture
  76. slot = getattr(context, "texture_slot", None)
  77. idblock = context_tex_datablock(context)
  78. if idblock:
  79. layout.template_preview(tex, parent=idblock, slot=slot)
  80. else:
  81. layout.template_preview(tex, slot=slot)
  82. # Show Alpha Button for Brush Textures, see #29502
  83. idblock = context_tex_datablock(context)
  84. if isinstance(idblock, Brush):
  85. layout.prop(tex, "use_preview_alpha")
  86. class TEXTURE_PT_context(TextureButtonsPanel, Panel):
  87. bl_label = ""
  88. bl_context = "texture"
  89. bl_options = {'HIDE_HEADER'}
  90. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  91. def draw(self, context):
  92. layout = self.layout
  93. tex = context.texture
  94. space = context.space_data
  95. pin_id = space.pin_id
  96. use_pin_id = space.use_pin_id
  97. user = context.texture_user
  98. col = layout.column()
  99. if not (use_pin_id and isinstance(pin_id, bpy.types.Texture)):
  100. pin_id = None
  101. if not pin_id:
  102. col.template_texture_user()
  103. if user or pin_id:
  104. col.separator()
  105. if pin_id:
  106. col.template_ID(space, "pin_id")
  107. else:
  108. propname = context.texture_user_property.identifier
  109. col.template_ID(user, propname, new="texture.new")
  110. if tex:
  111. col.separator()
  112. split = col.split(factor=0.2)
  113. split.label(text="Type")
  114. split.prop(tex, "type", text="")
  115. class TEXTURE_PT_node(TextureButtonsPanel, Panel):
  116. bl_label = "Node"
  117. bl_context = "texture"
  118. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  119. @classmethod
  120. def poll(cls, context):
  121. node = context.texture_node
  122. return node and (context.engine in cls.COMPAT_ENGINES)
  123. def draw(self, context):
  124. layout = self.layout
  125. node = context.texture_node
  126. ntree = node.id_data
  127. layout.template_node_view(ntree, node, None)
  128. class TextureTypePanel(TextureButtonsPanel):
  129. @classmethod
  130. def poll(cls, context):
  131. tex = context.texture
  132. engine = context.engine
  133. return tex and ((tex.type == cls.tex_type and not tex.use_nodes) and (engine in cls.COMPAT_ENGINES))
  134. class TEXTURE_PT_clouds(TextureTypePanel, Panel):
  135. bl_label = "Clouds"
  136. tex_type = 'CLOUDS'
  137. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  138. def draw(self, context):
  139. layout = self.layout
  140. layout.use_property_split = True
  141. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  142. tex = context.texture
  143. col = flow.column()
  144. col.prop(tex, "noise_basis", text="Noise Basis")
  145. col.separator()
  146. col.prop(tex, "noise_type", text="Type")
  147. col.separator()
  148. col = flow.column()
  149. col.prop(tex, "cloud_type")
  150. col.separator()
  151. col = flow.column()
  152. col.prop(tex, "noise_scale", text="Size")
  153. col.prop(tex, "noise_depth", text="Depth")
  154. col.prop(tex, "nabla", text="Nabla")
  155. class TEXTURE_PT_wood(TextureTypePanel, Panel):
  156. bl_label = "Wood"
  157. tex_type = 'WOOD'
  158. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  159. def draw(self, context):
  160. layout = self.layout
  161. layout.use_property_split = True
  162. flow = layout.grid_flow(row_major=True, columns=0, even_columns=False, even_rows=False, align=False)
  163. tex = context.texture
  164. col = flow.column()
  165. col.prop(tex, "noise_basis", text="Noise Basis")
  166. col.separator()
  167. col.prop(tex, "wood_type")
  168. col.separator()
  169. col = flow.column()
  170. col.prop(tex, "noise_basis_2", text="Second Basis")
  171. col = col.column()
  172. col.active = tex.wood_type in {'RINGNOISE', 'BANDNOISE'}
  173. col.prop(tex, "noise_type", text="Type")
  174. col.separator()
  175. sub = flow.column()
  176. sub.active = tex.wood_type in {'RINGNOISE', 'BANDNOISE'}
  177. sub.prop(tex, "noise_scale", text="Size")
  178. sub.prop(tex, "turbulence")
  179. sub.prop(tex, "nabla")
  180. class TEXTURE_PT_marble(TextureTypePanel, Panel):
  181. bl_label = "Marble"
  182. tex_type = 'MARBLE'
  183. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  184. def draw(self, context):
  185. layout = self.layout
  186. layout.use_property_split = True
  187. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  188. tex = context.texture
  189. col = flow.column()
  190. col.prop(tex, "noise_basis", text="Noise Basis")
  191. col.separator()
  192. col.prop(tex, "marble_type")
  193. col.separator()
  194. col = flow.column()
  195. col.prop(tex, "noise_basis_2", text="Second Basis")
  196. col.prop(tex, "noise_type", text="Type")
  197. col.separator()
  198. col = flow.column()
  199. col.prop(tex, "noise_scale", text="Size")
  200. col.prop(tex, "noise_depth", text="Depth")
  201. col.prop(tex, "turbulence")
  202. col.prop(tex, "nabla")
  203. class TEXTURE_PT_magic(TextureTypePanel, Panel):
  204. bl_label = "Magic"
  205. tex_type = 'MAGIC'
  206. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  207. def draw(self, context):
  208. layout = self.layout
  209. layout.use_property_split = True
  210. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=False)
  211. tex = context.texture
  212. col = flow.column()
  213. col.prop(tex, "noise_depth", text="Depth")
  214. col = flow.column()
  215. col.prop(tex, "turbulence")
  216. class TEXTURE_PT_blend(TextureTypePanel, Panel):
  217. bl_label = "Blend"
  218. tex_type = 'BLEND'
  219. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  220. def draw(self, context):
  221. layout = self.layout
  222. layout.use_property_split = True
  223. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  224. tex = context.texture
  225. col = flow.column()
  226. col.prop(tex, "progression")
  227. col.separator()
  228. col = flow.column()
  229. col.active = (tex.progression in {'LINEAR', 'QUADRATIC', 'EASING', 'RADIAL'})
  230. col.prop(tex, "use_flip_axis", text="Orientation")
  231. class TEXTURE_PT_stucci(TextureTypePanel, Panel):
  232. bl_label = "Stucci"
  233. tex_type = 'STUCCI'
  234. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  235. def draw(self, context):
  236. layout = self.layout
  237. layout.use_property_split = True
  238. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=False)
  239. tex = context.texture
  240. col = flow.column()
  241. col.prop(tex, "noise_basis", text="Noise Basis")
  242. col.separator()
  243. col.row().prop(tex, "stucci_type")
  244. col.separator()
  245. col = flow.column()
  246. col.prop(tex, "noise_type", text="Type")
  247. col.separator()
  248. col = flow.column()
  249. col.prop(tex, "noise_scale", text="Size")
  250. col.prop(tex, "turbulence")
  251. class TEXTURE_PT_image(TextureTypePanel, Panel):
  252. bl_label = "Image"
  253. tex_type = 'IMAGE'
  254. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  255. def draw(self, _context):
  256. # TODO: maybe expose the template_ID from the template image here.
  257. layout = self.layout
  258. del layout
  259. class TEXTURE_PT_image_settings(TextureTypePanel, Panel):
  260. bl_label = "Settings"
  261. bl_parent_id = 'TEXTURE_PT_image'
  262. tex_type = 'IMAGE'
  263. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  264. def draw(self, context):
  265. layout = self.layout
  266. tex = context.texture
  267. layout.template_image(tex, "image", tex.image_user)
  268. def texture_filter_common(tex, layout):
  269. layout.prop(tex, "filter_type", text="Filter Type")
  270. if tex.use_mipmap and tex.filter_type in {'AREA', 'EWA', 'FELINE'}:
  271. col = layout.column()
  272. if tex.filter_type == 'FELINE':
  273. col.prop(tex, "filter_lightprobes", text="Light Probes")
  274. else:
  275. col.prop(tex, "filter_eccentricity", text="Eccentricity")
  276. layout.prop(tex, "filter_size", text="Size")
  277. layout.prop(tex, "use_filter_size_min", text="Minimum Size")
  278. class TEXTURE_PT_image_sampling(TextureTypePanel, Panel):
  279. bl_label = "Sampling"
  280. bl_options = {'DEFAULT_CLOSED'}
  281. bl_parent_id = 'TEXTURE_PT_image'
  282. tex_type = 'IMAGE'
  283. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE'}
  284. def draw(self, context):
  285. layout = self.layout
  286. layout.use_property_split = True
  287. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  288. tex = context.texture
  289. col = flow.column()
  290. col.prop(tex, "use_interpolation")
  291. col.separator()
  292. col = flow.column()
  293. col.prop(tex, "use_mipmap")
  294. sub = col.column()
  295. sub.active = tex.use_mipmap
  296. sub.prop(tex, "use_mipmap_gauss", text="Gaussian Filter")
  297. col.separator()
  298. texture_filter_common(tex, flow)
  299. class TEXTURE_PT_image_alpha(TextureTypePanel, Panel):
  300. bl_label = "Alpha"
  301. bl_options = {'DEFAULT_CLOSED'}
  302. bl_parent_id = 'TEXTURE_PT_image'
  303. tex_type = 'IMAGE'
  304. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE'}
  305. def draw_header(self, context):
  306. tex = context.texture
  307. self.layout.prop(tex, "use_alpha", text="")
  308. def draw(self, context):
  309. layout = self.layout
  310. layout.use_property_split = True
  311. tex = context.texture
  312. col = layout.column()
  313. col.active = bool(tex.image and tex.image.alpha_mode != 'NONE')
  314. col.prop(tex, "use_calculate_alpha", text="Calculate")
  315. col.prop(tex, "invert_alpha", text="Invert")
  316. class TEXTURE_PT_image_mapping(TextureTypePanel, Panel):
  317. bl_label = "Mapping"
  318. bl_options = {'DEFAULT_CLOSED'}
  319. bl_parent_id = 'TEXTURE_PT_image'
  320. tex_type = 'IMAGE'
  321. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE'}
  322. def draw(self, context):
  323. layout = self.layout
  324. layout.use_property_split = True
  325. tex = context.texture
  326. col = layout.column()
  327. col.prop(tex, "use_flip_axis", text="Flip Axes")
  328. col.separator()
  329. subcol = layout.column()
  330. subcol.prop(tex, "extension") # use layout, to keep the same location in case of button cycling.
  331. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  332. if tex.extension == 'REPEAT':
  333. col = flow.column()
  334. sub = col.column(align=True)
  335. sub.prop(tex, "repeat_x", text="Repeat X")
  336. sub.prop(tex, "repeat_y", text="Y")
  337. col = flow.column()
  338. sub = col.column()
  339. sub.active = (tex.repeat_x > 1)
  340. sub.prop(tex, "use_mirror_x", text="Mirror X")
  341. sub = col.column()
  342. sub.active = (tex.repeat_y > 1)
  343. sub.prop(tex, "use_mirror_y", text="Y")
  344. elif tex.extension == 'CHECKER':
  345. subcol.separator()
  346. col = flow.column()
  347. col.prop(tex, "checker_distance", text="Distance")
  348. col = flow.column()
  349. col.prop(tex, "use_checker_even", text="Tiles Even")
  350. col.prop(tex, "use_checker_odd", text="Odd")
  351. else:
  352. del flow
  353. class TEXTURE_PT_image_mapping_crop(TextureTypePanel, Panel):
  354. bl_label = "Crop"
  355. bl_options = {'DEFAULT_CLOSED'}
  356. bl_parent_id = 'TEXTURE_PT_image_mapping'
  357. tex_type = 'IMAGE'
  358. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE'}
  359. def draw(self, context):
  360. layout = self.layout
  361. layout.use_property_split = True
  362. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=False)
  363. tex = context.texture
  364. col = flow.column(align=True)
  365. # col.prop(tex, "crop_rectangle")
  366. col.prop(tex, "crop_min_x", text="Minimum X")
  367. col.prop(tex, "crop_min_y", text="Y")
  368. col = flow.column(align=True)
  369. col.prop(tex, "crop_max_x", text="Maximum X")
  370. col.prop(tex, "crop_max_y", text="Y")
  371. class TEXTURE_PT_musgrave(TextureTypePanel, Panel):
  372. bl_label = "Musgrave"
  373. tex_type = 'MUSGRAVE'
  374. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  375. def draw(self, context):
  376. layout = self.layout
  377. layout.use_property_split = True
  378. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  379. tex = context.texture
  380. col = flow.column()
  381. col.prop(tex, "noise_basis", text="Noise Basis")
  382. col.separator()
  383. col.prop(tex, "musgrave_type")
  384. col.separator()
  385. col.prop(tex, "noise_scale", text="Size")
  386. col.prop(tex, "nabla")
  387. col.separator()
  388. col = flow.column()
  389. col.prop(tex, "dimension_max", text="Dimension")
  390. col.prop(tex, "lacunarity")
  391. col.prop(tex, "octaves")
  392. col.separator()
  393. musgrave_type = tex.musgrave_type
  394. col = flow.column()
  395. if musgrave_type in {'HETERO_TERRAIN', 'RIDGED_MULTIFRACTAL', 'HYBRID_MULTIFRACTAL'}:
  396. col.prop(tex, "offset")
  397. col.prop(tex, "noise_intensity", text="Intensity")
  398. if musgrave_type in {'RIDGED_MULTIFRACTAL', 'HYBRID_MULTIFRACTAL'}:
  399. col.prop(tex, "gain")
  400. class TEXTURE_PT_voronoi(TextureTypePanel, Panel):
  401. bl_label = "Voronoi"
  402. tex_type = 'VORONOI'
  403. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  404. def draw(self, context):
  405. layout = self.layout
  406. layout.use_property_split = True
  407. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=False)
  408. tex = context.texture
  409. col = flow.column()
  410. col.prop(tex, "distance_metric")
  411. sub = col.column()
  412. sub.active = tex.distance_metric == 'MINKOVSKY'
  413. sub.prop(tex, "minkovsky_exponent", text="Exponent")
  414. sub.separator()
  415. col = flow.column()
  416. col.prop(tex, "color_mode")
  417. col.prop(tex, "noise_intensity", text="Intensity")
  418. col.separator()
  419. col = flow.column()
  420. col.prop(tex, "noise_scale", text="Size")
  421. col.prop(tex, "nabla")
  422. class TEXTURE_PT_voronoi_feature_weights(TextureTypePanel, Panel):
  423. bl_label = "Feature Weights"
  424. bl_parent_id = "TEXTURE_PT_voronoi"
  425. tex_type = 'VORONOI'
  426. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  427. def draw(self, context):
  428. layout = self.layout
  429. layout.use_property_split = True
  430. flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, even_rows=False, align=True)
  431. tex = context.texture
  432. col = flow.column(align=True)
  433. col.prop(tex, "weight_1", text="First", slider=True)
  434. col.prop(tex, "weight_2", text="Second", slider=True)
  435. sub = flow.column(align=True)
  436. sub.prop(tex, "weight_3", text="Third", slider=True)
  437. sub.prop(tex, "weight_4", text="Fourth", slider=True)
  438. class TEXTURE_PT_distortednoise(TextureTypePanel, Panel):
  439. bl_label = "Distorted Noise"
  440. tex_type = 'DISTORTED_NOISE'
  441. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  442. def draw(self, context):
  443. layout = self.layout
  444. layout.use_property_split = True
  445. flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
  446. tex = context.texture
  447. col = flow.column()
  448. col.prop(tex, "noise_basis", text="Noise Basis")
  449. col.separator()
  450. col.prop(tex, "noise_distortion", text="Distortion")
  451. col.separator()
  452. col = flow.column()
  453. col.prop(tex, "distortion", text="Amount")
  454. col.prop(tex, "noise_scale", text="Size")
  455. col.prop(tex, "nabla")
  456. class TextureSlotPanel(TextureButtonsPanel):
  457. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  458. @classmethod
  459. def poll(cls, context):
  460. if not hasattr(context, "texture_slot"):
  461. return False
  462. return (context.engine in cls.COMPAT_ENGINES)
  463. class TEXTURE_PT_mapping(TextureSlotPanel, Panel):
  464. bl_label = "Mapping"
  465. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  466. @classmethod
  467. def poll(cls, context):
  468. idblock = context_tex_datablock(context)
  469. if isinstance(idblock, Brush) and not context.sculpt_object:
  470. return False
  471. if not getattr(context, "texture_slot", None):
  472. return False
  473. engine = context.engine
  474. return (engine in cls.COMPAT_ENGINES)
  475. def draw(self, context):
  476. layout = self.layout
  477. layout.use_property_split = True
  478. flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, even_rows=False, align=True)
  479. idblock = context_tex_datablock(context)
  480. tex = context.texture_slot
  481. if isinstance(idblock, Brush):
  482. if context.sculpt_object or context.image_paint_object:
  483. brush_texture_settings(layout, idblock, context.sculpt_object)
  484. else:
  485. col = flow.column()
  486. col.prop(tex, "texture_coords", text="Coordinates")
  487. # Note: the ORCO case used to call ob.data, "texco_mesh" prop.
  488. if tex.texture_coords == 'UV':
  489. ob = context.object
  490. if ob and ob.type == 'MESH':
  491. col.prop_search(tex, "uv_layer", ob.data, "uv_layers", text="Map")
  492. else:
  493. col.prop(tex, "uv_layer", text="Map")
  494. elif tex.texture_coords == 'OBJECT':
  495. col.prop(tex, "object", text="Object")
  496. col.separator()
  497. if isinstance(idblock, FreestyleLineStyle):
  498. col = flow.column()
  499. col.prop(tex, "mapping", text="Projection")
  500. col.separator()
  501. col = flow.column()
  502. col.prop(tex, "mapping_x", text="Mapping X")
  503. col.prop(tex, "mapping_y", text="Y")
  504. col.prop(tex, "mapping_z", text="Z")
  505. col.separator()
  506. col = flow.column(align=True)
  507. col.column().prop(tex, "offset")
  508. col = flow.column(align=True)
  509. col.column().prop(tex, "scale")
  510. class TEXTURE_PT_influence(TextureSlotPanel, Panel):
  511. bl_label = "Influence"
  512. bl_options = {'DEFAULT_CLOSED'}
  513. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  514. @classmethod
  515. def poll(cls, context):
  516. idblock = context_tex_datablock(context)
  517. if isinstance(idblock, Brush):
  518. return False
  519. if not getattr(context, "texture_slot", None):
  520. return False
  521. engine = context.engine
  522. return (engine in cls.COMPAT_ENGINES)
  523. def draw(self, context):
  524. layout = self.layout
  525. layout.use_property_split = True
  526. flow = layout.grid_flow(row_major=False, columns=0, even_columns=False, even_rows=False, align=False)
  527. idblock = context_tex_datablock(context)
  528. tex = context.texture_slot
  529. def factor_but(layout, toggle, factor, name):
  530. row = layout.row(align=True)
  531. row.active = getattr(tex, toggle)
  532. row.prop(tex, factor, text=name, slider=True)
  533. sub = row.row(align=True)
  534. sub.prop(tex, toggle, text="")
  535. return sub # XXX, temp. use_map_normal needs to override.
  536. if isinstance(idblock, ParticleSettings):
  537. col = flow.column()
  538. factor_but(col, "use_map_time", "time_factor", "General Time")
  539. factor_but(col, "use_map_life", "life_factor", "Lifetime")
  540. factor_but(col, "use_map_density", "density_factor", "Density")
  541. factor_but(col, "use_map_size", "size_factor", "Size")
  542. col.separator()
  543. col = flow.column()
  544. factor_but(col, "use_map_velocity", "velocity_factor", "Physics Velocity")
  545. factor_but(col, "use_map_damp", "damp_factor", "Damp")
  546. factor_but(col, "use_map_gravity", "gravity_factor", "Gravity")
  547. factor_but(col, "use_map_field", "field_factor", "Force Fields")
  548. col.separator()
  549. col = flow.column()
  550. factor_but(col, "use_map_length", "length_factor", "Hair Length")
  551. factor_but(col, "use_map_clump", "clump_factor", "Clump")
  552. factor_but(col, "use_map_twist", "twist_factor", "Twist")
  553. col = flow.column()
  554. factor_but(col, "use_map_kink_amp", "kink_amp_factor", "Kink Amplitude")
  555. factor_but(col, "use_map_kink_freq", "kink_freq_factor", "Kink Frequency")
  556. factor_but(col, "use_map_rough", "rough_factor", "Rough")
  557. elif isinstance(idblock, FreestyleLineStyle):
  558. col = flow.column()
  559. factor_but(col, "use_map_color_diffuse", "diffuse_color_factor", "Color")
  560. factor_but(col, "use_map_alpha", "alpha_factor", "Alpha")
  561. if not isinstance(idblock, ParticleSettings):
  562. col = flow.column()
  563. col.prop(tex, "blend_type", text="Blend")
  564. # Color is used on gray-scale textures
  565. col.prop(tex, "color", text="")
  566. class TextureColorsPoll:
  567. @classmethod
  568. def poll(cls, context):
  569. tex = context.texture
  570. return tex and (tex.type != 'NONE' or tex.use_nodes) and (context.engine in cls.COMPAT_ENGINES)
  571. class TEXTURE_PT_colors(TextureButtonsPanel, TextureColorsPoll, Panel):
  572. bl_label = "Colors"
  573. bl_options = {'DEFAULT_CLOSED'}
  574. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  575. def draw(self, context):
  576. layout = self.layout
  577. layout.use_property_split = True
  578. flow = layout.grid_flow(row_major=False, columns=0, even_columns=False, even_rows=False, align=False)
  579. tex = context.texture
  580. col = flow.column()
  581. col.prop(tex, "use_clamp", text="Clamp")
  582. col = flow.column(align=True)
  583. col.prop(tex, "factor_red", text="Multiply R")
  584. col.prop(tex, "factor_green", text="G")
  585. col.prop(tex, "factor_blue", text="B")
  586. col.separator()
  587. col = flow.column()
  588. col.prop(tex, "intensity")
  589. col.prop(tex, "contrast")
  590. col.prop(tex, "saturation")
  591. class TEXTURE_PT_colors_ramp(TextureButtonsPanel, TextureColorsPoll, Panel):
  592. bl_label = "Color Ramp"
  593. bl_options = {'DEFAULT_CLOSED'}
  594. bl_parent_id = 'TEXTURE_PT_colors'
  595. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  596. def draw_header(self, context):
  597. tex = context.texture
  598. self.layout.prop(tex, "use_color_ramp", text="")
  599. def draw(self, context):
  600. layout = self.layout
  601. tex = context.texture
  602. # Note: TODO after creation of a new texture, the template_color_ramp will be blank.
  603. # Possibly needs to be fixed in the template itself.
  604. is_active = bool(tex and tex.use_color_ramp)
  605. if is_active:
  606. layout.template_color_ramp(tex, "color_ramp", expand=True)
  607. else:
  608. layout.alignment = 'RIGHT'
  609. layout.label(text="Enable the Color Ramp first")
  610. class TEXTURE_PT_custom_props(TextureButtonsPanel, PropertyPanel, Panel):
  611. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  612. _context_path = "texture"
  613. _property_type = Texture
  614. @classmethod
  615. def poll(cls, context):
  616. return context.texture and (context.engine in cls.COMPAT_ENGINES)
  617. classes = (
  618. TEXTURE_MT_context_menu,
  619. TEXTURE_UL_texslots,
  620. TEXTURE_PT_preview,
  621. TEXTURE_PT_context,
  622. TEXTURE_PT_node,
  623. TEXTURE_PT_clouds,
  624. TEXTURE_PT_wood,
  625. TEXTURE_PT_marble,
  626. TEXTURE_PT_magic,
  627. TEXTURE_PT_blend,
  628. TEXTURE_PT_stucci,
  629. TEXTURE_PT_image,
  630. TEXTURE_PT_image_settings,
  631. TEXTURE_PT_image_alpha,
  632. TEXTURE_PT_image_mapping,
  633. TEXTURE_PT_image_mapping_crop,
  634. TEXTURE_PT_image_sampling,
  635. TEXTURE_PT_musgrave,
  636. TEXTURE_PT_voronoi,
  637. TEXTURE_PT_voronoi_feature_weights,
  638. TEXTURE_PT_distortednoise,
  639. TEXTURE_PT_influence,
  640. TEXTURE_PT_mapping,
  641. TEXTURE_PT_colors,
  642. TEXTURE_PT_colors_ramp,
  643. TEXTURE_PT_custom_props,
  644. )
  645. if __name__ == "__main__": # only for live edit.
  646. from bpy.utils import register_class
  647. for cls in classes:
  648. register_class(cls)