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
| #
# Afficher un tableau SOKOBAN dans la scène Blender
#
import bpy, os
levels = [
# 50 Tableaux (1 ligne = 1 tableau)
"0000111110000000000000001222100000000000000013221000000000000011122311000000000000122323210000000000111212112100011111101222121121111122551012322322222222225510111112111216112255100000122222111111111000001111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"1111111111110000000015522122222111000000155221232232210000001552213111122100000015522226211221000000155221212232110000001111112113232100000000123223232321000000001222212222210000000011111111111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"0000000000000000000000000000111111110000000000001222226100000000000012313211000000000000123223100000000000001132321000001111111112321211100015555221123223221000115552222322322210001555522111111111100011111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"0000000000011111111000000000000122555510111111111111225555101222212232322255551012333132232122555510122322222321225555101233213232311111111012232122222100000000112111111111000000001222212222110000000012222232221100000000122331332261000000001222212222110000000011111111111000000000000000000000000000000000000000000000000000000000000000000000",
"0000000000000000000000000000000111110000000000000001222111110000000000012131122100000000000122222321000111111111211122210001555522112322311100015555222232332110000155552211322326100001111111112232211000000000000123232210000000000001112112100000000000000122221000000000000001111110000000000000000000000000000000000000000000000000000000000000",
"1111110011100000000015522101161100000000155221112221000000001552222233210000000015522121232100000000155111212321000000001111232132210000000000012231232100000000000123223221000000000001221122210000000000011111111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"0000000111110000000001111111222110000000112126112332100000001222232222221000000012232211122210000000111211111311100000001232211125510000000012323232555100000000122221115551000000001233210155510000000012211101111100000000111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"0000011110000000000000000122111111111110000001222232223232100000012312321223221000000122323221222210000111231212211112100001613232322112221000012222321312221210000122232222323232100001111122111111111000000122222210000000000001222222100000000000015555551000000000000155555510000000000001555555100000000000011111111000000000000000000000000000",
"0000000000000000000000000000000111111100000000000001225551000000000111112255510000000001222222525100000000012211225551000000000112112255510000000011121111111100000000123332110000000011111223232111110001122213232221222100016232232222322321000111111233232111110000000012222221000000000000111111110000000000000000000000000000000000000000000000",
"0111001111111111111011611112222222122210123322233223232555101223331222232215551012322212332332155510111222122322221555101222221232323215551012222111111211155510112122122323221555101221121233232311551012551212232222221510125512123332333215101111121222222212151000001211111111121510000012222222222215100000111111111111111000000000000000000000",
"0000000000111100000000000111101221000000000111261113210000000011222222322100000001122323311211000000012213112222210000000121232332121110000001222321221232111110111122221223321222101111211232222222221015222211122111111110155255101111000000001555151000000000000015555510000000000000111111100000000000000000000000000000000000000000000000000000",
"1111111111111111000012222222222222210000121211111122222100001212232323231221000012122236322211211000121223232311155510001212223232211555100012111333232115551000122222121121155510001111122211222555100000001111122222111000000000001222221000000000000011111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"0001111111110000000000112221122111110000111222221221222211101223213212212255521012123163112121515210122121322122225252101232222321212151521012221122113232525210123212221221315152101123223222322355521001321111112222112210012210000111111111100111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"0000000111111100000001111111222221000000012222212363210000000133212221111111110001211155555511222100012223555555112121000121115555552222210011222111121112131100122132221223221210001223233322123112100012223232111332121000111112222232221210000000111211122212100000000012222212221000000000111111112210000000000000000111100000000000000000000000",
"0001111111100000000000012221221000000000000122322210000000000111213222111100000001223221132221000000012212623212310000000122122222232111100001121111311222221000012315555512122210000122355445231211100011221555551222100000122211122111111000001233221222100000000012212222221000000000111111222210000000000000011111100000000000000000000000000000",
"1111100000000000000012221100000000000000122221001111000000001232211112210000000012233232223100000000111621322221100000000122112232321100000001232211211251000000012213113221510000000111222355115100000000122221545551000000001233215555510000000012211111111100000000122100000000000000001111000000000000000000000000000000000000000000000000000000",
"0001111111111000000000015522122210000000000155222222100000000001552212211110000000111111122122110000001222222222222100000012212211221221000011112112211112110000122322111112122100001212322322123221000012632232221222110000111121121111111000000001222210000000000000011111100000000000000000000000000000000000000000000000000000000000000000000000",
"0000011111111111000000000122522122210000000001215222262100000111112115512111100011221255111222221110123215552223212232101222255211221121121011113113123212221210001121222213233212100012232121221231121000122222222222222210001221111111111122100011110000000001111000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"0011111100000000000000122261111000000000111112322210000000001222112222111100000012321221122221000000123212211111210000001123223222212100000011232321112121000000112122322121210000001121213122212100000011211122212121111110122322111121215555101222232222322255151011113223123222555510122222221221125555101111111111111111111000000000000000000000",
"0000111111111100000011111222222221111000122222122232216210001211111113111122111012122221121221325510121232222212212215101212322122222132551012122111211222221510121112212212213255101212222122111122151012132223223221325510122223212323212215101111231112222132551000012222332111555510000122222211011111100001111111100000000000000000000000000000",
"1111111110000000000012222222100000000000122222221111000000001121111212210000000011216112222100000000123332322331000000001221211232210000000012212112232111100000111122333231221000000122211222555510000001212221215525100000012221212115551000000111112322155510000000000112221111100000000000111110000000000000000000000000000000000000000000000000",
"1111110000011110000012222111111122111110122231221223221222101223223223212323221011323222126123222210122321111111111121101212221555555512310012112212555555122100121222355555555321001212321555525512210012232311113111123100123222111232223221101232222232322322221011211111123211111210122222222212222222101111111111111111111000000000000000000000",
"0000111111100000000000001221221111000000111112313212211000001552122122122210000015521231321223111100152212222213221221001552223122123222210015561221321322122100155212312222231221001552122133132212211015521231221223132210155212212212221222101152111122111112221001111001111000111110000000000000000000000000000000000000000000000000000000000000",
"1111111111111110000015555555555225111100155555555553351221001111111111132122211012222223223222223210112111122212232122101222222122211221211012231221211221112110123213111222211121101112232122122111211011122223211212212110012322122322323222100122322313332212221001221223222222111110012611221221221000000111111111111110000000000000000000000000",
"1111000000000000000012211111111111111000122122255155555510001221212111112555100011312222555555551000122211311111122111101232122222111111621011321232221111112210122321333112222222101222222122221313111012111121333332222100121222232222212221001212221122222222111012111111311111123210122222222100001222101111111111000011111000000000000000000000",
"0111111100000000000001221221111100000000112212215551110000001223122155522100000012321332555221000000122312215552510000001222123111111110000011322222223232100000112212233212221000000111111221133610000000000012222221100000000000111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"0111111111111111110001555222122221222110115555522311212132101555555122322122221015555551221221212210111111111232232322100012222213113211311001122232222123222210012211211121221132100123233222223223221001232222311321111110011111112262110000000000000111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"0000000001111100000000000111112221000000000011232232211110001111123223232115100012222222332211551000122111111211155210001121221222215552100012322212222155521000162132112111155510001111223233221155100000011223232235551000000012332232122510000000122232322111100000001111112221000000000000000111110000000000000000000000000000000000000000000000",
"1111100000000000000012221100000000000000123221111111110000001121212222222111111011212223131622122210122122222232122232101221112111111111211012211255455555212110112112454554542121101231111111111211321012232223223222232210122122212221222122101111111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"0000000111111111110000000001222122222100111110012222232321001222111112311212110012321122212112322100123226332121133321001121112221211222210011212221112111113100112122222322155551001221112112321555511012322232122215535210122112321221155552101111122211111155511000001111100001111100000000000000000000000000000000000000000000000000000000000000",
"0011110000000000000000122111111111000000011221122122210000000122312363222111100001322322123231221100112231121323222221001221221212223332210012322223223112111100123232131221221000001122111221113210000001221555522222100000011115555551111000000001555511110000000000015551100000000000000155510000000000000001111100000000000000000000000000000000",
"0000001111000000000000111112210000000000011222223100000000001123221121110000000016323212322100000000111121122231000000000155551323210000000001555512223100000000015555223321100000000155521232221000000001111113232210000000000000122211100000000000001321110000000000000012210000000000000000111100000000000000000000000000000000000000000000000000",
"1111111111110000000011222221122100000000112223222321000000001111211233210000000012223212222100000000123332121111000000001222121232110000000012212212232100000000123123122221000000001222551211110000000011115523216100000000155555123121000000001155551223210000000011155112222100000000111111111111000000000000000000000000000000000000000000000000",
"0111111111000000000001555522211000000000015151223211000000001155551212611000000012555512212211000000122222132113210000001121112232222100000001322323231221000000012122323211210000000122111221122100000001222211211211000000012232122322100000000111323222111000000000012211111000000000000111100000000000000000000000000000000000000000000000000000",
"1111111111110111111012221222212111555510122233122262255555101222121112221255551011211211122122555510012323222221212111100122323112212222221011112122111121211210122121322211212222101232232212112122211012123232222121222100122321121121211111001233222223322100000011211211123221000000012222101222210000000111111011111100000000000000000000000000",
"0000000000001111100011111001111112221000122211112232323210001232221121121122110012223232222232232100111232211211222221100012111112111113321001131111126112222210012322111311123221100123221222111221110001233232122233210000012222212221122100000111111155251110000000001555555555100000000015555555551000000000111111111110000000000000000000000000",
"1111111111100000000015555552221111111110155555522212211222101551112322223222221015552323212221122210155513111112222122101112222122213221321000122332323223112210001223222131321132100011121121222211221000012232321121111110000122223223221000000001122212122210000000001111161111100000000000001110000000000000000000000000000000000000000000000000",
"0000001111000000000011111112610000000000122222322100000000001222311231000000000011315551210000000000012355522100000000000121525121100000000001222121321000000000013223222210000000000122111111100000000001111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"0000000000000111111001111111111111555510112221122222115555101223311223261155551012222223323122555510122321123321212555101223211232212255551011211111211121151110112223223211222522101231112212111112111012223222122222221000122321323231112210001233312322210111100012222122332100000000111111222111000000000000011111000000000000000000000000000000",
"0000111111111111000000001222222222211000000012212133232210000000132131221126100000011211212321211000000122232132212100000001222123222121000000011232322211210000000122122112232100000001222211233121000011111133222122210000155551221111111100001515552110000000000015555222100000000000155552221000000000001111111110000000000000000000000000000000",
"0000000000011111000000000000001122211000000000000112222210000000000011223322100000000001123322321000000000012322223210001111000122233211111012211111111211222210152222222222223336101512111111121122211015121111111521323110155555555555212222101111111111111122321000000000000001122110000000000000001111000000000000000000000000000000000000000000",
"0000011111111000000000111122222211111100001222211232322261000012112113132323110011125555551223321100122255555512212221001212555555132232210012135555552331232100122211121113223211001112232232232232100000122322322322321000001111112221111110000000000111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"0000000011111110000000001111122122111100000012221222322221000111121332112112210011222222121221121110122111231322322322101555222212112212221015551222262121112110155512211122322322101111111101122212221000000000001111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"0111110000000000000001222100000000000000012121111111000000000122222236111111000001232113211122210000012111123222232100000121111121221321111011221111211322222210122312232212112112101222222222121555121011111122111225552210000001111012155512100000000000121112121000000000001222222210000000000011111111100000000000000000000000000000000000000000",
"1111101111000000000015551012211110000000155511122322100000001555511232231110000011555511222322100000111555211232321000001211222212232210000012211212111211110000123212132232222100001223262322223221000012221232332321110000122111111221110000001211000011110000000011100000000000000000000000000000000000000000000000000000000000000000000000000000",
"1111111111000000000012222222211110000000121111112122110000001212323232232100000012222222132221000000111322331221110000000012211212311000000000113122232610000000000122323211100000000001212223221000000000012112221210000000001122111112100000000012222222221000000000155555551110000000001555555510000000000011111111100000000000000000000000000000",
"0000000001111000000001111111112211000000112232222223211111001222112112221155510012133232331311555100121222622212225551001223121113322255510012322332232115555100111322222221111111000012211111110000000000111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"0011111111100000000000145414541000000000001545454510000000000014545454100000000000154545451000000000001454545410000000000011122211100000000000001222100000000000111111211111100000001222222222221010000012323232323210000000112323232321100000000132323232310000000001222363222100000000012211111221000000000111100011110000000000000000000000000000",
"0000000111100000000000000001221100000000000000012221100000000000000123321100000000000111322321100000001111222232221000001112212111112210000012222121555532100000121222325555121000001223212154551210000011122111121112100000001111263221131100000000011123222221000000000001221122210000000000011111111100000000000000000000000000000000000000000000",
"0000001111111111110000000115522221222100000011554232222321000001155451212123110000015545121212322100111155512212222121001221121222222222210012632321112212221100123222322212122210001113322212121212100000122232221212111110001231211111222222100013222100012222121000122111000112222210001221000000122221100011110000001111110000000000000000000000"
]
#
# Supprime tous les objets de type MESH présent dans la scène
#
def delete_all():
scene = bpy.context.scene
for ob in scene.objects:
if ob.type == 'MESH':
ob.select = True
else:
ob.select = False
bpy.ops.object.delete()
#
# Ajoute un cube à la scene
#
def createCube(name):
verts = [(1.0, 1.0, -1.0),
(1.0, -1.0, -1.0),
(-1.0, -1.0, -1.0),
(-1.0, 1.0, -1.0),
(1.0, 1.0, 1.0),
(1.0, -1.0, 1.0),
(-1.0, -1.0, 1.0),
(-1.0, 1.0, 1.0)]
faces = [(0, 1, 2, 3),
(4, 7, 6, 5),
(0, 4, 5, 1),
(1, 5, 6, 2),
(2, 6, 7, 3),
(4, 0, 3, 7)]
mesh_data = bpy.data.meshes.new("cube_mesh_data")
mesh_data.from_pydata(verts, [], faces)
mesh_data.update() # (calc_edges=True) not needed here
cube_object = bpy.data.objects.new(name, mesh_data)
scene = bpy.context.scene
scene.objects.link(cube_object)
cube_object.select = True
return cube_object
#
# Ajoute un plan à la scene
#
def createPlane(name):
verts = [(1.0, 1.0, -1.0),
(1.0, -1.0, -1.0),
(-1.0, -1.0, -1.0),
(-1.0, 1.0, -1.0)]
faces = [(0, 1, 2, 3)]
mesh_data = bpy.data.meshes.new("plane_mesh_data")
mesh_data.from_pydata(verts, [], faces)
mesh_data.update() # (calc_edges=True) not needed here
plane_object = bpy.data.objects.new(name, mesh_data)
scene = bpy.context.scene
scene.objects.link(plane_object)
plane_object.select = True
return plane_object
#
# Charger une image comme texture
#
def createMaterial(imgName, texName, matName):
realpath = os.path.expanduser(imgName)
try:
img = bpy.data.images.load(realpath)
except:
raise NameError("Cannot load image %s" % realpath)
tex = bpy.data.textures.new(texName, 'IMAGE')
print("Recast", tex, tex.type)
print("Done", tex, tex.type)
tex.image = img
mat = bpy.data.materials.new(matName)
mtex = mat.texture_slots.add()
mtex.texture = tex
mtex.texture_coords = 'ORCO'
mtex.use_map_color_diffuse = True
mtex.mapping = 'CUBE'
mat.diffuse_intensity = 0.5
mat.specular_intensity = 0
mat.emit = 0.1
mat.ambient = 0.5
mat.preview_render_type = 'CUBE'
mat.use_face_texture = True
return mat
#
# Affiche le niveau 'index'
#
def loadlevel(index):
lvl = levels[index]
x = -19
y = -10
pos = 0
while pos < len(lvl):
c = lvl[pos: pos+1]
if(c == '1'):
mesh = createCube("z_%d" % pos)
mesh.data.materials.append(matWall)
mesh.location.x = x
mesh.location.y = y
if(c == '2' or c == '6' or c == '3'):
mesh = createPlane("z_%d" % pos)
mesh.data.materials.append(matFloor)
mesh.location.x = x
mesh.location.y = y
if(c == '5' or c == '4'):
mesh = createPlane("z_%d" % pos)
mesh.data.materials.append(matZone)
mesh.location.x = x
mesh.location.y = y
if(c == '3'):
mesh = createCube("z_%d" % pos)
mesh.data.materials.append(matBox01)
mesh.location.x = x
mesh.location.y = y
if(c == '4'):
mesh = createCube("z_%d" % pos)
mesh.data.materials.append(matBox02)
mesh.location.x = x
mesh.location.y = y
x = x + 2
if(x > 19):
x = -19
y = y + 2
pos = pos + 1
#
# TEXTURES (Placer les votre)
#
matFloor = createMaterial("C:\workspace\python\\blender\\sokoban\\textures\\floor_01.jpg", "txt_floor_01", "mat_floor_01")
matWall = createMaterial("C:\workspace\python\\blender\\sokoban\\textures\\wall_01.jpg", "txt_wall_01", "mat_wall_01")
matBox01 = createMaterial("C:\workspace\python\\blender\\sokoban\\textures\\wood_box_01.jpg", "txt_wood_box_01", "mat_wood_box_01")
matBox02 = createMaterial("C:\workspace\python\\blender\\sokoban\\textures\\wood_box_02.jpg", "txt_wood_box_02", "mat_wood_box_02")
matZone = createMaterial("C:\workspace\python\\blender\\sokoban\\textures\\floor_zone.jpg", "txt_floor_zone", "mat_floor_zone")
#
# Programme principal
#
delete_all()
loadlevel(8) |
Partager