MCPcopy Create free account
hub / github.com/codereader/DarkRadiant / execute

Function execute

install/scripts/commands/export_obj.py:24–266  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22
23# The actual algorithm called by DarkRadiant is contained in the execute() function
24def execute():
25 script = "DarkRadiant Wavefront OBJ Export (*.obj)"
26 author = "Python port by greebo, based on original exporter C++ code in DarkRadiant and the ASE exporter scripts"
27 version = "0.2"
28
29 import darkradiant as dr
30
31 # Check if we have a valid selection
32
33 selectionInfo = GlobalSelectionSystem.getSelectionInfo()
34
35 # Don't allow empty selections or selected components only
36 if selectionInfo.totalCount == 0 or selectionInfo.totalCount == selectionInfo.componentCount:
37 errMsg = GlobalDialogManager.createMessageBox('No selection', 'Nothing selected, cannot run exporter.', dr.Dialog.ERROR)
38 errMsg.run()
39 return
40
41 # An exportable object found in the map
42 class Geometry(object):
43 name = '' # Name of the object to be exported
44 vertices = [] # Vertices
45 texcoords = [] # Texture coordinates
46 faces = [] # Each face in turn is an array of indices referencing the vertices and texcoords
47 # For simplicity, we assume that the referenced vertices and texcoords always
48 # have the same global index number.
49 def __init__(self, name):
50 self.name = name
51 self.vertices = []
52 self.texcoords = []
53 self.faces = []
54
55 # An exportable object found in the map
56 class Geometries(object):
57 vertexCount = 0 # Global Vertex Index (every vertex in an OBJ file has a unique number)
58 objects = [] # List of Geometry objects
59
60 # We put all of the objects we collect in the map into this array
61 # Before we write it to the output stream the vertices can be processed (e.g. centered)
62 geomlist = Geometries()
63
64 def processBrush(brushnode):
65 # Create a new exportable object
66 geometry = Geometry('Brush{0}'.format(len(geomlist.objects)))
67
68 numfaces = brushnode.getNumFaces()
69 for index in range(numfaces):
70 facenode = brushnode.getFace(index)
71 shader = facenode.getShader()
72
73 # Tels: skip if caulk and no caulk should be exported
74 if (shader == 'textures/common/caulk') and (int(GlobalRegistry.get('user/scripts/objExport/exportcaulk'))) == 0:
75 continue
76
77 winding = facenode.getWinding()
78
79 # Remember the index of the first vertex
80 firstVertex = geomlist.vertexCount
81

Callers 1

export_obj.pyFile · 0.70

Calls 15

GeometriesClass · 0.85
strClass · 0.85
xMethod · 0.80
yMethod · 0.80
zMethod · 0.80
SelectionWalkerClass · 0.70
printFunction · 0.50
createMessageBoxMethod · 0.45
runMethod · 0.45
createDialogMethod · 0.45
addEntryBoxMethod · 0.45
setElementValueMethod · 0.45

Tested by

no test coverage detected