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: December 22, 2007
Posts: 4610
Submissions: 106
Location: Hampton, Virginia USA

Reply with quote
Posted on Sun Nov 03, 2013 11:55 pm
Link to Post: Link to Post

Very Happy


"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 Mon Nov 04, 2013 2:34 pm
Link to Post: Link to Post

One article drafted, how to make a ring. So I made a new ring with a higher AR, just because and started to work on the second article. All good until I ran the physics and the rings pulled apart on a simple 2 in 1 chain consisting of 7 rings. Hmmmm.

I still have more testing to do but it seems as ring AR gets larger you need to bump up the "Solver Iterations" or the rings fall through each other again. Could also be a combination of scale affecting the rings not too sure just yet.
With the default torus AR (or there abouts) the default of 10 seems to work fine. With thinner rings I had to change the solver iterations to 40 before the rings did what they should. Maybe this is the problem you had WpA09?

To change the Solver Iterations value.
Go to the Scene tab on the right menu (a light, a sphere and a box). Find >Rigid Body World then change the "Solver Iterations:" from 10 to 40.


Mostly Harmless

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

Reply with quote
Posted on Tue Nov 05, 2013 12:10 am
Link to Post: Link to Post

Ok, a bit more testing and re-running my tests from yesterday and I think I've found the "magic" settings.

Adding the FIXED rigid body constraint isn't doing what I thought it was, you still need a Rigid Body just not the constraint.

I had changed the "Steps Per Second" from 60 to 360 along with bumping the "Solver Iterations" to 1000 then forgot I had done so.

After some more testing setting Steps Per Second set to 360 and Solver Iterations set to 40 seems to work with all of the chains and weaves I've tested.

I'm waiting on a 2145 ring sheet of E8in2 being gravity pulled into a wrong way layout of 17x33, should be a pretty worst case scenario. It's almost vertical at frame 42 and shows no signs of pulling apart thus far.

Both of the previous scripts do work at the default 60 and 10 but 360 and 40 thus far seem to be the best overall.

A bit more testing and I'll update the script(s).


Mostly Harmless

Joined: September 30, 2012
Posts: 255
Submissions: 13
Location: Sweden

Reply with quote
Posted on Tue Nov 05, 2013 1:10 am
Link to Post: Link to Post

The problem I have is that no rings show up. At all. I will look further into the matter but right now I am in a tight spot with exams and stuff haha. This weekend will be a completely Maille-related one. Either weaving or creating in blender.


"When in doubt... C4" - Jamie Hyneman

My YouTube channel: http://www.youtube.com/wpa09
My band: http://www.facebook.com/carnosus

"This is an art form, and we love to be recognized for our own work, and we'd all hope not to be confused with someone else."
- Charon, March 27, 2009

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

Reply with quote
Posted on Tue Nov 05, 2013 10:00 am
Link to Post: Link to Post

WpA09:
I think the prison in Kumla is interfeering with your Blender installation Smile

I cut and paste Levi's source code and it worked fine.

BR
C

Joined: September 30, 2012
Posts: 255
Submissions: 13
Location: Sweden

Reply with quote
Posted on Tue Nov 05, 2013 11:23 am
Link to Post: Link to Post

Carolides wrote:
WpA09:
I think the prison in Kumla is interfeering with your Blender installation Smile

I cut and paste Levi's source code and it worked fine.

BR
C


Haha, perhaps. But atleast we don't have a giant golfball in the middle of town Wink

Will try the same later.


"When in doubt... C4" - Jamie Hyneman

My YouTube channel: http://www.youtube.com/wpa09
My band: http://www.facebook.com/carnosus

"This is an art form, and we love to be recognized for our own work, and we'd all hope not to be confused with someone else."
- Charon, March 27, 2009

Joined: September 30, 2012
Posts: 255
Submissions: 13
Location: Sweden

Reply with quote
Posted on Mon Nov 11, 2013 10:22 am
Link to Post: Link to Post

I still can't get the script to work. When importing directly into Blender nothing happens. When imported directly into python and running it there, I get the error message:

Traceback (most recent call last):
File "D:\Python\Scripts\Blender_rings_2.py", line 8, in <module>
import bpy
ImportError: No module named 'bpy'

