learned from Povray, building a house and ???!!!

Hi
From building a tree in Blender I got to arabaro (java) form there to povray and
very nice in Blender 2.5.8 there is a Povray-addon using Povray 3.7 (not lower!) and
works nicely!

Got interested in Povray ans saw lots of examples available!

This povray-code e.g (main part, lighting camera etc. left off):


#declare Hx = 2.00;
#declare Hy = 3.50;
#declare Hz = 4.00;
#declare Roof_Angle = 25;//38; 

difference{
box { <-Hx,0,0>,< Hx,Hy,Hz>   
      texture { pigment{ color Green}
                finish { phong 1}
              } // end of texture
      scale <1,1,1> rotate<0,0,0> translate<0,0,0> 
    no_shadow
    } // end of box --------------------------------------

plane{ <0,-1,0>,0 
       texture { pigment{ color rgb<1,0,0>}
                 finish { phong 1}
               } // end of texture
       rotate<0,0,Roof_Angle>
       translate<0,Hy,0>
     }

plane{ <0,-1,0>,0 
       texture { pigment{ color rgb<1,1,1>}
                 finish { phong 1}
               } // end of texture
       rotate<0,0,-Roof_Angle>
       translate<0,Hy,0>
     }

}// end of difference

Showing how to use ‘difference’ ==> inspiring me to use a boolean Modifier
to lead me to:


import bpy
from math import radians
    #van de kubus schuine stukken afsnijden
#NL huis = EN house = DE Haus = FR maison
#NL neiging (an het dak)  = EN .. = DE Neigungg (des Daches)
def maakHuis(neigingLinks = 30, neigingRechts = 30):
    bpy.ops.mesh.primitive_cube_add()
    cube = bpy.context.active_object
    
    bpy.ops.mesh.primitive_plane_add()
    huis = bpy.context.active_object
    huis.name = "Huis"
    
    bpy.ops.transform.resize(value=(2, 2, 2))
    bpy.ops.transform.translate(value=(0, 0, 0.5))
    bpy.ops.transform.rotate(value=(radians(neigingLinks),), axis=(1, 0, 0), constraint_axis=(True, False, False))
    
    bpy.ops.object.modifier_add(type='BOOLEAN')
    mod = huis.modifiers[-1]
    print(mod.operation)
    mod.object = cube
    bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Boolean")
    
    bpy.ops.object.select_all(action='TOGGLE')
    cube.select = True
    bpy.ops.object.delete()
    
    #  deel 1  klaar   herhalen met tweede 'plane'    
    
    bpy.ops.mesh.primitive_plane_add()
    bpy.ops.transform.resize(value=(2, 2, 2))
    bpy.ops.transform.translate(value=(0, 0, 0.5))
    bpy.ops.transform.rotate(value=(-radians(neigingRechts),), axis=(1, 0, 0), constraint_axis=(True, False, False))
    mijnhuis = bpy.context.active_object
    mijnhuis.name = "mijn huis"
    bpy.ops.object.modifier_add(type='BOOLEAN')
    modmijnhuis = mijnhuis.modifiers[-1]
    modmijnhuis.object = huis
    bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Boolean")
    
    bpy.ops.object.select_all(action='TOGGLE')
    huis.select = True
    bpy.ops.object.delete() 
    mijnhuis.select = True
    bpy.ops.transform.translate(value=(0, 0, 1))
    return mijnhuis
maakHuis()

Nice, isn’t it?
Consequence, learn building objects from Povray!

A box in Povray needs lower left corner and upper right corner …
used in imitating building a truck :


