Hello everyone,
I’m trying to do something that should be very simple, but I must be
missing something somewhere.
The following python script successfully displays a plane with an attached
mono bitmap png image using a material in blender, when rendered with the
F12 key. My problem is that I need to do this in the game engine,
where materials can’t be used.
The material lines commented out with “##” are the only difference
I made to make the script run with no errors in the game engine.
With the material commented out, the plane appears but the image isn’t there.
The script runs on a non-pulsed “always” init sensor on an empty for testing.
I’ve tried many permutations, with different modes and UV info attached
to both face and vertexes, but with no success in seeing the image.
I’m using Blender 2.34 in FreeBSD, Python 2.3
What am I doing wrong ?
Python script follows:
=====
import Blender
from Blender import Texture, Image, NMesh, Material, Scene, Object
from math import *
import fcntl, sys, os
pi = 3.1415926
deg2rad = pi / 180.0
rad2deg = 180.0 / pi
def e2d(e):
return ( e * rad2deg )
def d2e(d):
return ( d * deg2rad )
def euler2deg( e3 ):
return( [ e2d( e3[0] ), e2d( e3[1] ), e2d( e3[2] )] )
def deg2euler( d3 ):
return( [ d2e( d3[0] ), d2e( d3[1] ), d2e( d3[2] )] )
def setPlane( nm, x0, y0, ww, hh ):
img = Image.Load("/home/S/PS/test00c.o.png")
bb = img.getSize()
print "image width: ", bb[0], " height: ", bb[1]
print "Images Now: ", Image.Get()
tx = Texture.New('Tex1')
tx.setType('Image')
tx.image = img
##mm = Material.Get()
##print "Materials: ", mm
##mat = Material.Get( "Material" )
##mat.setAlpha(0.0)
##mat.emit = 0.7
##mat.setAdd(0.8)
##mat.setRGBCol( 1.0, 1.0, 1.0 )
##mat.setTexture( 0, tx, Texture.TexCo.ORCO, Texture.MapTo.ALPHA )
tt = Texture.Get()
print "Textures: ", tt
xx = x0 + ww
yy = y0 + hh
me = NMesh.GetRaw()
v = NMesh.Vert( xx, y0, 0.0 )
#v.uvco = ( 1.0, 0.0 )
me.verts.append(v)
v = NMesh.Vert( xx, yy, 0.0 )
#v.uvco = ( 1.0, 1.0 )
me.verts.append(v)
v = NMesh.Vert( x0, yy, 0.0 )
#v.uvco = ( 0.0, 1.0 )
me.verts.append(v)
v = NMesh.Vert( x0, y0, 0.0 )
#v.uvco = ( 0.0, 0.0 )
me.verts.append(v)
f = NMesh.Face()
f.v.append( me.verts[0 ] )
f.v.append( me.verts[1 ] )
f.v.append( me.verts[2 ] )
f.v.append( me.verts[3 ] )
me.faces.append( f )
NMesh.PutRaw( me, nm, 1 )
# use prior uvco or following faceUV
me.hasVertexUV(0)
f.uv = [(1.0,0.0),(1.0,1.0),(0.0,1.0),(0.0,0.0)]
me.hasFaceUV(1)
print "ME has face UV: ", me.hasFaceUV()
f.image = img
f.flag = NMesh.FaceModes.TEX + NMesh.FaceModes.LIGHT + NMesh.FaceModes.TWOSIDE
#f.transp = NMesh.FaceTranspModes.ALPHA
f.transp = NMesh.FaceTranspModes.SOLID
#me.mode = NMesh.Modes.TWOSIDED
##me.addMaterial( mat )
color = NMesh.Col( 255, 255, 255, 0 )
f.col.append( color )
oo = Object.Get( 'Mesh' )
oo.setName( nm )
me.update()
print "ME has face UV: ", me.hasFaceUV()
Blender.Redraw()
setPlane( ‘plane1’, -5.5, -1.0, 11.0, 2.0 )
#setPlane( ‘plane2’, -1.0, -1.0, 2.0, 2.0 )
objects = Object.Get()
print "Objects: ", objects
camera = Object.Get(‘Camera’)
print "camera loc: ", camera.getLocation()
print "camera deltaloc: ", camera.getDeltaLocation()
print "camera euler: ", camera.getEuler()
print "camera euler: ", euler2deg( camera.getEuler() )
print "camera size: ", camera.getSize()
camera.setLocation(0.0, 0.0, 10.0)
camera.setEuler(deg2euler( [0.0, 0.0, 0.0] ))
lamp = Object.Get(‘Lamp’)
lamp.setLocation(0.0, 0.0, -5.0)
Blender.Redraw()
=====
The execution output is:
=====
Xlib: extension “XFree86-DRI” missing on display “:0.0”.
fcntl: Device not configured
image width: 704 height: 128
Images Now: [[Image “test00c.o.png”]]
Textures: [[Texture “Tex1”]]
ME has face UV: False
ME has face UV: True
Objects: [[Object “Camera”], [Object “Lamp”], [Object “Empty”], [Object “plane1”]]
camera loc: (0.0, 0.0, 10.0)
camera deltaloc: (0.0, 0.0, 0.0)
camera euler: [0.0000, 0.0000, 0.0000]
camera euler: [0.0, 0.0, 0.0]
camera size: (1.0, 1.0, 1.0)
GL_VERSION: 1.3 (1.3 Mesa 4.0.4)