storborg / pyweaving

Python Weaving Tools
Other
17 stars 11 forks source link

Aiming for new release #3

Open Neon22 opened 3 years ago

Neon22 commented 3 years ago

Thanks to covid lockdowns for the time to work on this. Always bothered me I could not use this module with handweaving.net sample wif files. Finally tracked it down.

There are lines missing in the WARP and WEFT COLOR sections which the spec says if not supplied should be using the default as defined (optionally) in the COLOR param in the WARP or WEFT section.

I am working in 3.9.7 FYI and all looking good so far. Addressed in Pull Request #4

Neon22 commented 3 years ago

Added ability to ignore extra treadles in Tieup. Some files include full treadle plan even though the draft uses only the first few.

Added ability to load the Author etc metadata as well as Notes. Made available via stats command Also added Source program and version - but not currently propagating to json file as maybe its now this program which is generating them. Especially if a wif file is saved eventually.

Neon22 commented 3 years ago

The branch grows:

Neon22 commented 3 years ago

Added Tartan and twill generators to pyweaving menu. more changes coming here with render options and stats.

Also outfile will use directory from infile if no directory defined in outfile.

Neon22 commented 3 years ago

Added ability to load wif files with liftplans. They were getting in but not rendering. wif reader adjust to pass liftplan setting in.

Started on render renaming for clarity but these changes totally superseded in next commit

Neon22 commented 3 years ago

Fairly large set of changes.

  1. Color class modified for wider use and can load Colors as well as tuples.

    • hex property added for svg target later
  2. Found problem where warp thread colors and drawdown were reversed horizontally. The Threading section was correct. Turns out this problem is invisible if the draft is symmetric.

  3. Large number of changes. Added a Drawstyle class - this defines the layout, spacing and flags different modes of showing the draft,

    • E.g. can have solid or blob markers, or use the thread color (will add numerics next)
    • can toggle visibility of line markers (ticks)
    • can adjust gaps between elements

More coming to try to maximise info that can be extracted from a wif.

  1. Show floats as an option - not yet in the command line but can be selected by modifying the Drawstyle class defaults in init manually
Neon22 commented 3 years ago

Add fix to get liftplan option back into render (still only png)

Also enhanced tartan generator to use the STA styles and deal with mirrrored and asymmetrical as wel as rectangles with sep warp and weft counts. Setup for Z and S twill but not propagated through yet

Neon22 commented 3 years ago

Major refactor too make all sections have a startpos and return an endpos. Can now rearrange layout.

Neon22 commented 3 years ago

Exercising the refactor to add a Title to the top of the draft

Neon22 commented 2 years ago

Added spacings to renderer. now can render warp and weft with variable spacing. I need a few more samples to ensure its all good.

Two styles - "Clarity" where a progression of larger boxes for larger threads.

two pass approach - finds all the spacings and fill sin defaults, finds ratios, determines box sizing and then stores on each thread as yarn_width iv.

Neon22 commented 2 years ago

Added Prelim satin generator. Calculates the satin numbers for regular satins. Not yet doing the two irregular ones 4,6 Also not yet drawing drafts.

Neon22 commented 2 years ago

Added ministats section under title with summary of warp,weft,yarns, floats, warp/weft balance Also heddle counts on LHS of the Threading. Listing number of heddles need for each shaft.

Neon22 commented 2 years ago

somewhere render without an outfile stopped working - fixed.

Neon22 commented 2 years ago

Updated the twill generator to take a shape string instead of a 2/2, 3/3, etc

So can do a 1/3 or a 3/2 or a 3/2S for an S shaped twill Can also combine complex twills. E.g. 1/3 2/2 3/1 1/1 will make an 18 shaft/treadle twill

Z is the default if no suffix on end of shape string

One day will add points, staggers, etc in eth threading section instead of a straight draw.

Neon22 commented 2 years ago

A few changes to support faulty wif files from various vendors. Also twill generator almost same as Tartan. usage: pyweaving twill [-h] [--render] [--renderfile RENDERFILE] [--renderstyle {solids,blobs,colors,numbers}] shape outfile where shape is something like "1/3 2/2Z" and "--renderfile auto" will autoname based on wif and put in same dir as wif.

Some refactoring and comment adjustments

Float length now correctly being presented. (was short by 1) Added Floating selvedge detection into ministats section.

Found neat trick used by Fiberworks to embed creation date into TEXT section as a comment. Will probably use/maintain ourselves. Required changes to RawConfigParser to read/write comments

Neon22 commented 2 years ago

Added Notes section under drawdown. If some notes then they are printed there under a heading. Last line is added if notes exist which indicates the source program and version

Neon22 commented 2 years ago

Render option can take an autopng or autosvg in place of the outfile. n image file named after the wif will be created.

Neon22 commented 2 years ago

More mods to RawConfigParser so we can read in creation date as comment. Revealed failure to load wif files from TempoWeave program. Wifs from this program have no blank lines and sprinkle comments everywhere even line 1. But end result is more robust so fine :)

Also fixed bug in auto option to render which was overzealous.

Neon22 commented 2 years ago

Added Tartans by Name

Can now generate a tartan using a name. E.g. pyweaving.exe tartan "Abercrombie" --direction S foo.wif --render --renderfile foo.png will find all the tartans containing Abercrombie and list them. A user can then select a unique tartan and get that generated: pyweaving.exe tartan "Abercrombie - TI" --direction S foo.wif --render --renderfile foo.png

The tartans taken from the weddslist website with permission. These are not impeccably sourced and cannot be relied upon for accuracy. Will add note in NOTES to indicate this.

Neon22 commented 2 years ago

Added named styles in a styles.json file. Ends up in a user folder .pyweaving commands modified to take --style name so a style can be used when generating or rendering

Neon22 commented 2 years ago

Just trying to get a few things straightened out and go for a 0.1 release where its stable and can offer working command line options and reads loads of wif files. Todo:

Then will begin work on extracting the structure by careful examination and a few more features

Neon22 commented 2 years ago

now have named styles for render, twill, tartan commands. Can reference a style defined in .pyweaving/styles. Master of this file is in data directory for distro and copied in when used initially. Omitting a style will use the Defaults style defined in styles.json

E.g. pyweaving.exe render --style mincolor "ashford echo1.wif" foo.png will render using the mincolor style.

Second feature is proper naming and refusal tooverwrite when using teh autopng or autosvg convention in render. E.g.pyweaving.exe render "ashford echo1.wif" autopng will try to name the render as: "ashford echo1.png" if that file exists then it will add a suffix and name it: "ashford echo1-01.png" if that exists then -02 etc.

alas svg not hooked up yet same as png but coming...

Neon22 commented 2 years ago

