This commit is contained in:
Nikita Kruglickiy
2020-12-27 21:29:46 +06:00
parent 1a0785862d
commit eaf0a90173
13 changed files with 116 additions and 86 deletions

View File

@@ -1,6 +1,6 @@
local MODEL_PLACEHOLDER = "models/holograms/cube.mdl"
local BUNDLE_SIZE = 30
local SEND_DELAY = 2
local BUNDLE_SIZE = 2
local SEND_DELAY = 0.5
MeshBuilder = class("MeshBuilder")
@@ -19,7 +19,6 @@ function MeshBuilder:initialize()
net.readEntity(function(ent)
if not self._objects[key] then
local holo = ent:toHologram()
if self._meshData[key] then
@@ -47,11 +46,12 @@ function MeshBuilder:initialize()
local color = net.readColor()
local mat = net.readString()
local parent = net.readEntity()
local relativeTo = net.readEntity()
if not self._objects[key] then
if isValid(parent) then
pos = parent:localToWorld(pos)
ang = parent:localToWorldAngles(ang)
if isValid(relativeTo) then
pos = relativeTo:localToWorld(pos)
ang = relativeTo:localToWorldAngles(ang)
end
local holo = holograms.create(pos, ang, MODEL_PLACEHOLDER, scale)
@@ -71,11 +71,9 @@ function MeshBuilder:initialize()
net.start("sendHolograms")
for k, v in pairs(self._bundle) do
if isValid(v) and type(v) == "Hologram" then
net.writeBit(1)
net.writeString(k)
net.writeEntity(v)
end
net.writeBit(1)
net.writeString(k)
net.writeEntity(v)
end
net.writeBit(0)
net.send(ply)
@@ -90,7 +88,7 @@ if CLIENT then
self._meshData = meshData
end
function MeshBuilder:setup(key, pos, ang, scale, color, mat, parent)
function MeshBuilder:setup(key, pos, ang, scale, color, mat, parent, relativeTo)
if not self._objects[key] and not self._bundle[key] and self._meshData[key] then
self._bundle[key] = {
pos = pos,
@@ -98,12 +96,13 @@ if CLIENT then
scale = scale,
color = color,
mat = mat,
parent = isValid(parent) and parent or chip()
parent = isValid(parent) and parent or chip(),
relativeTo = isValid(relativeTo) and relativeTo or chip()
}
end
end
function MeshBuilder:setupAll(pos, ang, scale, color, mat, parent)
function MeshBuilder:setupAll(pos, ang, scale, color, mat, parent, relativeTo)
for _, v in pairs(table.getKeys(self._meshData)) do
self:setup(v, pos, ang, scale, color, mat, parent)
end
@@ -121,6 +120,7 @@ if CLIENT then
net.writeColor(v.color)
net.writeString(v.mat)
net.writeEntity(v.parent)
net.writeEntity(v.relativeTo)
end
net.writeBit(0)
net.send()