Skip to content

Commit

Permalink
Add flexes and eye posing to E2 (#2810)
Browse files Browse the repository at this point in the history
* Add flex and eye functions
Add prototypes for bone scale and jiggle functions
Make entity:bones() return a copy its output

* E2Descriptions
Reduced and dynamicized cost for entity:getFlexes()

* setEyeTarget e2descriptions
Changed position (cost) of setFlexWeight(nn) (30 -> 10)

* Remove references to bone jiggle and scale

* Update E2Descriptions
  • Loading branch information
Denneisk authored Nov 3, 2023
1 parent d4fd71f commit 6a983ab
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 5 deletions.
6 changes: 1 addition & 5 deletions lua/entities/gmod_wire_expression2/core/bone.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ end
--- Returns an array containing all of <this>'s bones. This array's first element has the index 0!
e2function array entity:bones()
if not IsValid(this) then return { } end
return GetBones(this)
return table.Copy(GetBones(this))
end

--- Returns <this>'s number of bones.
Expand Down Expand Up @@ -418,7 +418,3 @@ e2function string toString(bone b)
end

WireLib.registerDebuggerFormat("BONE", e2_tostring_bone)

--[[************************************************************************]]--

-- TODO: constraints
5 changes: 5 additions & 0 deletions lua/entities/gmod_wire_expression2/core/custom/cl_prop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,8 @@ E2Helper.Descriptions["setPos(b:v)"] = "Sets the position of a bone."
E2Helper.Descriptions["setAng(b:a)"] = "Set the rotation of a bone."
E2Helper.Descriptions["ragdollSetPos(e:v)"] = "Sets the position of a ragdoll while preserving pose."
E2Helper.Descriptions["ragdollSetAng(e:a)"] = "Set the rotation of a ragdoll while preserving pose."
E2Helper.Descriptions["setEyeTarget(e:v)"] = "For NPCs, sets the eye target to the world position. For ragdolls, sets the eye target to the local eye position"
E2Helper.Descriptions["setEyeTargetLocal(e:v)"] = "Sets the eye target to the local eye position"
E2Helper.Descriptions["setEyeTargetWorld(e:v)"] = "Sets the eye target to the world position"
E2Helper.Descriptions["setFlexScale(e:n)"] = "Sets the flex scale of the entity"
E2Helper.Descriptions["setFlexWeight"] = "Sets the weight of the flex"
57 changes: 57 additions & 0 deletions lua/entities/gmod_wire_expression2/core/custom/prop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ e2function void entity:propStatic( number static )
end
end

-- Bones --
--------------------------------------------------------------------------------

e2function void bone:boneManipulate(vector pos, angle rot, isFrozen, gravity, collision)
Expand Down Expand Up @@ -828,6 +829,62 @@ e2function number propCanCreate()
return 0
end

-- Flexes --
--------------------------------------------------------------------------------

-- Setters

__e2setcost(10)

e2function void entity:setEyeTarget(vector pos)
if not ValidAction(self, this, "eyetarget") then return end
this:SetEyeTarget(pos)
end

e2function void entity:setFlexWeight(number flex, number weight)
if not ValidAction(self, this, "flexweight" .. flex) then return end
this:SetFlexWeight(flex, weight)
end

__e2setcost(30)

e2function void entity:setEyeTargetLocal(vector pos)
if not ValidAction(self, this, "eyetarget") then return end
if not this:IsRagdoll() then
local attachment = this:GetAttachment(this:LookupAttachment("eyes"))
if attachment then
pos = LocalToWorld(pos, angle_zero, attachment.Pos, attachment.Ang)
end
end
this:SetEyeTarget(pos)
end

e2function void entity:setEyeTargetWorld(vector pos)
if not ValidAction(self, this, "eyetarget") then return end
if this:IsRagdoll() then
local attachment = this:GetAttachment(this:LookupAttachment("eyes"))
if attachment then
pos = WorldToLocal(pos, angle_zero, attachment.Pos, attachment.Ang)
end
end
this:SetEyeTarget(pos)
end

__e2setcost(20)

e2function void entity:setFlexWeight(string flex, number weight)
flex = this:GetFlexIDByName(flex)
if flex then
if not ValidAction(self, this, "flexweight" .. flex) then return end
this:SetFlexWeight(flex, weight)
end
end

e2function void entity:setFlexScale(number scale)
if not ValidAction(self, this, "flexscale") then return end
this:SetFlexScale(scale)
end

registerCallback("construct",
function(self)
self.data.propSpawnEffect = true
Expand Down
69 changes: 69 additions & 0 deletions lua/entities/gmod_wire_expression2/core/entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,75 @@ e2function void entity:noCollideAll(number state)
this:SetCollisionGroup(state == 0 and COLLISION_GROUP_NONE or COLLISION_GROUP_WORLD)
end

--[[******************************************************************************]]
-- Flexes

__e2setcost(5)

e2function array entity:getFlexBounds(number flex)
if not IsValid(this) then return self:throw("Invalid entity!", {}) end
return { this:GetFlexBounds(flex) }
end

e2function number entity:getFlexCount()
if not IsValid(this) then return self:throw("Invalid entity!", 0) end
return this:GetFlexNum()
end

e2function number entity:getFlexID(string flex)
if not IsValid(this) then return self:throw("Invalid entity!", 0) end
return this:GetFlexIDByName(flex) or -1
end

e2function number entity:getFlexScale()
if not IsValid(this) then return self:throw("Invalid entity!", 0) end
return this:GetFlexScale()
end

e2function string entity:getFlexName(number id)
if not IsValid(this) then return self:throw("Invalid entity!", "") end
return this:GetFlexName(id) or ""
end

e2function number entity:getFlexWeight(number flex)
if not IsValid(this) then return self:throw("Invalid entity!", 0) end
return this:GetFlexWeight(flex)
end

e2function number entity:hasFlexes()
if not IsValid(this) then return self:throw("Invalid entity!", 0) end
return this:HasFlexManipulator() and 1 or 0
end

__e2setcost(15)

e2function array entity:getFlexBounds(string flex)
if not IsValid(this) then return self:throw("Invalid entity!", {}) end
flex = this:GetFlexIDByName(flex)
return flex and { this:GetFlexBounds(flex) } or {}
end

e2function number entity:getFlexWeight(string flex)
if not IsValid(this) then return self:throw("Invalid entity!", 0) end
flex = this:GetFlexIDByName(flex)
return flex and this:GetFlexWeight(flex) or 0
end

__e2setcost(50)

e2function array entity:getFlexes()
if not IsValid(this) then return self:throw("Invalid entity!", 0) end
local ret = {}
for i = 0, this:GetFlexNum() - 1 do
ret[i] = this:GetFlexName(i)
end
self.prf = self.prf + (#ret + 1) * 5
return ret
end

--[[******************************************************************************]]
-- End e2functions

hook.Add("OnEntityCreated", "E2_entityCreated", function(ent)
if not IsValid(ent) then return end -- Engine is precaching a model or bad addon

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 @@ -395,6 +395,16 @@ E2Helper.Descriptions["attachmentPos(e:s)"] = "Same as E:attachmentPos(E:lookupA
E2Helper.Descriptions["attachmentAng(e:s)"] = "Same as E:attachmentAng(E:lookupAttachment(attachmentName))"
E2Helper.Descriptions["attachments(e:)"] = "Returns array of attachment names of the entity"

-- Flexes
E2Helper.Descriptions["getFlexBounds"] = "Gets the upper and lower bounds of the flex if it exists"
E2Helper.Descriptions["getFlexCount(e:)"] = "Gets the number of flexes on the entity"
E2Helper.Descriptions["getFlexID(e:s)"] = "Gets the flex ID of the given name or -1 if it doesn't exist"
E2Helper.Descriptions["getFlexName(e:n)"] = "Gets the name of the flex"
E2Helper.Descriptions["getFlexScale(e:)"] = "Gets the flex scale of the entity"
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"

-- Vector
E2Helper.Descriptions["vec2(n)"] = "Makes a 2D vector"
E2Helper.Descriptions["vec2(nn)"] = "Makes a 2D vector"
Expand Down

0 comments on commit 6a983ab

Please sign in to comment.