Using Blender Python to create maille.
View previous topic | View next topic >
Post new topic Reply to topic
M.A.I.L. Forum Index -> Knitting Circle
   
Author Message

Joined: September 24, 2012
Posts: 93
Submissions: 1
Location: Stockholm, Sweden

Using Blender Python to create maille.
Reply with quote
Posted on Tue Oct 15, 2013 7:20 am
Link to Post: Link to Post

Hi,
I'm a very visual person and i'd like to see the final results fast. A lot of $$$ is spent in cutting rings for prototypes that end up in a box somewhere.

The cost of brass i can live with but cutting 200$ of silver is painful.

I "Stole" Zlosk's Povray code and started porting it to Blender. My trigonometry is not what it used to be so i have some issues understanding some of the variables but the results are promising.

Data so far:
I saw lorenzo writing somewhere that usually he is working in projects with up to 2 000 000 rings so i put that figure as the ceiling. It took my ASUS ROG laptop 2 hours to create 2 million E4-1 rings and position them in the XYZ space. A very good number imho.

Different textures haven't been used but i don't see it as an issue.

My question is:
Are there any articles where the Povray files created by Zlosk are discussed? Can't seem (lazy) to understand "ipv" and "iph" variables in his E4-1 code.

Should i write my own code that converts a picture to plain data to use when deciding the color of the rings?

I have even played with the game engine of Blender. Will try to "bump" a E4-1 weave and see how physics influence it.

After lots of Youtubing i believe Blender to be a nice tool to maille with. Imagine building a chain and seeing it how it behaves in the real world.

BR
C

Joined: February 7, 2012
Posts: 99
Submissions: 1

Reply with quote
Posted on Tue Oct 15, 2013 4:24 pm
Link to Post: Link to Post

Heh, 2 million torus(using an array, I presume). How many hours does it take for the screen to refresh every time you rotate the viewport? Reminds me of that time I solidified my fluid simulation and accidentally told it to subdivide 3 times. I think my computer still hasn't forgiven me.

By the way, we have solid body physics in the regular Blender engine now. No need to complicate things by going into game mode. The problem I see is hitboxes. In order to properly simulate chainmail, not even convex hull will work; you'll need to use mesh, and that's a drain on your machine even with only dozens of rings. I'd hate to think how long a simulation of thousands would take.

Though this does make me wonder if there's some combination of settings that would make the cloth simulator do the equivalent of chainmail. Problem is it doesn't stretch; a given patch has a very definite maximum and minimum length- and the width has a different range, to make matters worse.
So sheets seem troublesome, and for smaller, more complicated things like unit weaves, I'd like some QoL things like clipping while moving objects before I would spend my time on it.

Joined: February 15, 2002
Posts: 385
Submissions: 10

Reply with quote
Posted on Tue Oct 15, 2013 5:22 pm
Link to Post: Link to Post

iph = inches per horizontal ring
ipv = inches per vertical ring

I should have had the meanings of the variable names commented in the code. <yells>Bad programmer!</yells>


IGP (Irregular Grid Painter) Links:
Home | FAQ | Downloads

Joined: September 24, 2012
Posts: 93
Submissions: 1
Location: Stockholm, Sweden

Reply with quote
Posted on Tue Oct 15, 2013 6:39 pm
Link to Post: Link to Post

TheMuffinmaster wrote:
Heh, 2 million torus(using an array, I presume). How many hours does it take for the screen to refresh every time you rotate the viewport? Reminds me of that time I solidified my fluid simulation and accidentally told it to subdivide 3 times. I think my computer still hasn't forgiven me.

By the way, we have solid body physics in the regular Blender engine now. No need to complicate things by going into game mode. The problem I see is hitboxes. In order to properly simulate chainmail, not even convex hull will work; you'll need to use mesh, and that's a drain on your machine even with only dozens of rings. I'd hate to think how long a simulation of thousands would take.

Though this does make me wonder if there's some combination of settings that would make the cloth simulator do the equivalent of chainmail. Problem is it doesn't stretch; a given patch has a very definite maximum and minimum length- and the width has a different range, to make matters worse.
So sheets seem troublesome, and for smaller, more complicated things like unit weaves, I'd like some QoL things like clipping while moving objects before I would spend my time on it.


