コード例 #1
0
    def __init__(self, wall, o):
        self.wall = wall
        self.o = o
        # get neighbor EMPTYs for <o>
        o2 = wall.getCornerEmpty(o)
        self.o2 = o2
        o1 = wall.getPrevious(o2)
        self.o1 = o1

        context = wall.context
        # temporarily remove drivers for the segment EMPTY object
        o.driver_remove("location")

        # get neighbor EMPTYs for <o1> and <o2>
        e1 = wall.getPrevious(o1)
        attached1 = None if e1 else wall.getReferencesForAttached(o1)
        self.attached1 = attached1
        e2 = wall.getNext(o2)
        attached2 = None if e2 else wall.getReferencesForAttached(o2)
        self.attached2 = attached2
        # vectors
        if e1:
            v1 = o1.location - e1.location
        elif attached1:
            v1 = attached1[1].location - attached1[0].location
        if e2:
            v2 = e2.location - o2.location
        elif attached2:
            v2 = attached2[1].location - attached2[0].location

        p = None
        if (e1 or attached1) and (e2 or attached2):
            # check if v1 and v2 are parallel
            if v1.normalized().cross(v2.normalized()).length < zero2:
                # orient <o> along v1, which gives the same effect as orienting <o> along v2
                dy, dx = v1.y, v1.x
            else:
                # point where the lines defined by v1 and v2 intersect
                l1 = (e1, o1) if e1 else attached1
                l2 = (o2, e2) if e2 else attached2
                p = intersect_line_line(l1[0].location, l1[1].location,
                                        l2[0].location, l2[1].location)[0]
                # orient <o> along the line defined by <o> and <p>
                dy, dx = o.location.y - p.y, o.location.x - p.x
        elif e1 or attached1 or e2 or attached2:
            _v = v1 if e1 or attached1 else v2
            # orient <o> along <_v>
            dy, dx = _v.y, _v.x
        else:
            # orient <o> along the normal to the wall segment defined by <o>
            dy, dx = o1.location.x - o2.location.x, o2.location.y - o1.location.y

        o.rotation_euler[2] = math.atan2(dy, dx)
        context.scene.update()
        # adding drivers for o1 and o2
        addMoverDrivers(o1, o, p)
        addMoverDrivers(o2, o, p)

        makeActiveSelected(context, o)
コード例 #2
0
 def __init__(self, wall, o):
     self.wall = wall
     self.o = o
     # get neighbor EMPTYs for <o>
     o2 = wall.getCornerEmpty(o)
     self.o2 = o2
     o1 = wall.getPrevious(o2)
     self.o1 = o1
     
     context = wall.context
     # temporarily remove drivers for the segment EMPTY object
     o.driver_remove("location")
     
     # get neighbor EMPTYs for <o1> and <o2>
     e1 = wall.getPrevious(o1)
     attached1 = None if e1 else wall.getReferencesForAttached(o1)
     self.attached1 = attached1
     e2 = wall.getNext(o2)
     attached2 = None if e2 else wall.getReferencesForAttached(o2)
     self.attached2 = attached2
     # vectors
     if e1:
         v1 = o1.location - e1.location
     elif attached1:
         v1 = attached1[1].location - attached1[0].location
     if e2:
         v2 = e2.location - o2.location
     elif attached2:
         v2 = attached2[1].location - attached2[0].location
     
     p = None
     if (e1 or attached1) and (e2 or attached2):
         # check if v1 and v2 are parallel
         if v1.normalized().cross(v2.normalized()).length < zero2:
             # orient <o> along v1, which gives the same effect as orienting <o> along v2
             dy, dx = v1.y, v1.x
         else:
             # point where the lines defined by v1 and v2 intersect
             l1 = (e1, o1) if e1 else attached1
             l2 = (o2, e2) if e2 else attached2
             p = intersect_line_line(l1[0].location, l1[1].location, l2[0].location, l2[1].location)[0]
             # orient <o> along the line defined by <o> and <p>
             dy, dx = o.location.y-p.y, o.location.x-p.x
     elif e1 or attached1 or e2 or attached2:
         _v = v1 if e1 or attached1 else v2
         # orient <o> along <_v>
         dy, dx = _v.y, _v.x
     else:
         # orient <o> along the normal to the wall segment defined by <o>
         dy, dx = o1.location.x-o2.location.x, o2.location.y-o1.location.y
     
     o.rotation_euler[2] = math.atan2(dy, dx)
     context.scene.update()
     # adding drivers for o1 and o2
     addMoverDrivers(o1, o, p)
     addMoverDrivers(o2, o, p)
     
     makeActiveSelected(context, o)
コード例 #3
0
ファイル: ops.py プロジェクト: vvoovv/prokitektura-studio
    def execute(self, context):
        obj = appendFromFile(context, self.filepath)
        self.wall.insert(self.o, obj, Door)

        makeActiveSelected(context, obj)
        # Without bpy.ops.transform.translate() some complex stuff (some modifiers)
        # may not be initialized correctly
        bpy.ops.transform.translate()
        return {"FINISHED"}
コード例 #4
0
ファイル: ops.py プロジェクト: vvoovv/prokitektura-studio
 def execute(self, context):
     obj = appendFromFile(context, self.filepath)
     self.wall.insert(self.o, obj, Door)
     
     makeActiveSelected(context, obj)
     # Without bpy.ops.transform.translate() some complex stuff (some modifiers)
     # may not be initialized correctly
     bpy.ops.transform.translate()
     return {'FINISHED'}
コード例 #5
0
 def execute(self, context):
     obj = appendFromFile(context, self.filepath)
     # mark parent object as a container
     obj["container"] = 1
     obj.location = getLevelLocation(context)
     makeActiveSelected(context, obj)
     # Without bpy.ops.transform.translate() some complex stuff (some modifiers)
     # may not be initialized correctly
     bpy.ops.transform.translate()
     return {'FINISHED'}
コード例 #6
0
 def execute(self, context):
     obj = appendFromFile(context, self.filepath)
     # mark parent object as a container
     obj["container"] = 1
     obj.location = getLevelLocation(context)
     makeActiveSelected(context, obj)
     # Without bpy.ops.transform.translate() some complex stuff (some modifiers)
     # may not be initialized correctly
     bpy.ops.transform.translate()
     return {'FINISHED'}
コード例 #7
0
 def execute(self, context):
     if not context.scene.prk.workshopType in pContext.items:
         return {'FINISHED'}
     parent = context.object
     # reset the cache of nodes
     Template.nodeCache.reset()
     # getting the parent template (i.e. it doesn't contain the custom attribute <p>)
     for o in parent.children:
         if not "p" in o:
             self.makeParts(Template(o), context)
             makeActiveSelected(context, parent)
             break
     return {'FINISHED'}
コード例 #8
0
ファイル: ops.py プロジェクト: vvoovv/prokitektura-studio
 def execute(self, context):
     if not context.scene.prk.workshopType in pContext.items:
         return {'FINISHED'}
     parent = context.object
     # reset the cache of nodes
     Template.nodeCache.reset()
     # getting the parent template (i.e. it doesn't contain the custom attribute <p>)
     for o in parent.children:
         if not "p" in o:
             self.makeParts(Template(o), context)
             makeActiveSelected(context, parent)
             break
     return {'FINISHED'}
コード例 #9
0
    def execute(self, context):
        # template Blender object
        o = context.object
        t = Template(o, skipInit=True)
        prk = context.scene.prk
        props = prk.item

        if self.setBaseDirectory:
            prk.baseDirectory = os.path.dirname(os.path.dirname(
                self.directory))

        # find the selected vertices
        bm = t.bm
        v = [v for v in bm.verts if v.select]
        verts = (v[0].co, v[1].co)
        # check if <verts> have the same <z>-coordinate (i.e. <verts> are located horizontally)
        if abs(verts[1].z - verts[0].z) < zero2:
            # verts[0] must be the leftmost vertex
            if verts[0].x > verts[1].x:
                verts = (verts[1], verts[0])
                v = (v[1], v[0])
        else:
            # verts[0] must be the lower vertex
            if verts[0].z > verts[1].z:
                verts = (verts[1], verts[0])
                v = (v[1], v[0])

        # <a> is for asset
        a = appendFromFile(context, self.filepath)
        a.location = verts[0] + self.relativePosition * (verts[1] -
                                                         verts[0]) / 100.
        parent_set(o, a)
        a["t"] = "asset"
        a["t2"] = props.window.assetType
        # the path is set relative to <prk.baseDirectory>
        a["path"] = self.filepath[len(prk.baseDirectory) + 1:]
        # store <vids> for the tuple <v> of BMesh vertices as custom Blender object attributes
        a["vid1"] = t.getVid(v[0])
        a["vid2"] = t.getVid(v[1])
        t.bm.free()
        # side (left or right) for the asset
        if props.assetSideLr != 'n':
            # <slr> stands for <side left or right>
            a["slr"] = props.assetSideLr
        showWired(a)

        makeActiveSelected(context, a)
        # Without bpy.ops.transform.translate() some complex stuff (some modifiers)
        # may not be initialized correctly
        bpy.ops.transform.translate()
        return {'FINISHED'}
