Forums

3D object as an object in the UI
Last Post 05 Jan 2018 06:00 AM by Matt Wilson. 6 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Matt WilsonUser is Offline
New Member
New Member
Posts:12


--
31 Dec 2017 06:04 PM
    Hello,

    I'm trying to make a menu for my game that uses a 3D model instead of an image for a UI component. The main reason for doing this instead of an image is to utilize the idle animation on the character model that I have.

    I've been browsing the forums and documentation looking for a way to do this without much luck. I've seen some mention of RenderTarget, but I'm not sure if that is the right thing to pursue. Is it possible?

    Thanks,

    Matt
    Filip DušekUser is Offline
    Advanced Member
    Advanced Member
    Posts:695


    --
    01 Jan 2018 12:11 PM
    You can render anything to some RenderTarget (in MonoGame RenderTarget2D) and then create BitmapImage from that texture and use it for Image.Source.
    Something like this:

    
    renderTarget = new RenderTarget2D(GraphicsDevice,
                    100,
                    100,
                    false,
                    GraphicsDevice.PresentationParameters.BackBufferFormat,
                    DepthFormat.Depth24Stencil8);
    
                testImage = new BitmapImage();
                var texture = Engine.Instance.Renderer.CreateTexture(renderTarget);
                testImage.Texture = texture;
    
                uiRoot.Image.Source = testImage;
    
    
    Matt WilsonUser is Offline
    New Member
    New Member
    Posts:12


    --
    01 Jan 2018 07:38 PM
    Is this a fast enough operation to do every frame?

    Edit: Happy new year!
    Filip DušekUser is Offline
    Advanced Member
    Advanced Member
    Posts:695


    --
    01 Jan 2018 07:56 PM
    Performance is more about what are you going to render to that texture, not about how you use it in UI. Just don't change the size of that texture, so UI does not have to recompute on each frame.
    Matt WilsonUser is Offline
    New Member
    New Member
    Posts:12


    --
    01 Jan 2018 10:20 PM
    So I read through your BasicUI samples, and if I am understanding correctly, the process is as follows;

    You make a render target, assign it to the graphics device, draw whatever you want, convert that render target to a bitmap. Then you assign that bitmap to your view model. At some point you have to set the graphics device render target back to null.

    Does that look right?
    Filip DušekUser is Offline
    Advanced Member
    Advanced Member
    Posts:695


    --
    02 Jan 2018 05:26 PM
    yes
    Matt WilsonUser is Offline
    New Member
    New Member
    Posts:12


    --
    05 Jan 2018 06:00 AM
    All right, i got it working! This is a pretty powerful feature, its really cool to see it in action.

    Thanks for your help again!

    Matt
    You are not authorized to post a reply.