My comp is still on strike. Smile

I had to pull out the battery ... but a high end desktop should not have any problems. And my code is not refactrored yet. I just copied the algorithm from Zlosk.

In the next version that i will post i will place the torus upon creation instead of moving it in place afterwards. Even the rotation will be in one command. I used the copy paste approach for better understanding the algorithm.

BR
C

Joined: September 24, 2012
Posts: 93
Submissions: 1
Location: Stockholm, Sweden

Reply with quote
Posted on Tue Oct 15, 2013 6:40 pm
Link to Post: Link to Post

Zlosk wrote:
iph = inches per horizontal ring
ipv = inches per vertical ring

I should have had the meanings of the variable names commented in the code. <yells>Bad programmer!</yells>


Thanx Zlosk.

Your old code saved me tons of time.

BR
C

Joined: February 7, 2012
Posts: 99
Submissions: 1

Reply with quote
Posted on Tue Oct 15, 2013 8:41 pm
Link to Post: Link to Post

The problem is that while a desktop with a beefy graphics card may render maybe six times as fast(the result of a recent comparison between a friend's computer and my laptop), the 3D viewport and physics simulations will operate at almost the same speed(yes, I tested this as well). Turns out that stuff utilizes just the processor. Not only that, but only one core will be used, and while OpenGL is supposed to fix this, it does not.
Sounds like you're expecting a tenfold or more increase in speed, while what I've seen is more like 20%. Depends on the processor, of course, but you're not going to find one that will run more than twice as fast as the laptop's on a single core. The difference in clock speed in my test was about 30%.

Joined: September 24, 2012
Posts: 93
Submissions: 1
Location: Stockholm, Sweden

Reply with quote
Posted on Tue Oct 15, 2013 10:01 pm
Link to Post: Link to Post

TheMuffinmaster wrote:
The problem is that while a desktop with a beefy graphics card may render maybe six times as fast(the result of a recent comparison between a friend's computer and my laptop), the 3D viewport and physics simulations will operate at almost the same speed(yes, I tested this as well). Turns out that stuff utilizes just the processor. Not only that, but only one core will be used, and while OpenGL is supposed to fix this, it does not.
Sounds like you're expecting a tenfold or more increase in speed, while what I've seen is more like 20%. Depends on the processor, of course, but you're not going to find one that will run more than twice as fast as the laptop's on a single core. The difference in clock speed in my test was about 30%.


You saved me from spending 2500$ on o ROG desktop Smile

Joined: January 17, 2013
Posts: 373
Submissions: 5
Location: Probably in the garage...

Reply with quote
Posted on Wed Oct 16, 2013 6:57 pm || Last edited by Levi on Fri Nov 22, 2013 3:29 am; edited 1 time in total
Link to Post: Link to Post

Here is my current, not perfect but good enough for most way of making a simple 1 in 1 chain in Blender. If you can follow this you should know almost enough to make any other weave and simulate it.

1. Install Blender. Open Blender, click on the background to get rid of the start-up splash screen. Press Del on your keyboard, Left-click on the prompt to confirm the delete.
You should now have an empty workspace.

Some basic usage before I go on.
-When you left click somewhere on the screen a red and white circle with crosshairs shows up, this is your Origin. When you add an object it gets added to the scene at the point of origin.
-The screen is divided into 5 main items. Going clock-wise, at the top of the screen running the full width of the window is the File menu. To the far right running from top to bottom is the main tools menu. Along the bottom is the timeline window used for playing animations. On the far left is a smaller version of the tools menu. In the middle is the scene.

2.From the top menu, click Add > Mesh > Torus (bottom of the list). You now have a ring with limited functionality. If you want to muck with the "AR" values press F6 before you move the ring (I don't know why can't do it after moving, still figuring this out), an Add Torus menu will pop-up adjust the "major radius" and "minor radius" to change the AR. Leave the "segment" counts alone for now, you can also use Exterior/Interior to change the AR but it induces other changes. FYI: AR does not translate directly, play around.

3. Press Ctrl + Alt + Q. Your view will change to a four window, four perspective view. Going from top left to bottom right you will have, Top Ortho=TO, Camer Persp=CP, Front Ortho=FO and Right Ortho=RO.

4. Unless you moved your Origin point your ring should be dead-center in all four views. In the FO or RO window left-click on the blue arrow and drag the ring up a grid line or two as you do this you will see the ring rise in the CP window, release the mouse button when the ring is sufficiently elevated.

5. Lets rotate the ring so it's standing up instead of laying down. With your cursor in the RO window press R. A dotted line leading to your cursor will show up, as you move the cursor the ring will rotate. Press and hold the Ctrl key to force the rotation to 5 degree increments, the top of the timeline menu will have vanished and the degrees will be listed to the left side. Rotate the ring to 90 degrees and left-click to confirm, release Ctrl.

6. Chances are your ring looks pretty rough lets smooth it out by clicking on "Smooth" under Shading in the left tools menu. Yay, your ring now looks like a smooth ring.

Edit 11/21/2013: collisions are not required, step removed.
7. Make the main tools window a bit bigger by dragging the left edge out towards the middle. You want to be able to see all of the icons just above the push-pin with "Scene" beside it. Now click on Rigid Body and scroll down. In the Shape box change "Convex Hull" to "Mesh", change the Sensitivity Margin to 0.001, leave other settings as is.

8. Chances are you want something to "hold" the chain so we are going to make this ring stationary. Remove the checkmark beside "Dynamic" to make this ring stay in place. At this point the ring will act real it's just magically floating there. You may have noticed the ring now has a green outline, this indicates that is has a Rigid Body assigned to it.

9. Adding a second ring. In the FO window, center your cursor to the ring then press Shift+D to duplicate the ring. Now when you move your cursor the new ring will follow. Press and hold Ctrl then move the ring down one step, left-click to confirm and release Ctrl. You now have a figure eight looking thing.

10. Make the ring dynamic again by placing a checkmark in the "Dynamic" box in the main tools window.

11. Rotate the second ring. This time in the TO window press R, press and hold Ctrl and rotate the ring 90 degrees.

12. Press the play button in the timeline window. The bottom ring should fall and dangle a bit. We're getting there.

13. Add the third ring. In the FO or RO window select (right-click to select an object) the bottom or second ring and press Shift+D to duplicate it, press and hold Ctrl, move the ring down one step, left-click to confirm and release Ctrl. In the TO window rotate the ring 90 degrees same a before. At this point the default grid is too large to keep snapping to and the first and third rings are intersecting each other.

14. Move the third ring down a pinch. In the FO window left-click the blue arrow and drag the ring down. As mentioned above the grid is too big (it could be changed) so instead of aligning it we are just going to pull it down. If you press and hold Shift while moving an object you get much finer control over the movement. Make sure the third ring is still inside the second ring. You can test this by hitting play in the timeline window.

15. Make the chain longer. While pressing and holding Shift, right-click on the second ring to select them both. Now press Shift+D to duplicate them, move them down so they hang from the last ring, repeat a few more times. You now have a 1 in 1 chain to play with. Press play in the timeline window to watch the links drop and wiggle.

16. That's kinda boring. Ok, lets take it up a notch. At the top left of the timeline window you will see View, Select, Object. Click on Select > Select all by Type > Mesh, all of your rings should now be selected. In the FO window press R, press and hold Ctrl and rotate the whole chain 90 degrees so it's "laying flat". Still in the FO window click the blue arrow and move the whole chain up to the red line and more in view relative to the CP window.

17. Swing away little one. Press play in the timeline window and watch it go.

From here you can play around by adding more rings or other objects for the chain to bump into. These are bare tori they have no material assigned to them and lighting is just the one default lamp so it's pretty ugly but press F12 and see what it looks like rendered.

Because we're using a Mesh to make the objects solid under too much weight or velocity the rings will pull through each other with the heavy part falling off into infinity. Adding more stationary rings to hold the weight will prevents this to some degree.

Edit 11/21/2013: To correct this do the following.
From the right menu click on the "Scene" icon, it's a lamp, sphere and cube. In the "Rigid Body World" click the "Add Rigid Body World" button. Change the "Steps Per Second:" to "360" and the "Solver Iterations:" to "40".

I've posted my Blender file for the 1 in 1 chain here for download if you just want to play with it. 1.2MB in size, save then open from within Blender.

Here is a slightly done up render of the chain before I turned on physics.


And another just after turning on physics as the chain begins to fall.


I'm still learning but this seemed easy enough to pass on to others so enjoy. Render and simulation speeds are directly proportional to the CPU, the more math the CPU can crunch the better. Full renders use all available CPU cores otherwise it seems to try and use only one core. I don't have a CUDA capable GPU on-hand a the moment to test the performance increase when using CUDA from what I've read the increase is very significant.

Edit: Here is a little piece of J6in1 I made yesterday from the 1in1 chain.



Mostly Harmless

Joined: December 22, 2007
Posts: 4610
Submissions: 106
Location: Hampton, Virginia USA

Reply with quote
Posted on Wed Oct 16, 2013 7:10 pm
Link to Post: Link to Post

Levi, please please please submit that as an article? Pretty please with a cherry on top? Please...?


"I am a leaf on the wind." ~ Wash
Lorraine's Chains
Gallery Submission Guidelines

Joined: January 17, 2013
Posts: 373
Submissions: 5
Location: Probably in the garage...

Reply with quote
Posted on Wed Oct 16, 2013 7:26 pm
Link to Post: Link to Post

lorraine wrote:
Pretty please with a cherry on top?


With a request like that how can I refuse! It's in the queue for approval now.


Mostly Harmless

Joined: December 22, 2007
Posts: 4610
Submissions: 106
Location: Hampton, Virginia USA

Reply with quote
Posted on Wed Oct 16, 2013 9:11 pm
Link to Post: Link to Post

Levi wrote:
lorraine wrote:
Pretty please with a cherry on top?


With a request like that how can I refuse! It's in the queue for approval now.

YAY! Very Happy


"I am a leaf on the wind." ~ Wash
Lorraine's Chains
Gallery Submission Guidelines

Joined: September 24, 2012
Posts: 93
Submissions: 1
Location: Stockholm, Sweden

Reply with quote
Posted on Thu Oct 17, 2013 10:01 am
Link to Post: Link to Post

Levi.
You're a hero. Smile

Can the mods create a blender sticky post in articles where code can be submitted?
Nice to have instead of starting new threads for every new update.

Br
C

Joined: February 7, 2012
Posts: 99
Submissions: 1

Reply with quote
Posted on Thu Oct 17, 2013 11:52 am
Link to Post: Link to Post

Levi, could this not be simplified by using the array modifier? Or will the physics options apply to only the initial objects?

Joined: December 22, 2007
Posts: 4610
Submissions: 106
Location: Hampton, Virginia USA

Reply with quote
Posted on Thu Oct 17, 2013 4:36 pm
Link to Post: Link to Post

Carolides wrote:
Can the mods create a blender sticky post in articles where code can be submitted?
Nice to have instead of starting new threads for every new update.

There is a sticky in Weaves Discussion, 3D Rendering Faq - Tools that would be a good place for that.


"I am a leaf on the wind." ~ Wash
Lorraine's Chains
Gallery Submission Guidelines

Joined: January 17, 2013
Posts: 373
Submissions: 5
Location: Probably in the garage...

Reply with quote
Posted on Thu Oct 17, 2013 5:06 pm
Link to Post: Link to Post

TheMuffinmaster wrote:
Levi, could this not be simplified by using the array modifier? Or will the physics options apply to only the initial objects?


I'm not sure, with only a few hours of Blender use under my belt there are presumably thousands of things I don't know about the program.

After a quick read of the 2.6 array section, it certainly sounds like an array would make things simpler as ring counts increase.

I'll play around with it later today and see what I can come up with.


Mostly Harmless

Post new topic Reply to topic
Jump to:  
Page 1 of 7. Goto page 1, 2, 3, 4, 5, 6, 7  Next
All times are GMT. The time now is Thu Dec 13, 2018 11:15 pm
M.A.I.L. Forum Index -> Knitting Circle
Display posts from previous: