From 703fb535e90df6c5f1f26b65ff6e1d70fe602dfe Mon Sep 17 00:00:00 2001 From: Denneisk <20892685+Denneisk@users.noreply.github.com> Date: Fri, 29 Nov 2024 14:52:21 -0500 Subject: [PATCH 1/2] Add holoBonemerge --- .../gmod_wire_expression2/core/hologram.lua | 17 +++++++++++++++++ lua/wire/client/e2descriptions.lua | 1 + 2 files changed, 18 insertions(+) diff --git a/lua/entities/gmod_wire_expression2/core/hologram.lua b/lua/entities/gmod_wire_expression2/core/hologram.lua index f703fb6e1f..b822150356 100644 --- a/lua/entities/gmod_wire_expression2/core/hologram.lua +++ b/lua/entities/gmod_wire_expression2/core/hologram.lua @@ -1243,14 +1243,31 @@ e2function void holoParentAttachment(index, entity ent, string attachmentName) Parent_Hologram(Holo, ent, attachmentName) 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:RemoveEffects(BONEMERGE_FLAGS) Holo.ent:SetParent(nil) Holo.ent:SetParentPhysNum(0) end +__e2setcost(10) + +e2function void holoBonemerge(index, state) + local Holo = CheckIndex(self, index) + if not Holo then return end + + if state ~= 0 then + Holo.ent:AddEffects(BONEMERGE_FLAGS) + else + Holo.ent:RemoveEffects(BONEMERGE_FLAGS) + end +end + -- ----------------------------------------------------------------------------- __e2setcost(2) diff --git a/lua/wire/client/e2descriptions.lua b/lua/wire/client/e2descriptions.lua index ace246c7e8..88362a980f 100644 --- a/lua/wire/client/e2descriptions.lua +++ b/lua/wire/client/e2descriptions.lua @@ -1299,6 +1299,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" From c3b396b008ae38c776cb4e9a4001243a014e741b Mon Sep 17 00:00:00 2001 From: Denneisk <20892685+Denneisk@users.noreply.github.com> Date: Fri, 29 Nov 2024 16:16:44 -0500 Subject: [PATCH 2/2] Add holo bone parenting Add entity model bone functions --- .../gmod_wire_expression2/core/entity.lua | 35 ++++++++++++++ .../gmod_wire_expression2/core/hologram.lua | 46 +++++++++++++++++-- lua/wire/client/e2descriptions.lua | 11 ++++- 3 files changed, 88 insertions(+), 4 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/entity.lua b/lua/entities/gmod_wire_expression2/core/entity.lua index 4be7edff37..80a58d830f 100644 --- a/lua/entities/gmod_wire_expression2/core/entity.lua +++ b/lua/entities/gmod_wire_expression2/core/entity.lua @@ -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 diff --git a/lua/entities/gmod_wire_expression2/core/hologram.lua b/lua/entities/gmod_wire_expression2/core/hologram.lua index b822150356..5eff0b57b1 100644 --- a/lua/entities/gmod_wire_expression2/core/hologram.lua +++ b/lua/entities/gmod_wire_expression2/core/hologram.lua @@ -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,6 +1251,38 @@ 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) @@ -1251,7 +1291,7 @@ e2function void holoUnparent(index) if not Holo then return end Holo.ent:RemoveEffects(BONEMERGE_FLAGS) - Holo.ent:SetParent(nil) + Holo.ent:FollowBone(nil, 0) Holo.ent:SetParentPhysNum(0) end @@ -1259,7 +1299,7 @@ __e2setcost(10) e2function void holoBonemerge(index, state) local Holo = CheckIndex(self, index) - if not Holo then return end + if not Holo or not Holo.ent:GetParent():IsValid() then return end if state ~= 0 then Holo.ent:AddEffects(BONEMERGE_FLAGS) diff --git a/lua/wire/client/e2descriptions.lua b/lua/wire/client/e2descriptions.lua index 88362a980f..742e05822d 100644 --- a/lua/wire/client/e2descriptions.lua +++ b/lua/wire/client/e2descriptions.lua @@ -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,7 +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["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"