Exemple #1
0
import bge
from bge import texture
from bge import logic

cont = logic.getCurrentController()
obj = cont.owner

# the creation of the texture must be done once: save the
# texture object in an attribute of bge.logic module makes it persistent
if not hasattr(logic, 'video'):

    # identify a static texture by name
    matID = texture.materialID(obj, 'IMvideo.png')

    # create a dynamic texture that will replace the static texture
    logic.video = texture.Texture(obj, matID)

    # define a source of image for the texture, here a movie
    movie = logic.expandPath('//trailer_400p.ogg')
    logic.video.source = texture.VideoFFmpeg(movie)
    logic.video.source.scale = True

    # Note that we can change the ``Texture`` source at any time.
    # Suppose we want to switch between two movies during the game:
    logic.mySources[0] = texture.VideoFFmpeg('movie1.avi')
    logic.mySources[1] = texture.VideoFFmpeg('movie2.avi')

    #And then assign (and reassign) the source during the game
    logic.video.source = logic.mySources[movieSel]

    # quick off the movie, but it wont play in the background
Exemple #2
0
# Get the active camera
viewerCam = scene.active_camera

# Get the water reflections camera
waterCam = objects.get('waterCamera')
if not waterCam:
    raise Exception("Can't find the camera 'waterCamera'")

