-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassetpipeline.lua
65 lines (60 loc) · 1.83 KB
/
assetpipeline.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function JoinPath(a, b)
if a == "" then
return b
end
return a.."/"..b
end
function ExtractDirectory(path)
local i = #path
while i > 1 do
local c = string.sub(path, i, i)
if c == "/" or c == "\\" then
return string.sub(path, 1, i - 1)
end
i = i - 1
end
return ""
end
function ResolveRelativePath(currentDir, path)
local fullPath = currentDir
for component in string.gmatch(path, "([^/]+)/?") do
if component == ".." then
fullPath = ExtractDirectory(fullPath)
elseif component ~= "." then
fullPath = JoinPath(fullPath, component)
end
end
return fullPath
end
function ParseShaderIncludes(currentDir, contents)
local result = {}
for line in string.gmatch(contents, "[^\n\r]+") do
local _, _, relativePath = string.find(line, '#include%s+"(.+)"')
if relativePath ~= nil then
result[#result+1] = ResolveRelativePath(currentDir, relativePath)
end
end
return result
end
Rule("Assets/Shaders/(.*)_MTL%.shd", {
Parse = function(path, name)
local inputs = {string.format("Shaders/%s.metal", name)}
local outputs = {path}
return inputs, outputs, function(inputFilePath, contents)
local currentDir = ExtractDirectory(inputFilePath)
return ParseShaderIncludes(currentDir, contents)
end
end,
Execute = function(inputPaths, outputPaths)
print("Compiling " .. inputPaths[1])
local status, stdout, stderr = RunProcess("Tools/MTLShaderCompiler",
inputPaths[1], outputPaths[1])
if status ~= 0 then
return false, stderr
end
return true, nil
end
})
ContentDir("Shaders")
DataDir("Assets")
Manifest("AssetManifest.txt")