def add_box(lowerLeft = [-1,-1,-1],upperRight = [1,1,1]):
    #under #0 - #3, upper #4 - #7 #4 above #0
    height = abs(lowerLeft[2] - upperRight[2])
    width = abs(lowerLeft[1] - upperRight[1]) 
    vertices = [lowerLeft[0], lowerLeft[1], lowerLeft[2], #0
                lowerLeft[0], upperRight[1], lowerLeft[2], #1
                upperRight[0], upperRight[1] , lowerLeft[2],#2
                upperRight[0], lowerLeft[1], lowerLeft[2], #3
                lowerLeft[0], lowerLeft[1], upperRight[2], #4
                lowerLeft[0], upperRight[1], upperRight[2],#5
                upperRight[0], upperRight[1], upperRight[2],#6
                upperRight[0], lowerLeft[1], upperRight[2],#7
                ]
    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,
            ]

    verts_loc = vertices    
    mesh = bpy.data.meshes.new("Box")
    mesh.vertices.add(len(verts_loc) // 3)
    mesh.faces.add(len(faces) // 4)
    mesh.vertices.foreach_set("co", verts_loc)
    mesh.faces.foreach_set("vertices_raw", faces)
    mesh.update()

    # add the mesh as an object into the scene with this utility module
    from bpy_extras import object_utils
    object_utils.object_data_add(bpy.context, mesh)
    box = bpy.context.active_object
    box.name = "box"
    box.location = (0,0,0)
    return box

    

Makes me want to play MonoPoly!

14 quads, though it could be made with 9 and be easier to unwrap and map…

However, I love booleans operations, so top marks from me!

Do you mean ‘neiging’ == ‘inclination’ (or angle)

http://translate.google.co.uk/translate_t?oe=utf-8&rls=org.mozilla:en-US:unofficial&client=firefox-a&q=neiging&um=1&ie=UTF-8&sl=nl&tl=en&sa=X&ei=OaohTsfcEcOYhQfquYTEAw&ved=0CBcQrgYwAA
http://www.dict.cc/german-english/Neigung.html

indeed, neiging is Dutch for inclination :wink:

Problems with modifier Boolean, difference forced me to make a box, where faces shown may be selected. Deleting face 2 works perfect with [0,1,3,4,5] as parameter :wink:


def add_box(lowerLeft = [-1,-1,-1],upperRight = [1,1,1], withFaces = [0,1,2,3,4,5]):
    #under #0 - #3, upper #4 - #7 #4 above #0
    height = abs(lowerLeft[2] - upperRight[2])
    width = abs(lowerLeft[1] - upperRight[1]) 
    vertices = [lowerLeft[0], lowerLeft[1], lowerLeft[2], #0
                lowerLeft[0], upperRight[1], lowerLeft[2], #1
                upperRight[0], upperRight[1] , lowerLeft[2],#2
                upperRight[0], lowerLeft[1], lowerLeft[2], #3
                lowerLeft[0], lowerLeft[1], upperRight[2], #4
                lowerLeft[0], upperRight[1], upperRight[2],#5
                upperRight[0], upperRight[1], upperRight[2],#6
                upperRight[0], lowerLeft[1], upperRight[2],#7
                ]
    face= {}
    face[0] = (0, 1, 2, 3,)  
    face[1] = (4, 7, 6, 5,)  
    face[2] = (0, 4, 5, 1,)  
    face[3] = (1, 5, 6, 2,)  
    face[4] = (2, 6, 7, 3,)  
    face[5] = (4, 0, 3, 7,)
    faces = []
    for el in withFaces:
        faces.extend(face[el])
    
#    print("
============",faces)
    '''
    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,
            ]
    '''
    verts_loc = vertices
    
    mesh = bpy.data.meshes.new("Box")

    mesh.vertices.add(len(verts_loc) // 3)
    mesh.faces.add(len(faces) // 4)

    mesh.vertices.foreach_set("co", verts_loc)
    mesh.faces.foreach_set("vertices_raw", faces)
    mesh.update()

    # add the mesh as an object into the scene with this utility module
    from bpy_extras import object_utils
    object_utils.object_data_add(bpy.context, mesh)
    box = bpy.context.active_object
    box.name = "box"
    box.location = (0,0,0)
    return box    


So one example (totally script)
http://www.petergragert.info/pmwiki/uploads/Povray/truckHeli.gif

I am struggeling with modifiers in the script …
A box is gets three times cut via ‘DIFFERENCE’ boolean modifier.
I used a circumwent: building 3 the modifiers more or less after each other
bpy.ops.object.modifier_add(type=‘BOOLEAN’)
and the used objects were constructed EARLIER
Obj1, obj2, obj3
parentobject
build modifiers
use obj1 and apply
use obj2 and apply
use obj3 and apply

But I would like to work as follows:
parentobject
build first modifier
build obj1
apply modifier

build obj2

QUESTION: and now how to add a modifier for parentobject.

all deselecting all,
then
parentobject.select = True
now:
bpy.ops.object.modifier_add(type=‘BOOLEAN’)

does not do the job!

the modifier is attached to obj2!

Thus I do not know yet to select parentobject REALLY, that command I am asking for :wink:

found :wink:
it is something like this
bpy.context.scene.objects.active = bpy.data.objects[‘object which should get an modifier’]