Random level generator (0.3 for Blender 2.49)

Piichan What exactly is a 'tile" this is the hardest part of you wonderful script for me to understand.

@SHABA1
A tile is one of those squares on the floor, it’s a rectangular portion of space in a given floor

So is there any way of determining just how many blender units each tile is?

And I know this is a silly question, but did this script use to be called “Dungeon Creator”?

Nevermind is it still called “Dungeon Generator” I just looked at the first post’ link.

This is one of those wonderful blender scripts that I downloaded but never got around to using.

Hai,
Can you make it more parametric. If so I think it will be more useful for architects and interior designers
Thanks

@swathi
Sorry for the late reply.
What kind of parameters would need more specifically?

For the next version, for sure there will be a second interior generation algorithm.
Less obvious: custom meshes for your tile.
The problem with custom meshes is that they have a meaning (for example ceiling lamps) and should be connected in specific ways (for example elevated floors). So how can the user specify all this? I’ll have to choose a simple solution to start with.

I love this tool. Its easy to use. You have documented it very well,although it does require searching through this tread to find out how to make it work. If you need someone to make a pdf or html documentation page I would volunteer. My python coding skill are not very good but I do have a talent for explaining technical things.

Hai, I mean like parametric size(length,width and hight) for rooms and user defined positioning of doors and windows etc. Actually I have no idea how much coding it will take. But if you can it will be great.
Thanks

@SHABA1
Documentation writers are definitely ALWAYS welcome :smiley:
If you do anything in HTML, I could put it online, and the PDF could be in the zip download along with the script itself.

Hi, nice script … but for <= 2.49???

I am starting a conversion to 2.58(1) :wink: (if you agree piiichan) at my
wiki (will be removed if you do not agree) http://www.petergragert.info/pmwiki/pmwiki.php/Dungeon/Index

Why on a wiki? it is more suitable than a forum (and no restriction to the length of code as is here done) and as a boss I can …

See my first comment on the comments-page

Menu, first (default values?) is this 26-6

Any whishes can be put there or HERE …


First test … on the way

rooms [[15, 15, 0], [16, 12, 0], [3, 0, 0], [0, 2, 0], [0, 3, 0], [4, 27, 0], [3, 29, 0], [11, 29, 0], [6, 29, 0], [7, 29, 0]]
len(dungeon.dat)= 30
dat[0] = [[{‘linkUp’: False, ‘type’: 4294967295, ‘linkBelow’: False}], <snip not further interesting, only showing that it works …>
]]

Attachments


@PKHG
Very nice man :slight_smile:
If you have the time and motivation to port it, please go ahead.

Very interesting PKHG but you know all those number mean nothing to us no programmer types. BTW those colors in the screenshots on your wiki, were they from lights or colors you added to the walls and floors within blender?

The coloured dungeon is done using voronoi texture …
Oh, the lights were not yet available, they were done afterwords … (voronoi texture!)

can’t find the meaning of ‘uniform’ (in 249 version used in createLights)

Taking random.uniform
Works …
http://www.petergragert.info/pmwiki/uploads/Dungeon/withLightDungeon1.jpg

Going strong! UV-map works too (yet horizontal mirror to be done)

http://www.petergragert.info/pmwiki/uploads/Jpeg/DungeonWithImage.jpg

checked your site/forum,
looks nice,
but ? the script there is not uptodate to your pictures?
Ive got an error about using the add_object_data()
routine from the script-utils.
blender-2.581 r37173 … other addons using this function (like torus) are working.

Just a minute ago updated …

and again … did not know how to remove pictures
so the pictures got names dungeon_(a number, increasing…) :wink: seems to work nice!

Now the material part … (suggestion for floor and walls ? )

Working on the docs now. Doing this on my days off from work so do not hold your breath waiting. I tend to be a procrastinating perfectionist.

Now the material part … (suggestion for floor and walls ? )
@PKHG: What about something like this to ease material creation. This variation causes the createMesh function to generate 3 objects. One for the floor, one for the ceiling and one for the walls. It still does not deal with UV mapping, but at least gives the end user some flexibility for materials.


    def createMesh(self, createRoof=False, probaMat1=0.7, probaMat2=0.3):
        """Creates the 3D mesh representing the dungeon"""
        # create the mesh
        me_floor = bpy.data.meshes.new(name="dungeon_floor")
        me_ceiling = bpy.data.meshes.new(name="dungeon_ceiling")
        me_walls = bpy.data.meshes.new(name="dungeon_wall")
        
        #populate the mesh with faces
        totFaces = 0 # the total nb of face in the dungeon mesh

        faces_floor = []
        faces_ceiling = []
        faces_wall = []
        edges = []
        
        vertices_floor = []
        vertices_ceiling = []
        vertices_walls = []
        
        currentFloorFace = 0
        currentCeilingFace = 0
        currentWallFace = 0
        
        margin = 0.01 # a thin safety margin so that ceiling and floor faces aren't superimposed

        for z in range(self.dungeonHeight):
            totFloorConnections = 0 # the total number of connections with the floor below
            for x in range(self.dungeonWidth):
                for y in range(self.dungeonLength):
                    lvlHeight = z * self.wallHeight
                    # create floors and  walls (walls only at the edge of inside and outside)
                    if self.dat[x][y][z]['type'] == self.TYPE_INSIDE:
                        if not self.dat[x][y][z]['linkBelow']:
                            vertices_floor.append([x*self.cellSize,            y*self.cellSize,            lvlHeight])
                            vertices_floor.append([(x+1)*self.cellSize,        (y)*self.cellSize,            lvlHeight])
                            vertices_floor.append([(x+1)*self.cellSize,        (y+1)*self.cellSize,        lvlHeight])
                            vertices_floor.append([x*self.cellSize,            (y+1)*self.cellSize,        lvlHeight])
                            faces_floor.append([currentFloorFace*4+0,        currentFloorFace*4+1,        currentFloorFace*4+2,        currentFloorFace*4+3])
                            currentFloorFace += 1

                        # ceiling face
                        if createRoof and not self.dat[x][y][z]['linkUp']:
                            vertices_ceiling.append([x*self.cellSize,            (y+1)*self.cellSize,        lvlHeight + self.wallHeight - margin])
                            vertices_ceiling.append([(x+1)*self.cellSize,        (y+1)*self.cellSize,        lvlHeight + self.wallHeight - margin])
                            vertices_ceiling.append([(x+1)*self.cellSize,        (y)*self.cellSize,            lvlHeight + self.wallHeight - margin])
                            vertices_ceiling.append([x*self.cellSize,            y*self.cellSize,            lvlHeight + self.wallHeight - margin])
                            faces_ceiling.append([currentCeilingFace*4+0,        currentCeilingFace*4+1,        currentCeilingFace*4+2,        currentCeilingFace*4+3])
                            currentCeilingFace += 1

                        # west(left) wall intact: build it
                        if (0 &lt; x and self.dat[x-1][y][z]['type'] == self.TYPE_OUTSIDE) or x &lt;= 0:
                            vertices_walls.append([x*self.cellSize,        y*self.cellSize,            lvlHeight + 0])
                            vertices_walls.append([x*self.cellSize,        (y+1)*self.cellSize,        lvlHeight + 0])
                            vertices_walls.append([x*self.cellSize,        (y+1)*self.cellSize,        lvlHeight + self.wallHeight])
                            vertices_walls.append([x*self.cellSize,        y*self.cellSize,            lvlHeight + self.wallHeight])
                            faces_wall.append([currentWallFace*4+0,        currentWallFace*4+1,        currentWallFace*4+2,        currentWallFace*4+3])
                            currentWallFace += 1

                        # east(right) wall intact: build it
                        if (x &lt; self.dungeonWidth-1 and self.dat[x+1][y][z]['type'] == self.TYPE_OUTSIDE) or x &gt;= self.dungeonWidth-1:
                            vertices_walls.append([(x+1)*self.cellSize, (y+1)*self.cellSize, lvlHeight + 0])
                            vertices_walls.append([(x+1)*self.cellSize, (y)*self.cellSize,   lvlHeight + 0])
                            vertices_walls.append([(x+1)*self.cellSize, (y)*self.cellSize,   lvlHeight + self.wallHeight])
                            vertices_walls.append([(x+1)*self.cellSize, (y+1)*self.cellSize, lvlHeight + self.wallHeight])
                            faces_wall.append([currentWallFace*4+0, currentWallFace*4+1, currentWallFace*4+2, currentWallFace*4+3])
                            currentWallFace += 1

                        # south wall intact: build it
                        if (0 &lt; y and self.dat[x][y-1][z]['type'] == self.TYPE_OUTSIDE) or y &lt;= 0:
                            vertices_walls.append([(x+1)*self.cellSize, (y)*self.cellSize, lvlHeight + 0])
                            vertices_walls.append([(x)*self.cellSize,   (y)*self.cellSize, lvlHeight + 0])
                            vertices_walls.append([(x)*self.cellSize,   (y)*self.cellSize, lvlHeight + self.wallHeight])
                            vertices_walls.append([(x+1)*self.cellSize, (y)*self.cellSize, lvlHeight + self.wallHeight])
                            faces_wall.append([currentWallFace*4+0, currentWallFace*4+1, currentWallFace*4+2, currentWallFace*4+3])
                            currentWallFace += 1

                        # north wall intact: build it
                        if (y &lt; self.dungeonLength-1 and self.dat[x][y+1][z]['type'] == self.TYPE_OUTSIDE) or y &gt;= self.dungeonLength-1:
                            vertices_walls.append([x*self.cellSize,            (y+1)*self.cellSize,        lvlHeight + 0])
                            vertices_walls.append([(x+1)*self.cellSize,        (y+1)*self.cellSize,        lvlHeight + 0])
                            vertices_walls.append([(x+1)*self.cellSize,        (y+1)*self.cellSize,        lvlHeight + self.wallHeight])
                            vertices_walls.append([x*self.cellSize,            (y+1)*self.cellSize,        lvlHeight + self.wallHeight])
                            faces_wall.append([currentWallFace*4+0,        currentWallFace*4+1,        currentWallFace*4+2,        currentWallFace*4+3])
                            currentWallFace += 1


        # add vertices and faces
        me_floor.from_pydata(vertices_floor, edges, faces_floor)
        me_floor.validate(verbose=True)
        add_object_data(bpy.context, me_floor)
        ob = bpy.context.active_object
        ob.location = [0.0,0.0,0.0]
        mat = bpy.data.materials.new('mat_floors')
        ob.data.materials.append(mat)
        mat.diffuse_color = (0.6, 0.4, 0.2)
        
        me_walls.from_pydata(vertices_walls, edges, faces_wall)
        me_walls.validate(verbose=True)
        add_object_data(bpy.context, me_walls)
        ob = bpy.context.active_object
        ob.location = [0.0,0.0,0.0]
        mat = bpy.data.materials.new('mat_walls')
        ob.data.materials.append(mat)
        mat.diffuse_color = (0.2, 0.4, 0.6)
        
        me_ceiling.from_pydata(vertices_ceiling, edges, faces_ceiling)
        me_ceiling.validate(verbose=True)
        add_object_data(bpy.context, me_ceiling)
        ob = bpy.context.active_object
        ob.location = [0.0,0.0,0.0]
        mat = bpy.data.materials.new('mat_ceiling')
        ob.data.materials.append(mat)
        mat.diffuse_color = (0.4, 0.2, 0.6)

For my image, I joined the three meshes together, removed doubles and recalculated normals. I still get some funky normals in the viewport, however…?

Attachments


this is awesome !
its giving me an error in 2.58 though T~T

Will look at it … because my way of UV editiging is not yet possible because of API problems (not to be solved shortly) so
directly creating 3 sorts of meshes is a good idea and it looks like that you gave the solution already … YOU DID

Will change the source at the my wiki immediately :yes: