Author Topic: Putting a 3D object in a panel  (Read 23993 times)

Darkness

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 90
    • View Profile
Putting a 3D object in a panel
« on: January 15, 2014, 03:37:29 AM »
I'm getting into adding my character's model into a window so that the player can see what she looks like in gear.  Much like how it's done in WoW.  How is this done?  I tried looking it up, but I'm not sure what it's called.  My UI is 2D at the moment, but I figure there should be a way to add a 3D object to a window.

Any assistance would be greatly appreciated.

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Re: Putting a 3D object in a panel
« Reply #1 on: January 15, 2014, 05:07:16 AM »
NGUI is just using Unity game objects, so you may be able to do that. Try adding Unity mesh and render components to the NGUI element you want to contain the object (you can use an empty widget). Or write a simple bit of code to position the 3D object at the 2D component's location.

kitgui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: Putting a 3D object in a panel
« Reply #2 on: January 15, 2014, 03:59:32 PM »
Yeah just position the 3D model between your 2D panel and the camera

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Putting a 3D object in a panel
« Reply #3 on: January 15, 2014, 09:21:28 PM »
I would set up an off-screen camera rendering to a render texture, and would then draw this render texture using UITexture as any other NGUI widget.

Darkness

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 90
    • View Profile
Re: Putting a 3D object in a panel
« Reply #4 on: January 16, 2014, 03:14:26 AM »
*EDIT:*

Alright, I got the render to texture to work.  However, what do I need to do with materials and shaders?  I tried to change the unlit/transparent color shader that was attached, because my model is transparent and doesn't show up correctly.  What is the point of the material?  Does changing this require a material?  I won't play with it until anymore until I find out more.  Messing around with UITexture keeps messing things up, so I need to know more about it.

Either way, works great as far as getting the image in the right spot and all that.  Took all of 10 minutes.  Gotta love that.  :)
« Last Edit: January 16, 2014, 04:36:50 AM by Darkness »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Putting a 3D object in a panel
« Reply #5 on: January 17, 2014, 12:08:20 AM »
Setting a material instead of a shader just gives you more flexibility, in case there is more than one texture that needs to be used (like a bump map for example).

Darkness

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 90
    • View Profile
Re: Putting a 3D object in a panel
« Reply #6 on: January 17, 2014, 02:41:47 AM »
Setting a material instead of a shader just gives you more flexibility, in case there is more than one texture that needs to be used (like a bump map for example).

I figured as much.  However, it keeps giving me an error.  It won't allow for any shader to be added.  Only the unlit ones that you include work.  Even with my own material.  My character needs to be lit at all times and there aren't any shaders that work and they have to have Softclip as well.  Any idea how I can fix this?  My character is simply transparent and I can't do anything about it.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Putting a 3D object in a panel
« Reply #7 on: January 17, 2014, 11:14:57 PM »
Which shader are you referring to? Unity can't render things to a render texture properly that use textures with alpha in them. It's a well known issue with Unity that was never fixed. Even if you're using a solid shader, if the texture happens to have an alpha channel, and if the channel is not used, it still writes the alpha to the render texture, thus messing everything up.

Darkness

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 90
    • View Profile
Re: Putting a 3D object in a panel
« Reply #8 on: January 18, 2014, 02:34:13 AM »
Which shader are you referring to? Unity can't render things to a render texture properly that use textures with alpha in them. It's a well known issue with Unity that was never fixed. Even if you're using a solid shader, if the texture happens to have an alpha channel, and if the channel is not used, it still writes the alpha to the render texture, thus messing everything up.

The shader that comes with NGUI.  It's called Unlit/Premultiplied Colored (Softclip).  This is the closest I can get having a rendered texture that is not transparent.  I've tried other shaders and they just make everything look strange.  Either way, when I try any other shaders it gives an error and says "softclip must be enabled" or something like that.  Not sure how to fix it and if it's an NGUI problem or not.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Putting a 3D object in a panel
« Reply #9 on: January 18, 2014, 02:35:50 AM »
"Unlit/Premultiplied Colored (Soft Clip)" shader is meant for clipped panels. You shouldn't be choosing it yourself. NGUI automatically chooses it when needed. "Unlit/Premultiplied Colored" shader should be used instead.

Darkness

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 90
    • View Profile
Re: Putting a 3D object in a panel
« Reply #10 on: January 18, 2014, 03:41:10 AM »
"Unlit/Premultiplied Colored (Soft Clip)" shader is meant for clipped panels. You shouldn't be choosing it yourself. NGUI automatically chooses it when needed. "Unlit/Premultiplied Colored" shader should be used instead.

That's the thing, though.  The others give an error when used.  Not sure why, but they do.  So I can't even choose many shaders that actually work.  The error says it must use Softclip.  Is that something to do with the way NGUI handles these things?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Putting a 3D object in a panel
« Reply #11 on: January 18, 2014, 09:52:33 PM »
If you get an error then you likely moved the shaders from their default location inside the Resources folder. NGUI can't load shaders that aren't in the Resources folder.

Darkness

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 90
    • View Profile
Re: Putting a 3D object in a panel
« Reply #12 on: January 30, 2014, 10:25:54 AM »
If you get an error then you likely moved the shaders from their default location inside the Resources folder. NGUI can't load shaders that aren't in the Resources folder.

Hey, AM.  I haven't been able to tackle this issue until today, but I looked at the location of those shaders and they're in the correct folder.  I even deleted the NGUI directory and imported it again and got the same problem.  I used all of the shaders in the folder and only the transparent ones work, even though all of them are in the folder.  The error isn't fixed.  Here it is again.

Unlit/Texture doesn't have a clipped shader version for SoftClip
UnityEngine.Debug:LogError(Object)
UIDrawCall:CreateMaterial() (at Assets/NGUI/Scripts/Internal/UIDrawCall.cs:310)
UIDrawCall:RebuildMaterial() (at Assets/NGUI/Scripts/Internal/UIDrawCall.cs:325)
UIDrawCall:UpdateMaterials() (at Assets/NGUI/Scripts/Internal/UIDrawCall.cs:347)
UIDrawCall:Set(BetterList`1, BetterList`1, BetterList`1, BetterList`1, BetterList`1) (at Assets/NGUI/Scripts/Internal/UIDrawCall.cs:482)
UIPanel:SubmitDrawCall(UIDrawCall) (at Assets/NGUI/Scripts/UI/UIPanel.cs:1056)
UIPanel:FillAllDrawCalls() (at Assets/NGUI/Scripts/UI/UIPanel.cs:1013)
UIPanel:UpdateSelf() (at Assets/NGUI/Scripts/UI/UIPanel.cs:953)
UIPanel:LateUpdate() (at Assets/NGUI/Scripts/UI/UIPanel.cs:907)

I just want to get a shader that works which isn't transparent. 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Putting a 3D object in a panel
« Reply #13 on: January 30, 2014, 12:05:53 PM »
Unlit/Texture? That shader shouldn't be used. It doesn't have a version of it that supports clipping.

Change it to be Unlit/Transparent Colored.

Darkness

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 90
    • View Profile
Re: Putting a 3D object in a panel
« Reply #14 on: January 30, 2014, 06:33:32 PM »
Unlit/Texture? That shader shouldn't be used. It doesn't have a version of it that supports clipping.

Change it to be Unlit/Transparent Colored.

That shader makes it so that the character can barely be seen.  Either the character is transparent, or barely visable.  None of which looks right.  So I guess my question now is what can I do to get the character to show up in the window and look normal?  Transparent looks wrong because the characters is...well, transparent.  I need solid and lit up so the player can see it properly.