# Get the textures, or generate it
if not waterPlane['textures']:
    # Sometimes the image must be reduced in size
    sizeBackup = size[:]
    validTexture = False
    while not validTexture:
        g.reflection = texture.Texture(waterPlane, 0, 0)
        g.reflection.source = texture.ImageRender(scene, waterCam)
        g.reflection.source.capsize = [size[0], size[1]]
        g.reflection.source.background = [32, 128, 128, 0]
        bufout = texture.imageToArray(g.reflection.source)
        if (len(bufout) // size[0] // size[1] != 4):
            print(
                "Warning: Reflection texture size {0}x{1} not supported, will be reduced"
                .format(size[0], size[1]))
            size[0] = size[0] // 2
            size[1] = size[1] // 2
            continue
        validTexture = True
    print("Info: Reflection texture size = {0}x{1}".format(size[0], size[1]))
    size = sizeBackup[:]
    validTexture = False
Exemple #3
0
    def __init__(self, image_name, sensor_num, feed_2):
        import sys
        import bge
        from bge import texture
        import tempfile

        cont = bge.logic.getCurrentController()
        own = cont.owner
        img_w = 0
        img_h = 0

        try:
            matID = texture.materialID(own, image_name)
        except:
            print("Delicode NI mate Tools Error: No texture with name: " + image_name)
            pass

        try:
            self.image_texture = texture.Texture(own, matID)

            filename = "NI_mate_shared_map"

            if feed_2:
                filename = filename + str(2*(sensor_num-1)+2)
            else:
                filename = filename + str(2*(sensor_num-1)+1)

            filename = filename + ".data"

            file = open(tempfile.gettempdir() + "/" + filename, "rb")
            if sys.platform.startswith('darwin') or sys.platform.startswith('Linux'):
                self.file_map = mmap.mmap(file.fileno(), 0, mmap.PROT_READ, mmap.ACCESS_READ)
            else:
                self.file_map = mmap.mmap(file.fileno(), 0, None, mmap.ACCESS_READ)
            file.close()

            self.file_map.seek(0)

            w = 0
            h = 0

            if self.file_map.size() == 640*480*4:
                w = 640
                h = 480
            elif self.file_map.size() == 320*240*4:
                w = 320
                h = 240
            elif self.file_map.size() == 160*120*4:
                w = 160
                h = 120

            if w > 0 and h > 0:
                buf = self.file_map.read(w*h*4)

                self.image_texture.source = texture.ImageBuff()
                self.image_texture.source.filter = texture.FilterRGBA32()
                self.image_texture.source.load(buf, w, h)

                self.img_w = w
                self.img_h = h

            if feed_2:
                print("Delicode NI mate Tools replacing " + image_name + " with sensor " + str(sensor_num) + " live feed 2")
            else:
                print("Delicode NI mate Tools replacing " + image_name + " with sensor " + str(sensor_num) + " live feed 1")
        except Exception as e:
            print("Delicode NI mate Tools Error: Couldn't open NI mate feed " + tempfile.gettempdir() + "/" + filename)
            print("Reason: %s" % e)
            self.file_map = None
            pass
Exemple #4
0
ori = Matrix(activecam.orientation)

#delay reduction using delta offset
if 'oldori1' not in own:
    own['oldori1'] = activecam.orientation
    own['oldpos1'] = activecam.position
    own['deltaori1'] = own['oldori1'] - activecam.orientation
    own['deltapos1'] = own['oldpos1'] - activecam.position

own['deltaori1'] = own['oldori1'] - ori
own['deltapos1'] = own['oldpos1'] - pos

#orienting and positioning the refraction rendercamera
rendercam.orientation = ori - own['deltaori1'] * 1
rendercam.position = pos - own['deltapos1'] * 1

#storing the old orientation and position of the camera
own['oldori1'] = ori
own['oldpos1'] = pos

#rendering the refraction texture in tex channel 1
if not hasattr(g, 'blurtex'):
    g.blurtex = texture.Texture(own, 0, 0)
    g.blurtex.source = texture.ImageRender(scene, rendercam)
    g.blurtex.source.capsize = [texsize, texsize]
    g.blurtex.source.background = [100, 100, 100, 0]

#own.visible = False
g.blurtex.refresh(True)
own.visible = True
Exemple #5
0
flare = objlist['flare1']

#setting lens nad projection to watercamera
#rendercam.lens = activecam.lens
#rendercam.projection_matrix = activecam.projection_matrix

#disable visibility for the water surface during texture rendering
own.visible = False
flare.visible = False

###REFRACTION####################

#initializing camera for refraction pass
#rendercam.position = activecam.position
#rendercam.orientation = activecam.orientation


#rendering the refraction texture in tex channel 1
if not hasattr(g, 'tex'):
	g.tex = texture.Texture(own, 0, 0)
	g.tex.source = texture.ImageRender(scene,rendercam)
	g.tex.source.capsize = [texsize,texsize]
	g.tex.source.background = [100,100,100,0]

g.tex.refresh(True)

g.blurtex.refresh(True)

own.visible = True
flare.visible = True
Exemple #6
0
#invert normals when backface
if V < 0:
    normal = -normal
    cam['resettimer'] = 0
    cam['randomtime'] = (rf() * 5) * 2.0 - 1.0

#making a clipping plane buffer
plane = bgl.Buffer(bgl.GL_DOUBLE, [4],
                   [-normal[0], -normal[1], -normal[2], -D + offset])
bgl.glClipPlane(bgl.GL_CLIP_PLANE0, plane)
bgl.glEnable(bgl.GL_CLIP_PLANE0)

#rendering the reflection texture in tex channel 0
if not hasattr(g, 'reflection'):
    g.reflection = texture.Texture(own, 0, 0)
    g.reflection.source = texture.ImageRender(scene, watercamera)
    g.reflection.source.capsize = [reflsize, reflsize]
    g.reflection.source.background = [
        int(bgR * 255),
        int(bgG * 255),
        int(bgB * 255),
        int(bgA * 255)
    ]

g.reflection.refresh(True)

#restoring face culling to normal and disabling the geometry clipping
bgl.glCullFace(bgl.GL_BACK)
bgl.glDisable(bgl.GL_CLIP_PLANE0)
Exemple #7
0
    def texture2old(self):
        ''' Return to old texture. '''

        self.obj_texture = texture.Texture(self.obj, self.ID)
        self.obj_texture.refresh(True)
V = (activecam.position - own.position).normalized().dot(
    normal)  #VdotN to get frontface/backface

#invert normals when backface
if V < 0:
    normal = -normal

#making a clipping plane buffer
plane = bgl.Buffer(bgl.GL_DOUBLE, [4],
                   [-normal[0], -normal[1], -normal[2], -D + offset])
bgl.glClipPlane(bgl.GL_CLIP_PLANE0, plane)
bgl.glEnable(bgl.GL_CLIP_PLANE0)

#rendering the reflection texture in tex channel 0
if not hasattr(g, 'reflection2'):
    g.reflection2 = texture.Texture(own, 0, 0)
    g.reflection2.source = texture.ImageRender(scene, watercamera)
    g.reflection2.source.capsize = [reflsize, reflsize]
    g.reflection2.source.background = [
        int(bgR * 255),
        int(bgG * 255),
        int(bgB * 255),
        int(bgA * 255)
    ]

g.reflection2.refresh(True)

#restoring face culling to normal and disabling the geometry clipping
bgl.glCullFace(bgl.GL_BACK)
bgl.glDisable(bgl.GL_CLIP_PLANE0)