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 flexes and eye posing to E2 #2810

Merged
merged 5 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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 @@ -24,7 +24,7 @@
-- faster access to some math library functions
local abs = math.abs
local atan2 = math.atan2
local sqrt = math.sqrt

Check warning on line 27 in lua/entities/gmod_wire_expression2/core/bone.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: sqrt
local asin = math.asin
local Clamp = math.Clamp

Expand Down Expand Up @@ -108,7 +108,7 @@
--- 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))
thegrb93 marked this conversation as resolved.
Show resolved Hide resolved
Vurv78 marked this conversation as resolved.
Show resolved Hide resolved
end

--- Returns <this>'s number of bones.
Expand Down Expand Up @@ -418,7 +418,3 @@
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 @@ -298,7 +298,7 @@
local function removeAllIn( self, tbl )
local count = 0
for k,v in pairs( tbl ) do
if (IsValid(v) and isOwner(self,v) and !v:IsPlayer()) then

Check warning on line 301 in lua/entities/gmod_wire_expression2/core/custom/prop.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of '!' and 'not'
count = count + 1
v:Remove()
end
Expand Down Expand Up @@ -427,7 +427,7 @@

e2function void entity:propMakePersistent(number persistent)
if not ValidAction(self, this, "persist") then return end
if GetConVarString("sbox_persist") == "0" then return end

Check warning on line 430 in lua/entities/gmod_wire_expression2/core/custom/prop.lua

View workflow job for this annotation

GitHub Actions / lint

"Deprecated"

Deprecated: Use ConVar objects instead
if not gamemode.Call("CanProperty", self.player, "persist", this) then return end
this:SetPersistent(persistent ~= 0)
end
Expand Down Expand Up @@ -497,6 +497,7 @@
end
end

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

e2function void bone:boneManipulate(vector pos, angle rot, isFrozen, gravity, collision)
Expand Down Expand Up @@ -828,6 +829,62 @@
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
Loading