Reworked repo a little

Added a new 'dev' branch for trying out stuff, not guaranteed to be
stable
Added files for use with workshop
This commit is contained in:
David Hepworth 2013-04-15 18:40:45 +01:00
parent 48b54348cc
commit 825c612ac6
6 changed files with 579 additions and 611 deletions

View File

@ -1,13 +1,13 @@
Copyright (C) 2013 David 'Falcqn' Hepworth
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
Copyright (C) 2013 David 'Falcqn' Hepworth
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

11
addon.json Normal file
View File

@ -0,0 +1,11 @@
{
"title" : "MakeSpherical",
"type" : "tool",
"tags" : [ "fun", "build" ],
"ignore" :
[
"*.json",
"*.md",
"*.git*"
]
}

View File

@ -1,11 +0,0 @@
"AddonInfo"
{
"name" "Spherical Collisions Tool"
"version" "0.1"
"up_date" "30 June 2011"
"author_name" "Dave"
"author_url" ""
"info" "Give any prop or gmod/wire entity (ie thrusters, wheels) spherical collisions"
"override" "0"
}

View File

@ -1,327 +1,315 @@
/*
Copyright (C) 2012 David 'Falcqn' Hepworth [davidhepp2@gmail.com]
All rights not explicitly granted are reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and assosciated files
(the "software") to use the software without restriction in any and all compatible environments, regardless of whether
the use is part of a for-profit organisation or not. The software itself may UNDER NO CIRCUMSTANCES be sold, traded or
monetised in any fashion whatsoever.
The software may NOT be reuploaded to any distributor or redistributed at all unless given express written consent by all
authors and copyright holders. The software is free to modify for personal use, including but not limited to use on servers
whether they be "for-profit" organisations or not, provided that this license is left unaltered in any way.
Again, the software itself may UNDER NO CIRCUMSTANCES be sold, traded or monetised in any fashion whatsoever.
Any modifications of the software may not be distributed unless either express written consent is given by the authors and
copyright holders, or the modifications are part of a "FORK" on the website "GitHub".
The software and all of its assets included are property of their respective author(s).
The software is provided "As-Is" without warranty of any kind, express or implied, including but not limited to
the warranties of fitness for a particular purpose and noninfringement. In no event shall the authors or copyright
holders be held liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise
arising from, out of, or in connection with the software or the use of other dealings in the software.
Under no circumstances may this license be removed from any of the Software's files, documentation or code.
*/
AddCSLuaFile( "MakeSphericalCore.lua" )
MakeSpherical = MakeSpherical or {}
local MakeSpherical = MakeSpherical
function MakeSpherical.CanTool( ent )
if (
not ent:IsValid()
or string.find( ent:GetClass(), "npc_" ) or ( ent:GetClass() == "player" )
or string.find( ent:GetClass(), "prop_vehicle_" )
or ( ent:GetClass() == "prop_ragdoll" )
or ( ent:GetMoveType() ~= MOVETYPE_VPHYSICS )
or ( SERVER && not ent:GetPhysicsObject():IsValid() ) )
then return false
end
return true
end
if SERVER then
MakeSpherical.RenderOffsetEnts = {}
function MakeSpherical.ApplyLegacySphere( ply, ent, data )
local obb = ent:OBBMaxs() - ent:OBBMins()
ent.noradius = ent.noradius or math.max( obb.x, obb.y, obb.z ) / 2
-- This is the default radius used when left-clicked with the tool, not set by the slider.
-- It needs to be stored on the entity because it cannot be calculated after the radius has been set manually
-- The ent's OBB size changes when made spherical
-- In case the legacy dupe is old enough to not include these
data.mass = ent:GetPhysicsObject():GetMass() or data.mass
data.noradius = data.noradius or ent.noradius
data.isrenderoffset = 0
data.renderoffset = nil
data.obbcenter = ent:OBBCenter()
local phys = ent:GetPhysicsObject()
local ismove = phys:IsMoveable()
local issleep = phys:IsAsleep()
local radius = math.Clamp( data.radius, 1, 200 )
if data.enabled then
ent:PhysicsInitSphere( radius, phys:GetMaterial() )
ent:SetCollisionBounds( Vector( -radius, -radius, -radius ), Vector( radius, radius, radius ) )
else
ent:PhysicsInit( SOLID_VPHYSICS )
ent:SetMoveType( MOVETYPE_VPHYSICS )
ent:SetSolid( SOLID_VPHYSICS )
end
-- New physobject after applying spherical collisions
local phys = ent:GetPhysicsObject()
phys:SetMass( data.mass )
phys:EnableMotion( ismove )
if not issleep then phys:Wake() end
ent.noradius = data.noradius
ent.obbcenter = data.obbcenter
duplicator.StoreEntityModifier( ent, "MakeSphericalCollisions", data )
duplicator.ClearEntityModifier( ent, "sphere" )
end
function MakeSpherical.ApplySphericalCollisions( ply, ent, data )
local phys = ent:GetPhysicsObject()
local ismove = phys:IsMoveable()
local issleep = phys:IsAsleep()
local radius = math.Clamp( data.radius, 1, 200 )
if data.enabled then
ent:PhysicsInitSphere( radius, phys:GetMaterial() )
ent:SetCollisionBounds( Vector( -radius, -radius, -radius ) , Vector( radius, radius, radius ) )
else
ent:PhysicsInit( SOLID_VPHYSICS )
ent:SetMoveType( MOVETYPE_VPHYSICS )
ent:SetSolid( SOLID_VPHYSICS )
end
if data.isrenderoffset ~= 0 then
umsg.Start( "MakeSphericalAddRenderOffset" )
umsg.Short( ent:EntIndex() )
umsg.Vector( data.renderoffset )
umsg.End()
MakeSpherical.RenderOffsetEnts[ ent:EntIndex() ] = data.renderoffset
elseif data.isrenderoffset == 0 and MakeSpherical.RenderOffsetEnts[ ent:EntIndex() ] then
umsg.Start( "MakeSphericalRemoveRenderOffset" )
umsg.Short( ent:EntIndex() )
umsg.End()
end
-- New physobject after applying spherical collisions
local phys = ent:GetPhysicsObject()
phys:SetMass( data.mass )
phys:EnableMotion( ismove )
if not issleep then phys:Wake() end
data.radius = radius
ent.noradius = data.noradius
duplicator.StoreEntityModifier( ent, "MakeSphericalCollisions", data )
end
function MakeSpherical.ApplySphericalCollisionsE2( ent, enabled, radius )
local phys = ent:GetPhysicsObject()
local mass = phys:GetMass()
local ismove = phys:IsMoveable()
local issleep = phys:IsAsleep()
local radius = math.Clamp( radius, 1, 200 )
if enabled then
ent:PhysicsInitSphere( radius, phys:GetMaterial() )
ent:SetCollisionBounds( Vector( -radius, -radius, -radius ) , Vector( radius, radius, radius ) )
else
ent:PhysicsInit( SOLID_VPHYSICS )
ent:SetMoveType( MOVETYPE_VPHYSICS )
ent:SetSolid( SOLID_VPHYSICS )
end
-- New physobject after applying spherical collisions
local phys = ent:GetPhysicsObject()
phys:SetMass( mass )
phys:EnableMotion( ismove )
if not issleep then phys:Wake() end
end
function MakeSpherical.CopyConstraintData( ent, removeconstraints )
local constraintdata = {}
for _, v in pairs( constraint.GetTable( ent ) ) do
table.insert( constraintdata, v )
end
if removeconstraints then constraint.RemoveAll( ent ) end
return constraintdata
end
function MakeSpherical.ApplyConstraintData( ent, constraintdata )
if not ( table.Count( constraintdata ) > 0 and ent:IsValid() and ent:GetPhysicsObject():IsValid() ) then return end
for k, constr in pairs( constraintdata ) do
local factory = duplicator.ConstraintType[ constr.Type ]
if not factory then
Msg( "MakeSpherical: Unknown constraint type '" .. constr.Type .. "', skipping\n" )
break
end
-- Set up a table with "ent1 = Entity( n )" etc etc for use with the factory function
local args = {}
for i = 1, #factory.Args do
args[ i ] = constr[ factory.Args[ i ] ]
end
-- GG Wire team, spelling "Ctrl" wrong
-- This section is just to fix stuff like wire hydraulics that need "crontollers"
if constr.MyCrtl then
-- Apply the constraint & set all the crap wire hydraulics/winches need etc
local controller = Entity( constr.MyCrtl )
controller.constraint:Remove()
if constr.Type == "WireHydraulic" then
WireHydraulicTracking[ constr.MyCrtl ] = controller
elseif constr.Type == "WireWinch" then
WireWinchTracking[ constr.MyCrtl ] = controller
end
end
-- Apply the constraint
local constr, misc = factory.Func( unpack( args ) )
-- Wheels need their ent.Motor value set to their motor constraint
if ent:GetClass() == "gmod_wheel" or ent:GetClass() == "gmod_wire_wheel" then
ent.Motor = constr
end
end
end
hook.Add( "PlayerConnected", "MakeSphericalSyncOffsetTable", function( ply )
for k, v in pairs( MakeSpherical.ApplySphericalCollisions ) do
umsg.Start( "MakeSphericalAddRenderOffset" )
umsg.Short( k )
umsg.Vector( v )
umsg.End()
end
end )
duplicator.RegisterEntityModifier( "sphere", MakeSpherical.ApplyLegacySphere )
duplicator.RegisterEntityModifier( "MakeSphericalCollisions", MakeSpherical.ApplySphericalCollisions )
end
if CLIENT then
local temp = {}
usermessage.Hook( "MakeSphericalAddRenderOffset", function( um )
local id = um:ReadShort()
local offset = um:ReadVector()
local ent = Entity( id )
if not ent:IsValid() then
temp[ id ] = offset
return
end
ent.RenderOverride = function( self )
ent:SetRenderOrigin( ent:LocalToWorld( offset ) )
ent:SetupBones()
if ent.Draw then ent:Draw() else ent:DrawModel() end
ent:SetRenderOrigin( nil )
end
end )
usermessage.Hook( "MakeSphericalRemoveRenderOffset", function( um )
local ent = Entity( um:ReadShort() )
ent.RenderOverride = nil
end )
hook.Add( "OnEntityCreated", "MakeSphericalEntityAddedDelay", function( ent )
local id = ent:EntIndex()
if not temp[ id ] then return end
ent.RenderOverride = function( self )
ent:SetRenderOrigin( offset )
ent:SetupBones()
if ent.Draw then ent:Draw() else ent:DrawModel() end
ent:SetRenderOrigin( nil )
end
temp[ id ] = nil
end )
--[[
Copyright (C) 2013 David 'Falcqn' Hepworth
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]--
AddCSLuaFile( "MakeSphericalCore.lua" )
MakeSpherical = MakeSpherical or {}
local MakeSpherical = MakeSpherical
function MakeSpherical.CanTool( ent )
if (
not ent:IsValid()
or string.find( ent:GetClass(), "npc_" ) or ( ent:GetClass() == "player" )
or string.find( ent:GetClass(), "prop_vehicle_" )
or ( ent:GetClass() == "prop_ragdoll" )
or ( ent:GetMoveType() ~= MOVETYPE_VPHYSICS )
or ( SERVER && not ent:GetPhysicsObject():IsValid() ) )
then return false
end
return true
end
if SERVER then
MakeSpherical.RenderOffsetEnts = {}
function MakeSpherical.ApplyLegacySphere( ply, ent, data )
local obb = ent:OBBMaxs() - ent:OBBMins()
ent.noradius = ent.noradius or math.max( obb.x, obb.y, obb.z ) / 2
-- This is the default radius used when left-clicked with the tool, not set by the slider.
-- It needs to be stored on the entity because it cannot be calculated after the radius has been set manually
-- The ent's OBB size changes when made spherical
-- In case the legacy dupe is old enough to not include these
data.mass = ent:GetPhysicsObject():GetMass() or data.mass
data.noradius = data.noradius or ent.noradius
data.isrenderoffset = 0
data.renderoffset = nil
data.obbcenter = ent:OBBCenter()
local phys = ent:GetPhysicsObject()
local ismove = phys:IsMoveable()
local issleep = phys:IsAsleep()
local radius = math.Clamp( data.radius, 1, 200 )
if data.enabled then
ent:PhysicsInitSphere( radius, phys:GetMaterial() )
ent:SetCollisionBounds( Vector( -radius, -radius, -radius ), Vector( radius, radius, radius ) )
else
ent:PhysicsInit( SOLID_VPHYSICS )
ent:SetMoveType( MOVETYPE_VPHYSICS )
ent:SetSolid( SOLID_VPHYSICS )
end
-- New physobject after applying spherical collisions
local phys = ent:GetPhysicsObject()
phys:SetMass( data.mass )
phys:EnableMotion( ismove )
if not issleep then phys:Wake() end
ent.noradius = data.noradius
ent.obbcenter = data.obbcenter
duplicator.StoreEntityModifier( ent, "MakeSphericalCollisions", data )
duplicator.ClearEntityModifier( ent, "sphere" )
end
function MakeSpherical.ApplySphericalCollisions( ply, ent, data )
local phys = ent:GetPhysicsObject()
local ismove = phys:IsMoveable()
local issleep = phys:IsAsleep()
local radius = math.Clamp( data.radius, 1, 200 )
if data.enabled then
ent:PhysicsInitSphere( radius, phys:GetMaterial() )
ent:SetCollisionBounds( Vector( -radius, -radius, -radius ) , Vector( radius, radius, radius ) )
else
ent:PhysicsInit( SOLID_VPHYSICS )
ent:SetMoveType( MOVETYPE_VPHYSICS )
ent:SetSolid( SOLID_VPHYSICS )
end
if data.isrenderoffset ~= 0 then
umsg.Start( "MakeSphericalAddRenderOffset" )
umsg.Short( ent:EntIndex() )
umsg.Vector( data.renderoffset )
umsg.End()
MakeSpherical.RenderOffsetEnts[ ent:EntIndex() ] = data.renderoffset
elseif data.isrenderoffset == 0 and MakeSpherical.RenderOffsetEnts[ ent:EntIndex() ] then
umsg.Start( "MakeSphericalRemoveRenderOffset" )
umsg.Short( ent:EntIndex() )
umsg.End()
end
-- New physobject after applying spherical collisions
local phys = ent:GetPhysicsObject()
phys:SetMass( data.mass )
phys:EnableMotion( ismove )
if not issleep then phys:Wake() end
data.radius = radius
ent.noradius = data.noradius
duplicator.StoreEntityModifier( ent, "MakeSphericalCollisions", data )
end
function MakeSpherical.ApplySphericalCollisionsE2( ent, enabled, radius )
local phys = ent:GetPhysicsObject()
local mass = phys:GetMass()
local ismove = phys:IsMoveable()
local issleep = phys:IsAsleep()
local radius = math.Clamp( radius, 1, 200 )
if enabled then
ent:PhysicsInitSphere( radius, phys:GetMaterial() )
ent:SetCollisionBounds( Vector( -radius, -radius, -radius ) , Vector( radius, radius, radius ) )
else
ent:PhysicsInit( SOLID_VPHYSICS )
ent:SetMoveType( MOVETYPE_VPHYSICS )
ent:SetSolid( SOLID_VPHYSICS )
end
-- New physobject after applying spherical collisions
local phys = ent:GetPhysicsObject()
phys:SetMass( mass )
phys:EnableMotion( ismove )
if not issleep then phys:Wake() end
end
function MakeSpherical.CopyConstraintData( ent, removeconstraints )
local constraintdata = {}
for _, v in pairs( constraint.GetTable( ent ) ) do
table.insert( constraintdata, v )
end
if removeconstraints then constraint.RemoveAll( ent ) end
return constraintdata
end
function MakeSpherical.ApplyConstraintData( ent, constraintdata )
if not ( table.Count( constraintdata ) > 0 and ent:IsValid() and ent:GetPhysicsObject():IsValid() ) then return end
for k, constr in pairs( constraintdata ) do
local factory = duplicator.ConstraintType[ constr.Type ]
if not factory then
Msg( "MakeSpherical: Unknown constraint type '" .. constr.Type .. "', skipping\n" )
break
end
-- Set up a table with "ent1 = Entity( n )" etc etc for use with the factory function
local args = {}
for i = 1, #factory.Args do
args[ i ] = constr[ factory.Args[ i ] ]
end
-- GG Wire team, spelling "Ctrl" wrong
-- This section is just to fix stuff like wire hydraulics that need "crontollers"
if constr.MyCrtl then
-- Apply the constraint & set all the crap wire hydraulics/winches need etc
local controller = Entity( constr.MyCrtl )
controller.constraint:Remove()
if constr.Type == "WireHydraulic" then
WireHydraulicTracking[ constr.MyCrtl ] = controller
elseif constr.Type == "WireWinch" then
WireWinchTracking[ constr.MyCrtl ] = controller
end
end
-- Apply the constraint
local constr, misc = factory.Func( unpack( args ) )
-- Wheels need their ent.Motor value set to their motor constraint
if ent:GetClass() == "gmod_wheel" or ent:GetClass() == "gmod_wire_wheel" then
ent.Motor = constr
end
end
end
hook.Add( "PlayerConnected", "MakeSphericalSyncOffsetTable", function( ply )
for k, v in pairs( MakeSpherical.ApplySphericalCollisions ) do
umsg.Start( "MakeSphericalAddRenderOffset" )
umsg.Short( k )
umsg.Vector( v )
umsg.End()
end
end )
duplicator.RegisterEntityModifier( "sphere", MakeSpherical.ApplyLegacySphere )
duplicator.RegisterEntityModifier( "MakeSphericalCollisions", MakeSpherical.ApplySphericalCollisions )
end
if CLIENT then
local temp = {}
usermessage.Hook( "MakeSphericalAddRenderOffset", function( um )
local id = um:ReadShort()
local offset = um:ReadVector()
local ent = Entity( id )
if not ent:IsValid() then
temp[ id ] = offset
return
end
ent.RenderOverride = function( self )
ent:SetRenderOrigin( ent:LocalToWorld( offset ) )
ent:SetupBones()
if ent.Draw then ent:Draw() else ent:DrawModel() end
ent:SetRenderOrigin( nil )
end
end )
usermessage.Hook( "MakeSphericalRemoveRenderOffset", function( um )
local ent = Entity( um:ReadShort() )
ent.RenderOverride = nil
end )
hook.Add( "OnEntityCreated", "MakeSphericalEntityAddedDelay", function( ent )
local id = ent:EntIndex()
if not temp[ id ] then return end
ent.RenderOverride = function( self )
ent:SetRenderOrigin( offset )
ent:SetupBones()
if ent.Draw then ent:Draw() else ent:DrawModel() end
ent:SetRenderOrigin( nil )
end
temp[ id ] = nil
end )
end

View File

@ -1,49 +1,39 @@
/*
Copyright (C) 2012 David 'Falcqn' Hepworth [davidhepp2@gmail.com]
All rights not explicitly granted are reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and assosciated files
(the "software") to use the software without restriction in any and all compatible environments, regardless of whether
the use is part of a for-profit organisation or not. The software itself may UNDER NO CIRCUMSTANCES be sold, traded or
monetised in any fashion whatsoever.
The software may NOT be reuploaded to any distributor or redistributed at all unless given express written consent by all
authors and copyright holders. The software is free to modify for personal use, including but not limited to use on servers
whether they be "for-profit" organisations or not, provided that this license is left unaltered in any way.
Again, the software itself may UNDER NO CIRCUMSTANCES be sold, traded or monetised in any fashion whatsoever.
Any modifications of the software may not be distributed unless either express written consent is given by the authors and
copyright holders, or the modifications are part of a "FORK" on the website "GitHub".
The software and all of its assets included are property of their respective author(s).
The software is provided "As-Is" without warranty of any kind, express or implied, including but not limited to
the warranties of fitness for a particular purpose and noninfringement. In no event shall the authors or copyright
holders be held liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise
arising from, out of, or in connection with the software or the use of other dealings in the software.
Under no circumstances may this license be removed from any of the Software's files, documentation or code.
*/
MakeSpherical = MakeSpherical or {}
local MakeSpherical = MakeSpherical
e2function void entity:makeSpherical( number radius )
if not MakeSpherical.CanTool( this ) then return false end
local constraintdata = MakeSpherical.CopyConstraintData( this, true )
MakeSpherical.ApplySphericalCollisionsE2( this, true, radius, nil )
timer.Simple( 0.01, function() MakeSpherical.ApplyConstraintData( this, constraintdata ) end )
end
e2function void entity:removeSpherical()
if not MakeSpherical.CanTool( this ) then return false end
local constraintdata = MakeSpherical.CopyConstraintData( this, true )
MakeSpherical.ApplySphericalCollisionsE2( this, false, 0, nil )
timer.Simple( 0.01, function() MakeSpherical.ApplyConstraintData( this, constraintdata ) end )
--[[
Copyright (C) 2013 David 'Falcqn' Hepworth
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]--
MakeSpherical = MakeSpherical or {}
local MakeSpherical = MakeSpherical
e2function void entity:makeSpherical( number radius )
if not MakeSpherical.CanTool( this ) then return false end
local constraintdata = MakeSpherical.CopyConstraintData( this, true )
MakeSpherical.ApplySphericalCollisionsE2( this, true, radius, nil )
timer.Simple( 0.01, function() MakeSpherical.ApplyConstraintData( this, constraintdata ) end )
end
e2function void entity:removeSpherical()
if not MakeSpherical.CanTool( this ) then return false end
local constraintdata = MakeSpherical.CopyConstraintData( this, true )
MakeSpherical.ApplySphericalCollisionsE2( this, false, 0, nil )
timer.Simple( 0.01, function() MakeSpherical.ApplyConstraintData( this, constraintdata ) end )
end

View File

@ -1,215 +1,205 @@
/*
Copyright (C) 2012 David 'Falcqn' Hepworth [davidhepp2@gmail.com]
All rights not explicitly granted are reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and assosciated files
(the "software") to use the software without restriction in any and all compatible environments, regardless of whether
the use is part of a for-profit organisation or not. The software itself may UNDER NO CIRCUMSTANCES be sold, traded or
monetised in any fashion whatsoever.
The software may NOT be reuploaded to any distributor or redistributed at all unless given express written consent by all
authors and copyright holders. The software is free to modify for personal use, including but not limited to use on servers
whether they be "for-profit" organisations or not, provided that this license is left unaltered in any way.
Again, the software itself may UNDER NO CIRCUMSTANCES be sold, traded or monetised in any fashion whatsoever.
Any modifications of the software may not be distributed unless either express written consent is given by the authors and
copyright holders, or the modifications are part of a "FORK" on the website "GitHub".
The software and all of its assets included are property of their respective author(s).
The software is provided "As-Is" without warranty of any kind, express or implied, including but not limited to
the warranties of fitness for a particular purpose and noninfringement. In no event shall the authors or copyright
holders be held liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise
arising from, out of, or in connection with the software or the use of other dealings in the software.
Under no circumstances may this license be removed from any of the Software's files, documentation or code.
*/
AddCSLuaFile( "makespherical.lua" )
TOOL.Category = "Construction"
TOOL.Name = "#tool.makespherical.name"
TOOL.Command = nil
TOOL.ConfigName = nil
TOOL.ClientConVar[ "radius" ] = "20"
TOOL.ClientConVar[ "offset" ] = "0"
TOOL.ClientConVar[ "offset_x" ] = "0"
TOOL.ClientConVar[ "offset_y" ] = "0"
TOOL.ClientConVar[ "offset_z" ] = "0"
TOOL.ClientConVar[ "useobbcenter" ] = "0"
if CLIENT then
language.Add( "tool.makespherical.name", "Spherical Collisions" )
language.Add( "tool.makespherical.desc", "Gives entities a spherical collisions with a defined radius" )
language.Add( "tool.makespherical.0", "Left click to make an entity have spherical collisions based on its size. Right click to set collisions with a custom radius" )
language.Add( "tool.makespherical.1", "Left click to make an entity have spherical collisions based on its size. Right click to set collisions with a custom radius" )
function TOOL.BuildCPanel( panel )
panel:AddControl( "Header", { Text = "#tool.makespherical.name", Description = "#tool.makespherical.desc" } )
panel:AddControl( "Slider",
{
Label = "Set radius: ",
Type = "Float",
Min = "1",
Max = "200",
Command = "makespherical_radius"
})
panel:AddControl( "CheckBox",
{
Label = "Offset render origin?",
Command = "makespherical_offset"
})
panel:AddControl( "Label",
{
Text = "Note: This only changes the position the prop's model is drawn at, getting the position or bounding box center in Lua or in "
.. "E2 will give the exact same coordinates.\nThe prop's position will still be the center of the sphere."
})
panel:AddControl( "Slider",
{
Label = "X Offset",
Type = "Float",
Min = "-100",
Max = "100",
Command = "makespherical_offset_x"
})
panel:AddControl( "Slider",
{
Label = "Y Offset",
Type = "Float",
Min = "-100",
Max = "100",
Command = "makespherical_offset_y"
})
panel:AddControl( "Slider",
{
Label = "Z Offset",
Type = "Float",
Min = "-100",
Max = "100",
Command = "makespherical_offset_z"
})
panel:AddControl( "CheckBox",
{
Label = "Offset position by bounding box center instead",
Command = "makespherical_useobbcenter"
})
end
end
function TOOL:LeftClick( trace )
local ent = trace.Entity
if not MakeSpherical.CanTool( ent ) then return false end
if CLIENT then return true end
if not ent.noradius then
local OBB = ent:OBBMaxs() - ent:OBBMins()
ent.noradius = math.max( OBB.x, OBB.y, OBB.z) / 2
end
ent.obbcenter = ent.obbcenter or ent:OBBCenter()
local offsetvec = Vector( self:GetClientNumber( "offset_x" ), self:GetClientNumber( "offset_y" ), self:GetClientNumber( "offset_z" ) )
local data =
{
// I store the obbcenter and "obb radius" because they are altered when SetCollisionBounds is used
// This allows the spherical collisions to be reset even after duping
obbcenter = ent.obbcenter,
noradius = ent.noradius,
radius = ent.noradius,
mass = ent:GetPhysicsObject():GetMass(),
enabled = true,
isrenderoffset = self:GetClientNumber( "offset" ),
renderoffset = ( self:GetClientNumber( "useobbcenter" ) == 1 ) and -ent.obbcenter or offsetvec
}
local constraintdata = MakeSpherical.CopyConstraintData( ent, true )
MakeSpherical.ApplySphericalCollisions( self:GetOwner(), ent, data )
timer.Simple( 0.01, function() MakeSpherical.ApplyConstraintData( ent, constraintdata ) end )
return true
end
function TOOL:RightClick( trace )
local ent = trace.Entity
if not MakeSpherical.CanTool( ent ) then return false end
if CLIENT then return true end
if not ent.noradius then
local OBB = ent:OBBMaxs() - ent:OBBMins()
ent.noradius = math.max( OBB.x, OBB.y, OBB.z) / 2
end
ent.obbcenter = ent.obbcenter or ent:OBBCenter()
local offsetvec = Vector( self:GetClientNumber( "offset_x" ), self:GetClientNumber( "offset_y" ), self:GetClientNumber( "offset_z" ) )
local data =
{
obbcenter = ent.obbcenter,
noradius = ent.noradius,
radius = self:GetClientNumber( "radius" ),
mass = ent:GetPhysicsObject():GetMass(),
enabled = true,
isrenderoffset = self:GetClientNumber( "offset" ),
renderoffset = ( self:GetClientNumber( "useobbcenter" ) == 1 ) and -ent.obbcenter or offsetvec
}
local constraintdata = MakeSpherical.CopyConstraintData( ent, true )
MakeSpherical.ApplySphericalCollisions( self:GetOwner(), ent, data )
timer.Simple( 0.01, function() MakeSpherical.ApplyConstraintData( ent, constraintdata ) end )
return true
end
function TOOL:Reload( trace )
local ent = trace.Entity
if not MakeSpherical.CanTool( ent ) then return false end
if CLIENT then return true end
if not ent.noradius then
local OBB = ent:OBBMaxs() - ent:OBBMins()
ent.noradius = math.max( OBB.x, OBB.y, OBB.z) / 2
end
ent.obbcenter = ent.obbcenter or ent:OBBCenter()
local data =
{
obbcenter = ent.obbcenter,
noradius = ent.noradius,
radius = ent.noradius,
mass = ent:GetPhysicsObject():GetMass(),
enabled = false,
isrenderoffset = 0,
renderoffset = nil
}
local constraintdata = MakeSpherical.CopyConstraintData( ent, true )
MakeSpherical.ApplySphericalCollisions( self:GetOwner(), ent, data )
timer.Simple( 0.01, function() MakeSpherical.ApplyConstraintData( ent, constraintdata ) end )
return true
--[[
Copyright (C) 2013 David 'Falcqn' Hepworth
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]--
AddCSLuaFile( "makespherical.lua" )
TOOL.Category = "Construction"
TOOL.Name = "#tool.makespherical.name"
TOOL.Command = nil
TOOL.ConfigName = nil
TOOL.ClientConVar[ "radius" ] = "20"
TOOL.ClientConVar[ "offset" ] = "0"
TOOL.ClientConVar[ "offset_x" ] = "0"
TOOL.ClientConVar[ "offset_y" ] = "0"
TOOL.ClientConVar[ "offset_z" ] = "0"
TOOL.ClientConVar[ "useobbcenter" ] = "0"
if CLIENT then
language.Add( "tool.makespherical.name", "Spherical Collisions" )
language.Add( "tool.makespherical.desc", "Gives entities a spherical collisions with a defined radius" )
language.Add( "tool.makespherical.0", "Left click to make an entity have spherical collisions based on its size. Right click to set collisions with a custom radius" )
language.Add( "tool.makespherical.1", "Left click to make an entity have spherical collisions based on its size. Right click to set collisions with a custom radius" )
function TOOL.BuildCPanel( panel )
panel:AddControl( "Header", { Text = "#tool.makespherical.name", Description = "#tool.makespherical.desc" } )
panel:AddControl( "Slider",
{
Label = "Set radius: ",
Type = "Float",
Min = "1",
Max = "200",
Command = "makespherical_radius"
})
panel:AddControl( "CheckBox",
{
Label = "Offset render origin?",
Command = "makespherical_offset"
})
panel:AddControl( "Label",
{
Text = "Note: This only changes the position the prop's model is drawn at, getting the position or bounding box center in Lua or in "
.. "E2 will give the exact same coordinates.\nThe prop's position will still be the center of the sphere."
})
panel:AddControl( "Slider",
{
Label = "X Offset",
Type = "Float",
Min = "-100",
Max = "100",
Command = "makespherical_offset_x"
})
panel:AddControl( "Slider",
{
Label = "Y Offset",
Type = "Float",
Min = "-100",
Max = "100",
Command = "makespherical_offset_y"
})
panel:AddControl( "Slider",
{
Label = "Z Offset",
Type = "Float",
Min = "-100",
Max = "100",
Command = "makespherical_offset_z"
})
panel:AddControl( "CheckBox",
{
Label = "Offset position by bounding box center instead",
Command = "makespherical_useobbcenter"
})
end
end
function TOOL:LeftClick( trace )
local ent = trace.Entity
if not MakeSpherical.CanTool( ent ) then return false end
if CLIENT then return true end
if not ent.noradius then
local OBB = ent:OBBMaxs() - ent:OBBMins()
ent.noradius = math.max( OBB.x, OBB.y, OBB.z) / 2
end
ent.obbcenter = ent.obbcenter or ent:OBBCenter()
local offsetvec = Vector( self:GetClientNumber( "offset_x" ), self:GetClientNumber( "offset_y" ), self:GetClientNumber( "offset_z" ) )
local data =
{
// I store the obbcenter and "obb radius" because they are altered when SetCollisionBounds is used
// This allows the spherical collisions to be reset even after duping
obbcenter = ent.obbcenter,
noradius = ent.noradius,
radius = ent.noradius,
mass = ent:GetPhysicsObject():GetMass(),
enabled = true,
isrenderoffset = self:GetClientNumber( "offset" ),
renderoffset = ( self:GetClientNumber( "useobbcenter" ) == 1 ) and -ent.obbcenter or offsetvec
}
local constraintdata = MakeSpherical.CopyConstraintData( ent, true )
MakeSpherical.ApplySphericalCollisions( self:GetOwner(), ent, data )
timer.Simple( 0.01, function() MakeSpherical.ApplyConstraintData( ent, constraintdata ) end )
return true
end
function TOOL:RightClick( trace )
local ent = trace.Entity
if not MakeSpherical.CanTool( ent ) then return false end
if CLIENT then return true end
if not ent.noradius then
local OBB = ent:OBBMaxs() - ent:OBBMins()
ent.noradius = math.max( OBB.x, OBB.y, OBB.z) / 2
end
ent.obbcenter = ent.obbcenter or ent:OBBCenter()
local offsetvec = Vector( self:GetClientNumber( "offset_x" ), self:GetClientNumber( "offset_y" ), self:GetClientNumber( "offset_z" ) )
local data =
{
obbcenter = ent.obbcenter,
noradius = ent.noradius,
radius = self:GetClientNumber( "radius" ),
mass = ent:GetPhysicsObject():GetMass(),
enabled = true,
isrenderoffset = self:GetClientNumber( "offset" ),
renderoffset = ( self:GetClientNumber( "useobbcenter" ) == 1 ) and -ent.obbcenter or offsetvec
}
local constraintdata = MakeSpherical.CopyConstraintData( ent, true )
MakeSpherical.ApplySphericalCollisions( self:GetOwner(), ent, data )
timer.Simple( 0.01, function() MakeSpherical.ApplyConstraintData( ent, constraintdata ) end )
return true
end
function TOOL:Reload( trace )
local ent = trace.Entity
if not MakeSpherical.CanTool( ent ) then return false end
if CLIENT then return true end
if not ent.noradius then
local OBB = ent:OBBMaxs() - ent:OBBMins()
ent.noradius = math.max( OBB.x, OBB.y, OBB.z) / 2
end
ent.obbcenter = ent.obbcenter or ent:OBBCenter()
local data =
{
obbcenter = ent.obbcenter,
noradius = ent.noradius,
radius = ent.noradius,
mass = ent:GetPhysicsObject():GetMass(),
enabled = false,
isrenderoffset = 0,
renderoffset = nil
}
local constraintdata = MakeSpherical.CopyConstraintData( ent, true )
MakeSpherical.ApplySphericalCollisions( self:GetOwner(), ent, data )
timer.Simple( 0.01, function() MakeSpherical.ApplyConstraintData( ent, constraintdata ) end )
return true
end