Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bonemerging and model bone parenting to holos #3189

Merged
merged 3 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions lua/entities/gmod_wire_expression2/core/entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
61 changes: 59 additions & 2 deletions lua/entities/gmod_wire_expression2/core/hologram.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1243,14 +1251,63 @@ 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)
Holo.ent:SetParentPhysNum(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

-- -----------------------------------------------------------------------------

__e2setcost(2)
Expand Down
10 changes: 10 additions & 0 deletions lua/wire/client/e2descriptions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1292,13 +1298,17 @@ 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"
E2Helper.Descriptions["holoRemainingSpawns()"] = "Returns how many holograms can be created this execution"
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"
Expand Down
Loading