1
$\begingroup$

in BGE, I am trying to generate some images with matplotlib, then want to put these images as an object texture.

My first try was ok, I

  • generate the image (plplot)
  • save it to disk (PIL savefig)
  • load the image and put it as texture (Texture imageFFmpeg)

Code:

# plot data
plt.plot(x,y)
plt.savefig('plot.png')

# put image on object as texture
matID=bge.texture.materialID(here.objects['graph1'],"MAplot1mat")
bge.logic.gp1=bge.texture.Texture(here.objects['graph1'],matID)
url_ima=bge.logic.expandPath('//plot.png')
bge.logic.gp1.source=bge.logic.ImageFFmpeg(url_ima)
bge.logic.gp1.refresh(True)

I would like to avoid saving image on disk. So I tried to use an Image Buffer to let the matplotlib image (in memory) to be saved as an image buffer, to feed into the bge.texture. No way.

Code:

bge.logic.plot=bge.texture.Texture(scene.objects['floor'],0)
image_buffer=bge.texture.imageToArray(floor_figure)
bge.logic.floorplot.source=bge.texture.ImageBuff()
bge.logic.floorplot.source.load(image_buffer,20,20)

Question: is there a way to let an image from matplotlib (in memory, not saved onto disk) to fit into a texure?

Thank you, please ask for more info if my explanation is not clear enough.

Roberto

$\endgroup$
2
  • $\begingroup$ This answer might help, note some performance issues. Other answers containing image.pixels may give more examples. $\endgroup$
    – sambler
    Commented Oct 3, 2015 at 9:17
  • $\begingroup$ Thanks, but looks bge doesn't have the "data" class, it's only in bpy. I am now trying to understand how imageToArray() works, maybe it could help. $\endgroup$ Commented Oct 3, 2015 at 16:34

0

You must log in to answer this question.

Browse other questions tagged .