This commit is contained in:
Nikita Kruglickiy
2023-05-22 19:06:26 +03:00
parent 345e60cf1d
commit 09be0ea795
35 changed files with 1423 additions and 336 deletions

View File

@@ -30,7 +30,7 @@ function MeshBuilder:initialize(link)
net.receive("initialized", function()
net.readEntity(function(ply)
notification.addProgress(tostring(ply:getUserID()), string.format("%s is loading mesh", ply:getName()))
end)
end)
end)
net.receive("obj_parsed", function()
@@ -61,6 +61,14 @@ function MeshBuilder:initialize(link)
net.receive("objects", function()
self:_onReceiveObjects()
end)
hook.add("Removed", "_Removed", function()
for k, v in pairs(self._cachedMaterials) do
if type(v) == "Material" then
v:destroy()
end
end
end)
end
function MeshBuilder:_onObjLoaded(objData)
@@ -89,8 +97,9 @@ function MeshBuilder:_onReceiveObjects()
net.readEntity(function(ent)
local holo = ent:toHologram()
local isCustomMaterial = (#table.getKeys(mat) > 1 and mat.basetexture) or isURL(mat.basetexture)
if (isURL(mat.basetexture)) then
if (isCustomMaterial) then
mat = self:_createMaterial(mat.shader, mat.basetexture, mat.bumpmap, mat.options)
else
hasErr, mat = pcall(material.load, mat.basetexture)
@@ -144,7 +153,7 @@ function MeshBuilder:_setTexture(mat, name, texture, layoutOptions)
local y = layoutOptions.y or 0
local w = layoutOptions.w or 1024
local h = layoutOptions.h or 1024
layout(x, y, w, h)
end)
else
@@ -172,8 +181,13 @@ function MeshBuilder:_createMaterial(shader, basetexture, bumpmap, options)
self:_setTexture(mat, "$bumpmap", bumpmap, options.bumpLayout)
end
options.baseLayout = nil
options.bumpLayout = nil
for k, v in pairs(options) do
if type(v) == "string" then
if k == "envmap" then
mat:setTexture("$envmap", v)
elseif type(v) == "string" then
mat:setString("$" .. k, v)
elseif type(v) == "number" then
if string.match(tostring(v), "%.") then
@@ -184,12 +198,14 @@ function MeshBuilder:_createMaterial(shader, basetexture, bumpmap, options)
elseif type(v) == "nil" then
mat:setUndefined("$" .. k, v)
elseif type(v) == "Vector" then
mat:setVector("$" .. k, tostring(v))
mat:setVector("$" .. k, v)
end
end
self._cachedMaterials[checksum] = mat
--mat:recompute()
return mat
end

View File

@@ -3,7 +3,7 @@
-- @include /koptilnya/libs/workers.txt
require("/koptilnya/libs/workers.txt")
local TIMEOUT = 3
local TIMEOUT = 4
MeshBuilder = class("MeshBuilder")
@@ -94,7 +94,7 @@ function MeshBuilder:build(name, pos, ang, scale, color, mat, parent, relativeTo
end
table.insert(self._objects, {name = name, mat = mat, holo = holo})
return holo
end
@@ -104,7 +104,7 @@ function MeshBuilder:getResult()
else
timer.simple(TIMEOUT, function()
self._timeoutPassed = true
self:_sendObjects(self._players)
end)
end