Esempio n. 1
0
 def shade(self, stroke):
     originalSize = stroke.stroke_vertices_size()
     if originalSize < 4:
         return
     it = stroke.stroke_vertices_begin()
     invisible = 0
     it2 = StrokeVertexIterator(it)
     it2.increment()
     fe = self.get_fedge(it.object, it2.object)
     if fe.viewedge.qi != 0:
         invisible = 1
     while not it2.is_end:
         v = it.object
         vnext = it2.object
         if (v.nature & Nature.VIEW_VERTEX) != 0:
             #if (v.nature & Nature.T_VERTEX) != 0:
             fe = self.get_fedge(v, vnext)
             qi = fe.viewedge.qi
             if qi != 0:
                 invisible = 1
             else:
                 invisible = 0
         if invisible:
             v.attribute.visible = False
         it.increment()
         it2.increment()
Esempio n. 2
0
 def shade(self, stroke):
     originalSize = stroke.stroke_vertices_size()
     if originalSize < 4:
         return
     it = stroke.stroke_vertices_begin()
     invisible = 0
     it2 = StrokeVertexIterator(it)
     it2.increment()
     fe = self.get_fedge(it.object, it2.object)
     if fe.viewedge.qi != 0:
         invisible = 1
     while not it2.is_end:
         v = it.object
         vnext = it2.object
         if (v.nature & Nature.VIEW_VERTEX) != 0:
             #if (v.nature & Nature.T_VERTEX) != 0:
             fe = self.get_fedge(v, vnext)
             qi = fe.viewedge.qi
             if qi != 0:
                 invisible = 1
             else:
                 invisible = 0
         if invisible:
             v.attribute.visible = False
         it.increment()
         it2.increment()
Esempio n. 3
0
 def shade(self, stroke):
     l = stroke.length_2d
     stretch = self._l * l
     it0 = stroke.stroke_vertices_begin()
     it1 = StrokeVertexIterator(it0)
     it1.increment()
     itn = stroke.stroke_vertices_end()
     itn.decrement()
     itn_1 = StrokeVertexIterator(itn)
     itn_1.decrement()
     v0 = it0.object
     v1 = it1.object
     vn_1 = itn_1.object
     vn = itn.object
     p0 = v0.point_2d
     pn = vn.point_2d
     p1 = v1.point_2d
     pn_1 = vn_1.point_2d
     d1 = (p0 - p1).normalized()
     dn = (pn - pn_1).normalized()
     newFirst = p0 + d1 * float(stretch)
     newLast = pn + dn * float(stretch)
     v0.point = newFirst
     vn.point = newLast
     stroke.update_length()
Esempio n. 4
0
 def shade(self, stroke):
     l = stroke.length_2d
     stretch = self._l*l
     it0 = stroke.stroke_vertices_begin()
     it1 = StrokeVertexIterator(it0)
     it1.increment()
     itn = stroke.stroke_vertices_end()
     itn.decrement()
     itn_1 = StrokeVertexIterator(itn)
     itn_1.decrement()
     v0 = it0.object
     v1 = it1.object
     vn_1 = itn_1.object
     vn = itn.object
     p0 = v0.point_2d
     pn = vn.point_2d
     p1 = v1.point_2d
     pn_1 = vn_1.point_2d
     d1 = (p0 - p1).normalized()
     dn = (pn - pn_1).normalized()
     newFirst = p0+d1*float(stretch)
     newLast = pn+dn*float(stretch)
     v0.point = newFirst
     vn.point = newLast
     stroke.update_length()
Esempio n. 5
0
def stroke_normal(it):
    """
    Compute the 2D normal at the stroke vertex pointed by the iterator
    'it'.  It is noted that Normal2DF0D computes normals based on
    underlying FEdges instead, which is inappropriate for strokes when
    they have already been modified by stroke geometry modifiers.
    """
    # first stroke segment
    it_next = StrokeVertexIterator(it)
    it_next.increment()
    if it.is_begin:
        e = it_next.object.point_2d - it.object.point_2d
        n = mathutils.Vector((e[1], -e[0]))
        n.normalize()
        return n
    # last stroke segment
    it_prev = StrokeVertexIterator(it)
    it_prev.decrement()
    if it_next.is_end:
        e = it.object.point_2d - it_prev.object.point_2d
        n = mathutils.Vector((e[1], -e[0]))
        n.normalize()
        return n
    # two subsequent stroke segments
    e1 = it_next.object.point_2d - it.object.point_2d
    e2 = it.object.point_2d - it_prev.object.point_2d
    n1 = mathutils.Vector((e1[1], -e1[0]))
    n2 = mathutils.Vector((e2[1], -e2[0]))
    n1.normalize()
    n2.normalize()
    n = n1 + n2
    n.normalize()
    return n