used Creation date trick from some wif files as a comment. we now read and add this info to the Notes report we also write out creation date if not already defined (e.g. in generators

Also fixed Tartan disorder (twill tieup/warp) and shortened tartan names - too many spaces

Neon22 commented 2 years ago

Been unavailable for a while but back now. Several motley changes and drawdown presentation options. Bit of a side track from v0.1 stated goals. trying to get back on track.

Added:

Fixes:

Some svg renderer changes but all WIP

Neon22 commented 2 years ago

Optimize wif saving for smaller files by finding most used colors and referencing those as per first post so long ago in this thread..

Tartans:

Twill:

Render:

Only have python3 and svg on my list for official? work before new release ready...

Neon22 commented 2 years ago

OK big change - rewrote the SVG renderer to use svgwrite. Also hashed all yarns in the drawdown so only minimal set created then all referenced and drawn. So a large drawdown may only have 12 actual differently drawn threads in eth thousands that need to be displayed. E.g. plain weave. Having said that I was surprised that redraws in the browser are not as fast as I had hoped. so interactive adjustment of a large SVG file is not going to work if this program ever went interactive.

Also: If a style is selected which does not exist then a list of partial matching styles is presented at the CLI

Some cleanup of styles as vector shading options added.

Some classes now have repr defined.

CSS is precalculated for all colours and shading highlights/shadows

box sizing calculations for part placement in the renderers has been refactored out of the Imagerender class. Positional calcs refactored also in Renderers

Starting indicator position is cleaned up but still not autocalculating where it should really be for any given draft.

Next is refactoring for Python 3.

What should we name this. Version 0.8 ? I'd like to determine repeats and reflections in the warp and weft and present like Handowven mag does but maybe this should be a v0.9 then 1.0 would be bugfixes. ??

Neon22 commented 2 years ago

Added small commit to improve help when no args specified. Working on docs and python3

Neon22 commented 2 years ago

Python3 reorganisation done. now python 3.8 or above Also init has been refactored. So Draft, Drawstyle, Color in own files and init is very small

So will work on docs but need some input from you now Scott about releasing

Neon22 commented 2 years ago

Adding new feature to create a wif from an image of a drawdown.

Some minor changes to presenting color and in Draft.

So two commands added:

minor addition to reporting which files get created.. cleaned up the generators in cmd.py to factor common code

Neon22 commented 2 years ago

Changes added to support flake8. now working on tox/setup/manifest - what a nightmare :(

Neon22 commented 2 years ago

Basically testing now working

Docs now building using Sphinx

Docs added for Color, Drawstyle, and more to come Fixes to Color as revealed by test coverage Moved Drawstyle initiation into package init

No progress yet on packaging

Vrroom commented 6 months ago

Hi @Neon22,

Thanks for this work. I'm trying to synthesize the micro 3D geometry of a fabric based on the weave pattern.

I tried this repo as well as your fork. For some WIF files, it seems that some color in the palette is missing. I just replace it with [255, 255, 255]. Wanted to ask you if there is a better solution. I would have attached my WIF file but github isn't letting me.

Hope to hear from you soon! Thanks.

Neon22 commented 6 months ago

Hi @Vrroom, I have been continually improving the wif reader. if you have a wif with a problem, please try to raise an issue and include it. Otherwise just paste it into a comment. I'll have a go.

Vrroom commented 6 months ago

Thanks for your @Neon22. I can't attach the WIF here but this is the download link:

https://www.eatough.net/weave/WIF%20files/rosepath1.wif

The error I get is:

  File "*****/pyweaving/pyweaving/wif.py", line 209, in read
    self.put_warp(draft, wif_palette)
  File "*****/pyweaving/pyweaving/wif.py", line 72, in put_warp
    color = wif_palette[warp_color_map[thread_no]]
KeyError: 1
Neon22 commented 6 months ago

Hmm. I have no trouble reading it. Here it is with emphasised style Are you using my branch ? rosepath1

Neon22 commented 6 months ago

wif-missing-warp is the correct branch on my github

Vrroom commented 6 months ago

Ok ok. I'll try it out. Yeah I was using your master branch!

Neon22 commented 6 months ago

@Vrroom There are a few existing papers about modelling the fibres. Are you doing new research, extending an existing approach, or making a solution from existing approaches.

Reason I ask is recently also been working with https://github.com/gniknyh who has been making a cloth BSDF shader for his thesis?

So we now have a support tool that makes a normal and tangent map of a wif. Needs a bit more work to finish. Is it useful to you ?

Vrroom commented 6 months ago

Definitely very useful. In fact, I have been using your library, blender and mitsuba to make displacement and normal maps. The aim is to tile these on an arbitrary surfaces.

image

So far, we just want to reproduce existing research which is very hard to do. We have been playing with ThunderLoom but have found it difficult to get it working. Hence, we want to make our own rendering pipeline so that we maximally understand the nitty-gritties of it.

Vrroom commented 6 months ago

I have a stupid question? Why do we need tangent maps for rendering in general?

Neon22 commented 6 months ago

I think I see where you're coming from. Happy to discuss which approaches might suit you best. The reason we have a tangent map is because a realtime shader needs to go as fast as possible and so precalculating the normals/tangents means we can save precious time when calculating.

You can see latest webGL version of work done by Link here:

The second link is on my page and I have started to enhance it to what I need for a realtime viewer. I need to do work on the normal mapping code to get a better under/over warp/weft transitions and remove thw sharp edges. Unless you'd like to help of course :)

Vrroom commented 6 months ago

Sent you an email