Thread Tools Display Modes
03-28-15, 11:30 AM   #1
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Need Help with PlayerModel!

Hi, I have been trying to understand how PlayerModel's work and I get very strange behaviours.

This is my first attempt code:
Lua Code:
  1. f.model = CreateFrame("PlayerModel", nil, f)
  2. f.model:SetSize(600, 800)
  3. f.model:SetPoint("BOTTOMLEFT", f, "TOPLEFT", 100, -100)
  4. f.model:SetUnit("player")
  5. f.model:SetPosition(0, 0, -0.75)
  6. f.model:SetCustomCamera(1)
  7. f.model:SetCameraPosition(2.8, -1, 0.4)

But this causes the Lua error below which I do not know why:
Code:
<unnamed> is not using a custom camera.
I set a custom camera only because without a custom camera, the positioning and size etc kept getting changed and I have no clue why. I then changed the code to be used in an "OnShow" event like this:

Lua Code:
  1. f.model = CreateFrame("PlayerModel", nil, f)
  2. f.model:SetSize(600, 800)
  3. f.model:SetPoint("BOTTOMLEFT", f, "TOPLEFT", 100, -100)
  4. f.model:SetUnit("player")                  
  5.  
  6. f.model:SetScript("OnShow", function(self)
  7.     self:SetPosition(0, 0, -0.75)
  8.     self:SetCustomCamera(1)
  9.     self:SetCameraPosition(2.8, -1, 0.4)
  10. end)

This removed the strange Lua error but I get the same problem with the camera being altered some how. The first time the model is shown, the positioning is completely wrong but GetCameraPosition() shows the right numbers. The 2nd time is gets shown, it displays correctly and the number with GetCameraPosition() are the same as the first time.

Obviously I must be not understanding something important?
That is all the code as I'm just getting started.

Can anyone help me?
Thank you!

EDIT: Also even without using any custom cameras, altering any positions, or distance values, the first time it shows is always very different to the 2nd time it shows..

Last edited by Mayron : 03-28-15 at 11:36 AM.
  Reply With Quote
03-28-15, 11:40 AM   #2
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
I've been running some tests,

So far the only difference between the two appearances are this:

first time shown:
print(f.model:GetWorldScale()) -- prints 0.817...

second time shown:
print(f.model:GetWorldScale()) -- prints 0.581...

not sure if that's anything to do with it.
  Reply With Quote
03-28-15, 11:49 AM   #3
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
They are just weird in my experience. You could try various combinations of resetting the position (0, 0, 0) before setting it, or onhide, or onshow, but I can't remember if any of those actually made a difference.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
03-28-15, 12:07 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Do you have anywhere else in the code that sets the model's unit? For example, in response to the UNIT_MODEL_CHANGED event. When you tell a ModelFrame to set its unit, it resets camera position and rotation. Even if it's the same unit as before.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
03-28-15, 12:16 PM   #5
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Originally Posted by SDPhantom View Post
Do you have anywhere else in the code that sets the model's unit? For example, in response to the UNIT_MODEL_CHANGED event. When you tell a ModelFrame to set its unit, it resets camera position and rotation. Even if it's the same unit as before.
No I don't. That is all the code which is why I usually try to avoid PlayerModel's because they confuse me.
  Reply With Quote
03-28-15, 12:16 PM   #6
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Originally Posted by Lombra View Post
They are just weird in my experience. You could try various combinations of resetting the position (0, 0, 0) before setting it, or onhide, or onshow, but I can't remember if any of those actually made a difference.
Been experimenting with this idea but no luck.
  Reply With Quote
03-28-15, 12:27 PM   #7
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Is your OnShow script even firing? A frame is shown as soon as it's created (meaning, your frame is already shown when you set the OnShow handler).
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
03-28-15, 12:27 PM   #8
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
The way the model is displayed is affected by your screen resolution for god knows why, but if you're creating it as soon as the addon is loaded it will have a different scale than if you create it after the ui scale is applied, which happens later in the loading process.

