Thread Tools Display Modes
05-27-11, 01:34 AM   #1
leizeQ
A Murloc Raider
 
leizeQ's Avatar
AddOn Compiler - Click to view compilations
Join Date: Jun 2008
Posts: 8
Portrait:SetModelScale(number)

Hi.

I am trying to change the model scale of the player portrait.
i've tried to use the Portrait:PostUpdate() function but without success.

Code:
self.Portrait.PostUpdate = function(self, unit) self:SetModelScale(0.5) end
is it overwritten somewhere else?, is the SetModelScale not the right function to use? or am I missing some other stuff.

thanks.

edit: already answered, please disregard. i can post the solution if anyone has interest

Last edited by leizeQ : 05-27-11 at 01:43 AM.
  Reply With Quote
05-27-11, 07:50 AM   #2
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
Originally Posted by leizeQ View Post
edit: already answered, please disregard. i can post the solution if anyone has interest
Posting the solution is always a good idea. It potentially prevents the same question in the future and allows potentially better solutions to be posted.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
05-28-11, 04:46 AM   #3
leizeQ
A Murloc Raider
 
leizeQ's Avatar
AddOn Compiler - Click to view compilations
Join Date: Jun 2008
Posts: 8
Talking

so my intention was to use a portrait for the player without any border or background and placed on the bottom of the screen. but it was zoomed in too much so it was visible where are the borders of portrait frame.

so here are 2 solutions i've found/been told:

1. use Model:SetCamera(1) - this changes the whole portrait to something similar as in character screen (whole body seen), and it should be zoom-able

2. use PlayerModel:SetPortraitZoom(number)
  Reply With Quote
06-11-11, 07:56 AM   #4
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Regarding models. It got me thinking because I refreshed my model viewer today.



To get the camera zoom to the face of a model you have to use

Code:
SetPortraitZoom = 1
To zoom out but stay focus on the face area you can then use

Code:
SetCamDistanceScale = x
The other important values are SetPosition and SetRotation. Both are pretty obvious.

I still have the worgen male problem. Gonna try sth.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
06-11-11, 08:00 AM   #5
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
*edit*

IT WORKED...lol on first try.

@haste the "SetCamera 0" settings seems to be deprecated. Try this:

I changed the portrait.lua and male worgen portraits are now fixed.

Seems like: SetPortraitZoom is the new SetCamera.

lua Code:
  1. local Update = function(self, event, unit)
  2.     if(not unit or not UnitIsUnit(self.unit, unit)) then return end
  3.  
  4.     local portrait = self.Portrait
  5.     if(portrait.PreUpdate) then portrait:PreUpdate(unit) end
  6.  
  7.     if(portrait:IsObjectType'Model') then
  8.         local guid = UnitGUID(unit)
  9.         if(not UnitExists(unit) or not UnitIsConnected(unit) or not UnitIsVisible(unit)) then
  10.             portrait:SetModelScale(4.25)
  11.             portrait:SetPosition(0, 0, -1.5)
  12.             portrait:SetModel"Interface\\Buttons\\talktomequestionmark.mdx"
  13.         elseif(portrait.guid ~= guid or event == 'UNIT_MODEL_CHANGED') then
  14.             portrait:SetUnit(unit)
  15.             --portrait:SetCamera(0)
  16.             portrait:SetPortraitZoom(1)
  17.             portrait.guid = guid
  18.         else
  19.             --portrait:SetCamera(0)
  20.             portrait:SetPortraitZoom(1)
  21.         end
  22.     else
  23.         SetPortraitTexture(portrait, unit)
  24.     end
  25.  
  26.     if(portrait.PostUpdate) then
  27.         return portrait:PostUpdate(unit)
  28.     end
  29. end

First worgen male portrait working correctly
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 06-11-11 at 08:08 AM.
  Reply With Quote
06-11-11, 09:09 AM   #6
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
Delete your post, ASAP! Otherwise, I predict even more of those hairy beasts flooding the game, soon! NOooooO!
__________________
Rock: "We're sub-standard DPS. Nerf Paper, Scissors are fine."
Paper: "OMG, WTF, Scissors!"
Scissors: "Rock is OP and Paper are QQers. We need PvP buffs."

"neeh the game wont be remembered as the game who made blizz the most money, it will be remembered as the game who had the most QQ'ers that just couldnt quit the game for some reason..."

  Reply With Quote
06-11-11, 10:11 AM   #7
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Not need for so much code! this works perfect.

LUA Code:
  1. local function WorgenFix(self, unit)
  2.     if self:GetModel() and self:GetModel().find and self:GetModel():find("worgenmale") then
  3.         self:SetCamera(1)
  4.     end
  5. end

And add to your portraits.

LUA Code:
  1. Portrait.PostUpdate = WorgenFix
  Reply With Quote
06-11-11, 10:47 AM   #8
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
@Game
Sorry but my post is a bugfix for the oUF/elements/portrait.lua that haste is hopefully going to implement. I have no Github account otherwise I would post it there. Maybe someone else can.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
06-11-11, 05:48 PM   #9
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Originally Posted by zork View Post
@Game
Sorry but my post is a bugfix for the oUF/elements/portrait.lua that haste is hopefully going to implement. I have no Github account otherwise I would post it there. Maybe someone else can.
Oh, i through it was an OnUpdate one :P
  Reply With Quote
