Welcome to mirror list, hosted at ThFree Co, Russian Federation.

settings.py « add_mesh_rocks « add_mesh_extra_objects - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3e6a8df272f5bc25ed39e0a3f72e7ff3d2b6e82f (plain)
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
# Paul "BrikBot" Marshall
# Created: July 1, 2011
# Last Modified: November 17, 2011
# Homepage (blog): http://post.darkarsenic.com/
#                       //blog.darkarsenic.com/
# Thanks to Meta-Androco, RickyBlender, Ace Dragon, and PKHG for ideas
#   and testing.
#
# Coded in IDLE, tested in Blender 2.59.  NumPy Recommended.
# Search for "@todo" to quickly find sections that need work.
#
# ##### BEGIN GPL LICENSE BLOCK #####
#
#  The Blender Rock Creation tool is for rapid generation of
#  mesh rocks in Blender.
#  Copyright (C) 2011  Paul Marshall
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# ##### END GPL LICENSE BLOCK #####

# <pep8 compliant>

import inspect
import shutil
from . import utils
from xml.dom import minidom

basePath = inspect.getfile(inspect.currentframe())[0:-len("settings.py")]
path = basePath + "add_mesh_rocks.xml"

try:
    source = minidom.parse(path)
    print("Rock generator settings file found:\n" + path)
except:
    print("Rock generator settings file not found.  Creating settings file.")
    shutil.copy(basePath + "factory.xml", path)
    source = minidom.parse(path)

xmlDefault = source.getElementsByTagName('default')[0]
xmlPresets = source.getElementsByTagName('preset')
default = []
presets = []

# ----- Gets and Sets -----#


def getDefault():
    global default
    return default


def getPresetLists():
    global presets
    return presets


def getPreset(ID=0):
    global presets
    return presets[ID]

# ---------- Core ----------#


def parse():
    global xmlDefault
    global xmlPresets
    global default
    global presets

    # Parse default values
    default = parseNode(xmlDefault)

    # Parse preset values
    for setting in xmlPresets:
        presets.append(parseNode(setting))

    return '{FINISHED}'


# Takes a node and parses it for data.  Relies on that setting.xml has
#   a valid format as specified by the DTD.
# For some reason minidom places an empty child node for every other node.
def parseNode(setting, title=True):
    loc = 1

    if title:
        # Preset name (xmlPreset.childNodes[1]):
        title = setting.childNodes[loc].childNodes[0].data
        loc += 2

    # Preset size values (xmlPreset.childNodes[3]):
    scaleX = [float(setting.childNodes[loc].childNodes[1].childNodes[3].childNodes[0].data),
              float(setting.childNodes[loc].childNodes[1].childNodes[5].childNodes[0].data)]
    scaleY = [float(setting.childNodes[loc].childNodes[3].childNodes[3].childNodes[0].data),
              float(setting.childNodes[loc].childNodes[3].childNodes[5].childNodes[0].data)]
    scaleZ = [float(setting.childNodes[loc].childNodes[5].childNodes[3].childNodes[0].data),
              float(setting.childNodes[loc].childNodes[5].childNodes[5].childNodes[0].data)]
    skewX = float(setting.childNodes[loc].childNodes[7].childNodes[3].childNodes[0].data)
    skewY = float(setting.childNodes[loc].childNodes[9].childNodes[3].childNodes[0].data)
    skewZ = float(setting.childNodes[loc].childNodes[11].childNodes[3].childNodes[0].data)
    if setting.childNodes[loc].childNodes[13].childNodes[0].data == 'False':
        use_scale_dis = False
    else:
        use_scale_dis = True
    scale_fac = utils.toList(setting.childNodes[loc].childNodes[15].childNodes[0].data)
    loc += 2

    # Presst shape values (xmlPreset.childNodes[5]):
    deform = float(setting.childNodes[loc].childNodes[1].childNodes[0].data)
    rough = float(setting.childNodes[loc].childNodes[3].childNodes[0].data)
    detail = int(setting.childNodes[loc].childNodes[5].childNodes[0].data)
    display_detail = int(setting.childNodes[loc].childNodes[7].childNodes[0].data)
    smooth_fac = float(setting.childNodes[loc].childNodes[9].childNodes[0].data)
    smooth_it = int(setting.childNodes[loc].childNodes[11].childNodes[0].data)
    loc += 2

    # Preset material values (xmlPreset.childNodes[7]):
    loc += 2

    # Preset random values (xmlPreset.childNodes[9]):
    if setting.childNodes[loc].childNodes[1].childNodes[0].data == 'True':
        use_generate = True
    else:
        use_generate = False
    if setting.childNodes[loc].childNodes[3].childNodes[0].data == 'False':
        use_random_seed = False
    else:
        use_random_seed = True
    user_seed = int(setting.childNodes[loc].childNodes[5].childNodes[0].data)

    if title:
        parsed = [title, scaleX, scaleY, scaleZ, skewX, skewY, skewZ,
                  use_scale_dis, scale_fac, deform, rough, detail,
                  display_detail, smooth_fac, smooth_it,
                  use_generate, use_random_seed, user_seed]
    else:
        parsed = [scaleX, scaleY, scaleZ, skewX, skewY, skewZ, use_scale_dis,
                  scale_fac, deform, rough, detail, display_detail, smooth_fac,
                  smooth_it, use_generate, use_random_seed, user_seed]

    return parsed


def save():
    return '{FINISHED}'


def _print():
    for i in presets:
        print(i)
    return '{FINISHED}'