Py淡

Python, Python, Python! In the spirit of "import antigravity"

Using buffer protocol to dynamically texture with 2D numpy array in Panda3d

 

I followed this official blog post "Buffer protocol support" and came up with a short example of simple video player in panda3d using numpy 2d array as texture. The trick was to use setRamImage on Texture object. To do that, we have to setup the memory layout using setup2dTexture method.

setup2dTexture ( int x_size, int y_size, Texture::ComponentType component_type, Texture::Format format )

Texture format and Texture componentType need to be set correctly. By try and error, I figured that the combination of T_unsigned_byte and F_luminance works for 8 bit gray scale image.

 

f:id:i-namekawa:20150716180048p:plain

 

Panda3d has an avi file texture support by default. Read here: Playing MPG and AVI files - Panda3D Manual

So, normally you will not need what I showed above. That is merely for demonstration of dynamic texturing using numpy array.