Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pace.AddTool(L"convert to lua clientside models", function(part,sub)
- local function convert_to_vm(part)
- local mdl_string =
- [[
- if (vm:LookupBone("BONE") ~= nil) then
- local bnep,bnea = vm:GetBonePosition(vm:LookupBone("BONE"))
- bnep:Add(bnea:Forward()*POS_X)
- bnep:Add(bnea:Right()*POS_Y)
- bnep:Add(bnea:Up()*POS_Z)
- bnea:RotateAroundAxis(bnea:Forward(),ANG_X)
- bnea:RotateAroundAxis(bnea:Right(),ANG_Y)
- bnea:RotateAroundAxis(bnea:Up(),ANG_Z)
- local PART = ClientsideModel(MODEL,RENDERGROUP_OTHER)
- if not IsValid(PART) then return end
- local scale = Matrix()
- scale:SetScale(Vector(SCALE_X,SCALE_Y,SCALE_Z))
- PART:SetModel(MODEL)
- PART:SetNoDraw(false)
- PART:SetPos(bnep)
- PART:SetAngles(bnea)
- PART:SetColor(Color(COLOR_R,COLOR_G,COLOR_B))
- PART:SetMaterial(MAT)
- PART:SetSkin(SKIN)
- PART:EnableMatrix("RenderMultiply",scale)PARENT
- PART:DrawModel()
- PART:Remove()
- end
- ]]
- local ang = part:GetAngles()
- local pos = part:GetPosition()
- local scale = part:GetSize() * part:GetScale()
- local mdl = mdl_string
- :gsub("COLOR_R", part:GetColor().r)
- :gsub("COLOR_G", part:GetColor().g)
- :gsub("COLOR_B", part:GetColor().b)
- :gsub("SCALE_X", scale.x)
- :gsub("SCALE_Y", scale.y)
- :gsub("SCALE_Z", scale.z)
- :gsub("ANG_X", ang.x)
- :gsub("ANG_Y", ang.y)
- :gsub("ANG_Z", ang.z)
- :gsub("POS_X", pos.x)
- :gsub("POS_Y", pos.y)
- :gsub("POS_Z", pos.z)
- :gsub("MAT", ("%q"):format(part:GetMaterial() != nil and part:GetMaterial() or ""))
- :gsub("MODEL", ("%q"):format(part:GetModel()))
- :gsub("SKIN", part:GetSkin())
- :gsub("BONE", part:GetRealBoneName(part.Bone,LocalPlayer()))
- :gsub("PARENT", part:GetParent().ClassName != "group" and ("\nPART:SetParent(%s)"):format(part:GetParent().UniqueID) or "")
- :gsub("PART", part.UniqueID)
- for _, p in pairs(part:GetChildren()) do
- if p and p.ClassName == "model" and not p:IsHidden() and not p.wavefront_mesh then
- mdl = mdl .. convert_to_vm(p)
- end
- end
- return mdl
- end
- local function convert_to_wm(part)
- local mdl_string =
- [[
- local owner = self:GetOwner()
- if not IsValid(owner) then
- self:DrawModel()
- return
- else
- self:DrawShadow(false)
- end
- if (owner:LookupBone("BONE") ~= nil) then
- local bnep,bnea = owner:GetBonePosition(owner:LookupBone("BONE"))
- bnep:Add(bnea:Forward()*POS_X)
- bnep:Add(bnea:Right()*POS_Y)
- bnep:Add(bnea:Up()*POS_Z)
- bnea:RotateAroundAxis(bnea:Forward(),ANG_X)
- bnea:RotateAroundAxis(bnea:Right(),ANG_Y)
- bnea:RotateAroundAxis(bnea:Up(),ANG_Z)
- local PART = ClientsideModel(MODEL,RENDERGROUP_OTHER)
- if not IsValid(PART) then return end
- local scale = Matrix()
- scale:SetScale(Vector(SCALE_X,SCALE_Y,SCALE_Z))
- PART:SetModel(MODEL)
- PART:SetNoDraw(false)
- PART:SetPos(bnep)
- PART:SetAngles(bnea)
- PART:SetColor(Color(COLOR_R,COLOR_G,COLOR_B))
- PART:SetMaterial(MAT)
- PART:SetSkin(SKIN)
- PART:EnableMatrix("RenderMultiply",scale)PARENT
- PART:DrawModel()
- PART:Remove()
- end
- ]]
- local ang = part:GetAngles()
- local pos = part:GetPosition()
- local scale = part:GetSize() * part:GetScale()
- local mdl = mdl_string
- :gsub("COLOR_R", part:GetColor().r)
- :gsub("COLOR_G", part:GetColor().g)
- :gsub("COLOR_B", part:GetColor().b)
- :gsub("SCALE_X", scale.x)
- :gsub("SCALE_Y", scale.y)
- :gsub("SCALE_Z", scale.z)
- :gsub("ANG_X", ang.x)
- :gsub("ANG_Y", ang.y)
- :gsub("ANG_Z", ang.z)
- :gsub("POS_X", pos.x)
- :gsub("POS_Y", pos.y)
- :gsub("POS_Z", pos.z)
- :gsub("MAT", ("%q"):format(part:GetMaterial() != nil and part:GetMaterial() or ""))
- :gsub("MODEL", ("%q"):format(part:GetModel()))
- :gsub("SKIN", part:GetSkin())
- :gsub("BONE", part:GetRealBoneName(part.Bone,LocalPlayer()))
- :gsub("PARENT", part:GetParent().ClassName != "group" and ("\nPART:SetParent(%s)"):format(part:GetParent().UniqueID) or "")
- :gsub("PART", part.UniqueID)
- for _, p in pairs(part:GetChildren()) do
- if p and p.ClassName == "model" and not p:IsHidden() and not p.wavefront_mesh then
- mdl = mdl .. convert_to_wm(p)
- end
- end
- return mdl
- end
- local function convert_to_ent(part)
- local mdl_string =
- [[
- local bnep,bnea = self:GetPos(),self:GetAngles()
- bnep:Add(bnea:Forward()*POS_X)
- bnep:Add(bnea:Right()*POS_Y)
- bnep:Add(bnea:Up()*POS_Z)
- bnea:RotateAroundAxis(bnea:Forward(),ANG_X)
- bnea:RotateAroundAxis(bnea:Right(),ANG_Y)
- bnea:RotateAroundAxis(bnea:Up(),ANG_Z)
- local PART = ClientsideModel(MODEL,RENDERGROUP_OTHER)
- if not IsValid(PART) then return end
- local scale = Matrix()
- scale:SetScale(Vector(SCALE_X,SCALE_Y,SCALE_Z))
- PART:SetModel(MODEL)
- PART:SetNoDraw(false)
- PART:SetPos(bnep)
- PART:SetAngles(bnea)
- PART:SetColor(Color(COLOR_R,COLOR_G,COLOR_B))
- PART:SetMaterial(MAT)
- PART:SetSkin(SKIN)
- PART:EnableMatrix("RenderMultiply",scale)PARENT
- PART:DrawModel()
- PART:Remove()
- ]]
- local ang = part:GetAngles()
- local pos = part:GetPosition()
- local scale = part:GetSize() * part:GetScale()
- local mdl = mdl_string
- :gsub("COLOR_R", part:GetColor().r)
- :gsub("COLOR_G", part:GetColor().g)
- :gsub("COLOR_B", part:GetColor().b)
- :gsub("SCALE_X", scale.x)
- :gsub("SCALE_Y", scale.y)
- :gsub("SCALE_Z", scale.z)
- :gsub("ANG_X", ang.x)
- :gsub("ANG_Y", ang.y)
- :gsub("ANG_Z", ang.z)
- :gsub("POS_X", pos.x)
- :gsub("POS_Y", pos.y)
- :gsub("POS_Z", pos.z)
- :gsub("MAT", ("%q"):format(part:GetMaterial() != nil and part:GetMaterial() or ""))
- :gsub("MODEL", ("%q"):format(part:GetModel()))
- :gsub("SKIN", part:GetSkin())
- :gsub("BONE", part:GetRealBoneName(part.Bone,LocalPlayer()))
- :gsub("PARENT", part:GetParent().ClassName != "group" and ("\nPART:SetParent(%s)"):format(part:GetParent().UniqueID) or "")
- :gsub("PART", part.UniqueID)
- for _, p in pairs(part:GetChildren()) do
- if p and p.ClassName == "model" and not p:IsHidden() and not p.wavefront_mesh then
- mdl = mdl .. convert_to_ent(p)
- end
- end
- return mdl
- end
- if sub == 1 then
- file.CreateDir("pac3/converted")
- file.Write("pac3/converted/wm_"..part.UniqueID..".txt",convert_to_wm(part))
- LocalPlayer():ChatPrint("Code saved to to pac3/converted/wm_"..part.UniqueID..".txt")
- LocalPlayer():ChatPrint("Please note this is REALLY buggy and you WILL have to modify certain things (mainly parenting if you've used clone)")
- end
- if sub == 2 then
- file.CreateDir("pac3/converted")
- file.Write("pac3/converted/vm_"..part.UniqueID..".txt",convert_to_vm(part))
- LocalPlayer():ChatPrint("Code saved to to pac3/converted/vm_"..part.UniqueID..".txt")
- LocalPlayer():ChatPrint("Please note this is REALLY buggy and you WILL have to modify certain things (mainly parenting if you've used clone)")
- end
- if sub == 3 then
- file.CreateDir("pac3/converted")
- file.Write("pac3/converted/ent_"..part.UniqueID..".txt",convert_to_ent(part))
- LocalPlayer():ChatPrint("Code saved to to pac3/converted/ent_"..part.UniqueID..".txt")
- LocalPlayer():ChatPrint("Please note this is REALLY buggy and you WILL have to modify certain things (mainly parenting if you've used clone)")
- end
- end,L"world model/attached to player",L"viewmodel",L"entity")
Advertisement
Comments
-
- If I'm understanding this correctly, you've coded a tool to export a PAC3 character/costume from GMOD as a single model?
-
- no, this was made to convert PAC outfits to viewmodel/worldmodel substitutes for weapons. basically using PAC as a replacement for SWEP Creator
-
- 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