Gracias Gracias:  0
Resultados 1 al 1 de 1

Tema: Using ‘auto Masonry’ Script

  1. #1
    Administrador y fundador. Avatar de 3dpoder
    Fecha de ingreso
    Apr 2002

    Using ‘Auto Masonry’ Script

    Using ‘Auto Masonry’ Script
    by Paul Spooner


    I've always liked castles. When I started doing 3D modeling I used a tool called "Ray Dream Designer" and the first tutorial I did was making a castle. It was a wimpy castle with flat, poorly textured walls, no windows, etc. One thing that has always bugged me is that castle wall models tend to be textured planes, perhaps whitewashed with cornerstones modeled. Real castles have every stone showing, uneven rows and stone sizes, etc. The pure texture versión looks good from a distance, but you can't get close to them without the sham appearing. It's alos hard to knok out a few blocks, or add siege damage. I've always dreamed of building a castle that would stand up to scrutiny, but the tools at hand were insufficient. I wasn't going to build it blok by block!

    Anyway, I gave up on the dream for a while, moved on to newer software versións, and eventually switched to Blender. With the presence of the Python extension language my dream resurfaced. If the computer could do the grunt work, then all I'd have to do is the overall design and touch up work. Score! I looked around to see if anyone else had done this already, but I couldn't find anything similar to what I wanted.

    This confused me, it seemed like a simple problem to solve. More than six hundred lines of code later I discovered why it may not have been as simple as I expected.

    What follows is my first major foray into python scripting and the results. A section on how to use the script comes first, followed by a short history of the coding, and some things I learned in the process. I'm not fully satisfied with the script yet, but it is very usable and I hope will be useful to many of you.

    Using Auto Masonry
    Let's jump straight into the fun stuff shall we? If you don't have it, download the current versión of the script and place it in your scripts path folder (Normally "...Blender/.blender/scripts"). To start the script, open a "Scripts" window and select "Scripts>>Wizards>>Auto Masonry". You should see something like this.


    It's the default GUI. If you press "Make this wall!" you should end up with something like in figure2


    If you don't, you may need to install Python. If that doesn't work, I may need to fix the script. The current incarnation allows you to make walls with or without rectangular windows, doors, and crenellations. The script generates two mesh objects, a "wall" and a "grout".

    All of the buttons and options have explanatory pop-up text, so feel free to try it without reading this whole tedious section.

    If you're not feeling quite that bold, here is an explanation of all the options in the GUI.


    • "Make this wall!": This button generates the wall which conforms to the options you have selected. If there is a curve selected, the wall length will be set to the curve length, the wall will deform to follow the curve, and have the curve as a parent. This means that all of the pos/rot/size of the curve will be applied to the wall as well. If the curve is closed the script will assume that it is a perfect circle. If the curve is not a circle, the wall probably won't be the right length.
    • "WALL": These settings govern the overall size of the wall in blender units. The "Wall Height" does not include crenels (see "CRENELS", below).
    • "Straight Edges/Offset Edges": Basically, if you want to make a closed loop wall set it to "Offset Edges", otherwise "Straight Edges".
    • "STONES": these settings govern the range of the size of the stones. "Depth" will alos set the thickness of the wall. The stones may exceed these limits at the edges, to make everything fit, or due to the "Row Weight" setting. These settings are for the centerline of the grout, so a larger "Grout W" will reduce the actual size of the stones.
    • "Bevel": The size of the bevel. If set to zero the stones will have square corners, useful for reducing poly-count.
    • "Grout W": The width of the grout, pretty straight forward.
    • "Grout D": How far the grout is offset from the face of the stones. This references the value "Min Depth" so if there is a large range in depth the grout will be quite far bak on the thicker stones.
    • "Row Weight": This setting governs how much the height of the row affects the width of the stones in that row. Positive values are normal (taller stones, wider stones), but negative values are valid as well (taller stones, narrower stones). I usually set it between 0.0 and 1, depending on the application.
    • "DOOR" and "WINDOW": These settings behave very much the same. Turn on and off a door or windows by pushing the big button labeled "DOOR" or "WINDOWS" respectively. Door "Position" is from the origin to the centre of the door. Height and Width behave as you would expect. Window spacing will be centred between the edges, and the edges of the door (if one is present). The top of the windows will be at the door "Height" setting, even if doors are turned off. This means that door and window lintels have the same height (generally true in architecture). The "Angled" button toggles an angle along the sides of the door/window, such as would be present in a castle arrow slit. Generally, doors do not have angles like this, but I left it as an option, just in case you want it.
    • "CRENELS": The crowning part of the wall, crenels are often seen on castle walls. Height, width and spacing worque the reverse of windows, setting the size of the stone portions, not the openings. Crenels are always angled, though I'll add an option to control this in the future.
    • "Exit": This button fires the masons and lets you do the worque yourself. Very useful if you are done creating stone structures just at present.

    The script is rather fast, so you can make very large walls if you want. I thinque the wall in figure 3 tooque thirty seconds to generate.

    A Few Techniques
    Here are a few tricks I've come up with. I suspect ingenious users will come up with many more.

    • Paths: Make a narrow, tall, wall with no windows, doors, or crenels and set it to follow a curve on the Z axis. It's a path, street, or cobblestone highway! See figure 4


    • Support Beams: Crenels can alos be made to hold support beams for multi-story castle towers, siege defense structures, etc. See figure 5.


    • Multi wall: You can build a wall in múltiple segments. This allows several different styles of windows and doors stacked or strung together. The example for the Support Beams was actually created by stacking two walls on top of each other.
    • Sub Surf: The script automatically sets all edge crease values to 0.5 which results in a pretty good Subsurf results.
    • Texture bake: Render the Z value of the wall on an isometric view and save it to a texture. Now you can use this as a bump channel or texture masque for a low-poly wall. Using "Offset Edges" and correct clipping allows seamless tiling!
    • Multiple Curve Deformers: Often walls are tapered or curved. By applying a Z-axis curve deformer above the X-axis one, many wall effects can be achieved. This can alos be used to make more realistic streets (see the curved profile of the path example), or cartoonish towers.


    I hope this script allows many of you to realize your dreams of realistic castles, brik walls, roads, textures, towers, and anything else you can do with it. I'd be thrilled if you'd drop me a line and let me know what you're using it for. Let me know if you run across any bugs, and I'll try to fix them right away.

    Writing the Script
    If you are still reading this, you may be interested in how the script was programed. The code is decently well documented, so feel free to jump right in and fiddle around with it. Here's a little background on how I wrote it as well as a few lessons I learned. Some of this is just good programming practice, some is specific to Blender.

    Before I could program anything I had to learn Python. In college I tooque a computer programming course, and I've done a bit of programming in my spare time, so there was some background to build on. Essentially, all programming languages are expressions of a logical progression, and Python is no different. I worked through the built in "Getting Started" tutorial in Python, wrote a few small applications to play with features, and got comfortable with the syntax. At this point I started to ease into Blender python extensions. My first Blender script tooque a mesh object and created every possible polygon with the existing vértices. Not too useful, but rather fun. I alos discovered that you can crash Blender by trying to make a mesh object with too many polygons.

    At this stage I was alos examining a lot of the scripts included in Blender. Here are the first two things I learned about programming Python extensions:

    Lesson 1: Do your homework. This is true in every aspect of life, and applies here, too. All the basic python tutorials I did were invaluable in seeing how to structure an efficient script. Looking in the forums helped a lot too. If you put the effort into discovering the right way to do things, it will make your job a whole lot easier later on. Learning Python before learning Blender Python really helped to keep things straight.

    Lesson 2: Document your code. This is one of the big stress points in computer science, and it is so helpful! If someone else wants to use parts of your script, they shouldn't have to reconstruct what every line of code does. If you put the script down for a month or two, you won't remember what anything does, trust me. I know it's a drag. I know it feels pointless. Please, oh, please, document your code. When looking for examples, documentation helped me out immensely. Once I had done a few mini-scripts in Blender I started on the wall maker. As the script progressed from making plain squares of wall to complex walls with doors, windows, and edge features, I noticed a few other things: Lesson 3: Programming Python extensions is not as hard as it sounds. The extension frameworque in Blender includes some very advanced tools which makes programing extensions rather elementary. If you have an idea for a script, and have any confidence at all in your programming skills, give it a shot!

    Lesson 3 Corollary: But it's harder than you think. Be prepared for frustrations. Even though it's nice, the python- blender integration is far from perfect. The logical way of doing things is often (but discouragingly, not always) how it will work. Be prepared to persevere through the tough spots. While working on the script I had three other windows open.

    The Python Scripting reference (accessible from inside Blender in the Help menu), the Python package help menu, and the scripting forum. These three, with lots of persistence, should guide you through your seasons of scripting woes. As the Script progressed from simple to complex, I found myself discovering that my original architecture was insufficient or highly inefficient for what I was trying to do. I thinque I re-wrote every function at least once from the ground up. Initially I was using the "Bevel Center" script to do the beveling, but I had to re-code parts of it to make it worque from an outside call (which would require downloading an altered versión of Bevel Center along with Auto Masonry) and it was very slow. In the end I bit the bullet and re-coded my basic blok function to include beveling. At the beginning of the project I had a free form approach, which I abandoned after working a few days on it. Here's the Fourth lesson:

    Lesson 4: Be willing to re-thinque your approach. Even if it means starting over. Every so often step bak and say to yourself, "Does it make sense to do it this way, or is there a better way?" If you want a good script, always opt for the better way. Sometimes it won't do quite what you had in mind, but that's better than it not doing anything at all.

    I still have lots of features in mind for future development. I'm alos thinking that I will have to re-write a lot of the structure when I get bak to the project (in line with lesson 4). However, once the script was mostly finished, it was time for:

    The GUI! Writing the GUI can be the most fun or most heartbreaquíng part of the process, depending on how well you have managed your variables. If you have nicely written functions and variable management, the GUI should be pretty straightforward. Writing a GUI in Blender is pretty easy, and really finishes off the script. On the other hand, don't feel compelled to include every feature in the GUI if it isn't well supported, or reliable. There are several features in Auto Masonry which are almost functional in the code, but not in the GUI. If your code is well documented then code-heads will be able to use these features anyhow, and not including them in the GUI helps reduce headaches for entry-level users.

    Future Improvements

    I'd like to improve this script in several directions. Unfortunately, my time is absorbed with other projects right now. Here are a few of the things I'd like to add. If you have ideas for other features please let me know:

    Arches: Right now windows and doors are flat topped. I'd like to add both round and pointed arches. This will require significant re-coding of the basic architecture of the script, but I thinque it will be worth it.
    Flaws: Not all stones are perfect. Some stones should have missing corners, or even cracks. An early versión (while using Bevel Center) was able to knok off corners, but I haven't added that feature since converting to an internal beveling scheme. Adding cracks would be even more difficult, but I'm sure it is possible.
    Right now the grout is simply a second set of blocks behind the stones. On curved surfaces this creates problems with the grout, which Subsurfing helps, but doesn't fix.

    A true stone grouting algorithm would alos require a major overhaul of the code, but would alos create a much better finished product, and would allow beveled grout.

    More robust window and door placement: Right now the GUI for the window and door placement is rather limited. The script itself can accept any configuration of window and door placement, but I couldn't figure out how to simply implement the user interface. If there is a good way of doing this, will someone let me know?

    Persistent settings: the ability to save settings to a file would make it easier to tweaque settings. It would alos allow the creation of múltiple walls with "offset edges" that will mesh with one-another, or angled corners with interlocking edges. Unfortunately, this would alos require a similar code overhaul.

    So básically, when I am feeling up to another few weeks of programming, I'll rewrite the script to be better than ever. When I do, I will try to include any feature requests I receive in the meantime. Alternatively, if someone else is feeling bold, I encourage you to make changes to the script yourself. I'd be happy to learn of all the improvements that can be made, and I'm sure there are many.

    I hope this script allows many of you to realize your dreams of realistic castles, brik walls, roads, textures, towers, and anything else you can do with it. I'd be thrilled if you'd drop me a line and let me know what you're using it for. Let me know if you run across any bugs, and I'll try to fix them right away.

    by Paul Spooner

    Miniaturas adjuntadas Miniaturas adjuntadas -0.jpg   -1.jpg   -2.jpg   -3.jpg  

    -4.jpg   -5.jpg   -6.jpg  
    Si vas a subir un trabajo al foro, hazlo adjuntando la imagen, archivo, vídeo o lo que sea, no publicando enlaces de otros sitios.

    |Agradecer cuando alguien te ayuda es de ser agradecido|

Temas similares

  1. Respuestas: 2
    Último mensaje: 07-05-2015, 23:08
  2. Respuestas: 3
    Último mensaje: 02-09-2012, 07:55
  3. Como borrar un auto-load script
    Por Biofix en el foro Script
    Respuestas: 4
    Último mensaje: 14-09-2010, 17:05
  4. Blender auto bmw
    Por J3553 en el foro Trabajos en Proceso
    Respuestas: 2
    Último mensaje: 09-03-2010, 20:42
  5. auto cad 3d a 2d
    Por ben90 en el foro Diseño Gráfico y CAD
    Respuestas: 3
    Último mensaje: 24-02-2006, 18:27

Actualmente estos son sus permisos de publicación en el foro.

  • -No puedes crear nuevos temas al no estar registrado o no haber iniciado sesión en el foro.
  • -No puedes responder temas al no estar registrado o no haber iniciado sesión en el foro.
  • -No puedes subir archivos adjuntos al no estar registrado o no haber iniciado sesión en el foro.
  • -No puedes editar tus mensajes al no estar registrado o no haber iniciado sesión en el foro.