Anyway, you should probably be using model:SetPortraitZoom(n) rather than those camera functions.

Last edited by semlar : 03-28-15 at 12:34 PM.
  Reply With Quote
03-28-15, 12:44 PM   #9
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Originally Posted by Seerah View Post
Is your OnShow script even firing? A frame is shown as soon as it's created (meaning, your frame is already shown when you set the OnShow handler).
Sorry yes it definitely is firing. I have it anchored to a frame "f" which I control by showing and hiding it.

Originally Posted by semlar
The way the model is displayed is affected by your screen resolution for god knows why, but if you're creating it as soon as the addon is loaded it will have a different scale than if you create it after the ui scale is applied, which happens later in the loading process..
Thank you!!
Yeah I am creating it instantly which I think is the problem. I've added that block of code into an event which happens after the game has been loaded and it works now.. really strange but makes sense

Thanks everyone!
  Reply With Quote
03-28-15, 12:47 PM   #10
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
You need to create your model after the ADDON_LOADED trigger.

Lua Code:
  1. local model = CreateFrame("PlayerModel", nil, UIParent)
  2. model:SetSize(600, 800)
  3. model:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
  4. model:SetUnit("player")
  5. model:SetPosition(0, 0, -0.75)
  6. model:SetCustomCamera(1)
  7. model:SetCameraPosition(2.8, -1, 0.4)
  8. model:RefreshCamera()
  9.  
  10. model:Show()

Changing the scale of the model's frame or the UIScale will fuck up models which doesn't have their camera target set to 0,0,0.

I can point you to this code, where you can manipulate your model's camera stuff in real time:

http://www.wowinterface.com/forums/s...5&postcount=37

Last edited by Resike : 03-28-15 at 12:51 PM.
  Reply With Quote
03-28-15, 12:53 PM   #11
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Originally Posted by Resike View Post
You need to create your model after the ADDON_LOADED trigger.

Lua Code:
  1. local model = CreateFrame("PlayerModel", nil, UIParent)
  2. model:SetSize(600, 800)
  3. model:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
  4. model:SetUnit("player")
  5. model:SetPosition(0, 0, -0.75)
  6. model:SetCustomCamera(1)
  7. model:SetCameraPosition(2.8, -1, 0.4)
  8. model:RefreshCamera()
  9.  
  10. model:Show()

Changing the scale of the model's frame or the UIScale will fuck up models which doesn't have their camera target set to 0,0,0.
No clue why but I still get the Lua error when I use this code in "PLAYER_ENTERING_WORLD" and "ADDON_LOADED"

<unnamed> is not using a custom camera.
Time: 03/27/15 14:54:08
Count: 1
Stack: [C]: in function `SetCameraPosition'

Still no idea why I cannot have any camera functions being used outside of "OnShow".

EDIT: Thanks for the link. I will have to investigate further
  Reply With Quote
03-28-15, 01:25 PM   #12
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Mayron View Post
No clue why but I still get the Lua error when I use this code in "PLAYER_ENTERING_WORLD" and "ADDON_LOADED"

<unnamed> is not using a custom camera.
Time: 03/27/15 14:54:08
Count: 1
Stack: [C]: in function `SetCameraPosition'

Still no idea why I cannot have any camera functions being used outside of "OnShow".

EDIT: Thanks for the link. I will have to investigate further
Yeah i forgot that model:RefreshCamera() kills the model:SetCustomCamera(1) call, just add model:SetCustomCamera(1) after the model:RefreshCamera() again.
  Reply With Quote
03-28-15, 02:03 PM   #13
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
I don't remember well but i also think some model functions might return wrong values when called immediately after login. Maybe even the ADDON_LOADED event is too early too.
  Reply With Quote
03-29-15, 05:18 PM   #14
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
I updated some code in this thread:

http://www.wowinterface.com/forums/s...61&postcount=3

I'll dig deeper into models in the summer, when i'm (hopefully) gonna be back on this project:

http://www.wowinterface.com/forums/s...ad.php?t=48761
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Need Help with PlayerModel!


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