Beispiel #1
0
    def execute(self):
        bm = context.bm
        state = context.getState()
        shape = state.shape
        # get rectangle origin
        origin = shape.center()
        xVec = self.xSize/2 * xAxis
        yVec = self.ySize/2 * yAxis

        if self.replace:
            context.popState()
            shape.delete()
        
        # rotation matrix
        matrix = rotation_zNormal_xHorizontal(shape.firstLoop, shape.getNormal())
        shape = createRectangle((
            bm.verts.new( (-xVec - yVec)*matrix + origin),
            bm.verts.new( ( xVec - yVec)*matrix + origin),
            bm.verts.new( ( xVec + yVec)*matrix + origin),
            bm.verts.new( (-xVec + yVec)*matrix + origin)
        ))
        if self.operator:
            context.pushState(shape=shape)
            self.operator.execute()
            context.popState()
        elif self.replace:
            context.pushState(shape=shape)
 def execute(self):
     shape = context.getState().shape
     # We now know the absolute shape size, so let's update self.parts
     # for self.symmetric = True and self.relativeCoord1 = False
     if self.symmetric and not self.relativeCoord1:
         self.updateSymmetricAbsolute(shape)
     shapesWithRule = shape.extrude2(self.parts, self)
     # apply the rule for each shape in shapesWithRule list
     for entry in shapesWithRule:
         context.pushState(shape=entry[0])
         entry[1].execute()
         context.popState()
Beispiel #3
0
 def execute(self):
     shape = context.getState().shape
     # only 2D shapes can be copied at the moment!
     if not isinstance(shape, Shape2d): return
     
     duplicate = bmesh.ops.duplicate(context.bm, geom = (shape.face,))
     copiedFace = [entry for entry in duplicate["geom"] if isinstance(entry, bmesh.types.BMFace)][0]
     constructor = type(shape)
     copiedShape = constructor(copiedFace.loops[0])
     
     if self.operator:
         context.pushState(shape=copiedShape)
         self.operator.execute()
         context.popState()
def decompose_execute(shape, _parts):	
	# create a dict from the operatorDef list
	parts = {}
	for part in _parts:
		parts[part.value] = part
	
	# components is a dictionary with a comp-selector as the key and a list of 2D-shapes as the related value 
	components = shape.decompose(parts)
	if len(components)>0:
		# now apply the rule for each decomposed 2D-shape
		for selector in components:
			for _shape in components[selector]:
				context.pushState(shape=_shape)
				parts[selector].execute()
				context.popState()
Beispiel #5
0
	def execute(self):
		shape = context.getState().shape
		
		parts = self.parts if self.reverse==False else reversed(self.parts)
		# Calculate cuts.
		# cuts is a list of tuples (cutShape, ruleForTheCutShape)
		cuts = shape.split(self.direction, parts)
		
		if len(cuts)==1:
			# degenerate case, i.e. no cut is needed
			cuts[0][2].execute()
		else:
			# apply the rule for each cut
			for cut in cuts:
				context.pushState(shape=cut[1])
				cut[2].execute()
				context.popState()
Beispiel #6
0
    def execute(self):
        shape = context.getState().shape

        parts = self.parts if self.reverse == False else reversed(self.parts)
        # Calculate cuts.
        # cuts is a list of tuples (cutShape, ruleForTheCutShape)
        cuts = shape.split(self.direction, parts)

        if len(cuts) == 1:
            # degenerate case, i.e. no cut is needed
            cuts[0][2].execute()
        else:
            # apply the rule for each cut
            for cut in cuts:
                context.pushState(shape=cut[1])
                cut[2].execute()
                context.popState()
 def execute(self):
     shape = context.getState().shape
     face = shape.face
     self.init(len(face.verts))
     manager = Manager()
     roof = Roof(face.verts, shape.getNormal(), manager)
     # soffits
     if self.soffits:
         manager.rule = self.soffit
         roof.inset(*self.soffits, negate=True)
     # fascias
     if self.fasciaSize:
         manager.rule = self.fascia
         roof.translate(self.fasciaSize)
     # hip roof itself
     manager.rule = self.face
     roof.roof(*self.pitches)
     shape.delete()
     # finalizing: if there is a rule for the shape, execute it
     for entry in manager.shapes:
         context.pushState(shape=entry[0])
         entry[1].execute()
         context.popState()