Esempio n. 6
0
def stroke_normal(it):
    """
    Compute the 2D normal at the stroke vertex pointed by the iterator
    'it'.  It is noted that Normal2DF0D computes normals based on
    underlying FEdges instead, which is inappropriate for strokes when
    they have already been modified by stroke geometry modifiers.
    """
    # first stroke segment
    it_next = StrokeVertexIterator(it)
    it_next.increment()
    if it.is_begin:
        e = it_next.object.point_2d - it.object.point_2d
        n = mathutils.Vector((e[1], -e[0]))
        n.normalize()
        return n
    # last stroke segment
    it_prev = StrokeVertexIterator(it)
    it_prev.decrement()
    if it_next.is_end:
        e = it.object.point_2d - it_prev.object.point_2d
        n = mathutils.Vector((e[1], -e[0]))
        n.normalize()
        return n
    # two subsequent stroke segments
    e1 = it_next.object.point_2d - it.object.point_2d
    e2 = it.object.point_2d - it_prev.object.point_2d
    n1 = mathutils.Vector((e1[1], -e1[0]))
    n2 = mathutils.Vector((e2[1], -e2[0]))
    n1.normalize()
    n2.normalize()
    n = n1 + n2
    n.normalize()
    return n
Esempio n. 7
0
 def shade(self, stroke):
     it = stroke.stroke_vertices_begin()
     predTVertex = pyVertexNatureUP0D(Nature.T_VERTEX)
     while not it.is_end:
         if predTVertex(it) == 1:
             it2 = StrokeVertexIterator(it)
             it2.increment()
             if not (it.is_begin or it2.is_end):
                 it.increment()
                 continue
             n = self._n
             a = self._a
             if it.is_begin:
                 it3 = StrokeVertexIterator(it)
                 count = 0
                 while (not it3.is_end) and count < n:
                     att = it3.object.attribute
                     (tr, tl) = att.thickness
                     r = (a - 1.0) / float(n - 1) * (
                         float(n) / float(count + 1) - 1) + 1
                     #r = (1.0-a)/float(n-1)*count + a
                     att.thickness = (r * tr, r * tl)
                     it3.increment()
                     count = count + 1
             if it2.is_end:
                 it4 = StrokeVertexIterator(it)
                 count = 0
                 while (not it4.is_begin) and count < n:
                     att = it4.object.attribute
                     (tr, tl) = att.thickness
                     r = (a - 1.0) / float(n - 1) * (
                         float(n) / float(count + 1) - 1) + 1
                     #r = (1.0-a)/float(n-1)*count + a
                     att.thickness = (r * tr, r * tl)
                     it4.decrement()
                     count = count + 1
                 if it4.is_begin:
                     att = it4.object.attribute
                     (tr, tl) = att.thickness
                     r = (a - 1.0) / float(n - 1) * (
                         float(n) / float(count + 1) - 1) + 1
                     #r = (1.0-a)/float(n-1)*count + a
                     att.thickness = (r * tr, r * tl)
         it.increment()
Esempio n. 8
0
 def shade(self, stroke):
     it = stroke.stroke_vertices_begin()
     predTVertex = pyVertexNatureUP0D(Nature.T_VERTEX)
     while not it.is_end:
         if predTVertex(it) == 1:
             it2 = StrokeVertexIterator(it)
             it2.increment()
             if not (it.is_begin or it2.is_end):
                 it.increment()
                 continue
             n = self._n
             a = self._a
             if it.is_begin:
                 it3 = StrokeVertexIterator(it)
                 count = 0
                 while (not it3.is_end) and count < n:
                     att = it3.object.attribute
                     (tr, tl) = att.thickness
                     r = (a-1.0)/float(n-1)*(float(n)/float(count+1) - 1) + 1
                     #r = (1.0-a)/float(n-1)*count + a
                     att.thickness = (r*tr, r*tl)
                     it3.increment()
                     count = count + 1
             if it2.is_end:
                 it4 = StrokeVertexIterator(it)
                 count = 0
                 while (not it4.is_begin) and count < n:
                     att = it4.object.attribute
                     (tr, tl) = att.thickness
                     r = (a-1.0)/float(n-1)*(float(n)/float(count+1) - 1) + 1
                     #r = (1.0-a)/float(n-1)*count + a
                     att.thickness = (r*tr, r*tl)
                     it4.decrement()
                     count = count + 1
                 if it4.is_begin:
                     att = it4.object.attribute
                     (tr, tl) = att.thickness
                     r = (a-1.0)/float(n-1)*(float(n)/float(count+1) - 1) + 1
                     #r = (1.0-a)/float(n-1)*count + a
                     att.thickness = (r*tr, r*tl)
         it.increment()
Esempio n. 9
0
 def shade(self, stroke):
     it0 = stroke.stroke_vertices_begin()
     it1 = StrokeVertexIterator(it0)
     it1.increment()
     itn = stroke.stroke_vertices_end()
     itn.decrement()
     itn_1 = StrokeVertexIterator(itn)
     itn_1.decrement()
     v0 = it0.object
     v1 = it1.object
     if (v0.nature & Nature.CUSP) == 0 and (v1.nature & Nature.CUSP) == 0:
         d1 = (v0.point - v1.point).normalized()
         newFirst = v0.point + d1 * float(self._l)
         v0.point = newFirst
     vn_1 = itn_1.object
     vn = itn.object
     if (vn.nature & Nature.CUSP) == 0 and (vn_1.nature & Nature.CUSP) == 0:
         dn = (vn.point - vn_1.point).normalized()
         newLast = vn.point + dn * float(self._l)
         vn.point = newLast
     stroke.update_length()
Esempio n. 10
0
 def shade(self, stroke):
     it0 = stroke.stroke_vertices_begin()
     it1 = StrokeVertexIterator(it0)
     it1.increment()
     itn = stroke.stroke_vertices_end()
     itn.decrement()
     itn_1 = StrokeVertexIterator(itn)
     itn_1.decrement()
     v0 = it0.object
     v1 = it1.object
     if (v0.nature & Nature.CUSP) == 0 and (v1.nature & Nature.CUSP) == 0:
         d1 = (v0.point - v1.point).normalized()
         newFirst = v0.point+d1*float(self._l)
         v0.point = newFirst
     vn_1 = itn_1.object
     vn = itn.object
     if (vn.nature & Nature.CUSP) == 0 and (vn_1.nature & Nature.CUSP) == 0:
         dn = (vn.point - vn_1.point).normalized()
         newLast = vn.point + dn * float(self._l)
         vn.point = newLast
     stroke.update_length()
Esempio n. 11
0
 def shade(self, stroke):
     it = stroke.stroke_vertices_begin()
     it2 = StrokeVertexIterator(it)
     it2.increment()
     ## case where the first vertex is a TVertex
     v = it.object
     if (v.nature & Nature.T_VERTEX) != 0:
         tv = self.castToTVertex(v)
         if tv is not None:
             ve = self.get_fedge(v, it2.object).viewedge
             dir = self.findOrientation(tv, ve)
             if dir is not None:
                 #print(dir.x, dir.y)
                 v.attribute.set_attribute_vec2("orientation", dir)
     while not it2.is_end:
         vprevious = it.object
         v = it2.object
         if (v.nature & Nature.T_VERTEX) != 0:
             tv = self.castToTVertex(v)
             if tv is not None:
                 ve = self.get_fedge(vprevious, v).viewedge
                 dir = self.findOrientation(tv, ve)
                 if dir is not None:
                     #print(dir.x, dir.y)
                     v.attribute.set_attribute_vec2("orientation", dir)
         it.increment()
         it2.increment()
     ## case where the last vertex is a TVertex
     v = it.object
     if (v.nature & Nature.T_VERTEX) != 0:
         itPrevious = StrokeVertexIterator(it)
         itPrevious.decrement()
         tv = self.castToTVertex(v)
         if tv is not None:
             ve = self.get_fedge(itPrevious.object, v).viewedge
             dir = self.findOrientation(tv, ve)
             if dir is not None:
                 #print(dir.x, dir.y)
                 v.attribute.set_attribute_vec2("orientation", dir)
