mirror of
https://github.com/wiremod/wire.git
synced 2025-03-04 03:03:04 -05:00
Add bonemerging and model bone parenting to holos (#3189)
* Add holoBonemerge * Add holo bone parenting Add entity model bone functions
This commit is contained in:
parent
9ad5f1ede9
commit
049edb0b56
@ -1158,6 +1158,41 @@ e2function array entity:getFlexes()
|
||||
return ret
|
||||
end
|
||||
|
||||
--[[******************************************************************************]]
|
||||
-- Model bones
|
||||
|
||||
__e2setcost(5)
|
||||
|
||||
e2function number entity:getModelBoneCount()
|
||||
if not IsValid(this) then return self:throw("Invalid entity!", 0) end
|
||||
|
||||
return this:GetBoneCount()
|
||||
end
|
||||
|
||||
e2function number entity:getModelBoneIndex(string bone_name)
|
||||
if not IsValid(this) then return self:throw("Invalid entity!", 0) end
|
||||
|
||||
return this:LookupBone(bone_name) or -1
|
||||
end
|
||||
|
||||
e2function number entity:getModelBoneName(bone_index)
|
||||
if not IsValid(this) then return self:throw("Invalid entity!", "") end
|
||||
|
||||
return this:GetBoneName(bone_index) or ""
|
||||
end
|
||||
|
||||
__e2setcost(50)
|
||||
|
||||
e2function array entity:getModelBones()
|
||||
if not IsValid(this) then return self:throw("Invalid entity!", {}) end
|
||||
local ret = {}
|
||||
for i = 0, this:GetBoneCount() - 1 do
|
||||
ret[i] = this:GetBoneName(i)
|
||||
end
|
||||
self.prf = self.prf + (#ret + 1) * 5
|
||||
return ret
|
||||
end
|
||||
|
||||
--[[******************************************************************************]]
|
||||
-- End e2functions
|
||||
|
||||
|
@ -1190,9 +1190,17 @@ e2function void holoVisible(index, array players, visible)
|
||||
end
|
||||
|
||||
-- -----------------------------------------------------------------------------
|
||||
local function Parent_Hologram(holo, ent, attachment)
|
||||
---@param bone integer?
|
||||
local function Parent_Hologram(holo, ent, attachment, bone)
|
||||
if ent:GetParent() and ent:GetParent():IsValid() and ent:GetParent() == holo.ent then return end
|
||||
|
||||
if bone then
|
||||
if bone >= 0 and bone < ent:GetBoneCount() then
|
||||
holo.ent:FollowBone(ent, bone)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
holo.ent:SetParent(ent)
|
||||
|
||||
if attachment ~= nil then
|
||||
@ -1243,11 +1251,60 @@ e2function void holoParentAttachment(index, entity ent, string attachmentName)
|
||||
Parent_Hologram(Holo, ent, attachmentName)
|
||||
end
|
||||
|
||||
e2function void holoParentAttachment(index, otherindex, string attachmentName)
|
||||
local Holo = CheckIndex(self, index)
|
||||
if not Holo then return end
|
||||
|
||||
local Holo2 = CheckIndex(self, otherindex)
|
||||
if not Holo2 then return end
|
||||
|
||||
if not Check_Parents(Holo.ent, Holo2.ent) then return end
|
||||
|
||||
Parent_Hologram(Holo, Holo2.ent, attachmentName)
|
||||
end
|
||||
|
||||
e2function void holoParentBone(index, entity ent, bone)
|
||||
if not IsValid(ent) then return end
|
||||
local Holo = CheckIndex(self, index)
|
||||
if not Holo then return end
|
||||
|
||||
Parent_Hologram(Holo, ent, nil, bone)
|
||||
end
|
||||
|
||||
e2function void holoParentBone(index, otherindex, bone)
|
||||
local Holo = CheckIndex(self, index)
|
||||
if not Holo then return end
|
||||
|
||||
local Holo2 = CheckIndex(self, otherindex)
|
||||
if not Holo2 then return end
|
||||
|
||||
if not Check_Parents(Holo.ent, Holo2.ent) then return end
|
||||
|
||||
Parent_Hologram(Holo, Holo2.ent, nil, bone)
|
||||
end
|
||||
|
||||
-- Combination of EF_BONEMERGE and EF_BONEMERGE_FASTCULL, to avoid performance complaints.
|
||||
local BONEMERGE_FLAGS = bit.bor(EF_BONEMERGE, EF_BONEMERGE_FASTCULL)
|
||||
|
||||
e2function void holoUnparent(index)
|
||||
local Holo = CheckIndex(self, index)
|
||||
if not Holo then return end
|
||||
|
||||
Holo.ent:SetParent(nil)
|
||||
Holo.ent:RemoveEffects(BONEMERGE_FLAGS)
|
||||
Holo.ent:FollowBone(nil, 0)
|
||||
end
|
||||
|
||||
__e2setcost(10)
|
||||
|
||||
e2function void holoBonemerge(index, state)
|
||||
local Holo = CheckIndex(self, index)
|
||||
if not Holo or not Holo.ent:GetParent():IsValid() then return end
|
||||
|
||||
if state ~= 0 then
|
||||
Holo.ent:AddEffects(BONEMERGE_FLAGS)
|
||||
else
|
||||
Holo.ent:RemoveEffects(BONEMERGE_FLAGS)
|
||||
end
|
||||
end
|
||||
|
||||
-- -----------------------------------------------------------------------------
|
||||
|
@ -428,6 +428,12 @@ E2Helper.Descriptions["getFlexWeight"] = "Gets the weight of the flex"
|
||||
E2Helper.Descriptions["getFlexes(e:)"] = "Gets a 0-indexed array of all flexes and their names"
|
||||
E2Helper.Descriptions["hasFlexes(e:)"] = "Returns 1 if the entity has flexes"
|
||||
|
||||
-- Model bones
|
||||
E2Helper.Descriptions["getModelBoneCount(e:)"] = "Gets the number of bones on the entity's model. Note these are different from E2 bones"
|
||||
E2Helper.Descriptions["getModelBoneIndex(e:s)"] = "Gets the bone index of the given name or -1 if it doesn't exist"
|
||||
E2Helper.Descriptions["getModelBoneName(e:n)"] = "Gets the name of the bone"
|
||||
E2Helper.Descriptions["getModelBones(e:)"] = "Gets a 0-indexed array of all bones and their names. Note these are different from E2 bones"
|
||||
|
||||
-- Vector
|
||||
E2Helper.Descriptions["vec2(n)"] = "Makes a 2D vector"
|
||||
E2Helper.Descriptions["vec2(nn)"] = "Makes a 2D vector"
|
||||
@ -1292,6 +1298,9 @@ E2Helper.Descriptions["holoModelList()"] = "Returns the list of valid models\nSe
|
||||
E2Helper.Descriptions["holoParent(ne)"] = "Parents the hologram to an entity"
|
||||
E2Helper.Descriptions["holoParent(nn)"] = "Parents the hologram to another hologram"
|
||||
E2Helper.Descriptions["holoParentAttachment(nes)"] = "Parents the hologram to an entity's bone by its attachment name"
|
||||
E2Helper.Descriptions["holoParentAttachment(nns)"] = "Parents the hologram to another hologram's attachment by its attachment name"
|
||||
E2Helper.Descriptions["holoParentBone(nen)"] = "Parents the hologram to an entity's bone by its bone index. Note this is completely different from E2 (physics) bones"
|
||||
E2Helper.Descriptions["holoParentBone(nnn)"] = "Parents the hologram to another hologram's bone by its bone index. Note this is completely different from E2 (physics) bones"
|
||||
E2Helper.Descriptions["holoUnparent(n)"] = "Un-parents the hologram"
|
||||
E2Helper.Descriptions["holoPos(nv)"] = "Sets the position of the hologram"
|
||||
E2Helper.Descriptions["holoPos(n)"] = "Gets the position of the hologram"
|
||||
@ -1299,6 +1308,7 @@ E2Helper.Descriptions["holoRemainingSpawns()"] = "Returns how many holograms can
|
||||
E2Helper.Descriptions["holoReset(nsvvs)"] = "Similar to holoCreate, but reusing the old entity"
|
||||
E2Helper.Descriptions["holoScale(n)"] = "Returns the scale of the given hologram"
|
||||
E2Helper.Descriptions["holoScale(nv)"] = "Sets the scale of the given hologram, as a multiplier"
|
||||
E2Helper.Descriptions["holoBonemerge(nn)"] = "Enables bonemerge behavior on the hologram when the second argument is not 0"
|
||||
E2Helper.Descriptions["holoBoneScale(nn)"] = "Returns the scale of the given hologram bone"
|
||||
E2Helper.Descriptions["holoBoneScale(nnv)"] = "Sets the scale of the given hologram bone, as a multiplier"
|
||||
E2Helper.Descriptions["holoBoneScale(ns)"] = "Returns the scale of the given hologram named bone"
|
||||
|
Loading…
Reference in New Issue
Block a user