/
test_convert_shading.py
108 lines (76 loc) · 2.75 KB
/
test_convert_shading.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import os
import wand
from wand.image import Image
from wand.color import Color
def ImageMagicConvert():
'''
'''
from wand.image import Image
from wand.color import Color
from wand.display import display
dest_path = "D:/"
test_file = "d:/___TMP_CRY_ASSETS/Assets/models/Nature/Trees/Big/Textures/Tree10_ddna.tif"
filename, file_extension = os.path.splitext(os.path.basename(test_file))
base_filename = filename[0:-5]
original = Image(filename = test_file)
gloss_img = original.clone()
# gloss_img.type = 'grayscale'
# gloss_img.depth = 8
gloss_img.alpha_channel = 'off'
converted = original.convert('tga')
# converted.format = 'tga'
# gloss_img.composite_channel("green", original, 'copy')
# =================================================================================
# gloss_img = converted.fx("p.g:0", channel="red") #fill red channel
# gloss_img = gloss_img.fx("p.g:0", channel="blue")
# gloss_img.alpha_channel = 'off'
# gloss_img.level(0, 0, 1.0, 'red') #fill red channel white
# gloss_img.level(1, 0, 0.0, 'red') #fill red channel black
# gloss_img.level(1, 0, 1.0, 'red') #invert red channel
# =================================================================================
alpha_image = original.clone()
alpha_image.alpha_channel = 'extract'
alpha_image.convert('RGB')
gloss_img.composite_channel("green", alpha_image, 'copy')
gloss_img.level(1, 0, 0.0, 'red') #fill red channel black
gloss_img.level(1, 0, 0.0, 'blue')
# display(gloss_img)
# return
from wand.api import library
# display image
# from wand.display import display
# display(gloss_img)
# alpha_image = converted.channel_images['alpha']
# with converted.channel_images['red'] as alpha_image:
# alpha_image
# shading (R-metalness, G-roughness, B-specular)
exported_file = os.path.join(dest_path, base_filename + "_sh" + ".tga")
gloss_img.save(filename = exported_file)
exported_file = os.path.join(dest_path, base_filename + "_n.tga")
# converted.alpha_channel = False
# converted.alpha_channel = 'extract'
# converted.alpha_channel = 'remove'
converted.alpha_channel = 'off'
converted.save(filename = exported_file)
pass
def Test_2():
from wand.image import Image, COMPOSITE_OPERATORS
from wand.drawing import Drawing
from wand.display import display
from wand.api import library
wizard = Image(filename='wizard:')
rose = Image(filename='rose:')
# for o in COMPOSITE_OPERATORS:
# w=wizard.clone()
# r=rose.clone()
# with Drawing() as draw:
# draw.composite(operator=o, left=175, top=250,width=r.width, height=r.height, image=r)
# draw(w)
# display(w)
w = wizard.clone()
# with w.channel_images['red'] as red_image:
# display(red_image)
# print(list(w.channel_images)) ## OK.
#
# Test_2()
ImageMagicConvert()