Esempio n. 12
0
 def shade(self, stroke):
     it = stroke.stroke_vertices_begin()
     it2 = StrokeVertexIterator(it)
     it2.increment()
     ## case where the first vertex is a TVertex
     v = it.object
     if (v.nature & Nature.T_VERTEX) != 0:
         tv = self.castToTVertex(v)
         if tv is not None:
             ve = self.get_fedge(v, it2.object).viewedge
             dir = self.findOrientation(tv, ve)
             if dir is not None:
                 #print(dir.x, dir.y)
                 v.attribute.set_attribute_vec2("orientation", dir)
     while not it2.is_end:
         vprevious = it.object
         v = it2.object
         if (v.nature & Nature.T_VERTEX) != 0:
             tv = self.castToTVertex(v)
             if tv is not None:
                 ve = self.get_fedge(vprevious, v).viewedge
                 dir = self.findOrientation(tv, ve)
                 if dir is not None:
                     #print(dir.x, dir.y)
                     v.attribute.set_attribute_vec2("orientation", dir)
         it.increment()
         it2.increment()
     ## case where the last vertex is a TVertex
     v = it.object
     if (v.nature & Nature.T_VERTEX) != 0:
         itPrevious = StrokeVertexIterator(it)
         itPrevious.decrement()
         tv = self.castToTVertex(v)
         if tv is not None:
             ve = self.get_fedge(itPrevious.object, v).viewedge
             dir = self.findOrientation(tv, ve)
             if dir is not None:
                 #print(dir.x, dir.y)
                 v.attribute.set_attribute_vec2("orientation", dir)
Esempio n. 13
0
 def shade(self, stroke):
     it = stroke.stroke_vertices_begin()          ## get the first vertex
     itlast = stroke.stroke_vertices_end()        ##
     itlast.decrement()                           ## get the last one
     t = itlast.object.point - it.object.point    ## tangent direction
     itmiddle = StrokeVertexIterator(it)          ##
     while itmiddle.object.u < 0.5:               ## look for the stroke middle vertex
         itmiddle.increment()                     ##
     it = StrokeVertexIterator(itmiddle)
     it.increment()
     while not it.is_end: ## position all the vertices along the tangent for the right part
         it.object.point = itmiddle.object.point+t*(it.object.u-itmiddle.object.u)
         it.increment()
     it = StrokeVertexIterator(itmiddle)
     it.decrement()
     while not it.is_begin: ## position all the vertices along the tangent for the left part
         it.object.point = itmiddle.object.point-t*(itmiddle.object.u-it.object.u)
         it.decrement()
     it.object.point = itmiddle.object.point-t*itmiddle.object.u ## first vertex
     stroke.update_length()
Esempio n. 14
0
 def shade(self, stroke):
     it = stroke.stroke_vertices_begin()          ## get the first vertex
     itlast = stroke.stroke_vertices_end()        ##
     itlast.decrement()                           ## get the last one
     t = itlast.object.point - it.object.point    ## tangent direction
     itmiddle = StrokeVertexIterator(it)          ##
     while itmiddle.object.u < 0.5:               ## look for the stroke middle vertex
         itmiddle.increment()                     ##
     it = StrokeVertexIterator(itmiddle)
     it.increment()
     while not it.is_end: ## position all the vertices along the tangent for the right part
         it.object.point = itmiddle.object.point+t*(it.object.u-itmiddle.object.u)
         it.increment()
     it = StrokeVertexIterator(itmiddle)
     it.decrement()
     while not it.is_begin: ## position all the vertices along the tangent for the left part
         it.object.point = itmiddle.object.point-t*(itmiddle.object.u-it.object.u)
         it.decrement()
     it.object.point = itmiddle.object.point-t*itmiddle.object.u ## first vertex
     stroke.update_length()