Results 1 to 4 of 4
  1. #1

    [SOLVED] Dynamic Texture

    well, im throwing in the towel on this one.

    on one of my computers it crashes right away in 2.74 and the other it works fine. in 2.78c it doesnt do anything on either.

    both computers are pretty much the same software and blender wise.

    if someone could tell me why its not working that would be great.

    EDIT: apparently its working just fine on 2.74, still not sure about other versions.

    PS: there is also globalDict support, just delete the "#" in front of the logic.loadGlobalDict() and logic.saveGlobalDict() in the Main.py in "Py".
    Attached Files Attached Files
    Last edited by Daedalus_MDW; 14-Aug-17 at 08:18.
    System "IVAN" (rev 1.3b) - Win7 64bit - Blender 2.74:
    CPU- Intel i3-3220 3.30 Ghz | GPU- EVGA GTX 970 | RAM- GSkill Ares 16GB 1600 Mhz | MB- ASUS P8Z77-V LK



  2. #2
    Member sdfgeoff's Avatar
    Join Date
    May 2010
    Location
    Kalpana One
    Posts
    5,153
    Works fine for me.

    However, looking at the code: Don't create singletons. Don't store things inside bge.logic or bge.texture if you can help it. In fact, I'd say never do it. (different to what I would have said a year ago though).
    I'd also advise looking at pep8, just to make your python code consistant with everyone elses. only constants should be capitalised.

    Perhaps this function could be of use to you:
    Code:
    def replace_image(obj, path, mat_id, tex_id):
        '''Replaces the image associated with a mesh'''
        # The texture has to be stored in a place associated with other game data
        # so we store it in a game property. This name inlucdes the mat ID's and
        # tex ID's so that a single object with a complex setup does not have the
        # textures overwrite each other.
        prop_name = 'SHOW_PICTURE{}:{}'.format(mat_id, tex_id)
        if prop_name not in obj:
            tex = bge.texture.Texture(obj, mat_id, tex_id)
            obj[prop_name] = tex
        else:
            tex = obj[prop_name]
    
    
        # Load the image from the path
        raw = bge.texture.ImageFFmpeg(path)
    
    
        # Check to see that it loaded
        if raw.status != bge.texture.SOURCE_PLAYING:
            # Error in loading image
            raise ValueError("Unable to load image at {}".format(path))
    
    
        # Assign the new image to the texture and update the texture.
        tex.source = raw
        tex.refresh(True)
        return tex
    It will load the image from disk each time, so you may want to create a cache around the bge.texture.ImageFFmpeg call. Something like this may work:
    Code:
    import functools
    
    @functools.lru_cache(max_size=128)  # If you have more than 128 images at the same time, increase this number
    def load_image(path):
        return bge.texture.ImageFFmpeg(path)
    Last edited by sdfgeoff; 13-Aug-17 at 13:41.
    "Someone applied a roof texture to that wall" - martinsh

    Website: www.sdfgeoff.space



  3. #3
    funny, i tried it again today and works just fine on both computers now...

    this was just supposed to be a little experiment, not too worried about all that religious code stuff. yeah, i know about pep stuff, but i dont like it. plain and simple as that. i follow my own standard, which i think is perfectly appropriate for a hobbyist like myself.

    now i agree if i had any intention on making a job of it or contributing to a project then pep8 would be best.
    System "IVAN" (rev 1.3b) - Win7 64bit - Blender 2.74:
    CPU- Intel i3-3220 3.30 Ghz | GPU- EVGA GTX 970 | RAM- GSkill Ares 16GB 1600 Mhz | MB- ASUS P8Z77-V LK



  4. #4
    Member sdfgeoff's Avatar
    Join Date
    May 2010
    Location
    Kalpana One
    Posts
    5,153
    i follow my own standard, which i think is perfectly appropriate for a hobbyist like myself.
    If you're going to follow a standard, why not use an 'official' one? The only cost is the week or two it takes for your fingers to learn when to hit the shift key.....
    (I started off with my own style as well, and also found PEP8 to look 'ugly', but changed when I started working with large codebases and wanted to use consistency checking tools)
    "Someone applied a roof texture to that wall" - martinsh

    Website: www.sdfgeoff.space



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •