-
Notifications
You must be signed in to change notification settings - Fork 17
/
model_gen.py
136 lines (107 loc) · 4.04 KB
/
model_gen.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
#!usr/bin/env python
"""
HIERARCHY:
sdf
model
static
link
collision
geometry
heightmap
uri
size
pos
visual
geometry
heightmap
texture -- number of textures you want
diffuse
normal
size
blend -- number of textures - 1
min_height
fade_dist
uri
size
pos
"""
from lxml import etree as ET
def modelGenerator():
sdf = ET.Element("sdf",version="1.4")
model = ET.SubElement(sdf,"model",name="AutoGen Terrain")
static = ET.SubElement(model,"static")
static.text = "true"
link = ET.SubElement(model,"link",name="link")
#Collision element of the model
collision = ET.SubElement(link,"collision",name="collision")
geometry_collision = ET.SubElement(collision,"geometry")
heightmap_collision = ET.SubElement(geometry_collision,"heightmap")
uri = ET.SubElement(heightmap_collision,"uri")
uri.text = "model://autogen_terrain/materials/textures/heightmap.png"
size = ET.SubElement(heightmap_collision,"size")
size.text = "129 129 12"
pos = ET.SubElement(heightmap_collision,"pos")
pos.text = "0 0 0"
#Visual element of the model
visual = ET.SubElement(link,"visual",name="visual")
geometry_visual = ET.SubElement(visual,"geometry")
heightmap_visual = ET.SubElement(geometry_visual,"heightmap")
#Texture1
texture1 = ET.SubElement(heightmap_visual,"texture")
diffuse = ET.SubElement(texture1,"diffuse")
diffuse.text = "model://autogen_terrain/materials/textures/water.jpg"
normal = ET.SubElement(texture1,"normal")
normal.text = "file://media/materials/textures/flat_normal.png"
size = ET.SubElement(texture1,"size")
size.text = "5"
#Texture2
texture2 = ET.SubElement(heightmap_visual,"texture")
diffuse = ET.SubElement(texture2,"diffuse")
diffuse.text = "model://autogen_terrain/materials/textures/sand.jpg"
normal = ET.SubElement(texture2,"normal")
normal.text = "file://media/materials/textures/flat_normal.png"
size = ET.SubElement(texture2,"size")
size.text = "5"
#Texture3
texture3 = ET.SubElement(heightmap_visual,"texture")
diffuse = ET.SubElement(texture3,"diffuse")
diffuse.text = "model://autogen_terrain/materials/textures/grass.jpg"
normal = ET.SubElement(texture3,"normal")
normal.text = "file://media/materials/textures/flat_normal.png"
size = ET.SubElement(texture3,"size")
size.text = "5"
#Texture4
texture4 = ET.SubElement(heightmap_visual,"texture")
diffuse = ET.SubElement(texture4,"diffuse")
diffuse.text = "file://media/materials/textures/dirt_diffusespecular.png"
normal = ET.SubElement(texture4,"normal")
normal.text = "file://media/materials/textures/flat_normal.png"
size = ET.SubElement(texture4,"size")
size.text = "5"
#Blending Textures 1 and 2
blend = ET.SubElement(heightmap_visual,"blend")
min_height = ET.SubElement(blend,"min_height")
min_height.text = "0"
fade_dist = ET.SubElement(blend,"fade_dist")
fade_dist.text = "0.8"
#Blending Textures 2 and 3
blend = ET.SubElement(heightmap_visual,"blend")
min_height = ET.SubElement(blend,"min_height")
min_height.text = "0.1"
fade_dist = ET.SubElement(blend,"fade_dist")
fade_dist.text = "1.5"
#Blending Textures 3 and 4
blend = ET.SubElement(heightmap_visual,"blend")
min_height = ET.SubElement(blend,"min_height")
min_height.text = "3"
fade_dist = ET.SubElement(blend,"fade_dist")
fade_dist.text = "6"
uri = ET.SubElement(heightmap_visual,"uri")
uri.text = "model://autogen_terrain/materials/textures/heightmap.png"
size = ET.SubElement(heightmap_visual,"size")
size.text = "129 129 12"
pos = ET.SubElement(heightmap_visual,"pos")
pos.text = "0 0 0"
#print ET.tostring(sdf,pretty_print=True,xml_declaration=True)
tree = ET.ElementTree(sdf)
tree.write('model.sdf', pretty_print=True, xml_declaration=True)