texture-generator 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- texture_generator-0.3.0.dist-info/METADATA +143 -0
- texture_generator-0.3.0.dist-info/RECORD +27 -0
- texture_generator-0.3.0.dist-info/WHEEL +5 -0
- texture_generator-0.3.0.dist-info/entry_points.txt +2 -0
- texture_generator-0.3.0.dist-info/licenses/LICENSE +201 -0
- texture_generator-0.3.0.dist-info/top_level.txt +1 -0
- texture_generators/__init__.py +223 -0
- texture_generators/__main__.py +6 -0
- texture_generators/cli.py +487 -0
- texture_generators/core/__init__.py +1 -0
- texture_generators/core/colour.py +108 -0
- texture_generators/core/fibres.py +603 -0
- texture_generators/core/fields.py +122 -0
- texture_generators/core/film.py +315 -0
- texture_generators/core/lic.py +371 -0
- texture_generators/core/noise.py +200 -0
- texture_generators/core/shading.py +488 -0
- texture_generators/core/spectral.py +227 -0
- texture_generators/core/warp.py +74 -0
- texture_generators/core/worley.py +91 -0
- texture_generators/materials/__init__.py +42 -0
- texture_generators/materials/metal.py +1368 -0
- texture_generators/materials/paper.py +1655 -0
- texture_generators/materials/plastic.py +272 -0
- texture_generators/materials/wood.py +2329 -0
- texture_generators/py.typed +0 -0
- texture_generators/samples.py +439 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: texture-generator
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Procedural generator for random but realistic material textures (metal, plastic, wood, paper) as PNGs or numpy arrays
|
|
5
|
+
Author: Nick Powell
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/nmpowell/texture-generator
|
|
8
|
+
Project-URL: Issues, https://github.com/nmpowell/texture-generator/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/nmpowell/texture-generator/releases
|
|
10
|
+
Keywords: procedural,texture,noise,material,pbr,numpy
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Image Processing
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.14
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: click>=8.1
|
|
23
|
+
Requires-Dist: numpy>=2.0
|
|
24
|
+
Requires-Dist: pillow>=10.0
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# texture-generator
|
|
28
|
+
|
|
29
|
+
Generate random material textures with Python: metal, plastic, wood and paper,
|
|
30
|
+
as Pillow images or NumPy arrays. Choose a size and seed to create a reproducible
|
|
31
|
+
texture, then save it as a PNG. Generation runs locally using NumPy and Pillow,
|
|
32
|
+
without models, downloaded assets or network access.
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
Requires Python 3.14 or later.
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install texture-generator
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The distribution is named `texture-generator`; the Python import is
|
|
43
|
+
`texture_generators`, and the command-line program is `texture-gen`.
|
|
44
|
+
Installation includes NumPy, Pillow and Click (used by the CLI).
|
|
45
|
+
|
|
46
|
+
## Quickstart
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from texture_generators import generate
|
|
50
|
+
|
|
51
|
+
image = generate("wood", size=(640, 480), seed=42, variant="board")
|
|
52
|
+
image.save("wood.png")
|
|
53
|
+
print(image.mode, image.size)
|
|
54
|
+
# RGB (640, 480)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
This writes `wood.png` in the current directory. Sizes are `(width, height)`;
|
|
58
|
+
an integer such as `size=512` creates a square. Both dimensions must be at least
|
|
59
|
+
2 pixels. The same arguments reproduce the same image with the same package,
|
|
60
|
+
dependency versions and platform. Omit `seed` for a fresh texture.
|
|
61
|
+
|
|
62
|
+
For raw pixels or a labelled sheet of every variant:
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from texture_generators import generate_array, sample_sheet
|
|
66
|
+
|
|
67
|
+
pixels = generate_array("metal", size=256, seed=7, variant="brushed")
|
|
68
|
+
print(pixels.shape, pixels.dtype)
|
|
69
|
+
# (256, 256, 3) float32
|
|
70
|
+
|
|
71
|
+
sheet = sample_sheet(size=128, seed=7)
|
|
72
|
+
sheet.save("materials.png")
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Arrays contain RGB values in `[0, 1]`. The
|
|
76
|
+
[API reference](https://github.com/nmpowell/texture-generator/blob/main/docs/reference.md#python-api)
|
|
77
|
+
covers all public functions and material parameters.
|
|
78
|
+
|
|
79
|
+
## Command line
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
texture-gen wood --variant board --size 640x480 --seed 42 -o wood.png
|
|
83
|
+
texture-gen list
|
|
84
|
+
texture-gen sheet --size 128 --seed 7 -o materials.png
|
|
85
|
+
texture-gen wood --help
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
`python -m texture_generators` runs the same CLI. It also supports batches,
|
|
89
|
+
JSON reports, shell completion and browser galleries for comparing seeds and
|
|
90
|
+
parameters. See the
|
|
91
|
+
[CLI reference](https://github.com/nmpowell/texture-generator/blob/main/docs/reference.md#cli).
|
|
92
|
+
|
|
93
|
+
## Materials
|
|
94
|
+
|
|
95
|
+
| Material | Variants |
|
|
96
|
+
| --- | --- |
|
|
97
|
+
| Metal | `brushed`, `radial`, `polished`, `heat_tinted`, `oil_film`, `anodised_titanium`, `engine_turned` |
|
|
98
|
+
| Plastic | `glossy`, `matte`, `textured` |
|
|
99
|
+
| Wood | `board`, `planks` |
|
|
100
|
+
| Paper | `white`, `kraft`, `recycled`, `newsprint`, `laid`, `coated` |
|
|
101
|
+
|
|
102
|
+
The generators combine noise, material anatomy and lighting. Albedo, height and
|
|
103
|
+
roughness share underlying fields so visible features also affect shading.
|
|
104
|
+
These are procedural approximations with documented calibration assumptions.
|
|
105
|
+
Metal, plastic and wood do not tile seamlessly; paper tiles when creases are
|
|
106
|
+
disabled with `creases=0.0`.
|
|
107
|
+
|
|
108
|
+
Read the
|
|
109
|
+
[technical reference](https://github.com/nmpowell/texture-generator/blob/main/docs/reference.md)
|
|
110
|
+
for the algorithms, wood and paper models, core modules, performance estimates
|
|
111
|
+
and limitations. See the
|
|
112
|
+
[changelog](https://github.com/nmpowell/texture-generator/blob/main/CHANGELOG.md)
|
|
113
|
+
for changes and
|
|
114
|
+
[GitHub issues](https://github.com/nmpowell/texture-generator/issues)
|
|
115
|
+
to report a bug.
|
|
116
|
+
|
|
117
|
+
## Development
|
|
118
|
+
|
|
119
|
+
Install [uv](https://docs.astral.sh/uv/getting-started/installation/), then:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
git clone https://github.com/nmpowell/texture-generator.git
|
|
123
|
+
cd texture-generator
|
|
124
|
+
uv sync --locked
|
|
125
|
+
uv run pytest
|
|
126
|
+
uv run ruff check .
|
|
127
|
+
uv run ruff format --check .
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
`uv sync --locked` installs the project editable and uses the committed lockfile.
|
|
131
|
+
Use `uv run ruff format .` to apply formatting. The tests exercise rendering,
|
|
132
|
+
determinism, material physics, the CLI and built-package contents. Internal mypy
|
|
133
|
+
checks have existing findings and are informational; see the
|
|
134
|
+
[development notes](https://github.com/nmpowell/texture-generator/blob/main/docs/reference.md#development).
|
|
135
|
+
|
|
136
|
+
The version lives in `pyproject.toml`; `texture_generators.__version__` reads
|
|
137
|
+
the installed package metadata. The
|
|
138
|
+
[release guide](https://github.com/nmpowell/texture-generator/blob/main/docs/releasing.md)
|
|
139
|
+
covers artifact checks and Trusted Publishing.
|
|
140
|
+
|
|
141
|
+
## License
|
|
142
|
+
|
|
143
|
+
[Apache License 2.0](https://github.com/nmpowell/texture-generator/blob/main/LICENSE).
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
texture_generator-0.3.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
2
|
+
texture_generators/__init__.py,sha256=PDEzkrZjDihwLDDzJ8uYsfE0_4XvBH2kQCY75yBRgRE,7209
|
|
3
|
+
texture_generators/__main__.py,sha256=-un7EZjzE80hNsaGUysYH9YNubU2j38DWm3N-0lwU2U,151
|
|
4
|
+
texture_generators/cli.py,sha256=r4t92rq0MIJpvj9RZHWPhQQkoQojPGY1wnaj2znur30,15378
|
|
5
|
+
texture_generators/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
texture_generators/samples.py,sha256=jgKDasp5CjxD_fQ6mzvK9Q8t1lUrsko8ai_Umhn1IUA,16480
|
|
7
|
+
texture_generators/core/__init__.py,sha256=Sl-A5JIkyqlUpPa8z2BzCxMe1A5G_Gelo408ei8ZH5w,82
|
|
8
|
+
texture_generators/core/colour.py,sha256=lGAtzb0nX9G-beuVYSjl-lzHERJOHqSa41OLMDCEWkE,3649
|
|
9
|
+
texture_generators/core/fibres.py,sha256=gWsezSiK83iJl1xoIFrnSexwlpPj0Uo72jZ277vjmF0,29112
|
|
10
|
+
texture_generators/core/fields.py,sha256=TbnAkiOoZFp6eqLhWke21xYIe1cDpvitJjM6JabTcVk,4184
|
|
11
|
+
texture_generators/core/film.py,sha256=P5jUQYxRP0crOpIc45Dz_xHWXIkr8gh580dIpnIIpc8,12355
|
|
12
|
+
texture_generators/core/lic.py,sha256=gYQ3hFtQ2TXEB0MSI6dMhjIFN1PJ_41BgCE9oIjmoiM,17274
|
|
13
|
+
texture_generators/core/noise.py,sha256=NchTjrRMsKDo_SrQijnoAItHWb2P7lvuaHKB8RcEmEM,6083
|
|
14
|
+
texture_generators/core/shading.py,sha256=TaTBonRUoIAmR2uROt_56ehKerrkGSx33xkzh7ke53Q,22512
|
|
15
|
+
texture_generators/core/spectral.py,sha256=H1lYTrl2MbA7M7-ip5gn8IWcr80rwU2Thpqks8AXMqg,10235
|
|
16
|
+
texture_generators/core/warp.py,sha256=MizFVwccrfB_s6L1Gyc_r98TIH0oscwRqO9TzwdnjpM,2387
|
|
17
|
+
texture_generators/core/worley.py,sha256=XbXLxN9LqDG8fmE-j2WCtuBAGSFQi4ncI21WXW5AN_o,2956
|
|
18
|
+
texture_generators/materials/__init__.py,sha256=8ECR2dr7N9cAEigq5J1bXrPVbXvj2m7Fzc6BxlXp4ho,1373
|
|
19
|
+
texture_generators/materials/metal.py,sha256=9_yc4blm07n8vAmrUdqlWGnVJTWJa3t4j7NToVcE26U,56791
|
|
20
|
+
texture_generators/materials/paper.py,sha256=cXIBLMeVyjZSYtiOhSH0_JUH8yYvAc8D1fXtD1XUISQ,79488
|
|
21
|
+
texture_generators/materials/plastic.py,sha256=NmffUybHmPreY7QPBj7DLT96g6jRLCl-CORaHEbVAT8,12406
|
|
22
|
+
texture_generators/materials/wood.py,sha256=g0P_NeKhD9pAgZWyQnD18ycCYPvlSLOo_Lsk9liRHl8,108960
|
|
23
|
+
texture_generator-0.3.0.dist-info/METADATA,sha256=V7Utqz4jFPSOZ3D0WmZndWpMdqd7cSaxAbEIhnbNy-A,5261
|
|
24
|
+
texture_generator-0.3.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
25
|
+
texture_generator-0.3.0.dist-info/entry_points.txt,sha256=MqzQYw29Lc5ZfU3rcMLN0_kBB2B2_7g6pePF80aapxE,60
|
|
26
|
+
texture_generator-0.3.0.dist-info/top_level.txt,sha256=XUh5bE7QnSLNv2PYU7asxtExCxNTXK4LQ1xhczxtDOA,19
|
|
27
|
+
texture_generator-0.3.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
texture_generators
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"""Procedural texture generator: random but realistic metal/plastic/wood/paper PNGs.
|
|
2
|
+
|
|
3
|
+
Public API::
|
|
4
|
+
|
|
5
|
+
from texture_generators import generate, generate_array, MATERIALS, sample_sheet
|
|
6
|
+
|
|
7
|
+
img = generate("wood", size=512, seed=42)
|
|
8
|
+
img = generate("metal", size=(640, 480), variant="brushed")
|
|
9
|
+
arr = generate_array("wood", size=512, seed=42) # float32 (H, W, 3) in [0, 1]
|
|
10
|
+
sheet = sample_sheet(size=256, seed=7)
|
|
11
|
+
|
|
12
|
+
Every texture is produced from a single seeded ``np.random.Generator``, so the
|
|
13
|
+
same seed always yields byte-identical output.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
from importlib.metadata import version as _distribution_version
|
|
19
|
+
|
|
20
|
+
import numpy as np
|
|
21
|
+
from PIL import Image, ImageDraw
|
|
22
|
+
|
|
23
|
+
from .materials import MATERIALS, Material
|
|
24
|
+
|
|
25
|
+
__version__ = _distribution_version("texture-generator")
|
|
26
|
+
|
|
27
|
+
__all__ = [
|
|
28
|
+
"MATERIALS",
|
|
29
|
+
"VARIANTS_BY_MATERIAL",
|
|
30
|
+
"Material",
|
|
31
|
+
"__version__",
|
|
32
|
+
"all_pairs",
|
|
33
|
+
"generate",
|
|
34
|
+
"generate_array",
|
|
35
|
+
"resolve_variant",
|
|
36
|
+
"sample_sheet",
|
|
37
|
+
"to_image",
|
|
38
|
+
"variants",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
VARIANTS_BY_MATERIAL = {name: list(mod.VARIANTS) for name, mod in MATERIALS.items()}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def variants(material: str) -> list[str]:
|
|
45
|
+
"""Variant names for ``material``."""
|
|
46
|
+
return list(_module(material).VARIANTS)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def all_pairs() -> list[tuple[str, str]]:
|
|
50
|
+
"""Every ``(material, variant)`` combination, in registry order."""
|
|
51
|
+
return [(m, v) for m, mod in MATERIALS.items() for v in mod.VARIANTS]
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _module(material: str):
|
|
55
|
+
"""Look up a material module, raising a helpful ValueError."""
|
|
56
|
+
try:
|
|
57
|
+
return MATERIALS[material]
|
|
58
|
+
except KeyError:
|
|
59
|
+
valid = ", ".join(sorted(MATERIALS))
|
|
60
|
+
raise ValueError(
|
|
61
|
+
f"unknown material {material!r}; choose from: {valid}"
|
|
62
|
+
) from None
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _parse_size(size: int | tuple[int, int]) -> tuple[int, int]:
|
|
66
|
+
"""Normalise ``size`` to ``(height, width)`` in pixels."""
|
|
67
|
+
if isinstance(size, (tuple, list)):
|
|
68
|
+
if len(size) != 2:
|
|
69
|
+
raise ValueError("size tuple must be (width, height)")
|
|
70
|
+
w, h = int(size[0]), int(size[1])
|
|
71
|
+
else:
|
|
72
|
+
w = h = int(size)
|
|
73
|
+
if w < 2 or h < 2:
|
|
74
|
+
raise ValueError(f"size must be at least 2x2, got {w}x{h}")
|
|
75
|
+
return h, w
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _pick_variant(mod: Material, rng: np.random.Generator) -> str:
|
|
79
|
+
"""Draw one of ``mod``'s variants from ``rng``.
|
|
80
|
+
|
|
81
|
+
The single place the default variant is chosen, so a caller can learn which
|
|
82
|
+
variant a seed selects without duplicating (or perturbing) the draw.
|
|
83
|
+
"""
|
|
84
|
+
return str(mod.VARIANTS[int(rng.integers(0, len(mod.VARIANTS)))])
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def resolve_variant(
|
|
88
|
+
material: str,
|
|
89
|
+
seed: int | None = None,
|
|
90
|
+
variant: str | None = None,
|
|
91
|
+
) -> str:
|
|
92
|
+
"""Name the variant a render will use, without rendering it.
|
|
93
|
+
|
|
94
|
+
``variant`` is returned as given, once validated. With ``variant=None`` and
|
|
95
|
+
a concrete ``seed``, the return value is the variant
|
|
96
|
+
``generate(material, seed=seed)`` will render, so a caller can name it (in a
|
|
97
|
+
report or a filename) before rendering it. With ``seed=None`` this simply
|
|
98
|
+
draws one such variant from fresh entropy: each call is independent, and it
|
|
99
|
+
predicts nothing about a separate unseeded render.
|
|
100
|
+
|
|
101
|
+
Raises:
|
|
102
|
+
ValueError: on an unknown material or variant.
|
|
103
|
+
"""
|
|
104
|
+
mod = _module(material)
|
|
105
|
+
if variant is None:
|
|
106
|
+
return _pick_variant(mod, np.random.default_rng(seed))
|
|
107
|
+
if variant not in mod.VARIANTS:
|
|
108
|
+
valid = ", ".join(mod.VARIANTS)
|
|
109
|
+
raise ValueError(
|
|
110
|
+
f"unknown {material} variant {variant!r}; choose from: {valid}"
|
|
111
|
+
)
|
|
112
|
+
return variant
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def to_image(rgb: np.ndarray) -> Image.Image:
|
|
116
|
+
"""Convert a float32 (H, W, 3) array in [0, 1] to a PIL RGB image."""
|
|
117
|
+
arr = np.clip(np.asarray(rgb, dtype=np.float32), 0.0, 1.0)
|
|
118
|
+
return Image.fromarray((arr * 255.0 + 0.5).astype(np.uint8), mode="RGB")
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def generate_array(
|
|
122
|
+
material: str,
|
|
123
|
+
size: int | tuple[int, int] = 512,
|
|
124
|
+
seed: int | None = None,
|
|
125
|
+
variant: str | None = None,
|
|
126
|
+
**params,
|
|
127
|
+
) -> np.ndarray:
|
|
128
|
+
"""Generate a texture as a float32 ``(H, W, 3)`` array in ``[0, 1]``.
|
|
129
|
+
|
|
130
|
+
Same contract as :func:`generate` but without the PIL conversion, for
|
|
131
|
+
callers that want the raw pixels.
|
|
132
|
+
|
|
133
|
+
Args:
|
|
134
|
+
material: one of :data:`MATERIALS` (``metal``, ``plastic``, ``wood``,
|
|
135
|
+
``paper``).
|
|
136
|
+
size: ``N`` for a square texture or ``(width, height)``.
|
|
137
|
+
seed: integer seed; ``None`` draws fresh entropy.
|
|
138
|
+
variant: variant name, or ``None`` to pick one with the seeded rng.
|
|
139
|
+
**params: forwarded to the material module (e.g. ``specular``).
|
|
140
|
+
|
|
141
|
+
Raises:
|
|
142
|
+
ValueError: on an unknown material or variant.
|
|
143
|
+
"""
|
|
144
|
+
mod = _module(material)
|
|
145
|
+
h, w = _parse_size(size)
|
|
146
|
+
rng = np.random.default_rng(seed)
|
|
147
|
+
|
|
148
|
+
if variant is None:
|
|
149
|
+
variant = _pick_variant(mod, rng)
|
|
150
|
+
elif variant not in mod.VARIANTS:
|
|
151
|
+
valid = ", ".join(mod.VARIANTS)
|
|
152
|
+
raise ValueError(
|
|
153
|
+
f"unknown {material} variant {variant!r}; choose from: {valid}"
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
rgb = mod.generate((h, w), rng, variant, **params)
|
|
157
|
+
if rgb.shape[:2] != (h, w):
|
|
158
|
+
raise RuntimeError(
|
|
159
|
+
f"{material}/{variant} produced {rgb.shape[1::-1]}, expected {(w, h)}"
|
|
160
|
+
)
|
|
161
|
+
return rgb
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def generate(
|
|
165
|
+
material: str,
|
|
166
|
+
size: int | tuple[int, int] = 512,
|
|
167
|
+
seed: int | None = None,
|
|
168
|
+
variant: str | None = None,
|
|
169
|
+
**params,
|
|
170
|
+
) -> Image.Image:
|
|
171
|
+
"""Generate a texture and return it as a PIL RGB image.
|
|
172
|
+
|
|
173
|
+
Args:
|
|
174
|
+
material: one of :data:`MATERIALS` (``metal``, ``plastic``, ``wood``,
|
|
175
|
+
``paper``).
|
|
176
|
+
size: ``N`` for a square texture or ``(width, height)``.
|
|
177
|
+
seed: integer seed; ``None`` draws fresh entropy.
|
|
178
|
+
variant: variant name, or ``None`` to pick one with the seeded rng.
|
|
179
|
+
**params: forwarded to the material module (e.g. ``specular``).
|
|
180
|
+
|
|
181
|
+
Raises:
|
|
182
|
+
ValueError: on an unknown material or variant.
|
|
183
|
+
"""
|
|
184
|
+
return to_image(generate_array(material, size, seed, variant, **params))
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def sample_sheet(
|
|
188
|
+
size: int | tuple[int, int] = 256,
|
|
189
|
+
seed: int | None = None,
|
|
190
|
+
*,
|
|
191
|
+
columns: int | None = None,
|
|
192
|
+
**params,
|
|
193
|
+
) -> Image.Image:
|
|
194
|
+
"""Contact sheet with one labelled tile per material x variant.
|
|
195
|
+
|
|
196
|
+
``size`` is the per-tile size: ``N`` for square tiles or
|
|
197
|
+
``(width, height)``.
|
|
198
|
+
"""
|
|
199
|
+
pairs = all_pairs()
|
|
200
|
+
rng = np.random.default_rng(seed)
|
|
201
|
+
cols = columns or min(4, len(pairs))
|
|
202
|
+
rows = (len(pairs) + cols - 1) // cols
|
|
203
|
+
|
|
204
|
+
tile_h, tile_w = _parse_size(size)
|
|
205
|
+
pad = 6
|
|
206
|
+
label_h = max(14, tile_h // 16)
|
|
207
|
+
cell_w = tile_w + pad
|
|
208
|
+
cell_h = tile_h + label_h + pad
|
|
209
|
+
sheet = Image.new("RGB", (cols * cell_w + pad, rows * cell_h + pad), (24, 24, 26))
|
|
210
|
+
draw = ImageDraw.Draw(sheet)
|
|
211
|
+
|
|
212
|
+
for i, (material, variant) in enumerate(pairs):
|
|
213
|
+
tile_seed = int(rng.integers(0, 2**31 - 1))
|
|
214
|
+
tile = generate(material, size, seed=tile_seed, variant=variant, **params)
|
|
215
|
+
cx = pad + (i % cols) * cell_w
|
|
216
|
+
cy = pad + (i // cols) * cell_h
|
|
217
|
+
sheet.paste(tile, (cx, cy))
|
|
218
|
+
draw.text(
|
|
219
|
+
(cx + 2, cy + tile_h + 2),
|
|
220
|
+
f"{material}/{variant} #{tile_seed % 10000}",
|
|
221
|
+
fill=(225, 225, 225),
|
|
222
|
+
)
|
|
223
|
+
return sheet
|