House primitive

Hi all,

I’m writing a python script for procedural houses modeling and I get blocket for days after the 10 first lines… and I don’t understand why my script simply crashes Blender.

Here is the code, the goal is, in a mesh composed, of single separate edges, to selectt edges one by one, and (for the beginning) to extrude them.


# ArToKi-Homa.py (c) 2011 Thierry Maes (tmaes)
#
# ***** BEGIN GPL LICENSE BLOCK *****
#
#
# 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 2
# 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, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ***** END GPL LICENCE BLOCK *****


bl_info = {
    "name": "ArToKi-HoMa",
    "author": "Thierry Maes (tmaes)",
    "version": (0,0,0),
    "blender": (2, 6, 4),
    "api": 41889,
    "location": "Properties > Object > ArToKi HoMa",
    "description": "Create houses based on simple 2 point lines.",
    "warning": "",
    "wiki_url": "",
    "tracker_url": "",
    "category": "Object"}

"""
This addon is made for mass planification.
It create simple house primitives
"""




import bpy
 
class OBJECT_PT_ArToKi_HoMa(bpy.types.Panel):
    bl_label = "ArToKi - HoMa"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "object"
 
    def draw(self, context):
        layout = self.layout 
        obj = bpy.context.active_object
        row = layout.row()
        row.operator("object.homa_create_houses",text="Create Houses")
        
class OBJECT_OT_HoMa_create_houses(bpy.types.Operator):
    bl_label = "HoMa Create Houses"
    bl_idname = "object.homa_create_houses"
    bl_description = "Transforms 2 point lines to houses"
    @classmethod
    def poll(cls, context):
        return context.active_object is not None

    def execute(self, context):
        #main(context)
        #print('prout')
        for t in bpy.context.active_object.data.edges:            
            t.select=True            
            bpy.ops.object.mode_set(mode='EDIT')            
            bpy.ops.mesh.extrude_edges_move(TRANSFORM_OT_translate={"value":(0,5,0),"constraint_axis":(False,True,False),"constraint_orientation":'NORMAL'})
            bpy.ops.object.mode_set(mode='OBJECT')
            t.select=False 
        return {'FINISHED'}
    
        
        



        
        
 

# registering and menu integration
def register():
    bpy.utils.register_class(OBJECT_PT_ArToKi_HoMa)
    bpy.utils.register_class(OBJECT_OT_HoMa_create_houses)
 
# unregistering and removing menus
def unregister():
    bpy.utils.unregister_class(OBJECT_PT_ArToKi_HoMa)
    bpy.utils.unregister_class(OBJECT_OT_HoMa_create_houses)
 
if __name__ == "__main__":
    register()

If I test it just after rebooting my computer, it works once, every other try makes blender simply crash.

Does anyone have an idea?

Thanks in advance…


Thierry Maes

Hi, I guess your problem is that you can simply iterate trough edges as new edges are added in each operation, changing also their index value…! you should tag them somehow and work from that selection, try vertex groups or bevel property…? Also remember to deselect all and change edit select mode to edges first.

obviously! thank you…

here is a script I just did, it will extrude selected edges using operators, mark seams to tag edges and hide mesh to keep new selections from being extruded… kind of dirty but it works :stuck_out_tongue:

give it a look, have some fun on primitives and see if it helps with your code

http://dl.dropbox.com/u/16486113/Blender/archivos/normal_extrude_edges.py

Wow,that’s what I’m trying to do!
Have you finish the script yet,tmaes?
may I request a tutorial for it!

@liero okay, you answer my two actual principal questions in your script, thank you very much, let me one week to understand the world matrix things :smiley:
@junming ok i’ll put my evolution here as a tutorial I think it will also help me to ‘structurate’ the project.

Here is the project (I already coded it in maxscript, but I’m turning to Blender so…):

In my activities, I often have to fast modelize real Belgian little cities. What is important is orientation and approximative size off the objects.

The fastest way I found in Blender to do this is to integrate 3d ground with mapped aerial view, create a grease layer, and make a grease session with (for the moment) only 2 point lines (see screenshot). Then I convert the layer to path, then to mesh and I have the base for my town.



Now I need the script to separate this object (mesh) in primitives (Houses) and modelise them.

Script steps:
1- copy the base object in a new temporary one and select it (apply custom properties we will need later, I think)
2- for each edge, transform it in house by a procedural way, separate(or duplicate) it and rename it in style House.001
3- delete the temporary mesh
4- ‘drop’ the houses on the 3d ground (I saw a script doing that)

any comment appreciated…

here is a different workflow you can try:

  • convert yor grease pencil layer to bezier
  • edit mode > set spline type > poly
  • ctrl+T > -90 (tilt strokes)
  • curve geometry panel > extrude 1
  • add a solidify modifier > thickness 1

you can convert to mesh later…

Hi,
thank you, I worked hard both to understand your code, suggestions and the project becomes more precise, I will make changes in the workflow but not really what you suggest.

  • Instead of direct procedural building of houses, I will try to code a primitive “house”. and place it using base segments coordinates and orientation given by the grease session paths.
  • this primitive construction will be procedural, based on 6 vertices (in fact a base floor plan).

