Quantcast
WoWInterface - View Single Post - 3d model viewer addon
View Single Post
02-27-20, 11:24 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,234
It's a bit rough but something like: (you can paste the code into the website to create/download as an addon). The Show/Hide button is on the target frame (and assumes you are using the default UI).

Lua Code:
  1. local function SetFacing(self, deltaX)
  2.     self.deltaX = self.deltaX + (deltaX * 0.01)
  3.     self:SetFacing(self.deltaX)
  4. end
  5. local function SetPosition(self, x, y, z)
  6.     self.x = self.x + (x * 0.1)
  7.     self.y = self.y + (y * 0.01)
  8.     self.z = self.z + (z * 0.01)
  9.     self:SetPosition(self.x, self.y, self.z)
  10. end
  11.  
  12. local f = CreateFrame("Button", nil, TargetFrame, "UIPanelButtonTemplate")
  13. f:SetSize(50, 20)
  14. f:SetPoint("BOTTOMLEFT", TargetFrameNameBackground, "TOPLEFT")
  15. f:SetText("Show")
  16. f:SetScript("OnClick", function(self, button)
  17.     local Shown = not self.Model:IsShown()
  18.     self.Model:SetShown(Shown)
  19.     self:SetText(Shown and "Hide" or "Show")
  20. end)
  21.  
  22. f.Model = CreateFrame("PlayerModel", nil, UIParent)
  23. f.Model:Hide()
  24. f.Model:SetSize(200, 200)
  25. f.Model:SetPoint("CENTER", 200, 80)
  26. f.Model:EnableMouse(true)
  27. f.Model.deltaX = 0
  28. f.Model.x, f.Model.y, f.Model.z = 0, 0, 0
  29. f.Model:SetMovable(true)
  30. f.Model:SetResizable(true)
  31. f.Model:RegisterForDrag("LeftButton")
  32. f.Model.Texture = f.Model:CreateTexture()
  33. f.Model.Texture:Hide()
  34. f.Model.Texture:SetAllPoints()
  35. f.Model.Texture:SetTexture("Interface/BUTTONS/WHITE8X8")
  36. f.Model.Texture:SetVertexColor(0.2, 0.4, 0.7, 0.2)
  37.  
  38. f.Model:SetScript("OnDragStart", function(self, ...)
  39.     if not self.UnLock then return end
  40.     if IsAltKeyDown() then
  41.         self:StartSizing("BOTTOMRIGHT")
  42.     else
  43.         self:StartMoving()
  44.     end
  45. end)
  46. f.Model:SetScript("OnDragStop", function(self)
  47.      self:StopMovingOrSizing()
  48.      self.ButtonDown = nil
  49. end)
  50.  
  51. f.Model:SetScript("OnEvent", function(self, event, ...)
  52.     if event == "PLAYER_TARGET_CHANGED" then
  53.         self.Reset:GetScript("OnClick")(self.Reset)
  54.     else
  55.         self:SetUnit("target")
  56.     end
  57. end)
  58. f.Model:RegisterEvent("PLAYER_TARGET_CHANGED")
  59. f.Model:RegisterUnitEvent("UNIT_MODEL_CHANGED", target)
  60. f.Model:SetScript("OnMouseDown", function(self, button)
  61.     if self.UnLock then return end
  62.     self.ButtonDown = button
  63. end)
  64. f.Model:SetScript("OnMouseUp", function(self, button)
  65.     self.ButtonDown = nil
  66. end)
  67. f.Model:SetScript("OnMouseWheel", function(self, delta)
  68.     SetPosition(self, delta, 0, 0)
  69.  
  70. end)
  71. f.Model:SetScript("OnUpdate", function(self, elapsed)
  72.     if self.ButtonDown then
  73.         if self.ButtonDown == "LeftButton" then
  74.             if self.UnLock then return end
  75.             local deltaX, deltaY = GetScaledCursorDelta()
  76.             SetFacing(self, deltaX)
  77.         elseif self.ButtonDown == "RightButton" then
  78.             local x, y, z = GetScaledCursorDelta()
  79.             SetPosition(self, 0, x, y)
  80.         end
  81.     end
  82. end)
  83. f.Model.Reset = CreateFrame("Button", nil, f.Model, "UIPanelButtonTemplate")
  84. f.Model.Reset:SetSize(60, 20)
  85. f.Model.Reset:SetPoint("BOTTOMLEFT", f.Model, "TOPLEFT")
  86. f.Model.Reset:SetText("Reset")
  87. f.Model.Reset:SetScript("OnClick", function(self)
  88.     local parent = self:GetParent()
  89.     parent.zoom  = 0
  90.     parent.deltaX = 0
  91.     parent.x, parent.y, parent.z = 0, 0, 0
  92.     SetFacing(parent, 0)
  93.     SetPosition(parent, 0, 0, 0)
  94.     parent:SetUnit("target")
  95. end)
  96.  
  97. f.Model.Lock = CreateFrame("Button", nil, f.Model, "UIPanelButtonTemplate")
  98. f.Model.Lock:SetSize(60, 20)
  99. f.Model.Lock:SetPoint("BOTTOM", f.Model, "TOP")
  100. f.Model.Lock:SetText("Unlock")
  101. f.Model.Lock:SetScript("OnClick", function(self)
  102.     self:GetParent().UnLock = not self:GetParent().UnLock
  103.     self:SetText(self:GetParent().UnLock and "Lock" or "Unlock")
  104. end)
  105.  
  106. f.Model.Close = CreateFrame("Button", nil, f.Model)
  107. f.Model.Close:SetSize(22, 22)
  108. f.Model.Close:SetPoint("BOTTOMRIGHT", f.Model, "TOPRIGHT")
  109. f.Model.Close:SetNormalTexture("Interface/Buttons/UI-Panel-MinimizeButton-Up")
  110. f.Model.Close:SetPushedTexture("Interface/Buttons/UI-Panel-MinimizeButton-Down")
  111. f.Model.Close:SetHighlightTexture("Interface/Buttons/UI-Panel-MinimizeButton-Highlight", "ADD")
  112. f.Model.Close:SetScript("OnClick", function(self)
  113.     PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)
  114.     f:GetScript("OnClick")(f) -- Call the target frame button's click handler
  115. end)
  116.  
  117. f.Model.Background = CreateFrame("Button", nil, f.Model, "UIPanelButtonTemplate")
  118. f.Model.Background:SetSize(40, 20)
  119. f.Model.Background:SetPoint("RIGHT", f.Model.Close, "LEFT", -5, 0)
  120. f.Model.Background:SetText("Bg")
  121. f.Model.Background:SetScript("OnClick", function(self)
  122.     local parent = self:GetParent()
  123.     parent.Texture:SetShown(not parent.Texture:IsShown())
  124. end)
The zoom/facing numbers can be adjusted to suit your needs. Zooming/Rotating only work if the mouse starts on/over the 3D model (which is positioned to the right of center to try and avoid some overlaying of in-game character(s) (player etc.)).
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-28-20 at 03:05 PM.
  Reply With Quote