/
materialtest.py
84 lines (63 loc) · 3.79 KB
/
materialtest.py
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
import os
import darkradiant as dr
# Some interface tests
print("bc_rat can be modified" if GlobalMaterialManager.materialCanBeModified('bc_rat') else "bc_rat cannot be modified")
bcRatCopy = GlobalMaterialManager.copyMaterial('bc_rat', 'bc_rat_copy')
print("Got a copy of bc_rat named {0}".format(bcRatCopy.getName()))
print("The copy can be modified" if GlobalMaterialManager.materialCanBeModified(bcRatCopy.getName()) else "The copy cannot be modified?")
try:
bcRat = GlobalMaterialManager.getMaterial('bc_rat')
bcRat.setEditorImageExpressionFromString('this is gonna blow')
except RuntimeError as e:
print('An exception has been thrown: {}'.format(e))
print("Removing the copy again...")
GlobalMaterialManager.removeMaterial(bcRatCopy.getName())
print('Create an empty material named textures/python/blah...')
newMaterial = GlobalMaterialManager.createEmptyMaterial('textures/python/blah')
print("The new material can be modified" if GlobalMaterialManager.materialCanBeModified(newMaterial.getName()) else "The new material cannot be modified?")
renameResult = GlobalMaterialManager.renameMaterial(newMaterial.getName(), newMaterial.getName() + '_renamed')
print("The rename operation was successful" if renameResult else "The rename operation failed")
# Do something with the new material
print('The existing material reference now has the name {0}'.format(newMaterial.getName()))
filename = 'materials/_python_test.mtr'
newMaterial.setShaderFileName(filename)
newMaterial.setEditorImageExpressionFromString('textures/common/caulk')
newMaterial.setSortRequest(45.3)
print('Surface Type: {0}'.format(newMaterial.getSurfaceType()))
print('Cull type: {0}'.format(newMaterial.getCullType()))
print('Clamp type: {0}'.format(newMaterial.getClampType()))
print('Flags: {0}'.format(newMaterial.getMaterialFlags()))
print('Surface Flags: {0}'.format(newMaterial.getSurfaceFlags()))
print('Deform Type: {0}'.format(newMaterial.getDeformType()))
print('Deform Expression #1: {0}'.format(newMaterial.getDeformExpressionString(0)))
print('Deform Decl Name: {0}'.format(newMaterial.getDeformDeclName()))
print('Spectrum: {0}'.format(newMaterial.getSpectrum()))
print('DecalInfo.stayMilliSeconds: {0}'.format(newMaterial.getDecalInfo().stayMilliSeconds))
print('DecalInfo.fadeMilliSeconds: {0}'.format(newMaterial.getDecalInfo().fadeMilliSeconds))
print('DecalInfo.startColour: {0}'.format(newMaterial.getDecalInfo().startColour))
print('DecalInfo.endColour: {0}'.format(newMaterial.getDecalInfo().endColour))
print('Coverage: {0}'.format(newMaterial.getCoverage()))
print('Light Falloff Map Type: {0}'.format(newMaterial.getLightFalloffCubeMapType()))
# There are a couple of pre-defined sort requests, corresponding to the engine code
newMaterial.setSortRequest(dr.Material.SortRequest.NEAREST)
newMaterial.setClampType(dr.Material.ClampType.NOREPEAT) # clamp
newMaterial.setCullType(dr.Material.CullType.NONE) # twosided
newMaterial.setPolygonOffset(0.3)
newMaterial.setMaterialFlag(dr.Material.Flag.NOSHADOWS)
newMaterial.setSurfaceFlag(dr.Material.SurfaceFlag.LADDER)
newMaterial.setSurfaceFlag(dr.Material.SurfaceFlag.NONSOLID)
newMaterial.setSurfaceType(dr.Material.SurfaceType.WOOD)
newMaterial.setSpectrum(5)
newMaterial.setIsFogLight(1)
newMaterial.setIsBlendLight(0)
print('Full Material definition:\n{0}\n{{{1}}}'.format(newMaterial.getName(), newMaterial.getDefinition()))
GlobalMaterialManager.saveMaterial(newMaterial.getName())
newMaterial.clearMaterialFlag(dr.Material.Flag.NOSHADOWS)
newMaterial.clearSurfaceFlag(dr.Material.SurfaceFlag.NONSOLID)
newMaterial.setSurfaceType(dr.Material.SurfaceType.DEFAULT)
fullPath = GlobalFileSystem.findFile(filename) + filename
print(fullPath)
os.remove(fullPath)
print("Removing {0} again...".format(newMaterial.getName()))
GlobalMaterialManager.removeMaterial(newMaterial.getName())
print('--- Done ---')