1 # SPDX-FileCopyrightText: 2019-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 # Paul "BrikBot" Marshall
6 # Created: July 1, 2011
7 # Last Modified: November 17, 2011
8 # Homepage (blog): http://post.darkarsenic.com/
9 # //blog.darkarsenic.com/
10 # Thanks to Meta-Androco, RickyBlender, Ace Dragon, and PKHG for ideas
13 # Coded in IDLE, tested in Blender 2.59. NumPy Recommended.
14 # Search for "@todo" to quickly find sections that need work.
19 from xml
.dom
import minidom
21 basePath
= inspect
.getfile(inspect
.currentframe())[0:-len("settings.py")]
22 path
= basePath
+ "add_mesh_rocks.xml"
25 source
= minidom
.parse(path
)
26 # print("Rock generator settings file found:\n" + path)
28 print("Rock generator settings file not found. Creating settings file.")
29 shutil
.copy(basePath
+ "factory.xml", path
)
30 source
= minidom
.parse(path
)
32 xmlDefault
= source
.getElementsByTagName('default')[0]
33 xmlPresets
= source
.getElementsByTagName('preset')
37 # ----- Gets and Sets -----#
54 # ---------- Core ----------#
63 # Parse default values
64 default
= parseNode(xmlDefault
)
67 for setting
in xmlPresets
:
68 presets
.append(parseNode(setting
))
73 # Takes a node and parses it for data. Relies on that setting.xml has
74 # a valid format as specified by the DTD.
75 # For some reason minidom places an empty child node for every other node.
76 def parseNode(setting
, title
=True):
80 # Preset name (xmlPreset.childNodes[1]):
81 title
= setting
.childNodes
[loc
].childNodes
[0].data
84 # Preset size values (xmlPreset.childNodes[3]):
85 scaleX
= [float(setting
.childNodes
[loc
].childNodes
[1].childNodes
[3].childNodes
[0].data
),
86 float(setting
.childNodes
[loc
].childNodes
[1].childNodes
[5].childNodes
[0].data
)]
87 scaleY
= [float(setting
.childNodes
[loc
].childNodes
[3].childNodes
[3].childNodes
[0].data
),
88 float(setting
.childNodes
[loc
].childNodes
[3].childNodes
[5].childNodes
[0].data
)]
89 scaleZ
= [float(setting
.childNodes
[loc
].childNodes
[5].childNodes
[3].childNodes
[0].data
),
90 float(setting
.childNodes
[loc
].childNodes
[5].childNodes
[5].childNodes
[0].data
)]
91 skewX
= float(setting
.childNodes
[loc
].childNodes
[7].childNodes
[3].childNodes
[0].data
)
92 skewY
= float(setting
.childNodes
[loc
].childNodes
[9].childNodes
[3].childNodes
[0].data
)
93 skewZ
= float(setting
.childNodes
[loc
].childNodes
[11].childNodes
[3].childNodes
[0].data
)
94 if setting
.childNodes
[loc
].childNodes
[13].childNodes
[0].data
== 'False':
98 scale_fac
= utils
.toList(setting
.childNodes
[loc
].childNodes
[15].childNodes
[0].data
)
101 # Presst shape values (xmlPreset.childNodes[5]):
102 deform
= float(setting
.childNodes
[loc
].childNodes
[1].childNodes
[0].data
)
103 rough
= float(setting
.childNodes
[loc
].childNodes
[3].childNodes
[0].data
)
104 detail
= int(setting
.childNodes
[loc
].childNodes
[5].childNodes
[0].data
)
105 display_detail
= int(setting
.childNodes
[loc
].childNodes
[7].childNodes
[0].data
)
106 smooth_fac
= float(setting
.childNodes
[loc
].childNodes
[9].childNodes
[0].data
)
107 smooth_it
= int(setting
.childNodes
[loc
].childNodes
[11].childNodes
[0].data
)
110 # Preset material values (xmlPreset.childNodes[7]):
113 # Preset random values (xmlPreset.childNodes[9]):
114 if setting
.childNodes
[loc
].childNodes
[1].childNodes
[0].data
== 'True':
118 if setting
.childNodes
[loc
].childNodes
[3].childNodes
[0].data
== 'False':
119 use_random_seed
= False
121 use_random_seed
= True
122 user_seed
= int(setting
.childNodes
[loc
].childNodes
[5].childNodes
[0].data
)
125 parsed
= [title
, scaleX
, scaleY
, scaleZ
, skewX
, skewY
, skewZ
,
126 use_scale_dis
, scale_fac
, deform
, rough
, detail
,
127 display_detail
, smooth_fac
, smooth_it
,
128 use_generate
, use_random_seed
, user_seed
]
130 parsed
= [scaleX
, scaleY
, scaleZ
, skewX
, skewY
, skewZ
, use_scale_dis
,
131 scale_fac
, deform
, rough
, detail
, display_detail
, smooth_fac
,
132 smooth_it
, use_generate
, use_random_seed
, user_seed
]