here is the schema of the primitive, and the construction workflow for the path (grease)


thus new script workflow:
1 - explode a grease layer converted to path into single renamed curve path’s.
2 - place an object on every resulting path using its coordinates size and orientation.

any comment still appreciated!

btw: liero, for your code, I tried it a lot, and I don’t think it extudes edges perpendicularly to the base edge, for the rest, the seams system to tag is a good trick, and I watched the two matrix again but I still don’t understand the matrix things:D(joke)
What I found to extrude perpendicularly an edge i.e. Vector((a,b,0)), is that the two perpendicular vectors are Vector((-b,a,0)) and Vector((b,-a,0)). I always put 0 in Z as I consider working only in xy plan.

So here is the code for the primitive… (I’m proud:RocknRoll:)
I still need to clean the code but it works as I wanted.

It creates a new primitive (to use it, I run it, then I delete the created object, and use instead Add>Mesh>House , to have access to the creation properties)

feedback still appreciated…

Attachments

HoMa4.zip (2.28 KB)

Hi,

here is the primitive “House” :RocknRoll:.




Now I have to spread them on the ground. Inset addon must be activated to use it , to make flat roof put ridge height to 0.

thank you for help, feedback still appreciated!


tmaes

download it,thanks.
is it need to open windows or doors by user? I saw there is only house form in your pic,and there is a window gen in this forum made by dragonlee,is possible put it all together?or am I thinking too much =.=!

Yes, the goal here is to make a very simple customizable LPM basemesh for mass houses creation, now you can accommodate it, at this stage loopcuts and few extrudes are needed.
In fact, I have ideas on procedural floors/doors/windows creation, but for now I need to polish the objects:
1- create custom properties
2- write the ‘position script’ to add lots of houses to a scene
3- create an addon to edit selected House (re-creation based on its custom properties)
4- try to replace “default” generated floor plan by real one and then (in 2015) windows doors etc…

Hi,

I tested the mass houses scatter and it works for ±150 houses at a time, more freezes Blender ( I’d prefer 1000+).
I think the problem is in my procedure:
1- I take a mesh and explode it in edges
2- I catch each edge one by one, and replace it by a house, using the edges orientation, length (not yet) and location.

I think that the calculation is hard for the computer because it doesn’t let it “breath” between two houses, imo it need some break or view refresh (it’s a feeling)…
Here is the code of this ‘scatter’… anyone has an idea?

An other question: in the beginning of the script I duplicate and rename the base object, isn’t there a more programmer way to code it, for the moment it’s a bit trashy, i.e. when the base object name finishes with numbers:o.

thank you in advance…

Hi there,
Here are the first script’s results, soon the tutorial and the test scene…:ba:
This is my town, ± 3000 houses, 1 little hour of computation.
I putted all the same houses, it can be made by zones too, for now I’m testing stability, and although the scripts can be greatly improved by code cleaning(at least 50% computer time I think), it doesn’t often crash.(±87000 faces with ground)

feedback appreciated…




next images…




Hi tmaes,
Have you seen the “Houdini XML Procedural Cities” of cmivfx? it’s talking about building city by using python(but in houdini) ,maybe that will give you some ideas!
But I wish,look forward ,hope, your scripts can modeling the house more …particulars :evilgrin:

Hi,

I have a bit the impression I’m speaking alone…
Here is a video of the scripts running… now I stop flooding.:rolleyes:

last version:
ArToKi HoMa (5).zip (8.92 KB)

Things to know for the 2 points lines:

  • select the ground and make a grease layer working on surface (to trace on the ground)
  • trace 2 points lines during a session (in top view)
  • convert grease layer to path then to mesh.
  • (I don’t know why) separate all edges from this mesh to a new mesh rename this one so that there is no number at the end of the name (for that I know why but not how…for the moment).
  • obviously apply all rotate and scale play…

I prepare a test scene…

Tmaes this is great! WIll test this immediately.
How about some random variations (width height of houses, roof and without roofs) ?

nice work tmaes!
you may also want to consider instantiating models from a library…?
congrats

ok, been playing with scripts now, looking good, I like the script to edit your house later!
but again, a few models and different proportions could work -at least with current level of detail-

hi, thanks for feedback!
@tungee this is not really hard to code, some randomization…I’ll make it , but later, now what I try to do is to be accurate with the real situation.
Thank you for the link, I didn’t know… I think it’s the same kind of workflow…
@liero library, yes maybe some kind of pre-made settings… I also want to detail the basemesh a bit more, i.e. 4 pans roofs.
for now:

  • add interior face of wall (solidify + flip result) it will give ground floor, ceillings.
  • add good materials to good part of the houses (front, rear, left, right facade) maybe try to make base uv’s using known scale
  • I want to play a bit with my new toy (and Cycles :p) and continue on my town…
  • code cleaning 2 files of 350 lines each, it’s doable.
  • floorplan injection
  • manage houses gps coordinates, dream: street address…

Here is the test file:


viewport in cycles.

tmaes