This commit is contained in:
Nikita Kruglickiy 2021-03-22 01:19:28 +06:00
parent 20bd0f06d5
commit 813a7d27a7
4 changed files with 34 additions and 24 deletions

View File

@ -6,6 +6,19 @@ end
function accessorFunc(tbl, varName, name, defaultValue)
tbl[varName] = defaultValue
tbl["get" .. name] = function(self) return self[varName] end
tbl["set" .. name] = function(self, value) self[varName] = value end
tbl["get" .. name] = function(self)
return self[varName]
end
tbl["set" .. name] = function(self, value)
self[varName] = value
end
end
function rotateAround(entity, pivot, angles)
local pos = entity:getPos()
local localPivotPos = entity:worldToLocal(pivot)
entity:setAngles(angles)
pos = pos + (pivot - entity:localToWorld(localPivotPos))
entity:setPos(pos)
end

View File

@ -15,7 +15,8 @@ function MeshBuilder:initialize(link)
self._parser.onLoaded = function(parser, objData, meshData, usedTriangles)
self.meshData = meshData
self:_applyMeshes()
net.start("ready")
net.send()
end
net.receive("holograms", function()
@ -35,10 +36,8 @@ function MeshBuilder:initialize(link)
hasNext = net.readBit()
end
timer.simple(0, function()
self:onHologramsReceived(self._objects)
self:_applyMeshes()
end)
self:onHologramsReceived(self._objects)
self:_applyMeshes()
end)
end

View File

@ -7,7 +7,7 @@ local function setStatus(status)
end
function ObjParser:initialize(link, maxQuota)
self.maxQuota = maxQuota or 0.5
self.maxQuota = maxQuota or 0.6
local triangles = mesh.trianglesLeft()
@ -23,7 +23,7 @@ function ObjParser:initialize(link, maxQuota)
setStatus("File received, start parsing...")
hook.add("think", "loadingMesh", function()
while quotaAverage() < quotaMax() * self.maxQuota do
while math.max(quotaAverage(), quotaUsed()) < quotaMax() * self.maxQuota do
if loadMesh() then
setName(initialChipName)
self:onLoaded(objData, self.meshData, triangles - mesh.trianglesLeft())

View File

@ -8,6 +8,7 @@ function MeshBuilder:initialize(link, modelPlaceholder)
self._objectsNames = {}
self._objects = {}
self._readyPlayers = {}
http.get(link, function(response)
for object in string.gmatch(response, "^?\n?o%s([%w_%.%-]+)") do
@ -16,13 +17,16 @@ function MeshBuilder:initialize(link, modelPlaceholder)
self.isReady = true
self:onReady(self._objectsNames)
self:_sendHolograms()
for _, v in pairs(self._readyPlayers) do
self:_sendHolograms(v)
end
end)
hook.add("ClientInitialized", "MeshBuilder_ClientInitialized", function(ply)
if self.isReady then
self:_sendHolograms(ply)
end
net.receive("ready", function(len, ply)
table.insert(self._readyPlayers, ply)
self:_sendHolograms(ply)
end)
end
@ -45,10 +49,6 @@ function MeshBuilder:onReady(objectsNames)
end
function MeshBuilder:build(name, pos, ang, scale, color, mat, parent, relativeTo)
if not self.isReady then
throw("Call build methods when builder is ready!")
end
if isValid(relativeTo) then
pos = relativeTo:localToWorld(pos)
ang = relativeTo:localToWorldAngles(ang)
@ -63,13 +63,11 @@ function MeshBuilder:build(name, pos, ang, scale, color, mat, parent, relativeTo
end
table.insert(self._objects, {name = name, holo = holo})
return name, holo
end
function MeshBuilder:buildAll(pos, ang, scale, color, mat, parent, relativeTo)
if not self.isReady then
throw("Call build methods when builder is ready!")
end
for _, v in pairs(self._objectsNames) do
self:build(v, pos, ang, scale, color, mat, parent, relativeTo)
end