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

bge.texture.rst « rst « python_api « doc - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 996f79a313aa602ccedb7752234d472d73b216a6 (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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549

Game Engine bge.texture Module
==============================

.. note::
   This documentation is still very weak, and needs some help! Right now they are mostly a collection
   of the docstrings found in the bge.texture source code + some random places filled with text.

*****
Intro
*****

The bge.texture module allows you to manipulate textures during the game.

Several sources for texture are possible: video files, image files, video capture, memory buffer, camera render or a mix of that.

The video and image files can be loaded from the internet using an URL instead of a file name.

In addition, you can apply filters on the images before sending them to the GPU, allowing video effect: blue screen, color band, gray, normal map.

bge.texture uses FFmpeg to load images and videos. All the formats and codecs that FFmpeg supports are supported by this module, including but not limited to::

* AVI
* Ogg
* Xvid
* Theora
* dv1394 camera
* video4linux capture card (this includes many webcams)
* videoForWindows capture card (this includes many webcams)
* JPG

The principle is simple: first you identify a texture on an existing object using
the :materialID: function, then you create a new texture with dynamic content
and swap the two textures in the GPU.

The GE is not aware of the substitution and continues to display the object as always,
except that you are now in control of the texture.

When the texture object is deleted, the new texture is deleted and the old texture restored.

.. module:: bge.texture

.. class:: VideoFFmpeg(file [, capture=-1, rate=25.0, width=0, height=0])

   FFmpeg video source

   .. attribute:: status

      video status

   .. attribute:: range

      replay range

   .. attribute:: repeat

      repeat count, -1 for infinite repeat

      :type: int

   .. attribute:: framerate

      frame rate

      :type: float

   .. attribute:: valid

      Tells if an image is available

      :type: bool

   .. attribute:: image

      image data

   .. attribute:: size

      image size

   .. attribute:: scale

      fast scale of image (near neighbour)

   .. attribute:: flip

      flip image vertically

   .. attribute:: filter

      pixel filter

   .. attribute:: preseek

      number of frames of preseek

      :type: int

   .. attribute:: deinterlace

      deinterlace image

      :type: bool

   .. method:: play()

      Play (restart) video

   .. method:: pause()

      pause video

   .. method:: stop()

      stop video (play will replay it from start)

   .. method:: refresh()

      Refresh video - get its status

.. class:: ImageFFmpeg(file)

   FFmpeg image source

   .. attribute:: status

      video status

   .. attribute:: valid

      Tells if an image is available

      :type: bool

   .. attribute:: image

      image data

   .. attribute:: size

      image size

   .. attribute:: scale

      fast scale of image (near neighbour)

   .. attribute:: flip

      flip image vertically

   .. attribute:: filter

      pixel filter

   .. method:: refresh()

      Refresh image, i.e. load it

   .. method:: reload([newname])

      Reload image, i.e. reopen it

.. class:: ImageBuff()

   Image source from image buffer

   .. attribute:: filter

      pixel filter

   .. attribute:: flip

      flip image vertically

   .. attribute:: image

      image data

   .. method:: load(imageBuffer, width, height)

      Load image from buffer

   .. method:: plot(imageBuffer, width, height, positionX, positionY)

      update image buffer

   .. attribute:: scale

      fast scale of image (near neighbour)

   .. attribute:: size

      image size

   .. attribute:: valid

      bool to tell if an image is available

.. class:: ImageMirror(scene)

   Image source from mirror

   .. attribute:: alpha

      use alpha in texture

   .. attribute:: background

      background color

   .. attribute:: capsize

      size of render area

   .. attribute:: clip

      clipping distance

   .. attribute:: filter

      pixel filter

   .. attribute:: flip

      flip image vertically

   .. attribute:: image

      image data

   .. method:: refresh(imageMirror)

      Refresh image - invalidate its current content

   .. attribute:: scale

      fast scale of image (near neighbour)

   .. attribute:: size

      image size

   .. attribute:: valid

      bool to tell if an image is available

   .. attribute:: whole

      use whole viewport to render

.. class:: ImageMix()

   Image mixer

   .. attribute:: filter

      pixel filter

   .. attribute:: flip

      flip image vertically

   .. method:: getSource(imageMix)

      get image source

   .. method:: getWeight(imageMix)

      get image source weight


   .. attribute:: image

      image data

   .. method:: refresh(imageMix)

      Refresh image - invalidate its current content

   .. attribute:: scale

      fast scale of image (near neighbour)

   .. method:: setSource(imageMix)

      set image source

   .. method:: setWeight(imageMix)

      set image source weight

   .. attribute:: valid

      bool to tell if an image is available

.. class:: ImageRender(scene, camera)

   Image source from render

   .. attribute:: alpha

      use alpha in texture

   .. attribute:: background

      background color

   .. attribute:: capsize

      size of render area

   .. attribute:: filter

      pixel filter

   .. attribute:: flip

      flip image vertically

   .. attribute:: image

      image data

   .. method:: refresh(imageRender)

      Refresh image - invalidate its current content

   .. attribute:: scale

      fast scale of image (near neighbour)

   .. attribute:: size

      image size

   .. attribute:: valid

      bool to tell if an image is available

   .. attribute:: whole

      use whole viewport to render

.. class:: ImageViewport()

   Image source from viewport

   .. attribute:: alpha

      use alpha in texture

   .. attribute:: capsize

      size of viewport area being captured

   .. attribute:: filter

      pixel filter

   .. attribute:: flip

      flip image vertically

   .. attribute:: image

      image data

   .. attribute:: position

      upper left corner of captured area

   .. method:: refresh(imageViewport)

      Refresh image - invalidate its current content

   .. attribute:: scale

      fast scale of image (near neighbour)

   .. attribute:: size

      image size

   .. attribute:: valid

      bool to tell if an image is available

   .. attribute:: whole

      use whole viewport to capture

.. class:: Texture(gameObj)

   Texture objects

   .. attribute:: bindId

      OpenGL Bind Name

   .. method:: close(texture)

      Close dynamic texture and restore original

   .. attribute:: mipmap

      mipmap texture

   .. method:: refresh(texture)

      Refresh texture from source

   .. attribute:: source

      source of texture

.. class:: FilterBGR24()

   Source filter BGR24 objects

.. class:: FilterBlueScreen()

   Filter for Blue Screen objects

   .. attribute:: color

      blue screen color

   .. attribute:: limits

      blue screen color limits

   .. attribute:: previous

      previous pixel filter

.. class:: FilterColor()

   Filter for color calculations

   .. attribute:: matrix

      matrix [4][5] for color calculation

   .. attribute:: previous

      previous pixel filter

.. class:: FilterGray()

   Filter for gray scale effect

   .. attribute:: previous

      previous pixel filter

.. class:: FilterLevel()

   Filter for levels calculations

   .. attribute:: levels

      levels matrix [4] (min, max)

   .. attribute:: previous

      previous pixel filter

.. class:: FilterNormal()

   Filter for Blue Screen objects

   .. attribute:: colorIdx

      index of color used to calculate normal (0 - red, 1 - green, 2 - blue)

   .. attribute:: depth

      depth of relief

   .. attribute:: previous

      previous pixel filter

.. class:: FilterRGB24()

   Returns a new input filter object to be used with :class:`ImageBuff` object when the image passed
   to the ImageBuff.load() function has the 3-bytes pixel format BGR.

.. class:: FilterRGBA32()

   Source filter RGBA32 objects

.. function:: getLastError()

   Last error that occurred in a bge.texture function.

   :return: the description of the last error occurred in a bge.texture function.
   :rtype: string

.. function:: imageToArray(image,mode)

   Returns a :class:`~bgl.buffer` corresponding to the current image stored in a texture source object.

   :arg image: Image source object.
   :type image: object of type :class:`VideoFFmpeg`, :class:`ImageFFmpeg`, :class:`ImageBuff`, :class:`ImageMix`, :class:`ImageRender`, :class:`ImageMirror` or :class:`ImageViewport`
   :arg mode: optional argument representing the pixel format.
      You can use the characters R, G, B for the 3 color channels, A for the alpha channel,
      0 to force a fixed 0 color channel and 1 to force a fixed 255 color channel.
      Example: "BGR" will return 3 bytes per pixel with the Blue, Green and Red channels in that order.
      "RGB1" will return 4 bytes per pixel with the Red, Green, Blue channels in that order and the alpha channel forced to 255.
      The default mode is "RGBA".

   :type mode: string
   :rtype: :class:`~bgl.buffer`
   :return: A object representing the image as one dimensional array of bytes of size (pixel_size*width*height),
      line by line starting from the bottom of the image. The pixel size and format is determined by the mode
      parameter.

.. function materialID(object,name)

   Returns a numeric value that can be used in :class:`Texture` to create a dynamic texture.

   The value corresponds to an internal material number that uses the texture identified
   by name. name is a string representing a texture name with IM prefix if you want to
   identify the texture directly.    This method works for basic tex face and for material,
   provided the material has a texture channel using that particular texture in first
   position of the texture stack.    name can also have MA prefix if you want to identify
   the texture by material. In that case the material must have a texture channel in first
   position.

   If the object has no material that matches name, it generates a runtime error. Use try/except to catch the exception.

   Ex: bge.texture.materialID(obj, 'IMvideo.png')

   :arg object: the game object that uses the texture you want to make dynamic
   :type object: game object
   :arg name: name of the texture/material you want to make dynamic.
   :type name: string
   :rtype: integer

.. function setLogFile(filename)

   Sets the name of a text file in which runtime error messages will be written, in addition to the printing
   of the messages on the Python console. Only the runtime errors specific to the VideoTexture module
   are written in that file, ordinary runtime time errors are not written.

   :arg filename: name of error log file
   :type filename: string
   :rtype: integer