Beispiel #8
0
 def execute(self):
     shape = context.getState().shape
     face = shape.face
     self.init(len(face.verts))
     manager = Manager()
     roof = Roof(face.verts, shape.getNormal(), manager)
     # soffits
     if self.soffits:
         manager.rule = self.soffit
         roof.inset(*self.soffits, negate=True)
     # fascias
     if self.fasciaSize:
         manager.rule = self.fascia
         roof.translate(self.fasciaSize)
     # hip roof itself
     manager.rule = self.face
     roof.roof(*self.pitches)
     shape.delete()
     # finalizing: if there is a rule for the shape, execute it
     for entry in manager.shapes:
         context.pushState(shape=entry[0])
         entry[1].execute()
         context.popState()
 def execute(self):
     shape = context.getState().shape
     face = shape.face
     manager = Manager()
     polygon = Polygon(face.verts, shape.getNormal(), manager)
     manager.rule = self.side
     kwargs = {"height": self.height} if self.height else {}
     polygon.inset(*self.insets, **kwargs)
     # create a shape for the cap if necessary
     cap = self.cap
     if not isinstance(cap, Delete):
         shape = polygon.getShape(type(shape))
         if cap:
             context.pushState(shape=shape)
             self.cap.execute()
             context.popState()
     if not self.keepOriginal:
         context.facesForRemoval.append(face)
     # finalizing: if there is a rule for the shape, execute it
     for entry in manager.shapes:
         context.pushState(shape=entry[0])
         entry[1].execute()
         context.popState()
Beispiel #10
0
 def execute(self):
     shape = context.getState().shape
     face = shape.face
     manager = Manager()
     polygon = Polygon(face.verts, shape.getNormal(), manager)
     
     # process each inset
     for inset in self.insets:
         if isinstance(inset, tuple):
             height = inset[1]
             if isinstance(height, Operator):
                 rule = height
                 height = height.value
             else:
                 rule = self.side
             manager.rule = rule
             if float(inset[0]): # not zero
                 kwargs = {"height": height} if height else {}
                 polygon.inset(inset[0], **kwargs)
             else:
                 polygon.translate(height)
     # create a shape for the cap if necessary
     cap = self.cap
     if not isinstance(cap, Delete):
         shape = polygon.getShape(type(shape))
         if cap:
             context.pushState(shape=shape)
             self.cap.execute()
             context.popState()
     if not self.keepOriginal:
         context.facesForRemoval.append(face)
     # finalizing: if there is a rule for the shape, execute it
     for entry in manager.shapes:
         context.pushState(shape=entry[0])
         entry[1].execute()
         context.popState()
