Porting 3D model in 2D schene

Vale-gitVale-git Posts: 60Member

Hi, it is possible to import a 3d model from blender in 2d scene in godot? -like unity for example -
If possible how to accomplish that?
If not, there is any plan to make it possible in future?

Thank you

Answers

  • TwistedTwiglegTwistedTwigleg Posts: 1,000Admin

    You could try something similar to the 3D in 2D github demo repository.

  • Vale-gitVale-git Posts: 60Member

    Thank you for your answer. But they are demo. What I asked an "how to" specific for import models/animation from blender in godot 2d.

  • TwistedTwiglegTwistedTwigleg Posts: 1,000Admin

    I’m confused. You’re wanting to import 3D models from blender for use in Godot in a 2D game?

    If so, there are really only two ways I can think of:

    • You a technique like in the Godot demo repository, where you render a scene in 3D and then use the rendered image as the texture for a sprite.
    • You render all of your animations in blender and export them as a sprite sheet, and then use the sprite sheet in Godot.

    There could be other ways. If you’re looking for a tutorial then someone like Tybobobo would probably know more about what you’re looking for (as he makes Godot tutorials).

    I may be misinterpreting what you’re asking though. Could you give an example of what you’re trying to accomplish?

  • Vale-gitVale-git Posts: 60Member

    In blender you can accomplish easily shadow, 3d looking. In Godot's 2d environment you have to design from scratch all these.
    That's my request: using blender to make any model, animation and use them in 2d environment "Like Unity already do".

    Or even better... make 3d model in Godot 3d -Like blender do - and use them in Godot 2d.. "Like Unity already do".

    I know that is a long shot. For now I'm satisfied to import 3d Models in Godot 2d.

    ps. what your suggest - render in blender and export as sprite - is something that I already knew.

  • TwistedTwiglegTwistedTwigleg Posts: 1,000Admin

    Ok, so I did some research into how unity handles 3D assets in 2D. Having looked around, I think I now can better answer your question (through explaining the difference Unity and Godot have in rendering styles, when it comes to 2D. It’s kinda long... Sorry):


    Both Unity and Godot use OpenGL (and DirectX for Unity on windows) for rendering both their 3D scenes and their 2D scenes. OpenGL is intended to be used with 3D graphics, and though it can do 2D graphics as well, it’s technically not truely 2D like in the game engines of old.

    In modern game engines 2D is actually still 3D, but rendered with an orthographic camera. This is so it looks flat, and if you’re only using 2D sprites, then you’d never know it’s actually quads (squares) hanging in 3D space under the hood.

    The problem with using a 3D engine for 2D graphics is how do you make it pixel perfect? (I’m assuming you know what ‘pixel perfect’ means). Another problem is physics for 2D, but I’ll leave that for another day (as it’s not in the question, and I’d have to brush up on how physic engines work :smile: )

    ------*

    Unity handles this by using a pixel ratio, so it can convert pixels to unity units. Unity then scales the quad by the amount of pixels times the ratio. Then it renders the whole thing in an orthographic camera. Unity doesn’t try to hide that it’s 2D engine is actually 3D, just rendered flat. Because Unity decided to keep it’s 3D engine and 2D engine together, you can place 3D objects around in a 2D scene, because the 2D scenes is actually a 3D scene. (If you push the little 2D button in the Unity editor so it’s not in 2D mode, you can look around at your 2D scene in 3D)

    ------*

    Godot handles the pixel perfect problem by separating the 3D engine from the 2D engine. While Unity uses a pixel to unit ratio, Godot uses one pixel per unit (assuming no scaling). Godot makes quads with the size of the sprite in pixels, and then applies whatever scaling afterwards (if it’s scaled, otherwise it just stays the same size)

    This keeps things pixel perfect and has additional benefits like optimization specifically for 2D. However, because the 2D render engine is kept separate from the 3D, you cannot just mix and match them like you do in Unity, because they’re technically entirely different systems as far as the game engine is concerned (despite them both using OpenGL). The only way to mix ‘true’ 3D with ‘true’ 2D in Godot is either to render your 3D scene to a 2D texture, or to write a 2D stack on top of the existing 3D stack in Godot (basically write a system to handle 2D like in Unity).

    ------*

    All of this is to say you cannot really merge 3D and 2D together in Godot like you do in Unity, because of the difference in how they’re set up. Having tried to make my own game engine a couple times, I can say that both of these game engines are very powerful and feature packed, but how they handle stuff under the hood varies massively, and this leads to some interesting comparisons and workflows.

    (Also, I just find this kinda thing interesting. I’ve always liked reading about how game engines work under the hood :sunglasses: )


    Summery/TLDR:
    The short answer is: No. you cannot use 3D game assets in Godot like you would in Unity, because of their differing ways of handling 2D rendering.

    All that said, if you’ve found a way to make your 3D assets work in Godot 2D, then great! But personally I’m not aware of any method outside of the ones I’ve previously mentioned, though I’m sure someone else probably knows better than me :smile:

  • Vale-gitVale-git Posts: 60Member

    Thank you for your answer and your explanation. I knew already almost 80% what you wrote here.
    However this is not important, how much I understood.
    What is important to me is: how to use Godot.

    In order to do that , myself - and almost everyone in this planet - need some documentation/examples. Because even if is true that some people enjoy to understand how a game engine work under the hood the mostly other people are interested to use this "tool" to express their "talents" to make games in the easiest possible way. Why? because the most expansive think in this planet is the time.

    About my main question: If there is not yet any tool to "convert" a 3d model in a 2d sprite mean this is something important tha is missed. Why is important? For the same reason why people doing 2d game and struggle to give them an 3d impact nerveless.

    Why people doing that? [making 2d games and build them in such a way they will have a resemblance of 3d ones].

    There are a lot of reasons. But they do. Mean any tool that can help them to accomplish will be welcomed.

    If we use Godot we have to do some steps. If we use Unity the steps we need to obtain same result are different. - eventually faster. I'm not sure. Simple because I don't know what is the best way. Also because, probably, we need some other tools to facilitate our job - like a converter between 3d to 2d - even with some costs.

    Thank you.

    ps.: honestly is not so important to me if we have a game engine that is more that 1 gb and it need to be installed. Right? Is not that people don't have 2-3 gb free in hd... I'm wrong? :)

  • TwistedTwiglegTwistedTwigleg Posts: 1,000Admin

    No problem, I totally agree. :smiley:

    PS: I think having a game that’s a few GB large is fine. AAA games are in the dozens of GB now, so I see no reason to worry about file size. (Just my opinion though)

  • Vale-gitVale-git Posts: 60Member

    @TwistedTwigleg said:
    No problem, I totally agree. :smiley:

    PS: I think having a game that’s a few GB large is fine. AAA games are in the dozens of GB now, so I see no reason to worry about file size. (Just my opinion though)

    I was talking godot not a game.

    include

    if (godot.exe.size() || ().size() >= 1gb_ {
    cout<<"its ok :)) ";
    }

  • SchusterSchuster Posts: 322Member
    edited December 2017

    ..... :D ...honestly is not so important to me if we have a game engine that is more that 1 gb and it need to be installed
    Why go on a trip by bulldozer when I can drive light clever car :D :p

  • Vale-gitVale-git Posts: 60Member

    @Bishop said:
    ..... :D ...honestly is not so important to me if we have a game engine that is more that 1 gb and it need to be installed
    Why not go on a trip by bulldozer when I can drive light clever car :D :p

    I see that you like dream. Come back in this reality when you wake up. You can make these comparison with the purpose to troll people.

    Godot is not a "light clever car" or even a "bulldozer". I saw a old lady drove a "light clever car"... BUT you can ask to any old lady make a game with Godot...

  • Vale-gitVale-git Posts: 60Member

    Anyway.. Merry Christmas to everybody. :D

  • SchusterSchuster Posts: 322Member
    edited December 2017

    Ok :) ....Merry Christmas and if you get a hammer as a present....i have an answer to your question.
    Take this hammer and beat some 3d model until is flat and that you're gonna get 2d ;) :D

  • Shin-NiLShin-NiL Posts: 158Moderator

    Please guys, lets keep the conversation on the topic, ok? Don't forget that this can be used as a source of knowledge by another person with the same doubt.

    Thanks and Merry Christmas :)

  • RedPoppyRedPoppy Posts: 1Member
    edited December 2018

    Guys, thanks for the question and answers. I, too, was faced with the needs to use 3D models in a 2D scene. (the hero crosses under a bridge in an isometric scene). Now I think how to do it with other methods, for example, use several layers of TileMap (floor, walls, roofs + bridges + other, which is "above" a floor :D )
    Thanks.

  • Richard KainRichard Kain Posts: 22Member

    Using 3D models in a 2D scene is difficult. 2D in Godot is handled using pixel graphics, and is specific to pixel proportions. 2D in Unity is essentially handled no differently than 3D, they simply provide you with some basic tools for handling 2D assets. But you can treat "2D" objects in Unity the same as 3D, and vice-versa. So the integration between the two in Unity is more seamless and interchangeable.

    In Godot, I believe there are two basic approaches you can go for.

    1. Have a 3D scene layered on top of your 2D scene, and use that 3D scene to render your 3D models. This could be a bit tricky, especially if you wanted your 2D objects to ever be layered over your 3D scene. There are possibilities for such an approach, but it wouldn't be my first choice.
    2. Have a separate camera pointed at your 3D object, and use that camera to render the 3D object to a texture, which you then use as the texture for a basic 2D sprite. The 3D object would not need to be rendered anywhere but to the texture, and you could control the rendering based on whatever frame-rate you desire. The one downside to this is that you would need to make certain the target texture was large enough to accommodate any permutations in the 3D model's animations. This is a decent approach for keeping the integration tight without abandoning most of the strengths of 3D modeling.
  • kryzmakkryzmak Posts: 78Member

    Just what comes to my mind, when reading the comments from @TwistedTwigleg and @Richard Kain is that, why not just using the 3D engine and 3D world but changing the "projection" property of the Camera node to orthogonal. Then you would only have to fixate the camera to some point. Wouldn't this have the same effect like the view in 2D Engine? The one thing that would be hard (or even impossible) to implement would be the world environment (background, sky) but maybe there is another "workaround" for that kind of questions.

  • TwistedTwiglegTwistedTwigleg Posts: 1,000Admin

    @kryzmak said:
    Just what comes to my mind, when reading the comments from @TwistedTwigleg and @Richard Kain is that, why not just using the 3D engine and 3D world but changing the "projection" property of the Camera node to orthogonal. Then you would only have to fixate the camera to some point. Wouldn't this have the same effect like the view in 2D Engine? The one thing that would be hard (or even impossible) to implement would be the world environment (background, sky) but maybe there is another "workaround" for that kind of questions.

    Technically, this is doable, but you're not really working in a 2D scene then, but rather a 3D scene rendered flat into a 2D one. This means that you cannot use 2D specific nodes (like Tilemap, Sprite, KinematicBody2D, etc) because although the 3D scene is rendered flat with a orthographic perspective, it still is a 3D scene.


    In Unity everything in 2D is actually 3D but rendered flat using a orthographic perspective. Unity renders sprites and stuff using quads (two triangles in a square/rectange) and uses the Z axis to simulate draw order. This allows you to use 3D assets easily in 2D, since all you have to do is move the object on the Z axis until it is positioned correctly in relation to your 2D assets. By making it this way, it also allowed Unity to (relatively) quickly add 2D functionality to what was otherwise a 3D focused game engine.

    In Godot, the 2D side of the engine is kept separate from the 3D side, and is rendering in "true" 2D*. Everything in Godot on the 2D side is just a quad (two triangles in a square/rectangle) with a texture, with some minor exceptions (like the Polygon2D node). Godot's 2D side uses a Z index property to determine what should be drawn first* and positions all of the quads on the same Z position, effectively making eliminating the Z axis.

    This makes it hard to use 3D models and objects, so the Godot team decided to keep the 2D side and the 3D side separate since 3D often exist beyond a single point in 3D space on the Z axis. This also allowed for some performance boosts that otherwise would have been hard if not impossible.

    NOTE (*) I have not checked the source code for Godot or Unity on how they handle 2D internally, so I cannot say for sure. I am just making some educated guesses based on what I know from using OpenGL, Unity, and Godot.


    One thing that I didn't know about before when I was replying earlier, is that there is some 3D nodes that act like 2D ones, specifically Sprite3D and the nodes that extend from it. On top of that, SpatialMaterials have an option to render like a billboard and always face the camera.

    Knowing this, so long as you didn't mind potentially making your own 2D specific nodes if the need arises (for example, making your own Tilemap3D node), then there is nothing technically stopping you from combining 2D and 3D using a orthographic perspective, Sprite3D nodes for your sprites, and 3D models. Technically this would be just doing exactly what Unity did to add 2D support, but you'd just have to write some of the nodes yourself as you need them. It would just be a lot more work.

    Anyway, hopefully this helps explain the differences with Godot and Unity in 2D! :smile:

Sign In or Register to comment.