在 maxscript 中,似乎有两个选项可以通过紧凑的材质编辑器和 Slate 材质编辑器访问材质。问题在于,如果 max 设置为使用 Slate 编辑器,则尝试通过紧凑编辑器 ( currentMaterialLibrary, sceneMaterials, meditMaterials)访问/修改材料的脚本会失败,反之亦然。
有没有办法直接在 maxscript 中访问材料,而不管使用哪个编辑器?
一旦我有了材料,我想:
如果您想查找所有现有材料(在场景中与否),以下代码段将为您完成
for aMtlType in material.classes do
(
for aMtl in (getClassInstances aMtlType processAllAnimatables:true) do
(
print aMtl
-- Does this material exist in the scene or not?
if (findItem sceneMaterials aMtl) == 0 do (print "This material does not exist in the scene")
)
)
Run Code Online (Sandbox Code Playgroud)
我不太确定如何从现场清除它。您可以获取依赖项 (refs.dependents aMtl),然后将此材质的任何引用替换为新的默认材质。这应该有效,尽管我还没有尝试过(甚至没有尝试过运行它)。所以......测试它并小心使用:-)。
defMtl = ...
for d in refs.dependents aMtl do (
refIdx = 0
for i = 1 to refs.getNumRefs d do ( if (refs.getreference d i) == aMtl ) do ( refIdx = i )
refs.replaceReference aMtl refIdx defMtl
)
Run Code Online (Sandbox Code Playgroud)
对于您的第二个问题 - 检查属性 - 您可以检查它是否具有适当的属性并根据需要设置值
if (hasProperty aMtl "diffuse") do ( aMtl.diffuse = 0 )