def shade(self, stroke): for i in range(1, self._nbIter): it = stroke.stroke_vertices_begin() while not it.is_end: v = it.object p1 = v.point p2 = self._normalInfo(Interface0DIterator( it)) * self._lambda * self._curvatureInfo( Interface0DIterator(it)) v.point = p1 + p2 it.increment() stroke.update_length()
def normal_at_I0D(it: Interface0DIterator) -> Vector: """Normal at an Interface0D object. In contrast to Normal2DF0D this function uses the actual data instead of underlying Fedge objects. """ if it.at_last and it.is_begin: # corner-case return Vector((0, 0)) elif it.at_last: it.decrement() a, b = it.object, next(it) elif it.is_begin: a, b = it.object, next(it) # give iterator back in original state it.decrement() elif it.is_end: # just fail hard: this shouldn not happen raise StopIteration() else: # this case sometimes has a small difference with Normal2DF0D (1e-3 -ish) it.decrement() a = it.object curr, b = next(it), next(it) # give iterator back in original state it.decrement() return (b.point - a.point).orthogonal().normalized()
def shade(self, stroke): for i in range(1, self._nbIter): it = Interface0DIterator(stroke) for svert in it: svert.point += self._normalInfo( it) * self._lambda * self._curvatureInfo(it) stroke.update_length()
def shade(self, stroke): it = Interface0DIterator(stroke) for svert in it: normal = self._getNormal(it) a = self._a * (1 - 2 * (abs(svert.u - 0.5))) n = normal * a * cos(self._f * svert.u * 6.28) svert.point += n stroke.update_length()
def shade(self, stroke): it = stroke.stroke_vertices_begin() while not it.is_end: toto = Interface0DIterator(it) att = it.object.attribute att.color = (0.3, 0.4, 0.4) att.thickness = (0, 5) it.increment()
def shade(self, stroke): func = Curvature2DAngleF0D() it = Interface0DIterator(stroke) for svert in it: c = func(it) if c < 0 and bpy.app.debug_freestyle: print("py2DCurvatureColorShader: negative 2D curvature") color = 10.0 * c / pi svert.attribute.color = (color, color, color)
def shade(self, stroke): it = stroke.stroke_vertices_begin() z_min = 1 z_max = 0 while not it.is_end: z = self.__func(Interface0DIterator(it)) if z < z_min: z_min = z if z > z_max: z_max = z it.increment() z_diff = 1 / (z_max - z_min) it = stroke.stroke_vertices_begin() while not it.is_end: z = (self.__func(Interface0DIterator(it)) - z_min) * z_diff thickness = (1 - z) * self.__max + z * self.__min it.object.attribute.thickness = (thickness, thickness) it.increment()
def shade(self, stroke): it = stroke.stroke_vertices_begin() func = Curvature2DAngleF0D() while not it.is_end: c = func(Interface0DIterator(it)) if c < 0: print("negative 2D curvature") color = 10.0 * c / 3.1415 it.object.attribute.color = (color, color, color) it.increment()
def shade(self, stroke): it = Interface0DIterator(stroke) delta_threshold = self.threshold_max - self.threshold_min delta_thickness = self._thicknessMax - self._thicknessMin for svert in it: c = self._func(it) c = bound(self.threshold_min, c, self.threshold_max) t = (self.threshold_max - c) / delta_threshold * delta_thickness + self._thicknessMin svert.attribute.thickness = (t / 2.0, t / 2.0)
def shade(self, stroke): it = Interface0DIterator(stroke) z_indices = tuple(self.func(it) for _ in it) z_min, z_max = min(1, *z_indices), max(0, *z_indices) z_diff = 1 / (z_max - z_min) for svert, z_index in zip(stroke, z_indices): z = (z_index - z_min) * z_diff thickness = (1 - z) * self.__max + z * self.__min svert.attribute.thickness = (thickness, thickness)
def shade(self, stroke): z_min = 0.0 z_max = 1.0 a = (self.__max - self.__min) / (z_max - z_min) b = (self.__min * z_max - self.__max * z_min) / (z_max - z_min) it = stroke.stroke_vertices_begin() while not it.is_end: z = self.__func(Interface0DIterator(it)) thickness = a * z + b it.object.attribute.thickness = (thickness, thickness) it.increment()
def shade(self, stroke): it = Interface0DIterator(stroke) for svert in it: dir = self.func(it) if dir.length != 0.0: dir.normalize() fac = abs(dir.orthogonal() * self.orientation) b = self.thickness.min + fac * self.thickness.delta else: b = self.thickness.min self.blend_thickness(svert, b)
def shade(self, stroke): it = stroke.stroke_vertices_begin() func = MaterialF0D() xn = 0.312713 yn = 0.329016 Yn = 1.0 un = 4. * xn / (-2. * xn + 12. * yn + 3.) vn = 9. * yn / (-2. * xn + 12. * yn + 3.) while not it.is_end: mat = func(Interface0DIterator(it)) r = mat.diffuse[0] g = mat.diffuse[1] b = mat.diffuse[2] X = 0.412453 * r + 0.35758 * g + 0.180423 * b Y = 0.212671 * r + 0.71516 * g + 0.072169 * b Z = 0.019334 * r + 0.119193 * g + 0.950227 * b if (X, Y, Z) == (0, 0, 0): X = 0.01 Y = 0.01 Z = 0.01 u = 4. * X / (X + 15. * Y + 3. * Z) v = 9. * Y / (X + 15. * Y + 3. * Z) L = 116. * pow((Y / Yn), (1. / 3.)) - 16 U = 13. * L * (u - un) V = 13. * L * (v - vn) if L > self._threshold: L = L / 1.3 U = U + 10 else: L = L + 2.5 * (100 - L) / 5. U = U / 3.0 V = V / 3.0 u = U / (13. * L) + un v = V / (13. * L) + vn Y = Yn * pow(((L + 16.) / 116.), 3.) X = -9.0 * Y * u / ((u - 4.0) * v - u * v) Z = (9.0 * Y - 15.0 * v * Y - v * X) / (3.0 * v) r = 3.240479 * X - 1.53715 * Y - 0.498535 * Z g = -0.969256 * X + 1.875991 * Y + 0.041556 * Z b = 0.055648 * X - 0.204043 * Y + 1.057311 * Z r = max(0, r) g = max(0, g) b = max(0, b) it.object.attribute.color = (r, g, b) it.increment()
def shade(self, stroke): xn = 0.312713 yn = 0.329016 Yn = 1.0 un = 4.0 * xn / (-2.0 * xn + 12.0 * yn + 3.0) vn = 9.0 * yn / (-2.0 * xn + 12.0 * yn + 3.0) it = Interface0DIterator(stroke) for svert in it: mat = self._func(it) r, g, b, *_ = mat.diffuse X = 0.412453 * r + 0.35758 * g + 0.180423 * b Y = 0.212671 * r + 0.71516 * g + 0.072169 * b Z = 0.019334 * r + 0.11919 * g + 0.950227 * b if not any((X, Y, Z)): X = Y = Z = 0.01 u = 4.0 * X / (X + 15.0 * Y + 3.0 * Z) v = 9.0 * Y / (X + 15.0 * Y + 3.0 * Z) L = 116. * pow((Y / Yn), (1. / 3.)) - 16 U = 13. * L * (u - un) V = 13. * L * (v - vn) if L > self._threshold: L /= 1.3 U += 10. else: L = L + 2.5 * (100 - L) * 0.2 U /= 3.0 V /= 3.0 u = U / (13.0 * L) + un v = V / (13.0 * L) + vn Y = Yn * pow(((L + 16.) / 116.), 3.) X = -9. * Y * u / ((u - 4.) * v - u * v) Z = (9. * Y - 15 * v * Y - v * X) / (3. * v) r = 3.240479 * X - 1.53715 * Y - 0.498535 * Z g = -0.969256 * X + 1.875991 * Y + 0.041556 * Z b = 0.055648 * X - 0.204043 * Y + 1.057311 * Z r = max(0, r) g = max(0, g) b = max(0, b) svert.attribute.color = (r, g, b)
def shade(self, stroke, func=GetShapeF1D(), curvemat=CurveMaterialF0D()): shape = func(stroke)[0].id.first item = self.shape_map.get(shape) if len(stroke) > 2: if item is not None: item[0].append(stroke) else: # the shape is not yet present, let's create it. material = curvemat(Interface0DIterator(stroke)) *color, alpha = material.diffuse self.shape_map[shape] = ([stroke], color, alpha) # make the strokes of the second drawing invisible for v in stroke: v.attribute.visible = False
def shade(self, stroke): it = stroke.stroke_vertices_begin() while not it.is_end: v = it.object #print(self._getNormal.name) n = self._getNormal(Interface0DIterator(it)) p = v.point u = v.u a = self._a * (1 - 2 * (abs(u - 0.5))) n = n * a * cos(self._f * u * 6.28) #print(n.x, n.y) v.point = p + n #v.point = v.point+n*a*cos(f*v.u) it.increment() stroke.update_length()
def shade(self, stroke): n = stroke.stroke_vertices_size() i = 0 it = stroke.stroke_vertices_begin() func = DensityF0D(self.wsize) while not it.is_end: c = func(Interface0DIterator(it)) if c < self.threshold_min: c = self.threshold_min if c > self.threshold_max: c = self.threshold_max ## t = (c - self.threshold_min)/(self.threshold_max - self.threshold_min)*(self._thicknessMax-self._thicknessMin) + self._thicknessMin t = (self.threshold_max - c )/(self.threshold_max - self.threshold_min)*(self._thicknessMax-self._thicknessMin) + self._thicknessMin it.object.attribute.thickness = (t/2.0, t/2.0) i = i+1 it.increment()
def shade(self, stroke, attributes={'DIFF', 'SPEC', 'LINE'}): it = Interface0DIterator(stroke) if not self.use_ramp and self.attribute in attributes: for svert in it: material = self.func(it) if self.attribute == 'LINE': b = material.line[0:3] elif self.attribute == 'DIFF': b = material.diffuse[0:3] else: b = material.specular[0:3] a = svert.attribute.color svert.attribute.color = self.blend_ramp(a, b) else: for svert, value in iter_material_value(stroke, self.func, self.attribute): a = svert.attribute.color b = self.evaluate(value) svert.attribute.color = self.blend_ramp(a, b)
def iter_material_value(stroke, func, attribute): """Yields a specific material attribute from the vertex' underlying material.""" it = Interface0DIterator(stroke) for svert in it: material = func(it) # main if attribute == 'LINE': value = rgb_to_bw(*material.line[0:3]) elif attribute == 'DIFF': value = rgb_to_bw(*material.diffuse[0:3]) elif attribute == 'SPEC': value = rgb_to_bw(*material.specular[0:3]) # line separate elif attribute == 'LINE_R': value = material.line[0] elif attribute == 'LINE_G': value = material.line[1] elif attribute == 'LINE_B': value = material.line[2] elif attribute == 'LINE_A': value = material.line[3] # diffuse separate elif attribute == 'DIFF_R': value = material.diffuse[0] elif attribute == 'DIFF_G': value = material.diffuse[1] elif attribute == 'DIFF_B': value = material.diffuse[2] elif attribute == 'ALPHA': value = material.diffuse[3] # specular separate elif attribute == 'SPEC_R': value = material.specular[0] elif attribute == 'SPEC_G': value = material.specular[1] elif attribute == 'SPEC_B': value = material.specular[2] elif attribute == 'SPEC_HARDNESS': value = material.shininess else: raise ValueError("unexpected material attribute: " + attribute) yield (svert, value)
def diffuse_from_stroke(stroke, curvemat=CurveMaterialF0D()): material = curvemat(Interface0DIterator(stroke)) return material.diffuse
def __call__(self, inter): it = Interface0DIterator(inter) # sum the turns, check against n return sum(1 for _ in it if self.func(it) > self._a) > self._n
def shade(self, stroke): it = Interface0DIterator(stroke) for svert in it: z = self.func(it) thickness = self.a * z + self.b svert.attribute.thickness = (thickness, thickness)