ImageMix: scale

scale
  • Activates nearest scaling algorithm.

Type: 

  • boolean
  • True = activate nearest scaling algorithm
  • False = don't activate nearest scaling algorithm
Note:
  • Images being mixed must be the same size (dimensions).
     
  • ImageMix sources: ImageBuff, ImageFFmpeg, ImageMirror, ImageRender, ImageViewport and VideoFFmpeg.
  • Video Texture width and height should be a power of 2.
  • If the Video Texture is not a power of 2, the graphics pipeline automatically rescales the texture to a power of 2.
     
  • Graphics pipeline doesn't always use the nearest scaling algorithm.
Power of 2:
  • 2 x 2
  • 4 x 4
  • 8 x 8
  • 16 x 16
  • 32 x 32
  • 64 x 64
  • 128 x 128
  • 256 x 256
  • 512 x 512
  • etc
  • And any combination.  128 x 512 is a power of 2.
Example:
  • A texture of 300 x 300 will be automatically rescaled by the graphics pipeline to 512 x 512.
     
  • A texture of 130 x 520 will be automatically rescaled by the graphics pipeline to 256 x 1024
Sample Code

###################### get if using the nearest scaling algorithm

#import bge
import bge

# get current scene
scene = bge.logic.getCurrentScene()

# get list of objects in scene
objList = scene.objects

# get object named Painting
obj = objList["Painting"]

# get matID for the obj named Painting
# I named the material Canvas
matID = bge.texture.materialID(obj, "MACanvas")

# get the name of the image
# I'm using an image named Mona_Lisa.jpg
imageName_A = "Mona_Lisa.jpg"

# get image path
# Mona_Lisa.jpg is in same directory as saved blend
imagePath_A = bge.logic.expandPath('//' + imageName_A)

# get the name of the image
# I'm using an image named Vitruvian_Man.jpg
# it has the same dimensions as Mona_Lisa.jpg
imageName_B = "Vitruvian_Man.jpg"

# get image path
# Vitruvian_Man.jpg is in same directory as saved blend
imagePath_B = bge.logic.expandPath('//' + imageName_B)

# get images
image_A = bge.texture.ImageFFmpeg(imagePath_A)
image_B = bge.texture.ImageFFmpeg(imagePath_B)

# set the texture
mix = bge.texture.Texture(obj, matID)

# get the texture image
mix.source = bge.texture.ImageMix()

# set two sources for the image mix
# I named my images Mix1 and Mix2
mix.source.setSource("Mix1", image_A)
mix.source.setSource("Mix2", image_B)

# set the image weight for Mix1 and Mix2
# weights should add up to 256
mix.source.setWeight("Mix1", 100)
mix.source.setWeight("Mix2", 156)

# get if using nearest scaling algorithm
status = mix.source.scale

# save mix as an object variable
obj["Mix"] = mix

# update the image
mix.refresh(True)

Sample Code

###################### set status of nearest scaling algorithm

#import bge
import bge

# get current scene
scene = bge.logic.getCurrentScene()

# get list of objects in scene
objList = scene.objects

# get object named Painting
obj = objList["Painting"]

# get matID for the obj named Painting
# I named the material Canvas
matID = bge.texture.materialID(obj, "MACanvas")

# get the name of the image
# I'm using an image named Mona_Lisa.jpg
imageName_A = "Mona_Lisa.jpg"

# get image path
# Mona_Lisa.jpg is in same directory as saved blend
imagePath_A = bge.logic.expandPath('//' + imageName_A)

# get the name of the image
# I'm using an image named Vitruvian_Man.jpg
# it has the same dimensions as Mona_Lisa.jpg
imageName_B = "Vitruvian_Man.jpg"

# get image path
# Vitruvian_Man.jpg is in same directory as saved blend
imagePath_B = bge.logic.expandPath('//' + imageName_B)

# get images
image_A = bge.texture.ImageFFmpeg(imagePath_A)
image_B = bge.texture.ImageFFmpeg(imagePath_B)

# set the texture
mix = bge.texture.Texture(obj, matID)

# get the texture image
mix.source = bge.texture.ImageMix()

# set two sources for the image mix
# I named my images Mix1 and Mix2
mix.source.setSource("Mix1", image_A)
mix.source.setSource("Mix2", image_B)

# set the image weight for Mix1 and Mix2
# weights should add up to 256
mix.source.setWeight("Mix1", 100)
mix.source.setWeight("Mix2", 156)

# set scale to True
mix.source.scale = True

# save mix as an object variable
obj["Mix"] = mix

# update the image
mix.refresh(True)