LUModder

[EXPIRIMENTAL] PAC to Clientside Model Code

Jan 17th, 2016
395
0
Never
3
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.20 KB | None | 0 0
  1. pace.AddTool(L"convert to lua clientside models", function(part,sub)
  2.     local function convert_to_vm(part)
  3.         local mdl_string =
  4.         [[
  5.             if (vm:LookupBone("BONE") ~= nil) then
  6.                 local bnep,bnea = vm:GetBonePosition(vm:LookupBone("BONE"))
  7.                 bnep:Add(bnea:Forward()*POS_X)
  8.                 bnep:Add(bnea:Right()*POS_Y)
  9.                 bnep:Add(bnea:Up()*POS_Z)
  10.                 bnea:RotateAroundAxis(bnea:Forward(),ANG_X)
  11.                 bnea:RotateAroundAxis(bnea:Right(),ANG_Y)
  12.                 bnea:RotateAroundAxis(bnea:Up(),ANG_Z)
  13.  
  14.                 local PART = ClientsideModel(MODEL,RENDERGROUP_OTHER)
  15.                 if not IsValid(PART) then return end
  16.  
  17.                 local scale = Matrix()
  18.                 scale:SetScale(Vector(SCALE_X,SCALE_Y,SCALE_Z))
  19.  
  20.                 PART:SetModel(MODEL)
  21.                 PART:SetNoDraw(false)
  22.                 PART:SetPos(bnep)
  23.                 PART:SetAngles(bnea)
  24.                 PART:SetColor(Color(COLOR_R,COLOR_G,COLOR_B))
  25.                 PART:SetMaterial(MAT)
  26.                 PART:SetSkin(SKIN)
  27.                 PART:EnableMatrix("RenderMultiply",scale)PARENT
  28.                 PART:DrawModel()
  29.                 PART:Remove()
  30.             end
  31.         ]]
  32.  
  33.         local ang = part:GetAngles()
  34.         local pos = part:GetPosition()
  35.         local scale = part:GetSize() * part:GetScale()
  36.  
  37.         local mdl = mdl_string
  38.         :gsub("COLOR_R", part:GetColor().r)
  39.         :gsub("COLOR_G", part:GetColor().g)
  40.         :gsub("COLOR_B", part:GetColor().b)
  41.         :gsub("SCALE_X", scale.x)
  42.         :gsub("SCALE_Y", scale.y)
  43.         :gsub("SCALE_Z", scale.z)
  44.         :gsub("ANG_X", ang.x)
  45.         :gsub("ANG_Y", ang.y)
  46.         :gsub("ANG_Z", ang.z)
  47.         :gsub("POS_X", pos.x)
  48.         :gsub("POS_Y", pos.y)
  49.         :gsub("POS_Z", pos.z)
  50.         :gsub("MAT", ("%q"):format(part:GetMaterial() != nil and part:GetMaterial() or ""))
  51.         :gsub("MODEL", ("%q"):format(part:GetModel()))
  52.         :gsub("SKIN", part:GetSkin())
  53.         :gsub("BONE", part:GetRealBoneName(part.Bone,LocalPlayer()))
  54.         :gsub("PARENT", part:GetParent().ClassName != "group" and ("\nPART:SetParent(%s)"):format(part:GetParent().UniqueID) or "")
  55.         :gsub("PART", part.UniqueID)
  56.  
  57.         for _, p in pairs(part:GetChildren()) do
  58.             if p and p.ClassName == "model" and not p:IsHidden() and not p.wavefront_mesh then
  59.                 mdl = mdl .. convert_to_vm(p)
  60.             end
  61.         end
  62.  
  63.         return mdl
  64.     end
  65.  
  66.     local function convert_to_wm(part)
  67.         local mdl_string =
  68.         [[
  69.             local owner = self:GetOwner()
  70.             if not IsValid(owner) then
  71.                 self:DrawModel()
  72.                 return
  73.             else
  74.                 self:DrawShadow(false)
  75.             end
  76.             if (owner:LookupBone("BONE") ~= nil) then
  77.                 local bnep,bnea = owner:GetBonePosition(owner:LookupBone("BONE"))
  78.                 bnep:Add(bnea:Forward()*POS_X)
  79.                 bnep:Add(bnea:Right()*POS_Y)
  80.                 bnep:Add(bnea:Up()*POS_Z)
  81.                 bnea:RotateAroundAxis(bnea:Forward(),ANG_X)
  82.                 bnea:RotateAroundAxis(bnea:Right(),ANG_Y)
  83.                 bnea:RotateAroundAxis(bnea:Up(),ANG_Z)
  84.  
  85.                 local PART = ClientsideModel(MODEL,RENDERGROUP_OTHER)
  86.                 if not IsValid(PART) then return end
  87.  
  88.                 local scale = Matrix()
  89.                 scale:SetScale(Vector(SCALE_X,SCALE_Y,SCALE_Z))
  90.  
  91.                 PART:SetModel(MODEL)
  92.                 PART:SetNoDraw(false)
  93.                 PART:SetPos(bnep)
  94.                 PART:SetAngles(bnea)
  95.                 PART:SetColor(Color(COLOR_R,COLOR_G,COLOR_B))
  96.                 PART:SetMaterial(MAT)
  97.                 PART:SetSkin(SKIN)
  98.                 PART:EnableMatrix("RenderMultiply",scale)PARENT
  99.                 PART:DrawModel()
  100.                 PART:Remove()
  101.             end
  102.         ]]
  103.  
  104.         local ang = part:GetAngles()
  105.         local pos = part:GetPosition()
  106.         local scale = part:GetSize() * part:GetScale()
  107.  
  108.         local mdl = mdl_string
  109.         :gsub("COLOR_R", part:GetColor().r)
  110.         :gsub("COLOR_G", part:GetColor().g)
  111.         :gsub("COLOR_B", part:GetColor().b)
  112.         :gsub("SCALE_X", scale.x)
  113.         :gsub("SCALE_Y", scale.y)
  114.         :gsub("SCALE_Z", scale.z)
  115.         :gsub("ANG_X", ang.x)
  116.         :gsub("ANG_Y", ang.y)
  117.         :gsub("ANG_Z", ang.z)
  118.         :gsub("POS_X", pos.x)
  119.         :gsub("POS_Y", pos.y)
  120.         :gsub("POS_Z", pos.z)
  121.         :gsub("MAT", ("%q"):format(part:GetMaterial() != nil and part:GetMaterial() or ""))
  122.         :gsub("MODEL", ("%q"):format(part:GetModel()))
  123.         :gsub("SKIN", part:GetSkin())
  124.         :gsub("BONE", part:GetRealBoneName(part.Bone,LocalPlayer()))
  125.         :gsub("PARENT", part:GetParent().ClassName != "group" and ("\nPART:SetParent(%s)"):format(part:GetParent().UniqueID) or "")
  126.         :gsub("PART", part.UniqueID)
  127.  
  128.         for _, p in pairs(part:GetChildren()) do
  129.             if p and p.ClassName == "model" and not p:IsHidden() and not p.wavefront_mesh then
  130.                 mdl = mdl .. convert_to_wm(p)
  131.             end
  132.         end
  133.  
  134.         return mdl
  135.     end
  136.  
  137.     local function convert_to_ent(part)
  138.         local mdl_string =
  139.         [[
  140.             local bnep,bnea = self:GetPos(),self:GetAngles()
  141.             bnep:Add(bnea:Forward()*POS_X)
  142.             bnep:Add(bnea:Right()*POS_Y)
  143.             bnep:Add(bnea:Up()*POS_Z)
  144.             bnea:RotateAroundAxis(bnea:Forward(),ANG_X)
  145.             bnea:RotateAroundAxis(bnea:Right(),ANG_Y)
  146.             bnea:RotateAroundAxis(bnea:Up(),ANG_Z)
  147.  
  148.             local PART = ClientsideModel(MODEL,RENDERGROUP_OTHER)
  149.             if not IsValid(PART) then return end
  150.  
  151.             local scale = Matrix()
  152.             scale:SetScale(Vector(SCALE_X,SCALE_Y,SCALE_Z))
  153.  
  154.             PART:SetModel(MODEL)
  155.             PART:SetNoDraw(false)
  156.             PART:SetPos(bnep)
  157.             PART:SetAngles(bnea)
  158.             PART:SetColor(Color(COLOR_R,COLOR_G,COLOR_B))
  159.             PART:SetMaterial(MAT)
  160.             PART:SetSkin(SKIN)
  161.             PART:EnableMatrix("RenderMultiply",scale)PARENT
  162.             PART:DrawModel()
  163.             PART:Remove()
  164.         ]]
  165.  
  166.         local ang = part:GetAngles()
  167.         local pos = part:GetPosition()
  168.         local scale = part:GetSize() * part:GetScale()
  169.  
  170.         local mdl = mdl_string
  171.         :gsub("COLOR_R", part:GetColor().r)
  172.         :gsub("COLOR_G", part:GetColor().g)
  173.         :gsub("COLOR_B", part:GetColor().b)
  174.         :gsub("SCALE_X", scale.x)
  175.         :gsub("SCALE_Y", scale.y)
  176.         :gsub("SCALE_Z", scale.z)
  177.         :gsub("ANG_X", ang.x)
  178.         :gsub("ANG_Y", ang.y)
  179.         :gsub("ANG_Z", ang.z)
  180.         :gsub("POS_X", pos.x)
  181.         :gsub("POS_Y", pos.y)
  182.         :gsub("POS_Z", pos.z)
  183.         :gsub("MAT", ("%q"):format(part:GetMaterial() != nil and part:GetMaterial() or ""))
  184.         :gsub("MODEL", ("%q"):format(part:GetModel()))
  185.         :gsub("SKIN", part:GetSkin())
  186.         :gsub("BONE", part:GetRealBoneName(part.Bone,LocalPlayer()))
  187.         :gsub("PARENT", part:GetParent().ClassName != "group" and ("\nPART:SetParent(%s)"):format(part:GetParent().UniqueID) or "")
  188.         :gsub("PART", part.UniqueID)
  189.  
  190.         for _, p in pairs(part:GetChildren()) do
  191.             if p and p.ClassName == "model" and not p:IsHidden() and not p.wavefront_mesh then
  192.                 mdl = mdl .. convert_to_ent(p)
  193.             end
  194.         end
  195.  
  196.         return mdl
  197.     end
  198.  
  199.     if sub == 1 then
  200.         file.CreateDir("pac3/converted")
  201.         file.Write("pac3/converted/wm_"..part.UniqueID..".txt",convert_to_wm(part))
  202.         LocalPlayer():ChatPrint("Code saved to to pac3/converted/wm_"..part.UniqueID..".txt")
  203.         LocalPlayer():ChatPrint("Please note this is REALLY buggy and you WILL have to modify certain things (mainly parenting if you've used clone)")
  204.     end
  205.  
  206.     if sub == 2 then
  207.         file.CreateDir("pac3/converted")
  208.         file.Write("pac3/converted/vm_"..part.UniqueID..".txt",convert_to_vm(part))
  209.         LocalPlayer():ChatPrint("Code saved to to pac3/converted/vm_"..part.UniqueID..".txt")
  210.         LocalPlayer():ChatPrint("Please note this is REALLY buggy and you WILL have to modify certain things (mainly parenting if you've used clone)")
  211.     end
  212.  
  213.     if sub == 3 then
  214.         file.CreateDir("pac3/converted")
  215.         file.Write("pac3/converted/ent_"..part.UniqueID..".txt",convert_to_ent(part))
  216.         LocalPlayer():ChatPrint("Code saved to to pac3/converted/ent_"..part.UniqueID..".txt")
  217.         LocalPlayer():ChatPrint("Please note this is REALLY buggy and you WILL have to modify certain things (mainly parenting if you've used clone)")
  218.     end
  219. end,L"world model/attached to player",L"viewmodel",L"entity")
Advertisement
Comments
  • dirspon
    2 years
    # text 0.12 KB | 0 0
    1. If I'm understanding this correctly, you've coded a tool to export a PAC3 character/costume from GMOD as a single model?
    • LUModder
      2 years
      # text 0.14 KB | 0 0
      1. no, this was made to convert PAC outfits to viewmodel/worldmodel substitutes for weapons. basically using PAC as a replacement for SWEP Creator
  • dirspon
    2 years
    # text 0.10 KB | 0 0
    1. Ah. I was hopeful to find a way to export a character with PAC3 alterations as an individual model?
Add Comment
Please, Sign In to add comment