コード例 #10
0
ファイル: ops.py プロジェクト: vvoovv/prokitektura-studio
 def execute(self, context):
     # template Blender object
     o = context.object
     t = Template(o, skipInit = True)
     prk = context.scene.prk
     props = prk.item
     
     if self.setBaseDirectory:
         prk.baseDirectory = os.path.dirname(os.path.dirname(self.directory))
     
     # find the selected vertices
     bm = t.bm
     v = [v for v in bm.verts if v.select]
     verts = (v[0].co, v[1].co)
     # check if <verts> have the same <z>-coordinate (i.e. <verts> are located horizontally)
     if abs(verts[1].z - verts[0].z) < zero2:
         # verts[0] must be the leftmost vertex
         if verts[0].x > verts[1].x:
             verts = (verts[1], verts[0])
             v = (v[1], v[0])
     else:
         # verts[0] must be the lower vertex
         if verts[0].z > verts[1].z:
             verts = (verts[1], verts[0])
             v = (v[1], v[0])
     
     # <a> is for asset
     a = appendFromFile(context, self.filepath)
     a.location = verts[0] + self.relativePosition*(verts[1]-verts[0])/100.
     parent_set(o, a)
     a["t"] = "asset"
     a["t2"] = props.window.assetType
     # the path is set relative to <prk.baseDirectory>
     a["path"] = self.filepath[len(prk.baseDirectory)+1:]
     # store <vids> for the tuple <v> of BMesh vertices as custom Blender object attributes
     a["vid1"] = t.getVid(v[0])
     a["vid2"] = t.getVid(v[1])
     t.bm.free()
     # side (left or right) for the asset
     if props.assetSideLr != 'n':
         # <slr> stands for <side left or right>
         a["slr"] = props.assetSideLr
     showWired(a)
     
     makeActiveSelected(context, a)
     # Without bpy.ops.transform.translate() some complex stuff (some modifiers)
     # may not be initialized correctly
     bpy.ops.transform.translate()
     return {'FINISHED'}
コード例 #11
0
    def invoke(self, context, event):
        o = context.object
        bpy.ops.object.mode_set(mode='OBJECT')
        childOffset = createEmptyObject("offset_" + o.name,
                                        context.scene.cursor_location -
                                        o.location,
                                        False,
                                        empty_draw_size=0.01)
        childOffset["t"] = "offset"
        childOffset.parent = o

        # make <childOffset> the active object
        o.select = False
        makeActiveSelected(context, childOffset)
        return {'FINISHED'}
コード例 #12
0
ファイル: ops.py プロジェクト: vvoovv/prokitektura-studio
 def invoke(self, context, event):
     o = context.object
     bpy.ops.object.mode_set(mode='OBJECT')
     childOffset = createEmptyObject(
         "offset_" + o.name,
         context.scene.cursor_location - o.location,
         False,
         empty_draw_size=0.01
     )
     childOffset["t"] = "offset"
     childOffset.parent = o
     
     # make <childOffset> the active object
     o.select = False
     makeActiveSelected(context, childOffset)
     return {'FINISHED'}