Is this because my computer is odd and have D: as the standard drive but program files is still contained within C: (now that I'm typing this, it kind of makes sense...)? Although every program I've installed myself have their place on the D: drive, the "stock" programs are contained within C:

Meh Uber Raz


"When in doubt... C4" - Jamie Hyneman

My YouTube channel: http://www.youtube.com/wpa09
My band: http://www.facebook.com/carnosus

"This is an art form, and we love to be recognized for our own work, and we'd all hope not to be confused with someone else."
- Charon, March 27, 2009

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

Reply with quote
Posted on Mon Nov 11, 2013 1:19 pm
Link to Post: Link to Post

The pathing (C:.D:,) shouldn't be causing any problems.

If you copy the script from here then paste it into Notepad or some other text editor, does the script paste into it?

Now if you copy it from Notepad then paste it into Blender does it work?

At one point I recall having an issue like that where copying from a browser directly to Blender didn't work. I had to use a text editor as an intermediary.


Mostly Harmless

Joined: September 30, 2012
Posts: 255
Submissions: 13
Location: Sweden

Reply with quote
Posted on Mon Nov 11, 2013 2:38 pm
Link to Post: Link to Post

Levi wrote:
The pathing (C:.D:,) shouldn't be causing any problems.

If you copy the script from here then paste it into Notepad or some other text editor, does the script paste into it?

Now if you copy it from Notepad then paste it into Blender does it work?

At one point I recall having an issue like that where copying from a browser directly to Blender didn't work. I had to use a text editor as an intermediary.


Will try it!

EDIT: Nope, still ain't getting anything on-screen Confused


"When in doubt... C4" - Jamie Hyneman

My YouTube channel: http://www.youtube.com/wpa09
My band: http://www.facebook.com/carnosus

"This is an art form, and we love to be recognized for our own work, and we'd all hope not to be confused with someone else."
- Charon, March 27, 2009

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

Reply with quote
Posted on Mon Nov 11, 2013 10:00 pm
Link to Post: Link to Post

Does it paste into Notepad?


Mostly Harmless

Joined: September 30, 2012
Posts: 255
Submissions: 13
Location: Sweden

Reply with quote
Posted on Mon Nov 11, 2013 10:54 pm
Link to Post: Link to Post

Levi wrote:
Does it paste into Notepad?


Yes. But I'm thinking that it can't locate the BPY module within blender (which is really odd...) and I believe this to be the problem. Don't know how to fix that though.

Is there an easy way to set filepaths in which blender/python locates certain files from? The methods I've tried have yielded me no results except other error messages, which is a feature I don't like. I don't know how to better describe what I'm thinking.

Otherwise I'll just wait for that article and in the meantime I'll experiment with Python (as I am currently in the middle of such a programme/class at my university) to try to figure out how to surpass this mystery Very Happy


"When in doubt... C4" - Jamie Hyneman

My YouTube channel: http://www.youtube.com/wpa09
My band: http://www.facebook.com/carnosus

"This is an art form, and we love to be recognized for our own work, and we'd all hope not to be confused with someone else."
- Charon, March 27, 2009

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

Reply with quote
Posted on Tue Nov 12, 2013 12:15 am
Link to Post: Link to Post

In Blender click File, Load Factory Settings. Should restore Blender to defaults.

EDIT: You may also want to read this about Blender/Python paths and config files. From what I can tell an install of 2.68a is self-contained within it's folder and should not be affected by other versions. That being said if you did install it to a more common or shared folder and you have older versions of Python installed then chances are you will have trouble loading bpy among other things.
Fix, install/extract Blender 2.68a into it's own folder and it should be good.


Mostly Harmless

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

Reply with quote
Posted on Tue Nov 12, 2013 9:59 am
Link to Post: Link to Post

This snippet reads a picture and prints out the RGB and alpha values.
PNG file only tested.

My concern is how to handle the colors. Create runtime or read the file once, create the material and assign it to an array and then create the weave....
Problems, problems Smile

is_firefly function checks if color is close to white. Can be useful to add distinct colors to an array and then create materials.

BR
C

Code:
D = bpy.data
img = D.images.load("C:\\temp\\test.png")
pxs_slow = pixels = img.pixels
 
#recast, faster
pxs = list(pxs_slow)
 
w = width = img.size[0]
h = height = img.size[1]
 
num_pixels = len(pxs)
 
#equivalent statements
gl = grouped_list = [pxs[i:i+4] for i in range(0, num_pixels, 4)]
#gl = grouped_list = [pxs[i:i+4] for i in range(num_pixels)[::4]]


# Not used but can be useful.
def pic_index_to_coordinates(idx, width):
    row = int(idx / width)
    column = idx % width
    return row, column
 
 
def pic_coordinates_to_index(row, column, width):
    return row * width + column
 
 
def pic_rgba_from_index(idx, pxs):
    start_raw_index = idx * 4
    return pxs[start_raw_index:start_raw_index+4]
 
 
def is_firefly(rgba):
    if (any(rgba) == 1.0) and (sum(rgba) > 3.8):
        return True
 
print('image width: %d' % w) 
print('image height: %d' % h)
       
for x in range(0, w-1):
    for y in range(0, h-1):
        idx = pic_coordinates_to_index(x, y, w)
        rgba = pic_rgba_from_index(idx, pxs)
        print(x,y, '-->', rgba,'-->', is_firefly(rgba))

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

Reply with quote
Posted on Thu Nov 14, 2013 12:41 pm
Link to Post: Link to Post

Small update.

After a whole lot more playing around with scripting I now have a very basic version of BlenderIGP working. Smile It reads the pixel color data from a small image, creates a new material with that pixels color data, creates a ring then proceeds on to the next pixel/ring.
I have a bunch a garbage code to clean up and a bunch of commenting to insert but I'm almost done.

On another note, I've almost completed my first article on making a chain in Blender. It's a bit bigger then first envisioned but it should provide people will all the information needed to start making virtual chains. From making saw-cut rings, forming chains and weaves, adding 'metal like" materials, applying physics and rendering the scene.

I hope to have both submitted over the weekend.


Mostly Harmless

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

Reply with quote
Posted on Thu Nov 14, 2013 1:10 pm
Link to Post: Link to Post

Levi wrote:
Small update.

After a whole lot more playing around with scripting I now have a very basic version of BlenderIGP working. Smile It reads the pixel color data from a small image, creates a new material with that pixels color data, creates a ring then proceeds on to the next pixel/ring.
I have a bunch a garbage code to clean up and a bunch of commenting to insert but I'm almost done.

On another note, I've almost completed my first article on making a chain in Blender. It's a bit bigger then first envisioned but it should provide people will all the information needed to start making virtual chains. From making saw-cut rings, forming chains and weaves, adding 'metal like" materials, applying physics and rendering the scene.

I hope to have both submitted over the weekend.


Code ?

Post new topic Reply to topic
Jump to:  
Page 5 of 7. Goto page Previous  1, 2, 3, 4, 5, 6, 7  Next
All times are GMT. The time now is Sat Apr 04, 2020 8:22 am
M.A.I.L. Forum Index -> Knitting Circle
Display posts from previous: