Skip to content

Commit 049edb0

Browse files
authored
Add bonemerging and model bone parenting to holos (#3189)
* Add holoBonemerge * Add holo bone parenting Add entity model bone functions
1 parent 9ad5f1e commit 049edb0

File tree

3 files changed

+104
-2
lines changed

3 files changed

+104
-2
lines changed

lua/entities/gmod_wire_expression2/core/entity.lua

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,41 @@ e2function array entity:getFlexes()
11581158
return ret
11591159
end
11601160

1161+
--[[******************************************************************************]]
1162+
-- Model bones
1163+
1164+
__e2setcost(5)
1165+
1166+
e2function number entity:getModelBoneCount()
1167+
if not IsValid(this) then return self:throw("Invalid entity!", 0) end
1168+
1169+
return this:GetBoneCount()
1170+
end
1171+
1172+
e2function number entity:getModelBoneIndex(string bone_name)
1173+
if not IsValid(this) then return self:throw("Invalid entity!", 0) end
1174+
1175+
return this:LookupBone(bone_name) or -1
1176+
end
1177+
1178+
e2function number entity:getModelBoneName(bone_index)
1179+
if not IsValid(this) then return self:throw("Invalid entity!", "") end
1180+
1181+
return this:GetBoneName(bone_index) or ""
1182+
end
1183+
1184+
__e2setcost(50)
1185+
1186+
e2function array entity:getModelBones()
1187+
if not IsValid(this) then return self:throw("Invalid entity!", {}) end
1188+
local ret = {}
1189+
for i = 0, this:GetBoneCount() - 1 do
1190+
ret[i] = this:GetBoneName(i)
1191+
end
1192+
self.prf = self.prf + (#ret + 1) * 5
1193+
return ret
1194+
end
1195+
11611196
--[[******************************************************************************]]
11621197
-- End e2functions
11631198

lua/entities/gmod_wire_expression2/core/hologram.lua

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,9 +1190,17 @@ e2function void holoVisible(index, array players, visible)
11901190
end
11911191

11921192
-- -----------------------------------------------------------------------------
1193-
local function Parent_Hologram(holo, ent, attachment)
1193+
---@param bone integer?
1194+
local function Parent_Hologram(holo, ent, attachment, bone)
11941195
if ent:GetParent() and ent:GetParent():IsValid() and ent:GetParent() == holo.ent then return end
11951196

1197+
if bone then
1198+
if bone >= 0 and bone < ent:GetBoneCount() then
1199+
holo.ent:FollowBone(ent, bone)
1200+
return
1201+
end
1202+
end
1203+
11961204
holo.ent:SetParent(ent)
11971205

11981206
if attachment ~= nil then
@@ -1243,11 +1251,60 @@ e2function void holoParentAttachment(index, entity ent, string attachmentName)
12431251
Parent_Hologram(Holo, ent, attachmentName)
12441252
end
12451253

1254+
e2function void holoParentAttachment(index, otherindex, string attachmentName)
1255+
local Holo = CheckIndex(self, index)
1256+
if not Holo then return end
1257+
1258+
local Holo2 = CheckIndex(self, otherindex)
1259+
if not Holo2 then return end
1260+
1261+
if not Check_Parents(Holo.ent, Holo2.ent) then return end
1262+
1263+
Parent_Hologram(Holo, Holo2.ent, attachmentName)
1264+
end
1265+
1266+
e2function void holoParentBone(index, entity ent, bone)
1267+
if not IsValid(ent) then return end
1268+
local Holo = CheckIndex(self, index)
1269+
if not Holo then return end
1270+
1271+
Parent_Hologram(Holo, ent, nil, bone)
1272+
end
1273+
1274+
e2function void holoParentBone(index, otherindex, bone)
1275+
local Holo = CheckIndex(self, index)
1276+
if not Holo then return end
1277+
1278+
local Holo2 = CheckIndex(self, otherindex)
1279+
if not Holo2 then return end
1280+
1281+
if not Check_Parents(Holo.ent, Holo2.ent) then return end
1282+
1283+
Parent_Hologram(Holo, Holo2.ent, nil, bone)
1284+
end
1285+
1286+
-- Combination of EF_BONEMERGE and EF_BONEMERGE_FASTCULL, to avoid performance complaints.
1287+
local BONEMERGE_FLAGS = bit.bor(EF_BONEMERGE, EF_BONEMERGE_FASTCULL)
1288+
12461289
e2function void holoUnparent(index)
12471290
local Holo = CheckIndex(self, index)
12481291
if not Holo then return end
12491292

1250-
Holo.ent:SetParent(nil)
1293+
Holo.ent:RemoveEffects(BONEMERGE_FLAGS)
1294+
Holo.ent:FollowBone(nil, 0)
1295+
end
1296+
1297+
__e2setcost(10)
1298+
1299+
e2function void holoBonemerge(index, state)
1300+
local Holo = CheckIndex(self, index)
1301+
if not Holo or not Holo.ent:GetParent():IsValid() then return end
1302+
1303+
if state ~= 0 then
1304+
Holo.ent:AddEffects(BONEMERGE_FLAGS)
1305+
else
1306+
Holo.ent:RemoveEffects(BONEMERGE_FLAGS)
1307+
end
12511308
end
12521309

12531310
-- -----------------------------------------------------------------------------

lua/wire/client/e2descriptions.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,12 @@ E2Helper.Descriptions["getFlexWeight"] = "Gets the weight of the flex"
428428
E2Helper.Descriptions["getFlexes(e:)"] = "Gets a 0-indexed array of all flexes and their names"
429429
E2Helper.Descriptions["hasFlexes(e:)"] = "Returns 1 if the entity has flexes"
430430

431+
-- Model bones
432+
E2Helper.Descriptions["getModelBoneCount(e:)"] = "Gets the number of bones on the entity's model. Note these are different from E2 bones"
433+
E2Helper.Descriptions["getModelBoneIndex(e:s)"] = "Gets the bone index of the given name or -1 if it doesn't exist"
434+
E2Helper.Descriptions["getModelBoneName(e:n)"] = "Gets the name of the bone"
435+
E2Helper.Descriptions["getModelBones(e:)"] = "Gets a 0-indexed array of all bones and their names. Note these are different from E2 bones"
436+
431437
-- Vector
432438
E2Helper.Descriptions["vec2(n)"] = "Makes a 2D vector"
433439
E2Helper.Descriptions["vec2(nn)"] = "Makes a 2D vector"
@@ -1292,13 +1298,17 @@ E2Helper.Descriptions["holoModelList()"] = "Returns the list of valid models\nSe
12921298
E2Helper.Descriptions["holoParent(ne)"] = "Parents the hologram to an entity"
12931299
E2Helper.Descriptions["holoParent(nn)"] = "Parents the hologram to another hologram"
12941300
E2Helper.Descriptions["holoParentAttachment(nes)"] = "Parents the hologram to an entity's bone by its attachment name"
1301+
E2Helper.Descriptions["holoParentAttachment(nns)"] = "Parents the hologram to another hologram's attachment by its attachment name"
1302+
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"
1303+
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"
12951304
E2Helper.Descriptions["holoUnparent(n)"] = "Un-parents the hologram"
12961305
E2Helper.Descriptions["holoPos(nv)"] = "Sets the position of the hologram"
12971306
E2Helper.Descriptions["holoPos(n)"] = "Gets the position of the hologram"
12981307
E2Helper.Descriptions["holoRemainingSpawns()"] = "Returns how many holograms can be created this execution"
12991308
E2Helper.Descriptions["holoReset(nsvvs)"] = "Similar to holoCreate, but reusing the old entity"
13001309
E2Helper.Descriptions["holoScale(n)"] = "Returns the scale of the given hologram"
13011310
E2Helper.Descriptions["holoScale(nv)"] = "Sets the scale of the given hologram, as a multiplier"
1311+
E2Helper.Descriptions["holoBonemerge(nn)"] = "Enables bonemerge behavior on the hologram when the second argument is not 0"
13021312
E2Helper.Descriptions["holoBoneScale(nn)"] = "Returns the scale of the given hologram bone"
13031313
E2Helper.Descriptions["holoBoneScale(nnv)"] = "Sets the scale of the given hologram bone, as a multiplier"
13041314
E2Helper.Descriptions["holoBoneScale(ns)"] = "Returns the scale of the given hologram named bone"

0 commit comments

Comments
 (0)