MV3D - 3D rendering for RMMV with Babylon.js

● ARCHIVED · READ-ONLY
Started by Cutievirus 1560 posts Page 18 of 78 View original ↗
  1. @safermike really? that was the simplest thing in this, my main problem was the whole "recognizing height differences" thing that was kicking my ass. I mean, I made it work in 4 directions properly already, but on diagonals...

    Ok, to use my version of the code you'll need these functions, that are already on my mv3d-QSprite compatibility plugin by the way, they are one to turn the directions depending on the camera angle, the main one you'll use, but also two that first one uses, one get the direction and turn it into angles, then one to get an angle and turn into direction:
    JavaScript:
    mv3d.transform8DirectionYaw=function(dir,yaw=this.blendCameraYaw.currentValue(),reverse=false){
        if(dir==0){ return 0; }
        dir = this.numpadToAngle(dir);
        const c = yaw;
        if(reverse){
            dir=(dir-c).mod(360);
        }else{
            dir=(dir+c).mod(360);
        }
        return this.angleToNumpad(dir);
    }
    
    mv3d.numpadToAngle=function(numpad){
        var angle = 0;
        switch (numpad) {
            case 7: angle++;
            case 4: angle++;
            case 1: angle++;
            case 2: angle++;
            case 3: angle++;
            case 6: angle++;
            case 9: angle++;
            default: break;
        }
        return angle*45;
    }
    mv3d.angleToNumpad=function(angle){
        var numpad = 8;
        angle = Math.round(angle/45);
        switch (angle) {
            case 1:
                numpad = 9;
                break;
            case 2:
                numpad = 6;
                break;
            case 3:
                numpad = 3;
                break;
            case 4:
                numpad = 2;
                break;
            case 5:
                numpad = 1;
                break;
            case 6:
                numpad = 4;
                break;
            case 7:
                numpad = 7;
                break;
            default: break;
        }
        return numpad;
    }
    I know, the second and last ones may be overly-complicated... they work fine though.

    These ones are to actually change the controls on QMovement, they overwrite the old ones it uses for that:
    JavaScript:
    Game_Player.prototype.moveInputHorizontal = function(dir) {
      if (mv3d.isDisabled()) this.moveStraight(dir);
      else {
        if (QMovement.diagonal) {
          dir = mv3d.transform8DirectionYaw(dir,mv3d.blendCameraYaw.currentValue(),true);
          if ([1, 3, 7, 9].contains(dir)) {
            var diag = {
              1: [4, 2], 3: [6, 2],
              7: [4, 8], 9: [6, 8]
            }
            this.moveDiagonally(diag[dir][0], diag[dir][1]);
          } else this.moveStraight(dir);
        } else {
          this.moveStraight(mv3d.transformDirectionYaw(dir,mv3d.blendCameraYaw.currentValue(),true));
        }
      }
    };
        
    Game_Player.prototype.moveInputVertical = function(dir) {
      if (mv3d.isDisabled()) this.moveStraight(dir);
      else {
        if (QMovement.diagonal) {
          dir = mv3d.transform8DirectionYaw(dir,mv3d.blendCameraYaw.currentValue(),true);
          if ([1, 3, 7, 9].contains(dir)) {
            var diag = {
              1: [4, 2], 3: [6, 2],
              7: [4, 8], 9: [6, 8]
            }
            this.moveDiagonally(diag[dir][0], diag[dir][1]);
          } else this.moveStraight(dir);
        } else {
          this.moveStraight(mv3d.transformDirectionYaw(dir,mv3d.blendCameraYaw.currentValue(),true));
        }
      }
    };
      
    Game_Player.prototype.moveInputDiagonal = function(dir) {
      var diag = {
        1: [4, 2], 3: [6, 2],
        7: [4, 8], 9: [6, 8]
      }
      if (mv3d.isDisabled()) this.moveDiagonally(diag[dir][0], diag[dir][1]);
      else {
        dir = mv3d.transform8DirectionYaw(dir,mv3d.blendCameraYaw.currentValue(),true);
        if ([1, 3, 7, 9].contains(dir)) this.moveDiagonally(diag[dir][0], diag[dir][1]);
        else this.moveStraight(dir);
      }
    };
    
    Game_Player.prototype.moveWithAnalog = function() {
      var horz = Input._dirAxesA.x;
      var vert = Input._dirAxesA.y;
      if (horz === 0 && vert === 0) return;
      var radian = Math.atan2(vert, horz);
      radian += radian < 0 ? Math.PI * 2 : 0;
      if (!mv3d.isDisabled()) radian = (radian + (mv3d.blendCameraYaw.currentValue()*Math.PI/180)).mod(Math.PI*2);
      this.moveRadian(radian);
    };

    If that is really all you want, this is really all you need. save it as a name.js file and put it under both plugins on the plugin manager.
  2. @palatkorn I think you're asking how to know the camera's current rotation? This script will get that value for you.
    mv3d.blendCameraYaw.currentValue()
    And if you want the value normalized between 0 and 360
    mv3d.blendCameraYaw.currentValue().mod(360)
    Then you can run a conditional branch based on that value if you need to.

    @Parallax Panda
    To enter 1st person mode you just need to set the camera distance to zero with a plugin command.
    mv3d camera dist 0 1
    The zero is the value we're setting the distance to, and the one is the number of seconds for the transition.

    I'm not really good at writing an easy to understand help file, but it does still need work. Next time I rework the help file I also want to add some examples for script calls.
  3. Yes, I like you. Now I can set directions. It's great.


    Dread_Nyanak said:
    @palatkorn I think you're asking how to know the camera's current rotation? This script will get that value for you.
    mv3d.blendCameraYaw.currentValue()
    And if you want the value normalized between 0 and 360
    mv3d.blendCameraYaw.currentValue().mod(360)
    Then you can run a conditional branch based on that value if you need to.

    @Parallax Panda
    To enter 1st person mode you just need to set the camera distance to zero with a plugin command.
    mv3d camera dist 0 1
    The zero is the value we're setting the distance to, and the one is the number of seconds for the transition.

    I'm not really good at writing an easy to understand help file, but it does still need work. Next time I rework the help file I also want to add some examples for script calls.
  4. Waterguy said:
    That doesn't seem to be minimap, but "mipmap". notice a p instead of a ni. I...have no idea what that means, really.
    Mipmaps are smaller versions of textures that can be automatically generated. Basically, the farther the camera gets from something, the lower resolution a texture will become, and anything below the original resolution of the texture is called a mipmap.

    I don't know how it relates to this plugin because I haven't really used it yet, but I saw the opportunity to answer a question and I took it!
  5. Prescott said:
    Mipmaps are smaller versions of textures that can be automatically generated. Basically, the farther the camera gets from something, the lower resolution a texture will become, and anything below the original resolution of the texture is called a mipmap.

    I don't know how it relates to this plugin because I haven't really used it yet, but I saw the opportunity to answer a question and I took it!
    I see!
    This is a plugin to kinda turn mv 3d, thus the name mv3d, so I can see how things too far away would become smaller than the original size and thus would use a mipmap as you said...
    ...but now I am curious on what would happen if I turn it off...
  6. @Waterguy & @Dread_Nyanak
    Thanks for that explanation. Some stuff like "camera pitch" I didn't know about, some of the terms explained in more layman's terms might've been a good thing to add to the help file eventually.

    Also, thanks for explaining the whole 1st person camera angle for me. Is it possible to (in 1st person view) have the camera look slightly up or down? Like for example. You walk onto a tile and some story aspect triggers an auto event that makes you look up at something while some text is displayed. Then you look back down again. Is all I have to do to change the camera pitch temporary maybe?

    @Prescott
    I knew it must have had some other meaning. Although I had no idea what. I imagine that more than a few people will be confused by that plugin parameter though. It probably should have some clarifying description inside.
  7. I think you're referring to the zoom this character of one event, which I use this simple technique to handle.

    Set up the camera and then move yourself to the event spot. Back to the original

    When returning, you should set the camera again so that it doesn't Looking too close


    RdoPan.png

    Parallax Panda said:
    @Waterguy & @Dread_Nyanak
    Thanks for that explanation. Some stuff like "camera pitch" I didn't know about, some of the terms explained in more layman's terms might've been a good thing to add to the help file eventually.

    Also, thanks for explaining the whole 1st person camera angle for me. Is it possible to (in 1st person view) have the camera look slightly up or down? Like for example. You walk onto a tile and some story aspect triggers an auto event that makes you look up at something while some text is displayed. Then you look back down again. Is all I have to do to change the camera pitch temporary maybe?

    @Prescott
    I knew it must have had some other meaning. Although I had no idea what. I imagine that more than a few people will be confused by that plugin parameter though. It probably should have some clarifying description inside.
  8. Another basic thing about this plugin that I'd like to understand is how to properly set up the tileset. I understand that you have to put these tags in the notebox end place all plugin relevant information inside;

    <mv3d>

    </mv3d>

    But I'm not entirely sure how to write the content that's supposed to go inside. Can someone explain it to me using this example screenshot here? Let's say I want to properly set up this green "mesh" like alien auto-tile to work in a 1st person perspective dungeon. I'd want the wall parts to be the wall and the top part to be the top (and I guess, bottom). How would I need to write that?
    I get that I probably need to put down the x and y but is it the x and y inside the "select an image" window that I opened in the screenshot or is it the x and y in the database where each auto-tile is presented as just 1 tile? I'm a bit confused.
    VAvPaBo.png
    Bonus questions: I'd also like to understand how to set up slopes and water.

    Thanks to anyone who can explain it to me. :kaohi:

    @palatkorn
    I'm not sure if that's what I meant, because I'm not really looking to zoom in or out of anything. More the "effect" of the invisible 1st person hero(s) looking slightly up (at the roof) or down (at the floor). But maybe you're right and it's exactly what I'm asking for. I'd have to test it out to know for sure, but it's pretty late so I can't do it today. I will though (tomorrow, I hope).

    I do appreciate the help a lot.
  9. Parallax Panda said:
    Also, thanks for explaining the whole 1st person camera angle for me. Is it possible to (in 1st person view) have the camera look slightly up or down? Like for example. You walk onto a tile and some story aspect triggers an auto event that makes you look up at something while some text is displayed. Then you look back down again. Is all I have to do to change the camera pitch temporary maybe?
    Yup, just change the pitch to look up and then set it back down later.

    And about the tileset... ok, it is a bit confusing...
    first, you put the tileset you want to change, through the x and y as in the tileset screen. Your example is on A4, and on the editor is on the fifth column of the A4 image's tiles... well, it starts from 0 so it is 4, and... there are two different tiles there, the ceiling and the wall, by default the ceiling has the wall as its side and will rise the already-set "wall" height, but you can set it as a different one, and the wall has itself as the ceiling too. The ceiling is in the fifth row and the wall is on the sixth, so numbers 4 and 5.
    So to set them you'll set "A4,4,4" and "A4,4,5". For an example, I'll explain about A4,4,4 for not.
    So, they can be separated as top, the piece on top, side, the piece on walls and the like, bottom, for when it is floating and the like so it can be sen from bellow, and inside, for when it has a depth. As a depth, something on height 1 would count as something a bit lower and the sides of the border would show the inside tile instead - in the demo, you have it set for water and for the black pit tile.
    to set a tile for either position you can have two options: you can use the same way you set the tile you are setting, in this example A4,4,4 for the top, or you can go to the image itself and get a piece of it using the image positions, it would then be image,starting x, starting y, width to take and height to take. For example, in the demo water is set on the top as top(A1,24,72,48,48), meaning on the A1 image that water takes a piece on the image on pixels 24,72 and the image is 48x48. It is confusing for now, but gets easier with some experimenting. For now, let's use the whole tile as top, and the wall as side, meaning we have "A4,4,4:top(A4,4,4),side(A4,4,5)"

    Now, for slopes... I only know you set that tile, or region, to have "slope(1)". No idea why the 1 is needed, or what happens if you use a different number. @Dread_Nyanak I admit I wanted to ask about this earlier but forgot... are slopes limited to that number as tiles of height or something?
    Same for animation, really. I mean we have it automatic on the A1 tiles, water has it set as 1,0 and waterfalls as 0,1 if I remember right, an 1 on the first means threetiles of animation horizontally like typical water and 1 in the second means three tiles vertically like waterfall, and in the demo thereis a tile set with both just to show what happens when both are used. Does it also has to be only either 0 or 1 there?
  10. @Waterguy the extra number on slope(1) let you chose the degrees on the slope, if you use slope(1) would be 45 degrees, with slope(0.5) are 22.5 degrees , the height would let you chose the z position while the slope(#) let you chose the slopes degrees on that 48x48 square

    @Dread_Nyanak i been using the slopes a lot, but been thinking would be better to add a parameter to force the direction on a slope, i know you can chose it with the pasability direction, but when you wanna do a 2 tiles thick stairs, starts to work...kinda funny...depending on what kind of blocks are around, would be good to add an extra configuration, kinda like slope( 1, left) just in case you really want to put the stair in one direction but dont change the pasability direction on the tile ^^
  11. What an impressive Plugin, congratulation.
    I spent some time testing some stuff and here are some observations:

    *When exporting your demo on an FTP to try it on iPhone’s Safari browser, all GFX in events glitch (even the MC), we see more than one sprite/frame at once.

    *The “destination cursor” is missing.

    *The 3D is turned ON by default on every maps of a game, I think many user would prefer to turn it ON only on selected maps, like if you only have a 3D worldmap in the entire game for example, wouldn’t be convenient to turn the plugin OFF on hundreds of regular maps.

    The other way around might be better: OFF by default and having to turn it ON with a map-note.
    (Or maybe a plugin “main parameter” to select the default OFF/ON.)

    So far so good when it comes to performances, this is a nice surprise. Keep up the good work and Happy New Year!
  12. @Waterguy
    The number in slope(1) is the slope height. Higher than 1 makes it steeper, smaller than 1 makes it shallower.
    For animations, the number is the spacing for each frame. Using 2 will make each frame 2 tiles apart instead of 1. The default animated tiles have an animx of 2 for regular water tiles and animy of 1 for waterfall tiles.

    @k333
    More control over slope direction coming in next update.

    @KaYsEr
    Having an option for disabled by default would make it easier to add to existing projects. I think I might add that as an option.
  13. Is there a way to make the alpha ignore the parallax? On maps without it, it works on walls perfectly and stuff without anything behind it is rendered without alpha, but on maps with a parallax every single wall is hollow.
  14. I... see...
    well, not yet, but with some testing I may get it. Like, does putting 1 on the slope in a region means a slope from the water to the water would go up above the earth then? I plan for a map in a slightly flooded dungeon where you walk through some shallow water, that means I'd have to put the slope on the proper number as the region difference?

    On, and @k333 she mentioned earlier she was thinking on using the shadow pen to set directions since the original use does nothing anymore.

    @glaphen you mean that when you are on the side of the wall and the camera is inside it?
  15. Amazing! I'll definitely make use of this once I become more familiar with RPG Maker.
  16. Waterguy said:
    @glaphen you mean that when you are on the side of the wall and the camera is inside it?

    Ok maybe I wasn't paying attention enough, alpha is always on, just hard to tell with on certain tiles with certain back colors. Is there any way to turn off alpha for only bottom side of tiles, I tried setting everything individually in many ways but no matter what you can always see through the bottom tile.
  17. @glaphen uh, I honestly have no idea...
    did you set a bottom and/or inside to the tile? maybe that is what you need?
  18. Waterguy said:
    @glaphen uh, I honestly have no idea...
    did you set a bottom and/or inside to the tile? maybe that is what you need?

    Yeah I tried everything, but further testing seems like it makes everything alpha from the view of the side that is set to alpha, so if you set top, it will make everything viewed from top hollow even the parts not set as alpha. I sorta figured out how to make specific parts visible by making it only top, bottom doesn't matter and then making 2 separate roof tiles in B~D and setting it to star passibility, setting it to to fringe(0) or -2 for visible wall putting the tile on top of the original wall.

    Also setting the alpha with region commands works with alpha(x) when I need a side part as well on a specific wall see through when already set in tiles, but I don't see how to turn it off with regions unfortunately. I suppose not using it in the tileset and only using regions seems to work if I don't need regions for other things in that map at those spots.

    Ok I managed to solve all the problems I could see with that one map so here is how I did it if anyone else wants transparent walls, I'm using 45 pitch and no player controlled camera. Make a region in plugin settings with alpha(x). I use .92 since anything higher doesn't seem to work right and seems just turn it into bush vision or something. You need a tile in the tileset that is a copy of top of the wall top without autotile, or whatever you want the floor to be and make that tile a character as well if using near map edge. Use region on walls you want to see through and put the tile on top of it with C,2,0:fringe(-2) in tileset config for example on it so you don't see the parallax/fog, turn on star pass for it. Then use character event for any walls on the side that show a gap from map edge with notetag,
    <mv3d:z(0),x(+0.49),scale(gap,size),rot(90),shape(fence),shadow(0)>, place event at edge wherever you want to fit it, might need to edit x or rot if on right side of map as that is for left. If you want to use it with player controlled camera you probably need to fence off the back view with same method.
  19. oh, I think I get it, you want to be able to make the sides/top visible or transparent at will mid-game?
  20. Waterguy said:
    oh, I think I get it, you want to be able to make the sides/top visible or transparent at will mid-game?

    Not really, just wanted to not see parallax or fog through the transparent walls.