libraryextensions/blender/demos/CosyLogo.xtl

CosyLogo.xtl -- the CoSy logo as a Blender scene: the letters C, o, S, y as round tubes, toothpaste style, fused where they touch, glossy magenta on yellow, turned once round. Each letter is its center line, an array of points traced from the logo (pixels, y down); X_eTaL places them in meters, and Blender gives each line a round tube and round ends, then melts the tubes into one mesh. Shared by the demo (demos/cosy.xtl: the video) and its test (a tiny still). Import: "cy:" u_se< "CosyLogo"

source · imports bp: extensions/blender/lib/Bpy.xtl

The letters

ˡletterC : Int

value · line 16

the C: a big arc open to the right, top end to bottom end (pixels, x right, y down)

ˡletterC ← 10 2 r̲eshape 1045 160  950 108  820 100  705 140  652 250  665 385  745 480  880 515  1000 492  1062 440
Used in: ˡs̲cene

ˡletterS : Int

value · line 18

the S: top curl to bottom curl

ˡletterS ← 11 2 r̲eshape 1285 190  1250 120  1185 105  1125 140  1118 220  1180 285  1245 340  1265 430  1220 505  1150 505  1105 445
Used in: ˡs̲cene

ˡyArm : Int

value · line 20

the y's arm: down from the left and up into the stem

ˡyArm ← 6 2 r̲eshape 1312 235  1330 330  1370 410  1430 425  1485 360  1508 215
Used in: ˡs̲cene

ˡyStem : Int

value · line 22

the y's stem: down from the top right, below the line and back left

ˡyStem ← 6 2 r̲eshape 1512 215  1505 380  1475 520  1420 585  1360 560  1330 470
Used in: ˡs̲cene

ʰringAngles : Float

value (private) · line 25
ʰringAngles ← (3.141592653589793 ÷ 4.0) × f̲loat (r̲ange 8) − 1
Used in: ˡletterO

ˡletterO : Float

value · line 32

the o: a ring of eight points about (912, 355), 75 pixels out (a closed line)

      "cy:" u̲se< "CosyLogo"
      s̲hape ᶜʸletterO
8 2
ˡletterO ← 2 1 t̲ranspose (2 c̲at 8) r̲eshape (912.0 + 75.0 × c̲os ʰringAngles) c̲at 355.0 + 75.0 × s̲in ʰringAngles
Used in: ˡs̲cene

ˡradius : Float

value · line 34

the tubes' radius: 52 pixels, in meters

ˡradius ← 0.004 × 52.0
Used in: ʰt̲ube

ˡp̲lace : Num a => a -> Float

function · line 43

cy:p_lace points: pixels (n by 2) to meters (n by 3, z up, the letters upright in x z, facing -y): 250 pixels a meter, the logo's middle (1100, 340) at the origin

      "cy:" u̲se< "CosyLogo"
      ᶜʸp̲lace 2 2 r̲eshape 1100 340  1350 90
0.0 0.0 0.0
1.0 0.0 1.0
ˡp̲lace ← { p →
  n ← 1 s̲elect s̲hape p
  x ← 0.004 × (f̲loat 1 s̲elect₂ p) − 1100.0
  z ← 0.004 × 340.0 − f̲loat 2 s̲elect₂ p
  2 1 t̲ranspose (3 c̲at n) r̲eshape x c̲at (n r̲eshape 0.0) c̲at z
}
Used in: ʰt̲ube

The scene

ʰn̲ums : Any c => (a, b) -> c -> Char

function (private) · line 53
ʰn̲ums ← { (v, k) z → "nums('" c̲at (f̲ormat r̲avel v) c̲at "', " c̲at (f̲ormat k) c̲at ")" }
Used in: ʰt̲ube

ʰplayer : Char

value (private) · line 58
ʰplayer ← ("parts = []\n" c̲at
  "\n" c̲at
  "def tube(name, pts, r, closed):\n" c̲at
  "    cu = bpy.data.curves.new(name, 'CURVE')\n" c̲at
  "    cu.dimensions = '3D'\n" c̲at
  "    cu.bevel_mode = 'ROUND'\n" c̲at
  "    cu.bevel_depth = r\n" c̲at
  "    cu.bevel_resolution = 8\n" c̲at
  "    cu.resolution_u = 24\n" c̲at
  "    cu.use_fill_caps = True\n" c̲at
  "    sp = cu.splines.new('BEZIER')\n" c̲at
  "    sp.bezier_points.add(len(pts) - 1)\n" c̲at
  "    for b, p in zip(sp.bezier_points, pts):\n" c̲at
  "        b.co = p\n" c̲at
  "        b.handle_left_type = b.handle_right_type = 'AUTO'\n" c̲at
  "    sp.use_cyclic_u = closed\n" c̲at
  "    o = bpy.data.objects.new(name, cu)\n" c̲at
  "    scene.collection.objects.link(o)\n" c̲at
  "    parts.append(o)\n" c̲at
  "    if not closed:\n" c̲at
  "        for e in (pts[0], pts[-1]):\n" c̲at
  "            bpy.ops.mesh.primitive_uv_sphere_add(radius=r, location=e, segments=48, ring_count=24)\n" c̲at
  "            parts.append(bpy.context.active_object)\n" c̲at
  "\n" c̲at
  "def fuse(name, voxel):\n" c̲at
  "    bpy.ops.object.select_all(action='DESELECT')\n" c̲at
  "    for o in parts:\n" c̲at
  "        o.select_set(True)\n" c̲at
  "    bpy.context.view_layer.objects.active = parts[0]\n" c̲at
  "    bpy.ops.object.convert(target='MESH')\n" c̲at
  "    bpy.ops.object.join()\n" c̲at
  "    o = bpy.context.active_object\n" c̲at
  "    o.name = o.data.name = name\n" c̲at
  "    bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='BOUNDS')\n" c̲at
  "    o.location = (0.0, 0.0, 0.0)\n" c̲at
  "    m = o.modifiers.new('remesh', 'REMESH')\n" c̲at
  "    m.mode = 'VOXEL'\n" c̲at
  "    m.voxel_size = voxel\n" c̲at
  "    m = o.modifiers.new('smooth', 'LAPLACIANSMOOTH')\n" c̲at
  "    m.iterations = 8\n" c̲at
  "    m.lambda_factor = 0.6\n" c̲at
  "    m.use_volume_preserve = True\n" c̲at
  "    bpy.ops.object.modifier_apply(modifier='remesh')\n" c̲at
  "    bpy.ops.object.modifier_apply(modifier='smooth')\n" c̲at
  "    bpy.ops.object.shade_smooth()\n" c̲at
  "    bpy.data.orphans_purge(do_recursive=True)\n" c̲at
  "    return o\n" c̲at
  "\n")
Used in: ˡs̲cene

ʰt̲ube : (Num a, Any b) => (Char, a, Char) -> b -> Char

function (private) · line 108
ʰt̲ube ← { (name, p, closed) z → "tube('" c̲at name c̲at "', " c̲at ((ˡp̲lace p, 3) ʰn̲ums 0) c̲at ", " c̲at (f̲ormat ˡradius) c̲at ", " c̲at closed c̲at ")\n" }
Used in: ˡs̲cene

ʰplastic : Char

value (private) · line 111
ʰplastic ← "mat = bpy.data.materials.new('magenta plastic')\nmat.use_nodes = True\np = mat.node_tree.nodes['Principled BSDF']\np.inputs['Base Color'].default_value = (0.85, 0.0, 0.85, 1.0)\np.inputs['Roughness'].default_value = 0.28\np.inputs['Coat Weight'].default_value = 0.6\np.inputs['Coat Roughness'].default_value = 0.05\nlogo.data.materials.append(mat)\n\n"
Used in: ˡs̲cene

ʰt̲urntable : Num a => a -> Char