Beispiel #11
0
    def extrude(self):
        bm = context.bm

        loop = self.firstLoop
        normal = loop.face.normal
        # lower vertex (along the first loop)
        vert1 = loop.vert.co
        # neighbor of vert1 to the right
        vert = loop.link_loop_next.vert.co
        # vector from vert1 to vert
        vec1 = vert - vert1
        vec1.normalize()
        # vector along the height of the band of rectangles
        axis = loop.link_loop_prev.vert.co - vert1
        if self.closed:
            # the special case of a closed band of rectangles
            # previous loop
            _loop = loop.link_loop_prev.link_loops[0].link_loop_prev
            vec2 = vec1
            vec1 = vert1 - _loop.vert.co
            vec1.normalize()

            _vertEx1 = getInset(vert1, vec1, vec2, self.getDepth(_loop),
                                self.getDepth(loop), _loop.face.normal, axis)
            _vertEx2 = bm.verts.new(_vertEx1 + axis)
            _vertEx1 = bm.verts.new(_vertEx1)
            prevVertEx1 = _vertEx1
            prevVertEx2 = _vertEx2
            # restore vec1
            vec1 = vec2
        else:
            # extruded counterpart of vert1
            prevVertEx1 = vert1 + self.getDepth(loop) * normal
            # upper vertex (upper neighbor of vert1)
            prevVertEx2 = bm.verts.new(prevVertEx1 + axis)
            prevVertEx1 = bm.verts.new(prevVertEx1)
            # starting rectangle
            shape = createRectangle((loop.vert, prevVertEx1, prevVertEx2,
                                     loop.link_loop_prev.vert))
            if self.join.material:
                context.pushState(shape=shape)
                self.join.material.execute()
                context.popState()

        index = self.end1
        while True:
            context.facesForRemoval.append(loop.face)
            _loop = loop
            _loopNext = _loop.link_loop_next
            if index == self.end2:
                break
            # next loop
            loop = loop.link_loop_next.link_loops[0].link_loop_next
            # neighbor of vert to the right
            vert2 = loop.link_loop_next.vert.co
            # vector from vert to vert2
            vec2 = vert2 - vert
            vec2.normalize()
            vertEx1 = getInset(vert, vec1, vec2, self.getDepth(_loop),
                               self.getDepth(loop), normal, axis)
            vertEx2 = bm.verts.new(vertEx1 + axis)
            vertEx1 = bm.verts.new(vertEx1)
            shape = createRectangle(
                (prevVertEx1, vertEx1, vertEx2, prevVertEx2))
            if self.join.material:
                context.pushState(shape=shape)
                self.join.material.execute()
                context.popState()
            # lower cap
            shape = createRectangle(
                (_loop.vert, _loopNext.vert, vertEx1, prevVertEx1))
            if self.join.material:
                context.pushState(shape=shape)
                self.join.material.execute()
                context.popState()
            # upper cap
            shape = createRectangle(
                (_loopNext.link_loop_next.vert, _loop.link_loop_prev.vert,
                 prevVertEx2, vertEx2))
            if self.join.material:
                context.pushState(shape=shape)
                self.join.material.execute()
                context.popState()

            vec1 = vec2
            vert = vert2
            prevVertEx1 = vertEx1
            prevVertEx2 = vertEx2
            normal = loop.face.normal

            index = loop.face.index

        if self.closed:
            vertEx1 = _vertEx1
            vertEx2 = _vertEx2
        else:
            vertEx1 = vert + self.getDepth(loop) * normal
            vertEx2 = bm.verts.new(vertEx1 + axis)
            vertEx1 = bm.verts.new(vertEx1)
            # closing rectangle
            loop = loop.link_loop_next
            shape = createRectangle(
                (vertEx1, loop.vert, loop.link_loop_next.vert, vertEx2))
            if self.join.material:
                context.pushState(shape=shape)
                self.join.material.execute()
                context.popState()
        shape = createRectangle((prevVertEx1, vertEx1, vertEx2, prevVertEx2))
        if self.join.material:
            context.pushState(shape=shape)
            self.join.material.execute()
            context.popState()
        # lower cap
        shape = createRectangle(
            (_loop.vert, _loopNext.vert, vertEx1, prevVertEx1))
        if self.join.material:
            context.pushState(shape=shape)
            self.join.material.execute()
            context.popState()
        # upper cap
        shape = createRectangle(
            (_loopNext.link_loop_next.vert, _loop.link_loop_prev.vert,
             prevVertEx2, vertEx2))
        if self.join.material:
            context.pushState(shape=shape)
            self.join.material.execute()
            context.popState()
