Mask following cursor

  • #1, by stered86Saturday, 04. May 2019, 10:03 5 years ago
    Hi, everybody!

    I'm currently trying to achieve this: the player is holding a flashlight, which is set as a cursor. When he moves the flashlight-cursor to certain positions something has to appear on the background.

    I've installed the mask plugin and it works fine, but I don't know how to move the mask according to the cursor position. 

    So, basically, is there a way I can tell the engine to constantly change the position of the mask so that it follows my flashlight-cursor? Any idea if it is possible?

    Newbie

    62 Posts


  • #2, by afrlmeSaturday, 04. May 2019, 12:26 5 years ago
    you only have to move the mask image around like you would move around a regular scene object image/animation as masks are assigned to regular scene objects.

    as far as I remember, you would create a black or semi-transparent black/dark colored image to overlay over the scene, you would then create an image of a circle in white - needs to have a bit of transparency around the edges of the image - white image can also be faded towards the edges if you want to create feathering. you assign the circle image/scene object as the mask & the dark image/scene object as the object you want to mask. don't forget to assign a condition to the masked scene object image to hide it from the scene as it's not needed.

    Create a mainLoop function to update the position of the mask image - don't forget to offset it to center it on your cursor, as the position will be the top left of the image by default.

    That's about all I'm going to say for now. Just woke up not long ago, but maybe I can make a small example later on. You are using visionaire studio 5.x, yes?

    oh wait... don't need to make an example. it seems I already have a mouse position with circle in a test mask ved I have been using for testing out the different things that are possible with masks.  here you go: https://www.dropbox.com/s/5ytox8bee4pv8ur/mask_test.zip?dl=0

    set default scene to 003_mouse_pos.

    quick note: in that example I inversed the mask & object image colors. it all depends on exactly what you want. white object will be affected completely by the mask color, whereas a white mask will show the original color of the mask. the masking system uses multiply, so you need to that into account. I am also incorrect in that being the correct example of usage, as you are wanting to cutout a transparent bit in the dark image & not just show it, so that requires a fullscreen mask which is kind of buggy. anyway, like I said... I'll have a look into it later on - if I remember.

    P.S: have you tried using shaders? probably less hassle overall & Simon or someone could give you a working flashlight example.

    Imperator

    7278 Posts

  • #3, by stered86Saturday, 04. May 2019, 13:08 5 years ago
    No, I don't want to cut a transparent bit in a dark image! The flashlight should reveal an hidden message that's revealed by light, so maybe your example is what I need! I'll check it as soon as I can!

    Newbie

    62 Posts

  • #4, by afrlmeSaturday, 04. May 2019, 13:11 5 years ago
    yeah, it should work if that's all you are wanting to do.

    Imperator

    7278 Posts

  • #5, by stered86Sunday, 05. May 2019, 19:44 5 years ago
    It's strange, I tried importing my images into your project and it does exactly what it is supposed to do. Then I tried to recreate the same situation on my project, but NOTHING happens. I suppose there must be some code interfering with yours.

    I'll try and check it out on my own, but first I had an idea which could be simpler. I created an animation and assigned it to the mask object as its default animation. Then I edited a frame of that animation and put an "execute a script" action containing this code:

    local mask = ActiveAnimations["mask_anim"].AnimationCurrentPosition
    
    local curPos = getCursorPos()
    
    
    
    mask = {x = curPos.x, y = curPos.y}

    Theoretically it should update the position of the animation assigned to the mask object and move it to the cursor position, BUT... it just simply doesn't work.
    Any idea why?

    Newbie

    62 Posts

  • #6, by afrlmeSunday, 05. May 2019, 22:46 5 years ago
    Any errors mentioned in the log file?

    Imperator

    7278 Posts

  • #7, by stered86Monday, 06. May 2019, 09:44 5 years ago
    I get this error a lot of times (probably because the animation is infinite):
    9:41:37.322:error: object is empty
    
    9:41:37.322:stack traceback:
    
     [C]: in function 'debugerror'
    
     [string "function debugfunc(err) debugerror(err) end"]:1: in function 
    
     [C]: in function '__index'
    
     ..._SVN\trunk\Vatican_visionaire\plugins\Masking\player.lua:20: in function 
    
    9:41:37.322:Failed to execute hook function 'maskShaderCallback':  

    Assuming the "object" is the one containing the mask, I can't understand why it should be considered empty...

    EDIT: I tried a different approach. Editing my mainLoop I added this piece of code:

    function moveMask()
    
    local curPos = getCursorPos()
    
    Objects["mask_tastierino"].Offset = { x= curPos.x -200, y= curPos.y - 200 }
    
    end

    And it works fine, meaning the object "mask_tastierino" really follows the cursor and mask the object I need to mask. Problem is I get a strange result, because the masked object is shown even when the cursor is in different spots than the ones where the masked object should be shown. 
    Basically, if I move the cursor where the object should be shown, it works perfectly. BUT if I move the cursor away, there are spots where the object is shown as well, whereas it shouldn't because the masking object is far from it.

    Newbie

    62 Posts

  • #8, by afrlmeMonday, 06. May 2019, 11:58 5 years ago
    are you hiding the mask with a condition? also masks are kind of weird, you need to make sure that you add a bit of a transparent border around the edge of the mask & object image because sometimes it renders funny/incorrectly otherwise. Complicated shapes are usually fine, but simple shapes, like rectangles/squares seem to need a transparent border around them for some reason.

    Imperator

    7278 Posts

  • #9, by stered86Monday, 06. May 2019, 14:05 5 years ago
    Yes, I'm hiding the mask with a condition. 
    These are the images I'm using (they should be ok):


    And this is the weird effect I'm getting:

    Newbie

    62 Posts

  • #10, by afrlmeMonday, 06. May 2019, 15:21 5 years ago
    can you send me the ved & resources? or just the resources I need to check that scene/mask/masked object?

    Imperator

    7278 Posts

  • #11, by stered86Monday, 06. May 2019, 19:55 5 years ago
    Sure! I just sent you a private message!

    Newbie

    62 Posts