function (private) · line 115
ʰt̲urntable ← { frames → "pivot = bpy.data.objects.new('pivot', None)\nscene.collection.objects.link(pivot)\nlogo.parent = pivot\nscene.frame_start = 1\nscene.frame_end = " c̲at (f̲ormat frames) c̲at "\npivot.rotation_euler = (0.0, 0.0, 0.0)\npivot.keyframe_insert('rotation_euler', index=2, frame=1)\npivot.rotation_euler = (0.0, 0.0, 2 * math.pi)\npivot.keyframe_insert('rotation_euler', index=2, frame=" c̲at (f̲ormat frames + 1) c̲at ")\n\n" }
Used in: ˡs̲cene

ʰstudio : Char

value (private) · line 119
ʰstudio ← ("cam = bpy.data.objects.new('camera', bpy.data.cameras.new('camera'))\ncam.data.lens = 50\ncam.location = (0.0, -9.5, 0.6)\ncam.rotation_euler = (math.radians(86.4), 0.0, 0.0)\nscene.collection.objects.link(cam)\nscene.camera = cam\n" c̲at
  "for name, energy, size, at, turn in (('key', 900, 4, (-4, -5, 5), (50, 0, -35)), ('fill', 250, 6, (5, -4, -1), (95, 0, 50)), ('rim', 400, 4, (0, 5, 4), (-50, 0, 180))):\n" c̲at
  "    light = bpy.data.objects.new(name, bpy.data.lights.new(name, 'AREA'))\n" c̲at
  "    light.data.energy = energy\n" c̲at
  "    light.data.size = size\n" c̲at
  "    light.location = at\n" c̲at
  "    light.rotation_euler = tuple(math.radians(a) for a in turn)\n" c̲at
  "    scene.collection.objects.link(light)\n" c̲at
  "world = bpy.data.worlds.new('yellow')\nworld.use_nodes = True\nworld.node_tree.nodes['Background'].inputs['Color'].default_value = (1.0, 0.92, 0.0, 1.0)\nscene.world = world\n\n")
Used in: ˡs̲cene

ʰc̲ycles : Any d => (a, b, c) -> d -> Char

function (private) · line 132
ʰc̲ycles ← { (w, h, samples) z → "scene.render.engine = 'CYCLES'\nprefs = bpy.context.preferences.addons['cycles'].preferences\nif 'METAL' in [t[0] for t in prefs.get_device_types(bpy.context)]:\n    prefs.compute_device_type = 'METAL'\n    prefs.kernel_optimization_level = 'OFF'\n    prefs.get_devices()\n    for d in prefs.devices:\n        d.use = True\n    scene.cycles.device = 'GPU'\nscene.cycles.samples = " c̲at (f̲ormat samples) c̲at "\nscene.cycles.use_denoising = True\nscene.view_settings.view_transform = 'Standard'\nscene.render.resolution_x = " c̲at (f̲ormat w) c̲at "\nscene.render.resolution_y = " c̲at (f̲ormat h) c̲at "\nscene.render.resolution_percentage = 100\n\n" }
Used in: ˡs̲cene

ˡs̲cene : (Num c, Any f) => (a, b, c, d, e) -> f -> Char

function · line 140

(width, height, frames, voxel, samples) cy:s_cene 0: the whole script Blender runs: the five lines as tubes, fused into one mesh, CoSy (remeshed in voxels that size: smaller is smoother and slower), the plastic, the turntable in the frames, the studio, Cycles at that size and samples; then the report. The video is left to the caller (bp:v_ideo or bp:s_till), added after.

ˡs̲cene ← { (w, h, frames, voxel, samples) z →
  ((ᵇᵖhead c̲at ʰplayer c̲at (("C", ˡletterC, "False") ʰt̲ube 0) c̲at (("o", ˡletterO, "True") ʰt̲ube 0)) c̲at
    ((("S", ˡletterS, "False") ʰt̲ube 0) c̲at (("y arm", ˡyArm, "False") ʰt̲ube 0) c̲at (("y stem", ˡyStem, "False") ʰt̲ube 0)) c̲at
    ("logo = fuse('CoSy', " c̲at (f̲ormat voxel) c̲at ")\n\n" c̲at ʰplastic c̲at (ʰt̲urntable frames) c̲at ʰstudio) c̲at
    ((w, h, samples) ʰc̲ycles 0) c̲at ᵇᵖreport)
}
Used in: script