Beispiel #12
0
    def extrude(self):
        bm = context.bm
        
        loop = self.firstLoop
        normal = loop.face.normal
        # lower vertex (along the first loop)
        vert1 = loop.vert.co
        # neighbor of vert1 to the right
        vert = loop.link_loop_next.vert.co
        # vector from vert1 to vert
        vec1 = vert - vert1
        vec1.normalize()
        # vector along the height of the band of rectangles
        axis = loop.link_loop_prev.vert.co - vert1
        if self.closed:
            # the special case of a closed band of rectangles
            # previous loop
            _loop = loop.link_loop_prev.link_loops[0].link_loop_prev
            vec2 = vec1
            vec1 = vert1 - _loop.vert.co
            vec1.normalize()
            
            _vertEx1 = getInset(vert1, vec1, vec2, self.getDepth(_loop), self.getDepth(loop), _loop.face.normal, axis)
            _vertEx2 = bm.verts.new(_vertEx1 + axis)
            _vertEx1 = bm.verts.new(_vertEx1)
            prevVertEx1 = _vertEx1
            prevVertEx2 = _vertEx2
            # restore vec1
            vec1 = vec2
        else:
            # extruded counterpart of vert1
            prevVertEx1 = vert1 + self.getDepth(loop)*normal
            # upper vertex (upper neighbor of vert1)
            prevVertEx2 = bm.verts.new(prevVertEx1 + axis)
            prevVertEx1 = bm.verts.new(prevVertEx1)
            # starting rectangle
            shape = createRectangle((loop.vert, prevVertEx1, prevVertEx2, loop.link_loop_prev.vert))
            if self.join.material:
                context.pushState(shape=shape)
                self.join.material.execute()
                context.popState()

        index = self.end1
        while True:
            context.facesForRemoval.append(loop.face)
            _loop = loop
            _loopNext = _loop.link_loop_next
            if index==self.end2:
                break
            # next loop
            loop = loop.link_loop_next.link_loops[0].link_loop_next
            # neighbor of vert to the right
            vert2 = loop.link_loop_next.vert.co
            # vector from vert to vert2
            vec2 = vert2 - vert
            vec2.normalize()
            vertEx1 = getInset(vert, vec1, vec2, self.getDepth(_loop), self.getDepth(loop), normal, axis)
            vertEx2 = bm.verts.new(vertEx1 + axis)
            vertEx1 = bm.verts.new(vertEx1)
            shape = createRectangle((prevVertEx1, vertEx1, vertEx2, prevVertEx2))
            if self.join.material:
                context.pushState(shape=shape)
                self.join.material.execute()
                context.popState()
            # lower cap
            shape = createRectangle((_loop.vert, _loopNext.vert, vertEx1, prevVertEx1))
            if self.join.material:
                context.pushState(shape=shape)
                self.join.material.execute()
                context.popState()
            # upper cap
            shape = createRectangle((_loopNext.link_loop_next.vert, _loop.link_loop_prev.vert, prevVertEx2, vertEx2))
            if self.join.material:
                context.pushState(shape=shape)
                self.join.material.execute()
                context.popState()
            
            vec1 = vec2
            vert = vert2
            prevVertEx1 = vertEx1
            prevVertEx2 = vertEx2
            normal = loop.face.normal
            
            index = loop.face.index
        
        if self.closed:
            vertEx1 = _vertEx1
            vertEx2 = _vertEx2
        else:
            vertEx1 = vert + self.getDepth(loop)*normal
            vertEx2 = bm.verts.new(vertEx1 + axis)
            vertEx1 = bm.verts.new(vertEx1)
            # closing rectangle
            loop = loop.link_loop_next
            shape = createRectangle((vertEx1, loop.vert, loop.link_loop_next.vert, vertEx2))
            if self.join.material:
                context.pushState(shape=shape)
                self.join.material.execute()
                context.popState()
        shape = createRectangle((prevVertEx1, vertEx1, vertEx2, prevVertEx2))
        if self.join.material:
            context.pushState(shape=shape)
            self.join.material.execute()
            context.popState()
        # lower cap
        shape = createRectangle((_loop.vert, _loopNext.vert, vertEx1, prevVertEx1))
        if self.join.material:
            context.pushState(shape=shape)
            self.join.material.execute()
            context.popState()
        # upper cap
        shape = createRectangle((_loopNext.link_loop_next.vert, _loop.link_loop_prev.vert, prevVertEx2, vertEx2))
        if self.join.material:
            context.pushState(shape=shape)
            self.join.material.execute()
            context.popState()