コード例 #13
0
ファイル: ops.py プロジェクト: vvoovv/prokitektura-studio
 def invoke(self, context, event):
     o = context.object
     bpy.ops.object.mode_set(mode='OBJECT')
     assetType = context.scene.prk.item.window.assetType
     # Blender EMPTY  object as a placeholder for the offset
     a = createEmptyObject(
         o.name + "_" + assetType,
         context.scene.cursor_location - o.location,
         False,
         empty_draw_size=0.01
     )
     a["t"] = "asset"
     a["t2"] = assetType
     a.parent = o
     props = context.scene.prk.item
     # side (internal or external) for the asset
     if props.assetSideIe != 'n':
         # <sie> stands for <side internal or external>
         a["sie"] = props.assetSideIe
     
     # check if there is a selected vertex and if it defines the node's open end
     index = 0
     for v in o.data.vertices:
         if v.select:
             # iterate through vertex groups of the vertex <v>
             for g in v.groups:
                 name = o.vertex_groups[g.group].name
                 if name[:2] == "e_":
                     index = int(name[2:])
                     break
             if index:
                 break
     if index:
         # remember the index of the node's open end
         a["e"] = index
         
     
     # make <a> the active object
     o.select = False
     makeActiveSelected(context, a)
     return {'FINISHED'}
コード例 #14
0
 def setupMaster(self, context, point1, point2):
     o = self.o
     # create a master EMPTY resembling <o>
     master = createEmptyObject("tmp", o.location, empty_draw_type=o.empty_draw_type, empty_draw_size=o.empty_draw_size)
     master.lock_location[2] = True
     self.master = master
     # rotate master along the line defined by point1 and point2
     master.rotation_euler[2] = math.atan2(point2.y-point1.y, point2.x-point1.x)
     parent_set(o.parent, master)
     
     o.select = False
     # make <o> a slave of <master>
     # x
     x = o.driver_add("location", 0)
     addTransformsVariable(x, "x", master, "LOC_X")
     x.driver.expression = "x"
     # y
     y = o.driver_add("location", 1)
     addTransformsVariable(y, "y", master, "LOC_Y")
     y.driver.expression = "y"
     
     makeActiveSelected(context, master)
コード例 #15
0
    def invoke(self, context, event):
        o = context.object
        bpy.ops.object.mode_set(mode='OBJECT')
        assetType = context.scene.prk.item.window.assetType
        # Blender EMPTY  object as a placeholder for the offset
        a = createEmptyObject(o.name + "_" + assetType,
                              context.scene.cursor_location - o.location,
                              False,
                              empty_draw_size=0.01)
        a["t"] = "asset"
        a["t2"] = assetType
        a.parent = o
        props = context.scene.prk.item
        # side (internal or external) for the asset
        if props.assetSideIe != 'n':
            # <sie> stands for <side internal or external>
            a["sie"] = props.assetSideIe

        # check if there is a selected vertex and if it defines the node's open end
        index = 0
        for v in o.data.vertices:
            if v.select:
                # iterate through vertex groups of the vertex <v>
                for g in v.groups:
                    name = o.vertex_groups[g.group].name
                    if name[:2] == "e_":
                        index = int(name[2:])
                        break
                if index:
                    break
        if index:
            # remember the index of the node's open end
            a["e"] = index

        # make <a> the active object
        o.select = False
        makeActiveSelected(context, a)
        return {'FINISHED'}
コード例 #16
0
ファイル: ops.py プロジェクト: vvoovv/prokitektura-studio
 
 def execute(self, context):
     o = context.scene.objects.active
     area = None
     wall = getWallFromEmpty(context, self, o)
     if not wall:
         self.report({"ERROR"}, "To begin an area, select an EMPTY object belonging to the wall")
         return {'CANCELLED'}
     o = getAreaInstance(context, self).make(o, wall)
     if self.assignUv:
         area = getItem(context, self, o)
         area.assignUv()
     
     if self.createWalls:
         if not area:
             area = getItem(context, self, o)
         finish = FinFlat(context, self)
         finish.createFromArea(area)
         if self.assignUv:
             finish.assignUv()
     
     bpy.ops.object.select_all(action="DESELECT")
     makeActiveSelected(context, o)
コード例 #17
0
ファイル: ops.py プロジェクト: vvoovv/prokitektura-studio
def area_finish(context, op):
    o = getAreaInstance(context, op).finish()
    bpy.ops.object.select_all(action="DESELECT")