Repository navigation
Expand file tree
/
Copy pathMaterialLibrary_Utilities.ms
More file actions
143 lines (127 loc) · 3.85 KB
/
Copy pathMaterialLibrary_Utilities.ms
File metadata and controls
143 lines (127 loc) · 3.85 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
local configFile = (getFilenamePath (getThisScriptFilename()))+"CONFIG"
local logoPath = "T:\\logos\\CorganMediaLab_inverted.jpg"
local iconPath = (getFilenamePath (getThisScriptFilename()))+"mediaLab.ico"
local communicatorFile = (systemTools.getEnvVariable "TEMP")+"\\"+"MaterialLibrary_communicator.tmp"
local materialRoot
local bitmapRoot
local UVRoot
local texMapDir
local renderFile
local matLibFilenames
local categoryNames
local materialNames
local matLibs
local theImage = dotNetClass "System.Drawing.Image"
local fileClass = dotNetClass "System.IO.File"
local dnMouse dotNetClass "System.Windows.Input.Mouse"
local dnCursors dotNetClass "System.Windows.Input.Cursors"
local readyToDrop = false
local initializing = true
---------------------------- Functions ----------------------------------------
fn readSettings = (
print "read settings"
config = openFile configFile mode:"rt"
texMapDir = (filterString (readLine config) ">")[2] -- read first line
renderFile = (filterString (readLine config) ">")[2] -- read second line
materialRoot = (filterString (readLine config) ">")[2] -- read third line
bitmapRoot = materialRoot+"\\"+"Images"
UVRoot = materialRoot+"\\"+"UVCoordinates"
flush config; close config
)
fn loadLibraries = (
print "loadLibraries"
matLibFilenames = getFiles (materialRoot+"\\*.mat")
if matLibFilenames.count == 0 then (
matLibs = #()
false
)
else (
matLibs = for i in matLibFilenames collect (loadTempMaterialLibrary i)
true
)
)
fn checkAndDisplayProgress = (
print "background thread!"
messageBox "Your material preview is currently being rendered.\nYou will be notified when it is complete." title:"Material Storage"
estimatedTime = ""
-- while loop to check file
while estimatedTime != "Done" do (
communicator = openFile communicatorFile mode:"rt"
estimatedTime = readLine communicator -- read first line
flush communicator; close communicator
print estimatedTime
sleep 3
)
print "Material stored successfully"
messageBox "Your material preview is done rendering and the material has been successfully stored." title:"Material Successfully Stored"
)
-- hitTest function by MarcoBrunetta from cgsociety.org
-- Returns the object at the mouse position in the viewport
fn hitTest = (
local theRay=mapScreenToWorldRay mouse.pos
local dist=undefined
local theHit=undefined
local hitObject=undefined
for x in objects do
(
hitRay=intersectRay x theRay
if hitRay!=undefined then (
tempDist=distance hitRay.pos theRay.pos
if dist==undefined or tempDist<dist then
(
dist=tempDist
theHit=hitRay
hitObject = X
)
)
)
hitObject
)
-- Recursively get materials within a material
fn getAllSubMtls mtl = (
allSubMtls = #()
num = getNumSubMtls mtl
for i=1 to num do (
subMtl = getSubMtl mtl i
if subMtl != undefined do (
append allSubMtls subMtl
join allSubMtls (getAllSubMtls subMtl)
)
)
allSubMtls
)
-- Recursively get texture maps within a material
fn getAllSubTexMaps mtl_Tex = (
allSubTexMaps = #()
num = getNumSubTexmaps mtl_Tex
for i=1 to num do (
subTex = getSubTexmap mtl_Tex i
if subTex != undefined do (
append allSubTexMaps subTex
join allSubTexMaps (getAllSubTexMaps subTex)
)
)
allSubTexMaps
)
-- Recursively get all texture maps within all materials within a material
fn getAllTexInsideMtl mtl = (
allTex = #()
allMtls = join #(mtl) (getAllSubMtls mtl)
for m in allMtls do (
join allTex (getAllSubTexMaps m)
)
allTex
)
fn checkMaterialAssets mtl = (
allTex = getAllTexInsideMtl mtl
correctPath = true
for t in allTex do (
if (classOf t) == Bitmaptexture do (
if not (matchPattern (getFilenamePath t.filename) pattern:(texMapDir+"\\*") ignoreCase:true) do (
correctPath = false
break
)
)
)
correctPath
)