A simple parametric model of plain-knit yarn curves, with C code and other resources.
This repository provides code implementing closed-form expressions for smooth curves resembling a plain-knit stitch, suitable for appearance modeling and previsualization. A unique feature of this model is that it also describes the twisted yarn fibers running along this stitch, making it suitable for modeling marled yarn. Adjustable parameters control the knit spacing, loop roundness, yarn thickness, and rate of fiber twisting. Tileable displacement maps and code for generating curves are also provided.
-
Note. The note YarnCurve.pdf provides a more thorough description of the plain-knit curves, including a step-by-step derivation. The LaTeX source files for this note can be found in the note subdirectory.
-
Implementation. The code subdirectory contains a plain-C (ANSI C90) implementation of the curve functions, as well as routines for writing curves to the Wavefront OBJ mesh file format. This code should be easily portable to most other languages. Several implementations have been developed, in a variety of packages:
- C — this repo
- Python — by Tim Chen, with visualization in Grasshopper 3D
- Julia — by empet
- WebGPU — by Markus Schütz
- C#/Grasshopper — by Laurent Delrieu
- Displacement Maps. For rendering knit materials, it can be more efficient (or simply more convenient) to use a displacement map rather than explicit curve geometry. The images below provide tileable patterns for front and back displacements, as well as the associated alpha matte. Higher bit-depth images can be found in the displacement-maps directory, in OpenEXR and Radiance HDR/RGBE formats, which can help avoid shading artifacts. These maps were generated by generating tube geometry around the curves, and rendering depth images via an orthographic projection (in modo).
front | back | alpha |
---|---|---|
A Simple Parametric Model of Plain-Knit Yarns by Keenan Crane is licensed under a Creative Commons Attribution 4.0 International License. Code is released under an MIT License.
@misc{Crane:2023:SPM,
title = {{A Simple Parametric Model of Plain-Knit Yarns}},
author = {Crane, Keenan},
month = {3},
year = {2023},
howpublished = {online},
url = {https://github.com/keenancrane/plain-knit-yarn},
}