06-12-11, 11:44 AM   #10
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
zork, are you able to post your changes as a git format-patch (or diff)? That would allow me to commit the changes in your name. If it's too much hassle, let me know and I'll merge the changes in manually.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
06-12-11, 12:33 PM   #11
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
I registered and tried to pull a change request. No sure if I made that correct.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
06-12-11, 12:35 PM   #12
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Originally Posted by zork View Post
I registered and tried to pull a change request. No sure if I made that correct.
I did it for you :3

@ Haste did a pull request.
  Reply With Quote
06-12-11, 12:41 PM   #13
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Thank you.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
06-12-11, 01:03 PM   #14
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
You both did it actually. With one minute between :P. The change is "merged" onto the API-6 branch now.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
06-14-11, 01:51 PM   #15
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
I spent some time now testing. Doing dungeon in the dungeonfinder. I have to push another fix my first post was OK, but incomplete. Swapping between questionmark and model bugs so I had to fix it.

This works for me currently in any situation (going from mark to model or from model to mark or model to model)

lua Code:
  1. local Update = function(self, event, unit)
  2.     if(not unit or not UnitIsUnit(self.unit, unit)) then return end
  3.  
  4.     local portrait = self.Portrait
  5.     if(portrait.PreUpdate) then portrait:PreUpdate(unit) end
  6.  
  7.     if(portrait:IsObjectType'Model') then
  8.         local guid = UnitGUID(unit)
  9.         if(not UnitExists(unit) or not UnitIsConnected(unit) or not UnitIsVisible(unit)) then
  10.             portrait:ClearModel()
  11.             portrait:SetModel('interface\\buttons\\talktomequestionmark.m2')
  12.             portrait:SetCamDistanceScale(0.25)
  13.             portrait:SetPortraitZoom(0)
  14.             portrait:SetPosition(0,0,0.5)          
  15.             portrait.guid = nil
  16.         elseif(portrait.guid ~= guid or event == 'UNIT_MODEL_CHANGED') then
  17.             portrait:ClearModel()
  18.             portrait:SetUnit(unit)
  19.             portrait:SetCamDistanceScale(1)
  20.             portrait:SetPortraitZoom(1)
  21.             portrait:SetPosition(0,0,0)
  22.             portrait.guid = guid
  23.         end
  24.     else
  25.         SetPortraitTexture(portrait, unit)
  26.     end

The else condition can be removed entirely.
What was important is to reset the GUID on questionmark (because it would not change back if you had the GUI, got mark later. It would stuck in mark)
To make the model values apply the model must be cleared. Doesn't work otherwise.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 06-14-11 at 01:53 PM.
  Reply With Quote
06-17-11, 08:04 AM   #16
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
To bad so many of the model api functions are not documented.

But there is a function that sounds interesting.

# PlayerModel:RefreshCamera() - This function is not yet documented
# PlayerModel:RefreshUnit() - Updates the model's appearance to match that of its unit. Used in the default UI's inspect window when the player's target changes (changing the model to match the "new appearance" of the unit "target") or when the UNIT_MODEL_CHANGED event fires for the inspected unit (updating the model's appearance to reflect changes in the unit's equipment or shapeshift form).

More:
http://wowprogramming.com/docs/widgets/PlayerModel
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
10-17-11, 02:51 PM   #17
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
I revised my code and found the final bug.

Reseting the camdistancescale vales etc is needed before reseting the model otherwise it will not reload properly if you change from a gnome to a dwarf etc.

I originally thought that clearing the model would wipe the model attributes but that is not the case. The attributes have to be set before the model rendering.

lua Code:
  1. local Update = function(self, event, unit)
  2.     if(not unit or not UnitIsUnit(self.unit, unit)) then return end
  3.  
  4.     local portrait = self.Portrait
  5.     if(portrait.PreUpdate) then portrait:PreUpdate(unit) end
  6.  
  7.     if(portrait:IsObjectType'Model') then
  8.         local guid = UnitGUID(unit)
  9.         if(not UnitExists(unit) or not UnitIsConnected(unit) or not UnitIsVisible(unit)) then
  10.             portrait:SetCamDistanceScale(0.25)
  11.             portrait:SetPortraitZoom(0)
  12.             portrait:SetPosition(0,0,0.5)
  13.             portrait:ClearModel()
  14.             portrait:SetModel('interface\\buttons\\talktomequestionmark.m2')
  15.             portrait.guid = nil
  16.         elseif(portrait.guid ~= guid or event == 'UNIT_MODEL_CHANGED') then
  17.             portrait:SetCamDistanceScale(1)
  18.             portrait:SetPortraitZoom(1)
  19.             portrait:SetPosition(0,0,0)
  20.             portrait:ClearModel()
  21.             portrait:SetUnit(unit)
  22.             portrait.guid = guid
  23.         end
  24.     else
  25.         SetPortraitTexture(portrait, unit)
  26.     end
  27.  
  28.     if(portrait.PostUpdate) then
  29.         return portrait:PostUpdate(unit)
  30.     end
  31. end
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 10-18-11 at 01:12 AM.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Portrait:SetModelScale(number)

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off