Merge branch 'blender-v3.6-release'
[blender-addons.git] / render_povray / texturing_procedural.py
blobc20de7ae395f4810316576651c46ce0a1d188514
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 """Use Blender procedural textures exported to POV patterns."""
5 import bpy
8 def export_pattern(texture):
9 """Translate Blender procedural textures to POV patterns and write to pov file.
11 Function Patterns can be used to better access sub components of a pattern like
12 grey values for influence mapping
13 """
14 from .render import string_strip_hyphen
16 tex = texture
17 pat = tex.pov
18 pat_name = "PAT_%s" % string_strip_hyphen(bpy.path.clean_name(tex.name))
19 mapping_dif = "translate <%.4g,%.4g,%.4g> scale <%.4g,%.4g,%.4g>" % (
20 pat.tex_mov_x,
21 pat.tex_mov_y,
22 pat.tex_mov_z,
23 1.0 / pat.tex_scale_x,
24 1.0 / pat.tex_scale_y,
25 1.0 / pat.tex_scale_z,
27 text_strg = ""
29 def export_color_ramp(texture):
30 tex = texture
31 pat = tex.pov
32 col_ramp_strg = "color_map {\n"
33 for num_color, el in enumerate(tex.color_ramp.elements, start=1):
34 pos = el.position
35 col = el.color
36 col_r, col_g, col_b, col_a = col[0], col[1], col[2], 1 - col[3]
37 if pat.tex_pattern_type not in {
38 "checker",
39 "hexagon",
40 "square",
41 "triangular",
42 "brick",
44 col_ramp_strg += "[%.4g color rgbf<%.4g,%.4g,%.4g,%.4g>] \n" % (
45 pos,
46 col_r,
47 col_g,
48 col_b,
49 col_a,
51 if pat.tex_pattern_type in {"brick", "checker"} and num_color < 3:
52 col_ramp_strg += "color rgbf<%.4g,%.4g,%.4g,%.4g> \n" % (
53 col_r,
54 col_g,
55 col_b,
56 col_a,
58 if pat.tex_pattern_type == "hexagon" and num_color < 4:
59 col_ramp_strg += "color rgbf<%.4g,%.4g,%.4g,%.4g> \n" % (
60 col_r,
61 col_g,
62 col_b,
63 col_a,
65 if pat.tex_pattern_type == "square" and num_color < 5:
66 col_ramp_strg += "color rgbf<%.4g,%.4g,%.4g,%.4g> \n" % (
67 col_r,
68 col_g,
69 col_b,
70 col_a,
72 if pat.tex_pattern_type == "triangular" and num_color < 7:
73 col_ramp_strg += "color rgbf<%.4g,%.4g,%.4g,%.4g> \n" % (
74 col_r,
75 col_g,
76 col_b,
77 col_a,
80 col_ramp_strg += "} \n"
81 # end color map
82 return col_ramp_strg
84 # much work to be done here only defaults translated for now:
85 # pov noise_generator 3 means perlin noise
86 if tex.type not in {"NONE", "IMAGE"} and pat.tex_pattern_type == "emulator":
87 text_strg += "pigment {\n"
88 # ------------------------- EMULATE BLENDER VORONOI TEXTURE ------------------------- #
89 if tex.type == "VORONOI":
90 text_strg += "crackle\n"
91 text_strg += " offset %.4g\n" % tex.nabla
92 text_strg += " form <%.4g,%.4g,%.4g>\n" % (
93 tex.weight_1,
94 tex.weight_2,
95 tex.weight_3,
97 if tex.distance_metric == "DISTANCE":
98 text_strg += " metric 2.5\n"
99 if tex.distance_metric == "DISTANCE_SQUARED":
100 text_strg += " metric 2.5\n"
101 text_strg += " poly_wave 2\n"
102 if tex.distance_metric == "MINKOVSKY":
103 text_strg += " metric %s\n" % tex.minkovsky_exponent
104 if tex.distance_metric == "MINKOVSKY_FOUR":
105 text_strg += " metric 4\n"
106 if tex.distance_metric == "MINKOVSKY_HALF":
107 text_strg += " metric 0.5\n"
108 if tex.distance_metric == "CHEBYCHEV":
109 text_strg += " metric 10\n"
110 if tex.distance_metric == "MANHATTAN":
111 text_strg += " metric 1\n"
113 if tex.color_mode == "POSITION":
114 text_strg += "solid\n"
115 text_strg += "scale 0.25\n"
116 if tex.use_color_ramp:
117 text_strg += export_color_ramp(tex)
118 else:
119 text_strg += "color_map {\n"
120 text_strg += "[0 color rgbt<0,0,0,1>]\n"
121 text_strg += "[1 color rgbt<1,1,1,0>]\n"
122 text_strg += "}\n"
124 # ------------------------- EMULATE BLENDER CLOUDS TEXTURE ------------------------- #
125 if tex.type == "CLOUDS":
126 if tex.noise_type == "SOFT_NOISE":
127 text_strg += "wrinkles\n"
128 text_strg += "scale 0.25\n"
129 else:
130 text_strg += "granite\n"
131 if tex.use_color_ramp:
132 text_strg += export_color_ramp(tex)
133 else:
134 text_strg += "color_map {\n"
135 text_strg += "[0 color rgbt<0,0,0,1>]\n"
136 text_strg += "[1 color rgbt<1,1,1,0>]\n"
137 text_strg += "}\n"
139 # ------------------------- EMULATE BLENDER WOOD TEXTURE ------------------------- #
140 if tex.type == "WOOD":
141 if tex.wood_type == "RINGS":
142 text_strg += "wood\n"
143 text_strg += "scale 0.25\n"
144 if tex.wood_type == "RINGNOISE":
145 text_strg += "wood\n"
146 text_strg += "scale 0.25\n"
147 text_strg += "turbulence %.4g\n" % (tex.turbulence / 100)
148 if tex.wood_type == "BANDS":
149 text_strg += "marble\n"
150 text_strg += "scale 0.25\n"
151 text_strg += "rotate <45,-45,45>\n"
152 if tex.wood_type == "BANDNOISE":
153 text_strg += "marble\n"
154 text_strg += "scale 0.25\n"
155 text_strg += "rotate <45,-45,45>\n"
156 text_strg += "turbulence %.4g\n" % (tex.turbulence / 10)
158 if tex.noise_basis_2 == "SIN":
159 text_strg += "sine_wave\n"
160 if tex.noise_basis_2 == "TRI":
161 text_strg += "triangle_wave\n"
162 if tex.noise_basis_2 == "SAW":
163 text_strg += "ramp_wave\n"
164 if tex.use_color_ramp:
165 text_strg += export_color_ramp(tex)
166 else:
167 text_strg += "color_map {\n"
168 text_strg += "[0 color rgbt<0,0,0,0>]\n"
169 text_strg += "[1 color rgbt<1,1,1,0>]\n"
170 text_strg += "}\n"
172 # ------------------------- EMULATE BLENDER STUCCI TEXTURE ------------------------- #
173 if tex.type == "STUCCI":
174 text_strg += "bozo\n"
175 text_strg += "scale 0.25\n"
176 if tex.noise_type == "HARD_NOISE":
177 text_strg += "triangle_wave\n"
178 if tex.use_color_ramp:
179 text_strg += export_color_ramp(tex)
180 else:
181 text_strg += "color_map {\n"
182 text_strg += "[0 color rgbf<1,1,1,0>]\n"
183 text_strg += "[1 color rgbt<0,0,0,1>]\n"
184 text_strg += "}\n"
185 else:
186 if tex.use_color_ramp:
187 text_strg += export_color_ramp(tex)
188 else:
189 text_strg += "color_map {\n"
190 text_strg += "[0 color rgbf<0,0,0,1>]\n"
191 text_strg += "[1 color rgbt<1,1,1,0>]\n"
192 text_strg += "}\n"
194 # ------------------------- EMULATE BLENDER MAGIC TEXTURE ------------------------- #
195 if tex.type == "MAGIC":
196 text_strg += "leopard\n"
197 if tex.use_color_ramp:
198 text_strg += export_color_ramp(tex)
199 else:
200 text_strg += "color_map {\n"
201 text_strg += "[0 color rgbt<1,1,1,0.5>]\n"
202 text_strg += "[0.25 color rgbf<0,1,0,0.75>]\n"
203 text_strg += "[0.5 color rgbf<0,0,1,0.75>]\n"
204 text_strg += "[0.75 color rgbf<1,0,1,0.75>]\n"
205 text_strg += "[1 color rgbf<0,1,0,0.75>]\n"
206 text_strg += "}\n"
207 text_strg += "scale 0.1\n"
209 # ------------------------- EMULATE BLENDER MARBLE TEXTURE ------------------------- #
210 if tex.type == "MARBLE":
211 text_strg += "marble\n"
212 text_strg += "turbulence 0.5\n"
213 text_strg += "noise_generator 3\n"
214 text_strg += "scale 0.75\n"
215 text_strg += "rotate <45,-45,45>\n"
216 if tex.use_color_ramp:
217 text_strg += export_color_ramp(tex)
218 else:
219 if tex.marble_type == "SOFT":
220 text_strg += "color_map {\n"
221 text_strg += "[0 color rgbt<0,0,0,0>]\n"
222 text_strg += "[0.05 color rgbt<0,0,0,0>]\n"
223 text_strg += "[1 color rgbt<0.9,0.9,0.9,0>]\n"
224 text_strg += "}\n"
225 elif tex.marble_type == "SHARP":
226 text_strg += "color_map {\n"
227 text_strg += "[0 color rgbt<0,0,0,0>]\n"
228 text_strg += "[0.025 color rgbt<0,0,0,0>]\n"
229 text_strg += "[1 color rgbt<0.9,0.9,0.9,0>]\n"
230 text_strg += "}\n"
231 else:
232 text_strg += "[0 color rgbt<0,0,0,0>]\n"
233 text_strg += "[1 color rgbt<1,1,1,0>]\n"
234 text_strg += "}\n"
235 if tex.noise_basis_2 == "SIN":
236 text_strg += "sine_wave\n"
237 if tex.noise_basis_2 == "TRI":
238 text_strg += "triangle_wave\n"
239 if tex.noise_basis_2 == "SAW":
240 text_strg += "ramp_wave\n"
242 # ------------------------- EMULATE BLENDER BLEND TEXTURE ------------------------- #
243 if tex.type == "BLEND":
244 if tex.progression == "RADIAL":
245 text_strg += "radial\n"
246 if tex.use_flip_axis == "HORIZONTAL":
247 text_strg += "rotate x*90\n"
248 else:
249 text_strg += "rotate <-90,0,90>\n"
250 text_strg += "ramp_wave\n"
251 elif tex.progression == "SPHERICAL":
252 text_strg += "spherical\n"
253 text_strg += "scale 3\n"
254 text_strg += "poly_wave 1\n"
255 elif tex.progression == "QUADRATIC_SPHERE":
256 text_strg += "spherical\n"
257 text_strg += "scale 3\n"
258 text_strg += " poly_wave 2\n"
259 elif tex.progression == "DIAGONAL":
260 text_strg += "gradient <1,1,0>\n"
261 text_strg += "scale 3\n"
262 elif tex.use_flip_axis == "HORIZONTAL":
263 text_strg += "gradient x\n"
264 text_strg += "scale 2.01\n"
265 elif tex.use_flip_axis == "VERTICAL":
266 text_strg += "gradient y\n"
267 text_strg += "scale 2.01\n"
268 # text_strg+="ramp_wave\n"
269 # text_strg+="frequency 0.5\n"
270 text_strg += "phase 0.5\n"
271 if tex.use_color_ramp:
272 text_strg += export_color_ramp(tex)
273 else:
274 text_strg += "color_map {\n"
275 text_strg += "[0 color rgbt<1,1,1,0>]\n"
276 text_strg += "[1 color rgbf<0,0,0,1>]\n"
277 text_strg += "}\n"
278 if tex.progression == "LINEAR":
279 text_strg += " poly_wave 1\n"
280 if tex.progression == "QUADRATIC":
281 text_strg += " poly_wave 2\n"
282 if tex.progression == "EASING":
283 text_strg += " poly_wave 1.5\n"
285 # ------------------------- EMULATE BLENDER MUSGRAVE TEXTURE ------------------------- #
286 # if tex.type == 'MUSGRAVE':
287 # text_strg+="function{ f_ridged_mf( x, y, 0, 1, 2, 9, -0.5, 3,3 )*0.5}\n"
288 # text_strg+="color_map {\n"
289 # text_strg+="[0 color rgbf<0,0,0,1>]\n"
290 # text_strg+="[1 color rgbf<1,1,1,0>]\n"
291 # text_strg+="}\n"
292 # simplified for now:
294 if tex.type == "MUSGRAVE":
295 text_strg += "bozo scale 0.25 \n"
296 if tex.use_color_ramp:
297 text_strg += export_color_ramp(tex)
298 else:
299 text_strg += (
300 "color_map {[0.5 color rgbf<0,0,0,1>][1 color rgbt<1,1,1,0>]}ramp_wave \n"
303 # ------------------------- EMULATE BLENDER DISTORTED NOISE TEXTURE ------------------------- #
304 if tex.type == "DISTORTED_NOISE":
305 text_strg += "average\n"
306 text_strg += " pigment_map {\n"
307 text_strg += " [1 bozo scale 0.25 turbulence %.4g\n" % tex.distortion
308 if tex.use_color_ramp:
309 text_strg += export_color_ramp(tex)
310 else:
311 text_strg += "color_map {\n"
312 text_strg += "[0 color rgbt<1,1,1,0>]\n"
313 text_strg += "[1 color rgbf<0,0,0,1>]\n"
314 text_strg += "}\n"
315 text_strg += "]\n"
317 if tex.noise_distortion == "CELL_NOISE":
318 text_strg += " [1 cells scale 0.1\n"
319 if tex.use_color_ramp:
320 text_strg += export_color_ramp(tex)
321 else:
322 text_strg += "color_map {\n"
323 text_strg += "[0 color rgbt<1,1,1,0>]\n"
324 text_strg += "[1 color rgbf<0,0,0,1>]\n"
325 text_strg += "}\n"
326 text_strg += "]\n"
327 if tex.noise_distortion == "VORONOI_CRACKLE":
328 text_strg += " [1 crackle scale 0.25\n"
329 if tex.use_color_ramp:
330 text_strg += export_color_ramp(tex)
331 else:
332 text_strg += "color_map {\n"
333 text_strg += "[0 color rgbt<1,1,1,0>]\n"
334 text_strg += "[1 color rgbf<0,0,0,1>]\n"
335 text_strg += "}\n"
336 text_strg += "]\n"
337 if tex.noise_distortion in [
338 "VORONOI_F1",
339 "VORONOI_F2",
340 "VORONOI_F3",
341 "VORONOI_F4",
342 "VORONOI_F2_F1",
344 text_strg += " [1 crackle metric 2.5 scale 0.25 turbulence %.4g\n" % (
345 tex.distortion / 2
347 if tex.use_color_ramp:
348 text_strg += export_color_ramp(tex)
349 else:
350 text_strg += "color_map {\n"
351 text_strg += "[0 color rgbt<1,1,1,0>]\n"
352 text_strg += "[1 color rgbf<0,0,0,1>]\n"
353 text_strg += "}\n"
354 text_strg += "]\n"
355 else:
356 text_strg += " [1 wrinkles scale 0.25\n"
357 if tex.use_color_ramp:
358 text_strg += export_color_ramp(tex)
359 else:
360 text_strg += "color_map {\n"
361 text_strg += "[0 color rgbt<1,1,1,0>]\n"
362 text_strg += "[1 color rgbf<0,0,0,1>]\n"
363 text_strg += "}\n"
364 text_strg += "]\n"
365 text_strg += " }\n"
367 # ------------------------- EMULATE BLENDER NOISE TEXTURE ------------------------- #
368 if tex.type == "NOISE":
369 text_strg += "cells\n"
370 text_strg += "turbulence 3\n"
371 text_strg += "omega 3\n"
372 if tex.use_color_ramp:
373 text_strg += export_color_ramp(tex)
374 else:
375 text_strg += "color_map {\n"
376 text_strg += "[0.75 color rgb<0,0,0,>]\n"
377 text_strg += "[1 color rgb<1,1,1,>]\n"
378 text_strg += "}\n"
380 # ------------------------- IGNORE OTHER BLENDER TEXTURE ------------------------- #
381 else: # non translated textures
382 pass
383 text_strg += "}\n\n"
385 text_strg += "#declare f%s=\n" % pat_name
386 text_strg += "function{pigment{%s}}\n" % pat_name
387 text_strg += "\n"
389 elif pat.tex_pattern_type != "emulator":
390 text_strg += "pigment {\n"
391 text_strg += "%s\n" % pat.tex_pattern_type
392 if pat.tex_pattern_type == "agate":
393 text_strg += "agate_turb %.4g\n" % pat.modifier_turbulence
394 if pat.tex_pattern_type in {"spiral1", "spiral2", "tiling"}:
395 text_strg += "%s\n" % pat.modifier_numbers
396 if pat.tex_pattern_type == "quilted":
397 text_strg += "control0 %s control1 %s\n" % (
398 pat.modifier_control0,
399 pat.modifier_control1,
401 if pat.tex_pattern_type == "mandel":
402 text_strg += "%s exponent %s \n" % (pat.f_iter, pat.f_exponent)
403 if pat.tex_pattern_type == "julia":
404 text_strg += "<%.4g, %.4g> %s exponent %s \n" % (
405 pat.julia_complex_1,
406 pat.julia_complex_2,
407 pat.f_iter,
408 pat.f_exponent,
410 if pat.tex_pattern_type == "magnet" and pat.magnet_style == "mandel":
411 text_strg += "%s mandel %s \n" % (pat.magnet_type, pat.f_iter)
412 if pat.tex_pattern_type == "magnet" and pat.magnet_style == "julia":
413 text_strg += "%s julia <%.4g, %.4g> %s\n" % (
414 pat.magnet_type,
415 pat.julia_complex_1,
416 pat.julia_complex_2,
417 pat.f_iter,
419 if pat.tex_pattern_type in {"mandel", "julia", "magnet"}:
420 text_strg += "interior %s, %.4g\n" % (pat.f_ior, pat.f_ior_fac)
421 text_strg += "exterior %s, %.4g\n" % (pat.f_eor, pat.f_eor_fac)
422 if pat.tex_pattern_type == "gradient":
423 text_strg += "<%s, %s, %s> \n" % (
424 pat.grad_orient_x,
425 pat.grad_orient_y,
426 pat.grad_orient_z,
428 if pat.tex_pattern_type == "pavement":
429 num_tiles = pat.pave_tiles
430 num_pattern = 1
431 if pat.pave_sides == "4" and pat.pave_tiles == 3:
432 num_pattern = pat.pave_pat_2
433 if pat.pave_sides == "6" and pat.pave_tiles == 3:
434 num_pattern = pat.pave_pat_3
435 if pat.pave_sides == "3" and pat.pave_tiles == 4:
436 num_pattern = pat.pave_pat_3
437 if pat.pave_sides == "3" and pat.pave_tiles == 5:
438 num_pattern = pat.pave_pat_4
439 if pat.pave_sides == "4" and pat.pave_tiles == 4:
440 num_pattern = pat.pave_pat_5
441 if pat.pave_sides == "6" and pat.pave_tiles == 4:
442 num_pattern = pat.pave_pat_7
443 if pat.pave_sides == "4" and pat.pave_tiles == 5:
444 num_pattern = pat.pave_pat_12
445 if pat.pave_sides == "3" and pat.pave_tiles == 6:
446 num_pattern = pat.pave_pat_12
447 if pat.pave_sides == "6" and pat.pave_tiles == 5:
448 num_pattern = pat.pave_pat_22
449 if pat.pave_sides == "4" and pat.pave_tiles == 6:
450 num_pattern = pat.pave_pat_35
451 if pat.pave_sides == "6" and pat.pave_tiles == 6:
452 num_tiles = 5
453 text_strg += "number_of_sides %s number_of_tiles %s pattern %s form %s \n" % (
454 pat.pave_sides,
455 num_tiles,
456 num_pattern,
457 pat.pave_form,
459 # ------------------------- functions ------------------------- #
460 if pat.tex_pattern_type == "function":
461 text_strg += "{ %s" % pat.func_list
462 text_strg += "(x"
463 if pat.func_plus_x != "NONE":
464 if pat.func_plus_x == "increase":
465 text_strg += "*"
466 if pat.func_plus_x == "plus":
467 text_strg += "+"
468 text_strg += "%.4g" % pat.func_x
469 text_strg += ",y"
470 if pat.func_plus_y != "NONE":
471 if pat.func_plus_y == "increase":
472 text_strg += "*"
473 if pat.func_plus_y == "plus":
474 text_strg += "+"
475 text_strg += "%.4g" % pat.func_y
476 text_strg += ",z"
477 if pat.func_plus_z != "NONE":
478 if pat.func_plus_z == "increase":
479 text_strg += "*"
480 if pat.func_plus_z == "plus":
481 text_strg += "+"
482 text_strg += "%.4g" % pat.func_z
483 sort = -1
484 if pat.func_list in {
485 "f_comma",
486 "f_crossed_trough",
487 "f_cubic_saddle",
488 "f_cushion",
489 "f_devils_curve",
490 "f_enneper",
491 "f_glob",
492 "f_heart",
493 "f_hex_x",
494 "f_hex_y",
495 "f_hunt_surface",
496 "f_klein_bottle",
497 "f_kummer_surface_v1",
498 "f_lemniscate_of_gerono",
499 "f_mitre",
500 "f_nodal_cubic",
501 "f_noise_generator",
502 "f_odd",
503 "f_paraboloid",
504 "f_pillow",
505 "f_piriform",
506 "f_quantum",
507 "f_quartic_paraboloid",
508 "f_quartic_saddle",
509 "f_sphere",
510 "f_steiners_roman",
511 "f_torus_gumdrop",
512 "f_umbrella",
514 sort = 0
515 if pat.func_list in {
516 "f_bicorn",
517 "f_bifolia",
518 "f_boy_surface",
519 "f_superellipsoid",
520 "f_torus",
522 sort = 1
523 if pat.func_list in {
524 "f_ellipsoid",
525 "f_folium_surface",
526 "f_hyperbolic_torus",
527 "f_kampyle_of_eudoxus",
528 "f_parabolic_torus",
529 "f_quartic_cylinder",
530 "f_torus2",
532 sort = 2
533 if pat.func_list in {
534 "f_blob2",
535 "f_cross_ellipsoids",
536 "f_flange_cover",
537 "f_isect_ellipsoids",
538 "f_kummer_surface_v2",
539 "f_ovals_of_cassini",
540 "f_rounded_box",
541 "f_spikes_2d",
542 "f_strophoid",
544 sort = 3
545 if pat.func_list in {
546 "f_algbr_cyl1",
547 "f_algbr_cyl2",
548 "f_algbr_cyl3",
549 "f_algbr_cyl4",
550 "f_blob",
551 "f_mesh1",
552 "f_poly4",
553 "f_spikes",
555 sort = 4
556 if pat.func_list in {
557 "f_devils_curve_2d",
558 "f_dupin_cyclid",
559 "f_folium_surface_2d",
560 "f_hetero_mf",
561 "f_kampyle_of_eudoxus_2d",
562 "f_lemniscate_of_gerono_2d",
563 "f_polytubes",
564 "f_ridge",
565 "f_ridged_mf",
566 "f_spiral",
567 "f_witch_of_agnesi",
569 sort = 5
570 if pat.func_list in {
571 "f_helix1",
572 "f_helix2",
573 "f_piriform_2d",
574 "f_strophoid_2d",
576 sort = 6
577 if pat.func_list == "f_helical_torus":
578 sort = 7
579 if sort > -1:
580 text_strg += ",%.4g" % pat.func_P0
581 if sort > 0:
582 text_strg += ",%.4g" % pat.func_P1
583 if sort > 1:
584 text_strg += ",%.4g" % pat.func_P2
585 if sort > 2:
586 text_strg += ",%.4g" % pat.func_P3
587 if sort > 3:
588 text_strg += ",%.4g" % pat.func_P4
589 if sort > 4:
590 text_strg += ",%.4g" % pat.func_P5
591 if sort > 5:
592 text_strg += ",%.4g" % pat.func_P6
593 if sort > 6:
594 text_strg += ",%.4g" % pat.func_P7
595 text_strg += ",%.4g" % pat.func_P8
596 text_strg += ",%.4g" % pat.func_P9
597 text_strg += ")}\n"
598 # ------------------------- end functions ------------------------- #
599 if pat.tex_pattern_type not in {
600 "checker",
601 "hexagon",
602 "square",
603 "triangular",
604 "brick",
606 text_strg += "color_map {\n"
607 if tex.use_color_ramp:
608 for num_color, el in enumerate(tex.color_ramp.elements, start=1):
609 pos = el.position
610 col = el.color
611 col_r, col_g, col_b, col_a = col[0], col[1], col[2], 1 - col[3]
612 if pat.tex_pattern_type not in {
613 "checker",
614 "hexagon",
615 "square",
616 "triangular",
617 "brick",
619 text_strg += "[%.4g color rgbf<%.4g,%.4g,%.4g,%.4g>] \n" % (
620 pos,
621 col_r,
622 col_g,
623 col_b,
624 col_a,
626 if pat.tex_pattern_type in {"brick", "checker"} and num_color < 3:
627 text_strg += "color rgbf<%.4g,%.4g,%.4g,%.4g> \n" % (
628 col_r,
629 col_g,
630 col_b,
631 col_a,
633 if pat.tex_pattern_type == "hexagon" and num_color < 4:
634 text_strg += "color rgbf<%.4g,%.4g,%.4g,%.4g> \n" % (
635 col_r,
636 col_g,
637 col_b,
638 col_a,
640 if pat.tex_pattern_type == "square" and num_color < 5:
641 text_strg += "color rgbf<%.4g,%.4g,%.4g,%.4g> \n" % (
642 col_r,
643 col_g,
644 col_b,
645 col_a,
647 if pat.tex_pattern_type == "triangular" and num_color < 7:
648 text_strg += "color rgbf<%.4g,%.4g,%.4g,%.4g> \n" % (
649 col_r,
650 col_g,
651 col_b,
652 col_a,
654 else:
655 text_strg += "[0 color rgbf<0,0,0,1>]\n"
656 text_strg += "[1 color rgbf<1,1,1,0>]\n"
657 if pat.tex_pattern_type not in {
658 "checker",
659 "hexagon",
660 "square",
661 "triangular",
662 "brick",
664 text_strg += "} \n"
665 if pat.tex_pattern_type == "brick":
666 text_strg += "brick_size <%.4g, %.4g, %.4g> mortar %.4g \n" % (
667 pat.brick_size_x,
668 pat.brick_size_y,
669 pat.brick_size_z,
670 pat.brick_mortar,
672 text_strg += "%s \n" % mapping_dif
673 text_strg += "rotate <%.4g,%.4g,%.4g> \n" % (
674 pat.tex_rot_x,
675 pat.tex_rot_y,
676 pat.tex_rot_z,
678 text_strg += "turbulence <%.4g,%.4g,%.4g> \n" % (
679 pat.warp_turbulence_x,
680 pat.warp_turbulence_y,
681 pat.warp_turbulence_z,
683 text_strg += "octaves %s \n" % pat.modifier_octaves
684 text_strg += "lambda %.4g \n" % pat.modifier_lambda
685 text_strg += "omega %.4g \n" % pat.modifier_omega
686 text_strg += "frequency %.4g \n" % pat.modifier_frequency
687 text_strg += "phase %.4g \n" % pat.modifier_phase
688 text_strg += "}\n\n"
689 text_strg += "#declare f%s=\n" % pat_name
690 text_strg += "function{pigment{%s}}\n" % pat_name
691 text_strg += "\n"
692 return text_strg