Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Material.py « Blender « modules « python « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f24541f0f03fdae850f99b1e7fd09096c6c13028 (plain)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
"""The Blender Material module

  This module provides access to *Material* datablocks

  Example::

    from Blender import Material, NMesh, Object, Scene
    m = Material.New()                         # create free Material datablock
    m.rgbCol = (1.0, 0.0, 0.3)                    # assign RGB values
    mesh = NMesh.GetRaw()                      # get new mesh
    mesh.addMaterial(m)                        # add material to mesh
    object = Object.New('Mesh')                # create new object 
    object.link(mesh)                          # link mesh data to object
    Scene.getCurrent().link(ob)                # link object to current scene
"""

import _Blender.Material as _Material
import shadow
#import Blender.Curve as Curve

# These are getters and setters needed for emulation

def _getRGB(obj):
	return (obj.R, obj.G, obj.B)

def _getSpec(obj):
	return (obj.specR, obj.specG, obj.specB)

def _getMir(obj):
	return (obj.mirR, obj.mirG, obj.mirB)

def _setRGB(obj, rgb):
	obj.R, obj.G, obj.B = rgb

def _setSpec(obj, rgb):
	obj.specR, obj.specG, obj.specB = rgb

def _setMir(obj, rgb):
	obj.mirR, obj.mirG, obj.mirB = rgb



class Material(shadow.hasIPO, shadow.hasModes):
	"""Material DataBlock object

    See example in the Material module documentation on how to create
    an instance of a Material object.

  Attributes

    The following attributes are colour vectors (r, g, b)
	
    rgbCol     -- The color vector (R, G, B).
	              The RGB values can be accessed individually as .R, .G and .B 

    specCol    -- Specularity color vector (specR, specG, specG)

    mirCol     -- Mirror color vector (mirR, mirG, mirB)

    The following are float values:
	
    alpha      -- The transparency

    ref        -- Reflectivity float value

    emit       -- Emit intensity value 

    amb        -- Ambient intensity value 

    spec       -- specularity value 

    specTransp -- Specular transpareny 

    haloSize   -- Halo size

    mode       -- The material mode bit vector - see Material.ModeFlags

    hard       -- The hardness value

""" 

	_emulation = {'Mode'   : "mode",
	              'Ref'    : "ref",
				  'HaSize' : "haloSize",
				  'SpTra'  : "specTransp",
				  'Alpha'  : "alpha",
				  'Spec'   : "spec",
				  'Emit'   : "emit",
				  'Hard'   : "hard",
				  'Amb'    : "amb",
				 } 

	_getters   = {'rgbCol'  : _getRGB,
	              'specCol' : _getSpec,
				  'mirCol'  : _getMir,
                 } 

	_setters   = {'rgbCol'  : _setRGB,
	              'specCol' : _setSpec,
				  'mirCol'  : _setMir,
				  } 

	t = _Material.Modes

	Modes =         {'traceable' : t.TRACEABLE,
					 'shadow'    : t.SHADOW,
					 'shadeless' : t.SHADELESS,
					 'wire'      : t.WIRE,
					 'vcolLight' : t.VCOL_LIGHT,
					 'vcolPaint' : t.VCOL_PAINT,
					 'zTransp'   : t.ZTRANSP,
					 'zInvert'   : t.ZINVERT,
					 'onlyShadow': t.ONLYSHADOW,
					 'star'      : t.STAR,
					 'texFace'   : t.TEXFACE,
					 'noMist'    : t.NOMIST,
					} 

	t = _Material.HaloModes

	HaloModes =     { "rings"   : t.RINGS,
					  "lines"   : t.LINES,
					  "tex"     : t.TEX,
					  "haloPuno": t.PUNO,
					  "shade"   : t.SHADE,
					  "flare"   : t.FLARE,
					}


	del t

	def setMode(self, *args):
		"""Set the mode of 'self'. This function takes a variable number
of string arguments of the types listed in self.Modes.

  Example::

    m = Material.New()
    m.setMode('shadow', 'wire')
"""
		flags = 0
		try:
			for a in args:
				flags |= self.Modes[a]
		except:
			raise TypeError, "mode must be one of" % self.Modes.keys()
		self._object.mode = flags

	def setHaloMode(self, *args):
		"""Sets the material to Halo mode. 
This function takes a variable number of string arguments of the types 
listed in self.HaloModes"""
		flags = _Material.Modes.HALO

		try:
			for a in args:
				flags |= self.HaloModes[a]
		except:
			raise TypeError, "mode must be one of" % self.HaloModes.keys()
		self._object.mode = flags

	
class ModeFlags:
	"""Readonly dictionary

...containing Material mode bitvectors:

|------------------------------------------|
| Name         |  Description              |
|==========================================|
| TRACEABLE    | visible for shadow lamps  |
|------------------------------------------|
| SHADOW       | cast shadow               |
|------------------------------------------|
| SHADELESS    | do not shade              |
|------------------------------------------|
| WIRE         | draw in wireframe         |
|------------------------------------------|
| VCOL_LIGHT   | use vertex colors         |
|              | with lighting             |
|------------------------------------------|
| VCOL_PAINT   | vertex colours            |
|------------------------------------------|
| HALO         | Halo material             |
|------------------------------------------|
| ZTRANSP      | Z transparency            |
|------------------------------------------|
| ZINVERT      | invert Z                  |
|------------------------------------------|
| ONLYSHADOW   | only shadow, but          |
|              | don't render              |
|------------------------------------------|
| STAR         |  ?                        |
|------------------------------------------|
| TEXFACE      | textured faces            |
|------------------------------------------|
| NOMIST       | disable mist              |
|------------------------------------------|

These mode flags directly represent the buttons in the Material parameters
window (EditButtons)

Example::

  # be 'm' a material
  from Blender.Material.Modes import *
  m.mode |= (TRACEABLE + WIRE)    # Set 'wire' and 'traceable' flagsd
  m.mode &= ~SHADELESS            # clear 'shadeless' flag
"""
	
	t = _Material.Modes
	TRACEABLE  = t.TRACEABLE
	SHADOW     = t.SHADOW
	SHADELESS  = t.SHADELESS
	WIRE       = t.WIRE
	VCOL_LIGHT = t.VCOL_LIGHT
	VCOL_PAINT = t.VCOL_PAINT
	HALO       = t.HALO
	ZTRANSP    = t.ZTRANSP
	ZINVERT    = t.ZINVERT
	ONLYSHADOW = t.ONLYSHADOW
	STAR       = t.STAR
	TEXFACE    = t.TEXFACE
	NOMIST     = t.NOMIST
	del t
	
# override:
ModeFlags = _Material.Modes

def get(name = None):
	"""If 'name' given, the Material 'name' is returned if existing, 'None' otherwise.
If no name is given, a list of all Materials is returned"""
	if name:
		return Material(_Material.get(name))
	else:
		return shadow._List(_Material.get(), Material)
	
Get = get  # emulation

def New(name = None):
	"""Creates a new, empty Material and returns it. 

Example::

  from Blender import Material
  mat = Material.New()
"""
	mat = Material(_Material.New())
	if name:
		mat.name = name
	return mat