/
test.py
309 lines (227 loc) · 8.22 KB
/
test.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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# Some interface tests
# Test the Registry interface
value = GlobalRegistry.get('user/paths/appPath')
print(value)
worldspawn = Radiant.findEntityByClassname("worldspawn")
worldspawn.setKeyValue('test', 'success')
print('Worldspawn edited')
# Test the EClassManager interface
eclass = GlobalEntityClassManager.findClass('atdm:func_shooter')
print(eclass.getAttribute('editor_usage').getValue())
# Try creating a func_shooter entity
if not eclass.isNull():
shooter = GlobalEntityCreator.createEntity(eclass)
modelDef = GlobalEntityClassManager.findModel('tdm_ai_citywatch')
print('ModelDef mesh for tdm_ai_citywatch = ' + modelDef.mesh)
# Test iterating over C++ std::map
for anim in modelDef.anims:
print(anim + " = " + modelDef.anims[anim])
# Test implementing a eclass visitor interface
#class TestVisitor(EntityClassVisitor) :
# def visit(self, eclass):
# print(eclass.getAttribute('editor_usage').getValue())
#eclassVisitor = TestVisitor()
#GlobalEntityClassManager.forEachEntityClass(eclassVisitor)
# Test implementing a model def visitor interface
#class TestModelDefVisitor(ModelDefVisitor) :
# def visit(self, modelDef):
# print(modelDef.mesh)
#
#modelDefVisitor = TestModelDefVisitor()
#GlobalEntityClassManager.forEachModelDef(modelDefVisitor)
# Test traversing the scenegraph
class SceneWalker(SceneNodeVisitor) :
def pre(self, node):
print(node.getNodeType())
# Try to get a model from this node
model = node.getModel()
if not model.isNull():
print('Node is a model')
else:
print('Node is not a model')
return 1
walker = SceneWalker()
GlobalSceneGraph.root().traverse(walker)
# Test traversing the current selection
class Walker(SelectionVisitor) :
def visit(self, node):
# Try to "cast" the node to a brush
brush = node.getBrush()
# If the Brush is not NULL the cast succeeded
if not brush.isNull():
print(brush.getNumFaces())
else:
print('Node is not a brush')
# Try to cast the node to a patch
patch = node.getPatch()
# If the Patch is not NULL the cast succeeded
if not patch.isNull():
print('Node is a patch')
else:
print('Node is not a patch')
# Try to get a model from this node
model = node.getModel()
if not model.isNull():
print('Node is a model')
else:
print('Node is not a model')
visitor = Walker()
GlobalSelectionSystem.foreachSelected(visitor)
print('Map name is ' + GlobalMap.getMapName())
# Try to find the map's worldspawn
worldspawn = GlobalMap.getWorldSpawn()
if not worldspawn.isNull():
# Cast the node onto an entity
worldspawnent = worldspawn.getEntity()
if not worldspawnent.isNull():
print('Spawnclass of worldspawn: ' + worldspawnent.getKeyValue('spawnclass'))
else:
print('There is no worldspawn in this map yet')
# Test the entity visitor interface
class TestEntityVisitor(EntityVisitor) :
def visit(self, key, value):
print('Worldspawn has spawnarg: ' + key + ' = ' + value)
if not worldspawn.isNull():
tev = TestEntityVisitor()
# Cast the node onto an entity
worldspawnent = worldspawn.getEntity()
worldspawnent.forEachKeyValue(tev)
# Try to retrieve all keyvalues starting with "n"
keyvalues = worldspawnent.getKeyValuePairs('t')
for kv in keyvalues:
print('Keyvalue ' + kv[0] + ' = ' + kv[1])
# Test the commandsystem
GlobalCommandSystem.execute('texscale "0 0.1"')
# Test the GameManager interface
print('Mod path = ' + GlobalGameManager.getModPath())
game = GlobalGameManager.currentGame()
print('Current game type: ' + game.getKeyValue('type'))
print('VFS Search paths:')
vfsPaths = GlobalGameManager.getVFSSearchPaths()
for path in vfsPaths:
print(path)
# Test FileSystem (VFS)
class TestFileVisitor(FileVisitor) :
def visit(self, filename):
print('Found file: ' + filename)
filevisitor = TestFileVisitor()
GlobalFileSystem.forEachFile('skins/', 'skin', filevisitor, 99)
filecontents = GlobalFileSystem.readTextFile('skins/tdm_ai_guard_citywatch.skin');
print(filecontents)
# Test the Grid Interface
print('Current grid size = ' + str(GlobalGrid.getGridSize()))
# Test the ShaderSystem interface
class TestShaderVisitor(ShaderVisitor) :
def visit(self, shader):
if not shader.isNull():
print('Found shader: ' + shader.getName() + ' defined in ' + shader.getShaderFileName())
shadervisitor = TestShaderVisitor()
GlobalMaterialManager.foreachShader(shadervisitor)
shader = GlobalMaterialManager.getMaterialForName('bc_rat')
if not shader.isNull():
print('Shader ' + shader.getName() + ' is defined in ' + shader.getShaderFileName())
# Test finding a model
class ModelFinder(SceneNodeVisitor) :
def pre(self, node):
# Try to get a model from this node
model = node.getModel()
if not model.isNull():
print('Model information:')
print('Filename: ' + model.getFilename())
print('Model path: ' + model.getModelPath())
print('Surface count: ' + str(model.getSurfaceCount()))
print('Vertex count: ' + str(model.getVertexCount()))
print('Poly count: ' + str(model.getPolyCount()))
materials = model.getActiveMaterials()
print('Active Materials:')
for material in materials:
print(material)
for i in range(0, model.getSurfaceCount()):
surface = model.getSurface(i)
print('Surface: ' + str(i))
print(' Default Shader: ' + surface.getDefaultMaterial())
print(' Active Shader: ' + surface.getActiveMaterial())
print(' PolyCount: ' + str(surface.getNumTriangles()))
print(' Vertex Count: ' + str(surface.getNumVertices()))
s = Vector3(0,0,0)
numverts = surface.getNumVertices()
for v in range(0, numverts):
meshvertex = surface.getVertex(v)
s += meshvertex.vertex
print(' Sum of all vertices: ' + str(s.x()) + ',' + str(s.y()) + ',' + str(s.z()))
return 1
walker = ModelFinder()
GlobalSceneGraph.root().traverse(walker)
# Test the ModelSkinCache interface
#allSkins = GlobalModelSkinCache.getAllSkins()
#
#for skin in allSkins:
# modelskin = GlobalModelSkinCache.capture(skin)
# print('Skin found: ' + modelskin.getName())
v = Vector3(6,6,6)
v += Vector3(10,10,10)
print(v)
# Test patch manipulation
class PatchManipulator(SceneNodeVisitor) :
def pre(self, node):
# Try to get a patch from this node
patch = node.getPatch()
if not patch.isNull():
print('Patch information:')
print('Dimensions: ' + str(patch.getWidth()) + 'x' + str(patch.getHeight()))
w = 0
while w < patch.getWidth():
h = 0
while h < patch.getHeight():
# Push the vertex around a bit
ctrl = patch.ctrlAt(h,w)
ctrl.vertex += Vector3(0,0,10*(h-w))
h += 1
w += 1
patch.controlPointsChanged()
return 1
walker = PatchManipulator()
GlobalSceneGraph.root().traverse(walker)
# Test the SelectionSetManager interface
class SelectionSetWalker(SelectionSetVisitor) :
def visit(self, selectionset):
print(selectionset.getName())
walker = SelectionSetWalker()
GlobalSelectionSetManager.foreachSelectionSet(walker)
selSet = GlobalSelectionSetManager.createSelectionSet("TestSelectionSet")
selSet.assignFromCurrentScene()
selSet.deselect()
selSet.select()
selSet.clear()
if selSet.empty():
GlobalSelectionSetManager.deleteSelectionSet("TestSelectionSet")
print('')
soundshader = GlobalSoundManager.getSoundShader('tdm_ai_lady_alertdown_to_idle')
if not soundshader.isNull():
print('Name of this sound shader: ' + soundshader.getName())
radii = soundshader.getRadii()
print('Minimum radius in meters: ' + str(radii.getMin(1)))
print('Maximum radius in meters: ' + str(radii.getMax(1)))
fileList = soundshader.getSoundFileList()
for i in range(0, len(fileList)):
print(' Sound file used by this shader: ' + fileList[i])
if (len(fileList) > 0):
GlobalSoundManager.playSound(fileList[0])
# Test SelectionGroup interface
group = GlobalSelectionGroupManager.createSelectionGroup()
print('Created group with ID: ' + str(group.getId()))
# Test traversing the current selection
class GroupAdder(SelectionVisitor) :
def visit(self, node):
group.addNode(node)
visitor = Walker()
GlobalSelectionSystem.foreachSelected(visitor)
print('The group contains now ' + str(group.size()) + ' items')
# Deselect the group
GlobalSelectionGroupManager.setGroupSelected(group.getId(), 0)
# List nodes in this group
class SelectionGroupWalker(SelectionGroupVisitor) :
def visit(self, node):
print('Group Member: ' + node.getNodeType())
gropWalker = SelectionGroupWalker();
group.foreachNode(gropWalker)