A
This commit is contained in:
parent
8d7d399af5
commit
b5c524705b
@ -62,7 +62,7 @@ local Colors =
|
|||||||
ReverseLights = Color(120,120,120),
|
ReverseLights = Color(120,120,120),
|
||||||
RearLightsGlass = Color(150,40,40),
|
RearLightsGlass = Color(150,40,40),
|
||||||
FrontLightsBase = Color(30,30,30),
|
FrontLightsBase = Color(30,30,30),
|
||||||
FrontLights = Color(10,10,10),
|
FrontLights = Color(50,50,50),
|
||||||
FrontLightsGlass = Color(140,140,140),
|
FrontLightsGlass = Color(140,140,140),
|
||||||
Floor = Color(50,50,50),
|
Floor = Color(50,50,50),
|
||||||
Dashboard = Color(50,50,50),
|
Dashboard = Color(50,50,50),
|
||||||
@ -170,19 +170,8 @@ if SERVER then
|
|||||||
|
|
||||||
local result = builder:getResult()
|
local result = builder:getResult()
|
||||||
else
|
else
|
||||||
function init()
|
PERMA.onPermissionsGained = function()
|
||||||
builder = MeshBuilder:new(LINK)
|
builder = MeshBuilder:new(LINK)
|
||||||
end
|
end
|
||||||
|
PERMA.build()
|
||||||
if hasPermission("http.get") and hasPermission("mesh") and hasPermission("entities.setRenderProperty", chip()) then
|
|
||||||
init()
|
|
||||||
else
|
|
||||||
setupPermissionRequest({"http.get", "mesh", "entities.setRenderProperty"}, "", true)
|
|
||||||
|
|
||||||
hook.add("permissionrequest", "_permissionrequest", function()
|
|
||||||
if permissionRequestSatisfied() then
|
|
||||||
init()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -52,19 +52,8 @@ if SERVER then
|
|||||||
|
|
||||||
local result = builder:getResult()
|
local result = builder:getResult()
|
||||||
else
|
else
|
||||||
function init()
|
PERMA.onPermissionsGained = function()
|
||||||
builder = MeshBuilder:new(LINK)
|
builder = MeshBuilder:new(LINK)
|
||||||
end
|
end
|
||||||
|
PERMA.build()
|
||||||
if hasPermission("http.get") and hasPermission("mesh") and hasPermission("entities.setRenderProperty", chip()) then
|
|
||||||
init()
|
|
||||||
else
|
|
||||||
setupPermissionRequest({"http.get", "mesh", "entities.setRenderProperty"}, "", true)
|
|
||||||
|
|
||||||
hook.add("permissionrequest", "_permissionrequest", function()
|
|
||||||
if permissionRequestSatisfied() then
|
|
||||||
init()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -25,19 +25,8 @@ if SERVER then
|
|||||||
|
|
||||||
builder:getResult()
|
builder:getResult()
|
||||||
else
|
else
|
||||||
function init()
|
PERMA.onPermissionsGained = function()
|
||||||
builder = MeshBuilder:new(LINK)
|
builder = MeshBuilder:new(LINK)
|
||||||
end
|
end
|
||||||
|
PERMA.build()
|
||||||
if hasPermission("http.get") and hasPermission("mesh") and hasPermission("entities.setRenderProperty", chip()) then
|
|
||||||
init()
|
|
||||||
else
|
|
||||||
setupPermissionRequest({"http.get", "mesh", "entities.setRenderProperty"}, "", true)
|
|
||||||
|
|
||||||
hook.add("permissionrequest", "_permissionrequest", function()
|
|
||||||
if permissionRequestSatisfied() then
|
|
||||||
init()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -24,19 +24,8 @@ if SERVER then
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
function init()
|
PERMA.onPermissionsGained = function()
|
||||||
builder = MeshBuilder:new(LINK)
|
builder = MeshBuilder:new(LINK)
|
||||||
end
|
end
|
||||||
|
PERMA.build()
|
||||||
if hasPermission("http.get") and hasPermission("mesh") and hasPermission("entities.setRenderProperty", chip()) then
|
|
||||||
init()
|
|
||||||
else
|
|
||||||
setupPermissionRequest({"http.get", "mesh", "entities.setRenderProperty"}, "", true)
|
|
||||||
|
|
||||||
hook.add("permissionrequest", "_permissionrequest", function()
|
|
||||||
if permissionRequestSatisfied() then
|
|
||||||
init()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
-- @include /koptilnya/mesh_loader/builder.txt
|
-- @include /koptilnya/mesh_loader/builder.txt
|
||||||
require("/koptilnya/mesh_loader/builder.txt")
|
require("/koptilnya/mesh_loader/builder.txt")
|
||||||
|
|
||||||
local LINK = "https://www.dropbox.com/s/x2esgnl33i8if2w/vaz2106.obj?dl=1"
|
local LINK = "https://raw.githubusercontent.com/koptilnya/gmod-data/main/vaz2106.obj"
|
||||||
local SCALE = Vector(0.9)
|
local SCALE = Vector(0.9)
|
||||||
local MATERIALS = {
|
local MATERIALS = {
|
||||||
Exterior = "phoenix_storms/mrref2",
|
Exterior = "phoenix_storms/mrref2",
|
||||||
@ -70,7 +70,6 @@ if SERVER then
|
|||||||
|
|
||||||
builder:build("Body__Exterior", Vector(0), Angle(0), SCALE, COLORS.Exterior, MATERIALS.Exterior, chip(), chip())
|
builder:build("Body__Exterior", Vector(0), Angle(0), SCALE, COLORS.Exterior, MATERIALS.Exterior, chip(), chip())
|
||||||
|
|
||||||
builder:build("Glass", Vector(0), Angle(0), SCALE, COLORS.Glass, MATERIALS.Glass, chip(), chip())
|
|
||||||
builder:build("Body__WindowsLine__Rubber", Vector(0), Angle(0), SCALE, COLORS.Insulation, MATERIALS.Insulation, chip(), chip())
|
builder:build("Body__WindowsLine__Rubber", Vector(0), Angle(0), SCALE, COLORS.Insulation, MATERIALS.Insulation, chip(), chip())
|
||||||
builder:build("Body__TrunkLine__Rubber", Vector(0), Angle(0), SCALE, COLORS.Insulation, MATERIALS.Insulation, chip(), chip())
|
builder:build("Body__TrunkLine__Rubber", Vector(0), Angle(0), SCALE, COLORS.Insulation, MATERIALS.Insulation, chip(), chip())
|
||||||
|
|
||||||
@ -154,21 +153,12 @@ if SERVER then
|
|||||||
builder:build("RightRearDoor__Interior__DoorInterior", Vector(0), Angle(0), SCALE, COLORS.DoorInterior, MATERIALS.DoorInterior, chip(), chip())
|
builder:build("RightRearDoor__Interior__DoorInterior", Vector(0), Angle(0), SCALE, COLORS.DoorInterior, MATERIALS.DoorInterior, chip(), chip())
|
||||||
builder:build("RightRearDoor__Handle__Chrome", Vector(0), Angle(0), SCALE, COLORS.DoorHandle, MATERIALS.DoorHandle, chip(), chip())
|
builder:build("RightRearDoor__Handle__Chrome", Vector(0), Angle(0), SCALE, COLORS.DoorHandle, MATERIALS.DoorHandle, chip(), chip())
|
||||||
|
|
||||||
|
builder:build("Glass", Vector(0), Angle(0), SCALE, COLORS.Glass, MATERIALS.Glass, chip(), chip())
|
||||||
|
|
||||||
builder:getResult()
|
builder:getResult()
|
||||||
else
|
else
|
||||||
function init()
|
PERMA.onPermissionsGained = function()
|
||||||
builder = MeshBuilder:new(LINK)
|
builder = MeshBuilder:new(LINK)
|
||||||
end
|
end
|
||||||
|
PERMA.build()
|
||||||
if hasPermission("http.get") and hasPermission("mesh") and hasPermission("entities.setRenderProperty", chip()) then
|
|
||||||
init()
|
|
||||||
else
|
|
||||||
setupPermissionRequest({"http.get", "mesh", "entities.setRenderProperty"}, "", true)
|
|
||||||
|
|
||||||
hook.add("permissionrequest", "_permissionrequest", function()
|
|
||||||
if permissionRequestSatisfied() then
|
|
||||||
init()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -13,10 +13,10 @@ local CONFIG = {
|
|||||||
},
|
},
|
||||||
Clutch = {
|
Clutch = {
|
||||||
DeviceId = 0,
|
DeviceId = 0,
|
||||||
InputId = 2,
|
InputId = 7,
|
||||||
Type = JOYSTICK_INPUT_TYPE.Axis,
|
Type = JOYSTICK_INPUT_TYPE.Axis,
|
||||||
Handler = function(value)
|
Handler = function(value)
|
||||||
return math.remap(value, 0, 65535, 0, 1)
|
return math.remap(value, 0, 65535, 1, 0)
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
Throttle = {
|
Throttle = {
|
||||||
@ -24,7 +24,7 @@ local CONFIG = {
|
|||||||
InputId = 1,
|
InputId = 1,
|
||||||
Type = JOYSTICK_INPUT_TYPE.Axis,
|
Type = JOYSTICK_INPUT_TYPE.Axis,
|
||||||
Handler = function(value)
|
Handler = function(value)
|
||||||
return math.remap(value, 0, 65535, 0, 1)
|
return math.remap(value, 0, 65535, 1, 0)
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
Brake = {
|
Brake = {
|
||||||
@ -32,7 +32,7 @@ local CONFIG = {
|
|||||||
InputId = 5,
|
InputId = 5,
|
||||||
Type = JOYSTICK_INPUT_TYPE.Axis,
|
Type = JOYSTICK_INPUT_TYPE.Axis,
|
||||||
Handler = function(value)
|
Handler = function(value)
|
||||||
return math.remap(value, 0, 65535, 0, 1)
|
return math.remap(value, 0, 65535, 1, 0)
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
Handbrake = {
|
Handbrake = {
|
||||||
@ -45,7 +45,7 @@ local CONFIG = {
|
|||||||
},
|
},
|
||||||
GearUp = {
|
GearUp = {
|
||||||
DeviceId = 0,
|
DeviceId = 0,
|
||||||
InputId = 3,
|
InputId = 4,
|
||||||
Type = JOYSTICK_INPUT_TYPE.Button,
|
Type = JOYSTICK_INPUT_TYPE.Button,
|
||||||
Handler = function(value)
|
Handler = function(value)
|
||||||
return math.remap(value, 0, 128, 0, 1)
|
return math.remap(value, 0, 128, 0, 1)
|
||||||
@ -53,19 +53,75 @@ local CONFIG = {
|
|||||||
},
|
},
|
||||||
GearDown = {
|
GearDown = {
|
||||||
DeviceId = 0,
|
DeviceId = 0,
|
||||||
InputId = 0,
|
InputId = 5,
|
||||||
Type = JOYSTICK_INPUT_TYPE.Button,
|
Type = JOYSTICK_INPUT_TYPE.Button,
|
||||||
Handler = function(value)
|
Handler = function(value)
|
||||||
return math.remap(value, 0, 128, 0, 1)
|
return math.remap(value, 0, 128, 0, 1)
|
||||||
end
|
end
|
||||||
}
|
},
|
||||||
|
Gear1 = {
|
||||||
|
DeviceId = 0,
|
||||||
|
InputId = 8,
|
||||||
|
Type = JOYSTICK_INPUT_TYPE.Button,
|
||||||
|
Handler = function(value)
|
||||||
|
return math.remap(value, 0, 128, 0, 1)
|
||||||
|
end
|
||||||
|
},
|
||||||
|
Gear2 = {
|
||||||
|
DeviceId = 0,
|
||||||
|
InputId = 9,
|
||||||
|
Type = JOYSTICK_INPUT_TYPE.Button,
|
||||||
|
Handler = function(value)
|
||||||
|
return math.remap(value, 0, 128, 0, 1)
|
||||||
|
end
|
||||||
|
},
|
||||||
|
Gear3 = {
|
||||||
|
DeviceId = 0,
|
||||||
|
InputId = 10,
|
||||||
|
Type = JOYSTICK_INPUT_TYPE.Button,
|
||||||
|
Handler = function(value)
|
||||||
|
return math.remap(value, 0, 128, 0, 1)
|
||||||
|
end
|
||||||
|
},
|
||||||
|
Gear4 = {
|
||||||
|
DeviceId = 0,
|
||||||
|
InputId = 11,
|
||||||
|
Type = JOYSTICK_INPUT_TYPE.Button,
|
||||||
|
Handler = function(value)
|
||||||
|
return math.remap(value, 0, 128, 0, 1)
|
||||||
|
end
|
||||||
|
},
|
||||||
|
Gear5 = {
|
||||||
|
DeviceId = 0,
|
||||||
|
InputId = 12,
|
||||||
|
Type = JOYSTICK_INPUT_TYPE.Button,
|
||||||
|
Handler = function(value)
|
||||||
|
return math.remap(value, 0, 128, 0, 1)
|
||||||
|
end
|
||||||
|
},
|
||||||
|
Gear6 = {
|
||||||
|
DeviceId = 0,
|
||||||
|
InputId = 13,
|
||||||
|
Type = JOYSTICK_INPUT_TYPE.Button,
|
||||||
|
Handler = function(value)
|
||||||
|
return math.remap(value, 0, 128, 0, 1)
|
||||||
|
end
|
||||||
|
},
|
||||||
|
GearR = {
|
||||||
|
DeviceId = 0,
|
||||||
|
InputId = 14,
|
||||||
|
Type = JOYSTICK_INPUT_TYPE.Button,
|
||||||
|
Handler = function(value)
|
||||||
|
return math.remap(value, 0, 128, 0, 1)
|
||||||
|
end
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if CLIENT and player() == owner() then
|
if CLIENT and player() == owner() then
|
||||||
local data = {}
|
local data = {}
|
||||||
local isDirty = false
|
local isDirty = false
|
||||||
|
|
||||||
hook.add("think", "_think", function()
|
hook.add("tick", "_tick", function()
|
||||||
for k, v in pairs(CONFIG) do
|
for k, v in pairs(CONFIG) do
|
||||||
local value = 0
|
local value = 0
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
NULL_ENTITY = entity(0)
|
NULL_ENTITY = entity(0)
|
||||||
CURRENT_PLAYER = player()
|
CURRENT_PLAYER = player()
|
||||||
OWNER = owner()
|
OWNER = owner()
|
||||||
|
IS_ME = CURRENT_PLAYER == OWNER
|
||||||
TICK_INTERVAL = game.getTickInterval()
|
TICK_INTERVAL = game.getTickInterval()
|
||||||
RAD_TO_RPM = 9.5493
|
RAD_TO_RPM = 9.5493
|
||||||
93
koptilnya/libs/perma.txt
Normal file
93
koptilnya/libs/perma.txt
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
-- @include /koptilnya/libs/table.txt
|
||||||
|
-- @shared
|
||||||
|
|
||||||
|
require("/koptilnya/libs/table.txt")
|
||||||
|
|
||||||
|
if not PERMA then
|
||||||
|
PERMA = {}
|
||||||
|
|
||||||
|
if CLIENT then
|
||||||
|
PERMA.list = {}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if CLIENT then
|
||||||
|
function PERMA.add(permission)
|
||||||
|
if not table.hasValue(PERMA.list, permission) then
|
||||||
|
table.insert(PERMA.list, permission)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function PERMA.addTable(permissions)
|
||||||
|
for _, v in ipairs(permissions) do
|
||||||
|
PERMA.add(v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function PERMA.remove(permission)
|
||||||
|
table.removeByValue(PERMA.list, permission)
|
||||||
|
end
|
||||||
|
|
||||||
|
function PERMA.removeTable(permissions)
|
||||||
|
for _, v in ipairs(permissions) do
|
||||||
|
PERMA.remove(v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function PERMA.clear()
|
||||||
|
PERMA.list = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
function PERMA.check(permission)
|
||||||
|
return hasPermission(permission)
|
||||||
|
end
|
||||||
|
|
||||||
|
function PERMA.checkTable(permissions)
|
||||||
|
local prohibited = table.filter(PERMA.list, function(permission)
|
||||||
|
return not hasPermission(permission)
|
||||||
|
end)
|
||||||
|
|
||||||
|
return #prohibited == 0, prohibited
|
||||||
|
end
|
||||||
|
|
||||||
|
function PERMA:build(description)
|
||||||
|
description = description or ""
|
||||||
|
|
||||||
|
local hasAccess, prohibited = PERMA.checkTable(PERMA.list)
|
||||||
|
|
||||||
|
local function onPermissionsGained()
|
||||||
|
PERMA:onPermissionsGained()
|
||||||
|
|
||||||
|
net.start("onPermissionsGained")
|
||||||
|
net.send()
|
||||||
|
|
||||||
|
hook.remove("permissionrequest", "PERMA_permissionrequest")
|
||||||
|
end
|
||||||
|
|
||||||
|
if not hasAccess then
|
||||||
|
setupPermissionRequest(prohibited, description, true)
|
||||||
|
|
||||||
|
hook.add("permissionrequest", "PERMA_permissionrequest", function()
|
||||||
|
if permissionRequestSatisfied() then
|
||||||
|
onPermissionsGained()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
else
|
||||||
|
onPermissionsGained()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- STUB
|
||||||
|
|
||||||
|
function PERMA:onPermissionsGained()
|
||||||
|
end
|
||||||
|
else
|
||||||
|
net.receive("onPermissionsGained", function(len, ply)
|
||||||
|
PERMA:onPermissionsGained(ply)
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- STUB
|
||||||
|
|
||||||
|
function PERMA:onPermissionsGained(ply)
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -1,60 +0,0 @@
|
|||||||
-- @shared
|
|
||||||
|
|
||||||
local PERMISSIONS_BUILDER = PERMISSIONS_BUILDER or {}
|
|
||||||
|
|
||||||
if CLIENT then
|
|
||||||
PERMISSIONS_BUILDER.list = PERMISSIONS_BUILDER.list or {}
|
|
||||||
|
|
||||||
local function onPermissionsGained()
|
|
||||||
PERMISSIONS_BUILDER:onPermissionsGained()
|
|
||||||
|
|
||||||
net.start("onPermissionsGained")
|
|
||||||
net.send()
|
|
||||||
end
|
|
||||||
|
|
||||||
function PERMISSIONS_BUILDER:add(permission)
|
|
||||||
if not table.hasValue(self.list, permission) then
|
|
||||||
table.insert(self.list, permission)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function PERMISSIONS_BUILDER:build(description)
|
|
||||||
description = description or ""
|
|
||||||
|
|
||||||
local allPermissionsGained = true
|
|
||||||
for k, v in pairs(self.list) do
|
|
||||||
if not hasPermission(v) then
|
|
||||||
allPermissionsGained = false
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if allPermissionsGained then
|
|
||||||
onPermissionsGained()
|
|
||||||
else
|
|
||||||
setupPermissionRequest(self.list, description, true)
|
|
||||||
|
|
||||||
hook.add("permissionrequest", "PERMISSIONS_BUILDER_permissionrequest", function()
|
|
||||||
if permissionRequestSatisfied() then
|
|
||||||
onPermissionsGained()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- STUB
|
|
||||||
|
|
||||||
function PERMISSIONS_BUILDER:onPermissionsGained()
|
|
||||||
end
|
|
||||||
else
|
|
||||||
net.receive("onPermissionsGained", function(len, ply)
|
|
||||||
PERMISSIONS_BUILDER:onPermissionsGained(ply)
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- STUB
|
|
||||||
|
|
||||||
function PERMISSIONS_BUILDER:onPermissionsGained(ply)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return PERMISSIONS_BUILDER
|
|
||||||
@ -1,12 +1,19 @@
|
|||||||
-- @name koptilnya/libs/workers
|
-- @name koptilnya/libs/workers
|
||||||
|
|
||||||
WORKERS = {}
|
WORKERS = {}
|
||||||
WORKERS_QUOTA = 0.4
|
WORKERS_QUOTA = 0.7
|
||||||
|
|
||||||
|
local function canProcess()
|
||||||
|
local exp1 = (math.max(chip():getQuotaAverage(), chip():getQuotaUsed()) + (chip():getQuotaUsed() - math.max(chip():getQuotaAverage(), chip():getQuotaUsed())) * 0.01) / chip():getQuotaMax() < WORKERS_QUOTA
|
||||||
|
local exp2 = math.max(quotaTotalAverage(), quotaTotalUsed()) < quotaMax() * WORKERS_QUOTA
|
||||||
|
|
||||||
|
return exp1 and exp2
|
||||||
|
end
|
||||||
|
|
||||||
local function execWorker(worker)
|
local function execWorker(worker)
|
||||||
local status
|
local status
|
||||||
|
|
||||||
while math.max(quotaAverage(), quotaUsed()) < quotaMax() * WORKERS_QUOTA do
|
while canProcess() do
|
||||||
status = worker()
|
status = worker()
|
||||||
|
|
||||||
if status == 1 or status == 2 then
|
if status == 1 or status == 2 then
|
||||||
|
|||||||
@ -1,8 +1,21 @@
|
|||||||
-- @name koptilnya/mesh_loader/builder
|
-- @name koptilnya/mesh_loader/builder
|
||||||
-- @include sv_builder.txt
|
-- @include sv_builder.txt
|
||||||
-- @include cl_builder.txt
|
-- @include cl_builder.txt
|
||||||
|
-- @include /koptilnya/libs/perma.txt
|
||||||
|
|
||||||
|
require("/koptilnya/libs/perma.txt")
|
||||||
|
|
||||||
if SERVER then
|
if SERVER then
|
||||||
require("sv_builder.txt")
|
require("sv_builder.txt")
|
||||||
else
|
else
|
||||||
|
PERMA.addTable({
|
||||||
|
"http.get",
|
||||||
|
"hologram.create",
|
||||||
|
"material.create",
|
||||||
|
"material.load",
|
||||||
|
"material.urlcreate",
|
||||||
|
"mesh"
|
||||||
|
})
|
||||||
|
|
||||||
require("cl_builder.txt")
|
require("cl_builder.txt")
|
||||||
end
|
end
|
||||||
|
|||||||
@ -3,9 +3,11 @@
|
|||||||
-- @include /koptilnya/libs/table.txt
|
-- @include /koptilnya/libs/table.txt
|
||||||
-- @include obj_parser.txt
|
-- @include obj_parser.txt
|
||||||
-- @include /koptilnya/libs/utils.txt
|
-- @include /koptilnya/libs/utils.txt
|
||||||
|
-- @include /koptilnya/libs/constants.txt
|
||||||
require("/koptilnya/libs/table.txt")
|
require("/koptilnya/libs/table.txt")
|
||||||
require("obj_parser.txt")
|
require("obj_parser.txt")
|
||||||
require("/koptilnya/libs/utils.txt")
|
require("/koptilnya/libs/utils.txt")
|
||||||
|
require("/koptilnya/libs/constants.txt")
|
||||||
|
|
||||||
MeshBuilder = class("MeshBuilder")
|
MeshBuilder = class("MeshBuilder")
|
||||||
|
|
||||||
@ -14,23 +16,17 @@ function MeshBuilder:initialize(link)
|
|||||||
self.meshData = {}
|
self.meshData = {}
|
||||||
|
|
||||||
self._objects = {}
|
self._objects = {}
|
||||||
|
self._cachedMaterials = {}
|
||||||
self._parser = ObjParser:new(link)
|
self._parser = ObjParser:new(link)
|
||||||
self._parser.onLoaded = function(parser, objData)
|
self._parser.onLoaded = function(parser, objData)
|
||||||
self:onObjLoaded(objData)
|
self:_onObjLoaded(objData)
|
||||||
end
|
end
|
||||||
self._parser.onParsed = function(parser, meshData, usedTriangles)
|
self._parser.onParsed = function(parser, meshData, usedTriangles)
|
||||||
net.start("obj_parsed")
|
self:_onObjParsed(meshData, usedTriangles)
|
||||||
net.send()
|
|
||||||
|
|
||||||
self:onObjParsed(meshData, usedTriangles)
|
|
||||||
|
|
||||||
self.meshData = meshData
|
|
||||||
|
|
||||||
self:_applyMeshes()
|
|
||||||
end
|
end
|
||||||
self._cachedMaterials = {}
|
self._parser:parse()
|
||||||
|
|
||||||
if player() == owner() then
|
if IS_ME then
|
||||||
net.receive("initialized", function()
|
net.receive("initialized", function()
|
||||||
net.readEntity(function(ply)
|
net.readEntity(function(ply)
|
||||||
notification.addProgress(tostring(ply:getUserID()), string.format("%s is loading mesh", ply:getName()))
|
notification.addProgress(tostring(ply:getUserID()), string.format("%s is loading mesh", ply:getName()))
|
||||||
@ -42,12 +38,47 @@ function MeshBuilder:initialize(link)
|
|||||||
notification.kill(tostring(ply:getUserID()))
|
notification.kill(tostring(ply:getUserID()))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
net.receive("player_disconnect", function()
|
||||||
|
notification.kill(net.readString())
|
||||||
|
end)
|
||||||
|
|
||||||
|
net.receive("starfall_error", function()
|
||||||
|
net.readEntity(function(ply)
|
||||||
|
notification.kill(tostring(ply:getUserID()))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
net.start("initialized")
|
hook.add("starfallerror", "_starfallerror", function(ent, ply, err)
|
||||||
|
if ent ~= chip() then return end
|
||||||
|
|
||||||
|
net.start("starfall_error")
|
||||||
|
net.writeEntity(ply)
|
||||||
net.send()
|
net.send()
|
||||||
|
end)
|
||||||
|
|
||||||
net.receive("objects", function()
|
net.receive("objects", function()
|
||||||
|
self:_onReceiveObjects()
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
function MeshBuilder:_onObjLoaded(objData)
|
||||||
|
self:onObjLoaded(objData)
|
||||||
|
end
|
||||||
|
|
||||||
|
function MeshBuilder:_onObjParsed(meshData, usedTriangles)
|
||||||
|
net.start("obj_parsed")
|
||||||
|
net.send()
|
||||||
|
|
||||||
|
self:onObjParsed(meshData, usedTriangles)
|
||||||
|
|
||||||
|
self.meshData = meshData
|
||||||
|
|
||||||
|
self:_applyMeshes()
|
||||||
|
end
|
||||||
|
|
||||||
|
function MeshBuilder:_onReceiveObjects()
|
||||||
self._objects = {}
|
self._objects = {}
|
||||||
|
|
||||||
local hasNext = net.readBit()
|
local hasNext = net.readBit()
|
||||||
@ -81,15 +112,17 @@ function MeshBuilder:initialize(link)
|
|||||||
self:onHologramsReceived(self._objects)
|
self:onHologramsReceived(self._objects)
|
||||||
self:_applyMeshes()
|
self:_applyMeshes()
|
||||||
end)
|
end)
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function MeshBuilder:_applyMeshes()
|
function MeshBuilder:_applyMeshes()
|
||||||
for _, v in pairs(self._objects) do
|
for _, v in pairs(self._objects) do
|
||||||
if self.meshData[v.name] ~= nil then
|
if self.meshData[v.name] ~= nil then
|
||||||
|
local color = v.holo:getColor()
|
||||||
|
|
||||||
|
v.holo:setRenderBounds(Vector(-200), Vector(200))
|
||||||
v.holo:setMesh(self.meshData[v.name])
|
v.holo:setMesh(self.meshData[v.name])
|
||||||
v.holo:setMeshMaterial(v.mat)
|
v.holo:setMeshMaterial(v.mat)
|
||||||
v.holo:setRenderBounds(Vector(-200), Vector(200))
|
|
||||||
v.meshApplied = true
|
v.meshApplied = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -105,6 +138,8 @@ function MeshBuilder:_setTexture(mat, name, texture, layoutOptions)
|
|||||||
layoutOptions = layoutOptions or {}
|
layoutOptions = layoutOptions or {}
|
||||||
|
|
||||||
mat:setTextureURL(name, texture, function(_, _, _, _, layout)
|
mat:setTextureURL(name, texture, function(_, _, _, _, layout)
|
||||||
|
if not layout then return end
|
||||||
|
|
||||||
local x = layoutOptions.x or 0
|
local x = layoutOptions.x or 0
|
||||||
local y = layoutOptions.y or 0
|
local y = layoutOptions.y or 0
|
||||||
local w = layoutOptions.w or 1024
|
local w = layoutOptions.w or 1024
|
||||||
|
|||||||
@ -11,6 +11,12 @@ local function setStatus(status)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function ObjParser:initialize(link)
|
function ObjParser:initialize(link)
|
||||||
|
self.link = link
|
||||||
|
self.rawData = nil
|
||||||
|
self.objData = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
function ObjParser:parse()
|
||||||
addWorker(coroutine.wrap(function()
|
addWorker(coroutine.wrap(function()
|
||||||
setStatus("Getting file...")
|
setStatus("Getting file...")
|
||||||
|
|
||||||
@ -18,24 +24,25 @@ function ObjParser:initialize(link)
|
|||||||
coroutine.yield(1)
|
coroutine.yield(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
local objData
|
local rawObj
|
||||||
http.get(link, function(response)
|
http.get(self.link, function(response)
|
||||||
objData = response
|
rawObj = response
|
||||||
end)
|
end)
|
||||||
|
|
||||||
while not objData do
|
while not rawObj do
|
||||||
coroutine.yield(1)
|
coroutine.yield(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
self:onLoaded(objData)
|
self.rawObj = rawObj
|
||||||
|
self:onLoaded(rawObj)
|
||||||
local triangles = mesh.trianglesLeft()
|
|
||||||
|
|
||||||
setStatus("File received, start parsing...")
|
setStatus("File received, start parsing...")
|
||||||
|
|
||||||
self.meshData = mesh.createFromObj(objData, true)
|
local triangles = mesh.trianglesLeft()
|
||||||
|
|
||||||
self:onParsed(self.meshData, triangles - mesh.trianglesLeft())
|
self.objData = mesh.createFromObj(self.rawObj, true)
|
||||||
|
|
||||||
|
self:onParsed(self.objData, triangles - mesh.trianglesLeft())
|
||||||
|
|
||||||
setName(initialChipName)
|
setName(initialChipName)
|
||||||
|
|
||||||
|
|||||||
@ -3,18 +3,29 @@
|
|||||||
-- @include /koptilnya/libs/workers.txt
|
-- @include /koptilnya/libs/workers.txt
|
||||||
require("/koptilnya/libs/workers.txt")
|
require("/koptilnya/libs/workers.txt")
|
||||||
|
|
||||||
|
local TIMEOUT = 3
|
||||||
|
|
||||||
MeshBuilder = class("MeshBuilder")
|
MeshBuilder = class("MeshBuilder")
|
||||||
|
|
||||||
function MeshBuilder:initialize(link, modelPlaceholder)
|
function MeshBuilder:initialize(link, modelPlaceholder)
|
||||||
self.link = link
|
self.link = link
|
||||||
self.modelPlaceholder = modelPlaceholder or "models/holograms/cube.mdl"
|
self.modelPlaceholder = modelPlaceholder or "models/holograms/cube.mdl"
|
||||||
|
|
||||||
self._objectsNames = {}
|
|
||||||
self._objects = {}
|
self._objects = {}
|
||||||
self._objectsToSend = {}
|
self._players = {}
|
||||||
self._playersWithAccess = {}
|
self._timeoutPassed = false
|
||||||
self._firstTimePlayers = find.allPlayers()
|
|
||||||
self._firstTimeSended = false
|
PERMA.onPermissionsGained = function(_, ply)
|
||||||
|
table.insert(self._players, ply)
|
||||||
|
|
||||||
|
net.start("initialized")
|
||||||
|
net.writeEntity(ply)
|
||||||
|
net.send(owner())
|
||||||
|
|
||||||
|
if self._timeoutPassed then
|
||||||
|
self:_sendObjects(ply)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
net.receive("obj_parsed", function(len, ply)
|
net.receive("obj_parsed", function(len, ply)
|
||||||
net.start("obj_parsed")
|
net.start("obj_parsed")
|
||||||
@ -24,69 +35,31 @@ function MeshBuilder:initialize(link, modelPlaceholder)
|
|||||||
self:onPlayerParsedObj(ply)
|
self:onPlayerParsedObj(ply)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
net.receive("initialized", function(len, ply)
|
hook.add("PlayerDisconnected", "MeshBuilder_PlayerDisconnected", function(ply)
|
||||||
net.start("initialized")
|
table.removeByValue(self._players, ply)
|
||||||
|
|
||||||
|
net.start("player_disconnect")
|
||||||
|
net.writeString(tostring(ply:getUserID()))
|
||||||
|
net.writeString(ply:getName())
|
||||||
|
net.send(owner())
|
||||||
|
end)
|
||||||
|
|
||||||
|
net.receive("starfall_error", function()
|
||||||
|
print("starfall_error")
|
||||||
|
|
||||||
|
net.readEntity(function(ply)
|
||||||
|
net.start("starfall_error")
|
||||||
net.writeEntity(ply)
|
net.writeEntity(ply)
|
||||||
net.send(owner())
|
net.send(owner())
|
||||||
|
|
||||||
table.insert(self._playersWithAccess, ply)
|
|
||||||
|
|
||||||
if self._firstTimeSended then
|
|
||||||
self:_sendObjects(ply)
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
hook.add("ClientInitialized", "MeshBuilder_ClientInitialized", function(ply)
|
|
||||||
if #self._firstTimePlayers > 0 then
|
|
||||||
table.removeByValue(self._firstTimePlayers, ply)
|
|
||||||
|
|
||||||
if #self._firstTimePlayers == 0 then
|
|
||||||
self:_sendObjects(self._playersWithAccess)
|
|
||||||
|
|
||||||
self._firstTimeSended = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
hook.add("PlayerConnected", "MeshBuilder_PlayerConnected", function(ply)
|
|
||||||
if not self._firstTimeSended then
|
|
||||||
table.insert(self._firstTimePlayers, ply)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
hook.add("PlayerDisconnected", "MeshBuilder_PlayerDisconnected", function(ply)
|
|
||||||
table.removeByValue(self._firstTimePlayers, ply)
|
|
||||||
end)
|
|
||||||
|
|
||||||
addWorker(coroutine.wrap(function()
|
|
||||||
while not http.canRequest() do
|
|
||||||
coroutine.yield(1)
|
|
||||||
end
|
|
||||||
|
|
||||||
local objData
|
|
||||||
http.get(link, function(response)
|
|
||||||
objData = response
|
|
||||||
end)
|
|
||||||
|
|
||||||
while not objData do
|
|
||||||
coroutine.yield(1)
|
|
||||||
end
|
|
||||||
|
|
||||||
self:onObjectLoaded(objData)
|
|
||||||
|
|
||||||
self:onObjectParsed(self._objectsNames)
|
|
||||||
|
|
||||||
return 2
|
|
||||||
end))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function MeshBuilder:_sendObjects(target)
|
function MeshBuilder:_sendObjects(target)
|
||||||
if #self._objectsToSend == 0 then
|
if #self._objects == 0 then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
net.start("objects")
|
net.start("objects")
|
||||||
for _, v in pairs(self._objectsToSend) do
|
for _, v in pairs(self._objects) do
|
||||||
net.writeBit(1)
|
net.writeBit(1)
|
||||||
net.writeString(v.name)
|
net.writeString(v.name)
|
||||||
net.writeTable(type(v.mat) == "table" and v.mat or { basetexture = tostring(v.mat) })
|
net.writeTable(type(v.mat) == "table" and v.mat or { basetexture = tostring(v.mat) })
|
||||||
@ -102,7 +75,6 @@ function MeshBuilder:reset()
|
|||||||
end
|
end
|
||||||
|
|
||||||
self._objects = {}
|
self._objects = {}
|
||||||
self._objectsToSend = {}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function MeshBuilder:build(name, pos, ang, scale, color, mat, parent, relativeTo)
|
function MeshBuilder:build(name, pos, ang, scale, color, mat, parent, relativeTo)
|
||||||
@ -113,6 +85,7 @@ function MeshBuilder:build(name, pos, ang, scale, color, mat, parent, relativeTo
|
|||||||
|
|
||||||
local holo = holograms.create(pos, ang, self.modelPlaceholder, scale)
|
local holo = holograms.create(pos, ang, self.modelPlaceholder, scale)
|
||||||
holo:setColor(color)
|
holo:setColor(color)
|
||||||
|
holo:setRenderMode(color.a == 255 and RENDERMODE.NORMAL or RENDERMODE.TRANSCOLOR)
|
||||||
|
|
||||||
if isValid(parent) then
|
if isValid(parent) then
|
||||||
holo:setParent(parent)
|
holo:setParent(parent)
|
||||||
@ -124,22 +97,20 @@ function MeshBuilder:build(name, pos, ang, scale, color, mat, parent, relativeTo
|
|||||||
end
|
end
|
||||||
|
|
||||||
function MeshBuilder:getResult()
|
function MeshBuilder:getResult()
|
||||||
table.copyFromTo(self._objects, self._objectsToSend)
|
if self._timeoutPassed then
|
||||||
|
self:_sendObjects(self._players)
|
||||||
|
else
|
||||||
|
timer.simple(TIMEOUT, function()
|
||||||
|
self._timeoutPassed = true
|
||||||
|
|
||||||
if self._firstTimeSended then
|
self:_sendObjects(self._players)
|
||||||
self:_sendObjects(self._playersWithAccess)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
return self._objectsToSend
|
return self._objects
|
||||||
end
|
end
|
||||||
|
|
||||||
-- STUB
|
-- STUB
|
||||||
|
|
||||||
function MeshBuilder:onObjectLoaded(objData)
|
|
||||||
end
|
|
||||||
|
|
||||||
function MeshBuilder:onObjectParsed(objectsNames)
|
|
||||||
end
|
|
||||||
|
|
||||||
function MeshBuilder:onPlayerParsedObj(ply)
|
function MeshBuilder:onPlayerParsedObj(ply)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user