Exemplo n.º 1
0
 def create(self, obj, wall, o1, o2):
     self.obj = obj
     self.o1 = o1
     self.o2 = o2
     self.lookup()
     
     left = o1["l"]
     # set the initial locaton of the object at the middle of the wall segment
     sign = 1. if left else -1.
     obj.location = (o1.location + o2.location + sign*self.width.location.x*(o2.location-o1.location).normalized())/2.
     obj.location.z = self.floorToWindow
     
     # set drivers for EMPTYs controlling interior and exterior parts of the window
     # the interior part
     i = self.int.driver_add("location", 1)
     addSinglePropVariable(i, "w", o2, "[\"w\"]")
     i.driver.expression = "-w/2."
     # the exterior part
     e = self.ext.driver_add("location", 1)
     addSinglePropVariable(e, "w", o2, "[\"w\"]")
     e.driver.expression = "w/2."
     
     addBooleanModifier(wall.mesh, o2["g"], self.envelope)
     
     rz = obj.driver_add("rotation_euler", 2)
     addTransformsVariable(rz, "x1", o2 if left else o1, "LOC_X")
     addTransformsVariable(rz, "x2", o1 if left else o2, "LOC_X")
     addTransformsVariable(rz, "y1", o2 if left else o1, "LOC_Y")
     addTransformsVariable(rz, "y2", o1 if left else o2, "LOC_Y")
     rz.driver.expression = "atan2(y2-y1,x2-x1)"
     
     self.keepRatioCenter()
Exemplo n.º 2
0
    def create(self, obj, wall, o1, o2):
        self.obj = obj
        self.o1 = o1
        self.o2 = o2
        self.lookup()

        left = o1["l"]
        # set the initial locaton of the object at the middle of the wall segment
        sign = 1. if left else -1.
        obj.location = (o1.location + o2.location +
                        sign * self.width.location.x *
                        (o2.location - o1.location).normalized()) / 2.
        obj.location.z = self.floorToWindow

        # set drivers for EMPTYs controlling interior and exterior parts of the window
        # the interior part
        i = self.int.driver_add("location", 1)
        addSinglePropVariable(i, "w", o2, "[\"w\"]")
        i.driver.expression = "-w/2."
        # the exterior part
        e = self.ext.driver_add("location", 1)
        addSinglePropVariable(e, "w", o2, "[\"w\"]")
        e.driver.expression = "w/2."

        addBooleanModifier(wall.mesh, o2["g"], self.envelope)

        rz = obj.driver_add("rotation_euler", 2)
        addTransformsVariable(rz, "x1", o2 if left else o1, "LOC_X")
        addTransformsVariable(rz, "x2", o1 if left else o2, "LOC_X")
        addTransformsVariable(rz, "y1", o2 if left else o1, "LOC_Y")
        addTransformsVariable(rz, "y2", o1 if left else o2, "LOC_Y")
        rz.driver.expression = "atan2(y2-y1,x2-x1)"

        self.keepRatioCenter()
Exemplo n.º 3
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)
Exemplo n.º 4
0
 def keepRatioCenter(self):
     o1 = self.o1
     o2 = self.o2
     left = o1["l"]
     # calculate the ratio
     l = self.o2.location - self.o1.location
     k = (self.obj.location - self.o1.location).dot(l)
     l = l.length
     k = k/l
     # half width of the item
     w = self.width.location.x/2.
     k = ( (k-w) if left else (k+w) ) / l
     sign1 = "+" if left else "-"
     sign2 = "-" if left else "+"
     
     x = self.obj.driver_add("location", 0)
     addTransformsVariable(x, "x1", o1, "LOC_X")
     addTransformsVariable(x, "x2", o2, "LOC_X")
     addTransformsVariable(x, "y1", o1, "LOC_Y")
     addTransformsVariable(x, "y2", o2, "LOC_Y")
     addLocDiffVariable(x, "d", o1, o2)
     # the width of the window
     addTransformsVariable(x, "wi", self.width, "LOC_X")
     # the width of the wall
     addSinglePropVariable(x, "wa", o2, "[\"w\"]")
     x.driver.expression = "x1+(x2-x1)*("+str(k)+sign1+"wi/2/d)"+sign1+"(y2-y1)*wa/2/d"
     
     y = self.obj.driver_add("location", 1)
     addTransformsVariable(y, "y1", o1, "LOC_Y")
     addTransformsVariable(y, "y2", o2, "LOC_Y")
     addTransformsVariable(y, "x1", o1, "LOC_X")
     addTransformsVariable(y, "x2", o2, "LOC_X")
     addLocDiffVariable(y, "d", o1, o2)
     # the width of the window
     addTransformsVariable(y, "wi", self.width, "LOC_X")
     # the width of the wall
     addSinglePropVariable(y, "wa", o2, "[\"w\"]")
     y.driver.expression = "y1+(y2-y1)*("+str(k)+sign1+"wi/2/d)"+sign2+"(x2-x1)*wa/2/d"
Exemplo n.º 5
0
def addMoverDrivers(e, o, p=None):
    """
    Add drivers
    
    Args:
        e: A slave, a corner EMPTY that is a direct neighbor of <o>
        o: Segment EMPTY
        p: Intersection point of wall segments that are neighbors of the wall segment defined by <o>.
        If p not preset, add drivers so the current location of <e> is defined by
        the vector (e.location-o.location)
    """

    if p:
        # inital vector connecting <p> and <o>
        m0 = o.location - p
        # initial vector connecting <p> and <e> divided by m0.length_squared
        v0 = (e.location - p) / m0.length_squared

        # x
        x = e.driver_add("location", 0)
        addTransformsVariable(x, "ox", o, "LOC_X")
        addTransformsVariable(x, "oy", o, "LOC_Y")
        # p.x +(m0.x*(ox-p.x)+m0.y*(oy-p.y))*v0.x
        x.driver.expression = strf(p.x) + "+(" + strf(m0.x) + "*(ox-" + strf(
            p.x) + ")+" + strf(m0.y) + "*(oy-" + strf(p.y) + "))*" + strf(v0.x)
        # y
        y = e.driver_add("location", 1)
        addTransformsVariable(y, "ox", o, "LOC_X")
        addTransformsVariable(y, "oy", o, "LOC_Y")
        # p.y +(m0.x*(ox-p.x)+m0.y*(oy-p.y))*v0.y
        y.driver.expression = strf(p.y) + "+(" + strf(m0.x) + "*(ox-" + strf(
            p.x) + ")+" + strf(m0.y) + "*(oy-" + strf(p.y) + "))*" + strf(v0.y)
    else:
        # x
        x = e.driver_add("location", 0)
        addTransformsVariable(x, "x", o, "LOC_X")
        x.driver.expression = "x+(" + strf(e.location.x) + ")-(" + strf(
            o.location.x) + ")"
        # y
        y = e.driver_add("location", 1)
        addTransformsVariable(y, "y", o, "LOC_Y")
        y.driver.expression = "y+(" + strf(e.location.y) + ")-(" + strf(
            o.location.y) + ")"
Exemplo n.º 6
0
def addMoverDrivers(e, o, p=None):
    """
    Add drivers
    
    Args:
        e: A slave, a corner EMPTY that is a direct neighbor of <o>
        o: Segment EMPTY
        p: Intersection point of wall segments that are neighbors of the wall segment defined by <o>.
        If p not preset, add drivers so the current location of <e> is defined by
        the vector (e.location-o.location)
    """
    
    if p:
        # inital vector connecting <p> and <o>
        m0 = o.location - p
        # initial vector connecting <p> and <e> divided by m0.length_squared
        v0 = (e.location - p)/m0.length_squared
        
        # x
        x = e.driver_add("location", 0)
        addTransformsVariable(x, "ox", o, "LOC_X")
        addTransformsVariable(x, "oy", o, "LOC_Y")
        # p.x +(m0.x*(ox-p.x)+m0.y*(oy-p.y))*v0.x
        x.driver.expression = strf(p.x) + "+("+strf(m0.x)+"*(ox-"+strf(p.x)+")+"+strf(m0.y)+"*(oy-"+strf(p.y)+"))*"+strf(v0.x)
        # y
        y = e.driver_add("location", 1)
        addTransformsVariable(y, "ox", o, "LOC_X")
        addTransformsVariable(y, "oy", o, "LOC_Y")
        # p.y +(m0.x*(ox-p.x)+m0.y*(oy-p.y))*v0.y
        y.driver.expression = strf(p.y) + "+("+strf(m0.x)+"*(ox-"+strf(p.x)+")+"+strf(m0.y)+"*(oy-"+strf(p.y)+"))*"+strf(v0.y)
    else:
        # x
        x = e.driver_add("location", 0)
        addTransformsVariable(x, "x", o, "LOC_X")
        x.driver.expression = "x+("+strf(e.location.x)+")-("+strf(o.location.x)+")"
        # y
        y = e.driver_add("location", 1)
        addTransformsVariable(y, "y", o, "LOC_Y")
        y.driver.expression = "y+("+strf(e.location.y)+")-("+strf(o.location.y)+")"
Exemplo n.º 7
0
    def keepRatioCenter(self):
        o1 = self.o1
        o2 = self.o2
        left = o1["l"]
        # calculate the ratio
        l = self.o2.location - self.o1.location
        k = (self.obj.location - self.o1.location).dot(l)
        l = l.length
        k = k / l
        # half width of the item
        w = self.width.location.x / 2.
        k = ((k - w) if left else (k + w)) / l
        sign1 = "+" if left else "-"
        sign2 = "-" if left else "+"

        x = self.obj.driver_add("location", 0)
        addTransformsVariable(x, "x1", o1, "LOC_X")
        addTransformsVariable(x, "x2", o2, "LOC_X")
        addTransformsVariable(x, "y1", o1, "LOC_Y")
        addTransformsVariable(x, "y2", o2, "LOC_Y")
        addLocDiffVariable(x, "d", o1, o2)
        # the width of the window
        addTransformsVariable(x, "wi", self.width, "LOC_X")
        # the width of the wall
        addSinglePropVariable(x, "wa", o2, "[\"w\"]")
        x.driver.expression = "x1+(x2-x1)*(" + str(
            k) + sign1 + "wi/2/d)" + sign1 + "(y2-y1)*wa/2/d"

        y = self.obj.driver_add("location", 1)
        addTransformsVariable(y, "y1", o1, "LOC_Y")
        addTransformsVariable(y, "y2", o2, "LOC_Y")
        addTransformsVariable(y, "x1", o1, "LOC_X")
        addTransformsVariable(y, "x2", o2, "LOC_X")
        addLocDiffVariable(y, "d", o1, o2)
        # the width of the window
        addTransformsVariable(y, "wi", self.width, "LOC_X")
        # the width of the wall
        addSinglePropVariable(y, "wa", o2, "[\"w\"]")
        y.driver.expression = "y1+(y2-y1)*(" + str(
            k) + sign1 + "wi/2/d)" + sign2 + "(x2-x1)*wa/2/d"