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

Reply with quote
Posted on Tue Oct 29, 2013 12:32 pm
Link to Post: Link to Post

Damn it looks so nice!
Some rusty iron texture and it would be perfect.

Br
C

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

Reply with quote
Posted on Tue Oct 29, 2013 12:57 pm
Link to Post: Link to Post

Thanks, I'm patient but until I get another 8GB I'm not going to dress it up too much. I do agree some rusty mild steel rings would look pretty trick all piled up like that.
The worst part is it only takes my processor 2:18.50 minutes to render the scene but it takes about 5 minutes for it to swap out enough RAM to do the render then another 5 minutes to swap the data back into RAM.


Mostly Harmless

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

Reply with quote
Posted on Tue Oct 29, 2013 1:05 pm
Link to Post: Link to Post

By the way.
Having the physics in the script adds an overall 15% to the total creation time.
Still a fraction compared to the 6+ hours it took you to create the scene.

Br
C

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

Reply with quote
Posted on Tue Oct 29, 2013 11:57 pm
Link to Post: Link to Post

Carolides wrote:
Damn it looks so nice!
Some rusty iron texture and it would be perfect.


Mm, not to mention a little delicious bump mapping thrown in on top...

I wonder if you could do this with the cloth modifier and use the stretch function to determine the spacing of the rings instead of elongating them.
Probably not.

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

Reply with quote
Posted on Wed Oct 30, 2013 8:15 am
Link to Post: Link to Post

Tip:

Using 4 minor segments creates Square rings Smile

Gotta work on the parameter file now.


BR
C

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

Reply with quote
Posted on Wed Oct 30, 2013 1:48 pm
Link to Post: Link to Post

I made the script fully dependant on CSV.

Cleaned the code alot and using a for loop to traverse the array created by the CSV read. It has increased the performance alot.

The new code:

Code:
#
# Initial code by Zlosk (mailler@zlosk.com) 11-18-2002 for POV-Ray
# Ported by Carolides (Changed some variable names so they make sense to me
# Use as you please but not commercially
#

# Imports
import bpy
from bpy import context
from math import cos, sin, radians, atan, asin
import time

#
# Function Init
# Description: Initializes all values required for the script.
# Parameters: None
#

def Init():
   
    # Global variables
    global DEBUG
    global f_Main_Ring_Wire_Diameter
    global f_Main_Ring_Inner_Diameter
    global i_Ring_Multiple
    global f_AR
    global f_iph
    global f_ipv
    global f_ang
    global obj_Torus
    # Debug output   
    DEBUG = False
   
    # Declare ring sizes
    f_Main_Ring_Wire_Diameter = 0.0625
    f_Main_Ring_Inner_Diameter = 4*1.0625 * f_Main_Ring_Wire_Diameter
   
    i_Ring_Multiple = 10
   
    # Perform secondary calcs
   
    f_Main_Ring_Wire_Diameter = i_Ring_Multiple * f_Main_Ring_Wire_Diameter
    f_Main_Ring_Inner_Diameter = i_Ring_Multiple * f_Main_Ring_Inner_Diameter
   
    f_AR = f_Main_Ring_Inner_Diameter / f_Main_Ring_Wire_Diameter
   
    f_iph = f_Main_Ring_Wire_Diameter * (0.9215*f_AR-0.1566)
    f_ipv = 2*f_Main_Ring_Wire_Diameter * (-0.0582*f_AR*f_AR*f_AR + 0.8677*f_AR*f_AR - 3.2996*f_AR+6.2401)
    f_ang = asin(f_Main_Ring_Wire_Diameter/f_iph)*45/atan(1)
   
    if DEBUG == True:
        print ('Function Init()')
        print ('Initial Values:')
        print ('    Wire Diameter: ' + str(f_Main_Ring_Wire_Diameter))
        print ('    Inner Diameter: ' + str(f_Main_Ring_Inner_Diameter))
        print ('    Ring Multiple: ' + str(i_Ring_Multiple))
        print ('    Aspect Ratio: ' + str(f_AR))
        print ('    f_iph: ' + str(f_iph))
        print ('    f_ipv: ' + str(f_ipv))
        print ('    Angle: ' + str(f_ang))
        print ('\n')
   
    obj_Torus = bpy.ops.mesh.primitive_torus_add
   
   
       
    mat_red = makeMaterial('Red', (1,0,0), (1,1,1), 1)
    mat_white = makeMaterial('White', (1,1,1), (1,1,1), 1)
    mat_white = makeMaterial('Black', (0,0,0), (1,1,1), 1)
    mat_white = makeMaterial('Yellow', (1,0.994,0), (1,1,1), 1)
    mat_white = makeMaterial('Blue', (0.078,0.404,1), (1,1,1), 1)
   
#
# Function readCSVfile
# used for getting dimensions of the weave and color composition
# Parameters: file <Name>
#
def readCSVFile(file):
    global value_vector
   
    # Init

    value_vector = []
   
    # Open file
    file = open(file, "r")
   
    # Loop over line in file
    for line in file:
        # Split line at ";"
        split_line = line.split(";")     
        value_vector.append(split_line)
   
    # Set number of rows and columns of the patch
    i_Rows = len(value_vector)   
    i_Columns = len(value_vector[1])
   
    # Close file
    file.close()
    if DEBUG == True:
        i_r = 0
        i_c = 0
        print ('Function readCSVFile()')
        print ('Initial Values:')
        print ('    Rows:' + str(i_Rows))
        print ('    Columns:'+ str(i_Columns))
        while i_r <= i_Rows - 1:
            while i_c <= i_Columns - 1:
                print ('    Value(' + str(i_r) + ',' + str(i_c) + '): ' + str(value_vector[i_r][i_c]))
                i_c += 1
            i_r += 1
            i_c = 0
           

def makeMaterial(name, diffuse, specular, alpha):
    mat = bpy.data.materials.new(name)
    mat.diffuse_color = diffuse
    mat.diffuse_shader = 'LAMBERT'
    mat.diffuse_intensity = 1.0
    mat.specular_color = specular
    mat.specular_shader = 'COOKTORR'
    mat.specular_intensity = 0.5
    mat.alpha = alpha
    mat.ambient = 1
    return mat
 
def setMaterial(ob, mat):
    me = ob.data
    me.materials.append(mat)
   
def clearAll():
    #unselect everything
    # <insert>
    # bpy.ops.object.select_all()
     
    # gather list of items of interest.
    candidate_list = [item.name for item in bpy.data.objects if item.type == "MESH"]
     
    # select them only.
    for object_name in candidate_list:
      bpy.data.objects[object_name].select = True
     
    # remove all selected.
    bpy.ops.object.delete()
     
    # remove the meshes, they have no users anymore.
    for item in bpy.data.meshes:
      bpy.data.meshes.remove(item)
                 
def CreateSheet(physics):
    i_major_segments = 12
    i_minor_segments = 12
   
    prev_row = 0
    prev_col = 0
   
    for i_Row, inner_list in enumerate(value_vector):
        for i_Column, item in enumerate(inner_list):
            if i_Column % 2 == 0:       
                obj_Torus(location=((i_Column)* f_iph/2, - i_Row * f_ipv, 0.0), rotation=(0, f_ang, 0), major_segments=i_major_segments, minor_segments=i_minor_segments, minor_radius=f_Main_Ring_Wire_Diameter / 2, major_radius=(f_Main_Ring_Inner_Diameter + f_Main_Ring_Wire_Diameter) / 2)
                setMaterial(bpy.context.object, bpy.data.materials[str(value_vector[i_Row][i_Column]).rstrip("\n")])
                if physics == True:               
                    bpy.ops.rigidbody.object_add(type='ACTIVE')
                    bpy.ops.object.modifier_add(type='COLLISION')
                    bpy.context.object.rigid_body.collision_shape = 'MESH'
                    bpy.context.object.rigid_body.collision_margin = 0.001     
            else:
                obj_Torus(location=((i_Column + 0.5)*f_iph/2,-(i_Row+0.5)*f_ipv,0.0), rotation=(0, -f_ang, 0), major_segments=i_major_segments, minor_segments=i_minor_segments, minor_radius=f_Main_Ring_Wire_Diameter / 2, major_radius=(f_Main_Ring_Inner_Diameter + f_Main_Ring_Wire_Diameter) / 2)
                setMaterial(bpy.context.object, bpy.data.materials[str(value_vector[i_Row][i_Column]).rstrip("\n")]) 
                if physics == True:
                    #bpy.context.object.name = "Ring_" + str(i_loopindex_outer) + "_" + str(i_loopindex_inner) + "_2"
                    bpy.ops.rigidbody.object_add(type='ACTIVE')
                    bpy.ops.object.modifier_add(type='COLLISION')
                    bpy.context.object.rigid_body.collision_shape = 'MESH'
                    bpy.context.object.rigid_body.collision_margin = 0.001     
   
           
   
Init()
readCSVFile("C:\\temp\\Sweden.csv")   
clearAll()
CreateSheet(True)


Using the following CSV (Supposed to be a swedish flag)

Code:
Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue
Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue
Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue
Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue
Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue
Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue
Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue
Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue
Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue
Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue
Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue
Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue
Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow
Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow
Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow
Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow
Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow
Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow
Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue
Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue
Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue
Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue
Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue
Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue
Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue
Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue
Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue
Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue
Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue
Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Yellow;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue;Blue

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

Reply with quote
Posted on Thu Oct 31, 2013 12:31 pm
Link to Post: Link to Post

Nice flag Carolides.

While the .CSV thing is quite cool, I'm wondering if there isn't a way to pull pixel data directly from an image file. I imagine you'd probably have to use a non-compressed file type like a .BMP and it would have to be pretty small from a resolution perspective.

I've been meaning to read up on it but everything is crazy busy for me these days.


Mostly Harmless

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

Reply with quote
Posted on Thu Oct 31, 2013 1:25 pm
Link to Post: Link to Post

Can look into it.
Creating module files with general functions.

Br
C

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

Reply with quote
Posted on Sun Nov 03, 2013 5:48 pm
Link to Post: Link to Post

Eureka!!!

I've figured out how to make the weaves stay together in a much more true to life way.

Here is the script to make a sheet of E4in1 with 7 anchor rings (red ones) and 147 weaved rings (blue one). Don't worry, it generates within a few seconds.

To run the script.
Highlight everything below in the Code: section (between the white lines) and copy it. Ctrl+C to copy.
Open Blender, click past startup, press X to delete the box. Across the top menu where is says Default click the little boxes to the left of it and choose Scripting.

At the bottom of the left light gray screen click the + New, now right-click in that light gray screen and choose Paste or Ctrl+V. You should now have a the script in the text box.
Depending on your screen resolution you may have to make the light gray window a bit bigger by sliding the middle divider to the right until you can see the "Run Script" button. Once you can see the button click it a few seconds later a bunch of rings will show up.

Switch back to Default view from the top menu.
The rings are pretty big so you may want to scale them down a pinch. From the bottom menu choose "Select" > Select All by Type > Mesh, all of the rings should be selected with a green outline. Press S, .5, Enter. Now lets slide it back into view a bit, Press G, Y, -20, Enter.

Click the Play button from the animation window and enjoy. The first time it plays it will be slow while it figures out the physics, once it's gone through all 250 frames the animation will run much quicker on the second loop.

For more fun add a sphere for the sheet to bump into. From the top menu click Add > Mesh > UV Sphere. From the left menu get to the physics tab (bouncy ball), may have to make the menu bigger to see it. Once on the physics tab, click on Rigid Body, change it's type to Passive and under Rigid Body Collisions set it's shape to Sphere. Move the sphere into the path of the sheet. Quad view (Ctrl+Alt+Q when your cursor is in the viewport) is handy for positioning the sphere. With the sphere in place switch back to User Persp by pressing Ctrl+Alt+Q then 0 (on NumPad) followed by . (on NumPad) then scroll wheel to zoom out a bit.

Clear the physics cache after adding a new object or it will be ignored. To clear the cache quickly just press the |<< button on the animation menu once or twice until the yellow line disappears. Press Play, the physics will re-build and on the second loop it should play fairly well.

Code:

#
# Initial code by Zlosk (mailler@zlosk.com) 11-18-2002 for POV-Ray
# Ported by Carolides (Changed some variable names so they make sense to me
# Use as you please but not commercially
# Tweaked a bit by Levi

# Imports
import bpy
from bpy import context
from math import cos, sin, radians, atan, asin


cursor = context.scene.cursor_location

# Declare and lock layers
bpy.context.scene.layers[0] = False
bpy.context.scene.layers[2] = True


# Declare ring sizes
f_Main_Ring_Wire_Diameter = 0.0625
f_Main_Ring_Inner_Diameter = 4*1.0625 * f_Main_Ring_Wire_Diameter

i_Columns = 0
i_Rows = 0

# To make the first row stiff
bl_stiff_row = True


i_loopindex_outer = -10
i_loopindex_inner = -6
i_loopindex_inner_reset = i_loopindex_inner
i_Ring_Multiple = 10
Infinite_Dist_Multiple = 40

# Perform secondary calcs

f_Main_Ring_Wire_Diameter = i_Ring_Multiple * f_Main_Ring_Wire_Diameter
f_Main_Ring_Inner_Diameter = i_Ring_Multiple * f_Main_Ring_Inner_Diameter

f_AR = f_Main_Ring_Inner_Diameter / f_Main_Ring_Wire_Diameter

iph = f_Main_Ring_Wire_Diameter * (0.9215*f_AR-0.1566)
ipv = 2*f_Main_Ring_Wire_Diameter * (-0.0582*f_AR*f_AR*f_AR + 0.8677*f_AR*f_AR - 3.2996*f_AR+6.2401)
ang = asin(f_Main_Ring_Wire_Diameter/iph)*45/atan(1)

print ('AR: ' + str(f_AR))
print ('iph: ' + str(iph))
print ('ipv: ' + str(ipv))
print ('ang: ' + str(ang))

obj_Torus = bpy.ops.mesh.primitive_torus_add

def makeMaterial(name, diffuse, specular, alpha):
    mat = bpy.data.materials.new(name)
    mat.diffuse_color = diffuse
    mat.diffuse_shader = 'LAMBERT'
    mat.diffuse_intensity = 1.0
    mat.specular_color = specular
    mat.specular_shader = 'COOKTORR'
    mat.specular_intensity = 0.5
    mat.alpha = alpha
    mat.ambient = 1
    return mat
 
def setMaterial(ob, mat):
    me = ob.data
    me.materials.append(mat)
   
mat_red = makeMaterial('Red', (1,0,0), (1,1,1), 1)
mat_blue = makeMaterial('BlueSemi', (0,0,1), (0.5,0.5,0), 0.5)
 
while i_loopindex_outer <= i_Rows:
    while i_loopindex_inner <= i_Columns:
        if bl_stiff_row == True:
            obj_Torus(location=(i_loopindex_inner * iph - -0.55, - i_loopindex_outer * ipv + 0.55, 0.0), rotation=(0, ang, 0), minor_radius=f_Main_Ring_Wire_Diameter / 2, major_radius=(f_Main_Ring_Inner_Diameter + f_Main_Ring_Wire_Diameter) / 2)
            setMaterial(bpy.context.object, mat_red)
            bpy.ops.rigidbody.object_add(type='ACTIVE')
            bpy.ops.rigidbody.constraint_add(type='FIXED')
            bpy.context.object.rigid_body.collision_shape = 'MESH'
            bpy.context.object.rigid_body.collision_margin = 0.001
            bpy.context.object.rigid_body_constraint.disable_collisions = False
            bpy.context.object.rigid_body.enabled = False
            bpy.context.active_object.rotation_euler=[1.57, 0.0, -1.57]
   
            obj_Torus(location=((i_loopindex_inner + 0.5)*iph,-(i_loopindex_outer+0.5)*ipv,0.0), rotation=(0, -ang, 0), minor_radius=f_Main_Ring_Wire_Diameter / 2, major_radius=(f_Main_Ring_Inner_Diameter + f_Main_Ring_Wire_Diameter) / 2)
            setMaterial(bpy.context.object, mat_blue)
            bpy.ops.rigidbody.object_add(type='ACTIVE')
            bpy.ops.rigidbody.constraint_add(type='FIXED')
            bpy.context.object.rigid_body.collision_shape = 'MESH'           
            bpy.context.object.rigid_body.collision_margin = 0.001
            bpy.context.object.rigid_body.enabled = True
            bpy.context.object.rigid_body_constraint.disable_collisions = False
            bpy.context.active_object.rotation_euler=[0, 0.26, 0]
        else:               
            obj_Torus(location=(i_loopindex_inner * iph, - i_loopindex_outer * ipv, 0.0), rotation=(0, ang, 0), minor_radius=f_Main_Ring_Wire_Diameter / 2, major_radius=(f_Main_Ring_Inner_Diameter + f_Main_Ring_Wire_Diameter) / 2)
            setMaterial(bpy.context.object, mat_blue)
            bpy.ops.rigidbody.object_add(type='ACTIVE')
            bpy.ops.rigidbody.constraint_add(type='FIXED')
            bpy.context.object.rigid_body_constraint.disable_collisions = False
            bpy.context.object.rigid_body.collision_shape = 'MESH'
            bpy.context.object.rigid_body.collision_margin = 0.001
            bpy.context.object.rigid_body.enabled = True
            bpy.context.active_object.rotation_euler=[0, -0.26, 0]
   
            obj_Torus(location=((i_loopindex_inner + 0.5)*iph,-(i_loopindex_outer+0.5)*ipv,0.0), rotation=(0, -ang, 0), minor_radius=f_Main_Ring_Wire_Diameter / 2, major_radius=(f_Main_Ring_Inner_Diameter + f_Main_Ring_Wire_Diameter) / 2)
            setMaterial(bpy.context.object, mat_blue)
            bpy.ops.rigidbody.object_add(type='ACTIVE')
            bpy.ops.rigidbody.constraint_add(type='FIXED')
            bpy.context.object.rigid_body_constraint.disable_collisions = False
            bpy.context.object.rigid_body.collision_shape = 'MESH'
            bpy.context.object.rigid_body.collision_margin = 0.001
            bpy.context.object.rigid_body.enabled = True
            bpy.context.active_object.rotation_euler=[0, 0.26, 0]
        i_loopindex_inner += 1
    i_loopindex_outer += 1
    bl_stiff_row = False
    i_loopindex_inner = i_loopindex_inner_reset


Just for fun I made a sheet of J4in1 with 2273 rings and let it smash into a brass rod. Smile

Frame 1


Frame 21


Frame 41


Frame 241


I also pieced together an animated gif showing it in action here. It's 3.2MB so give it a minute.

As you can see the weaves are now strong enough to handle the forces of falling and colliding with other objects in a much more realistic way.

The key was adding a rigid body constraint of FIXED to the rings. Under enough "virtual pressure" the rings will still fail but it's much closer to real life than before.

P.S. Yes, Lorraine I am going to get all of this clearly documented and written up in a proper article (or five) in the near future. Wink


Mostly Harmless

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

Reply with quote
Posted on Sun Nov 03, 2013 6:30 pm
Link to Post: Link to Post

For some reason I can't get the script to work. I have tried some different techniques but none seem to create anything in my window. I'm in no hurry, even though it would be nice to see it on my own computer, so I'll wait for that article you were talking about 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 Sun Nov 03, 2013 7:23 pm
Link to Post: Link to Post

No technique required, just copy the script, go into scripting view, click new, paste the script and click "Run Script" or Alt+P and the rings should show up.

I've tried it on a few machines along with a few different builds of Blender 2.6 without an issues. If it still won't work let me know how far into the process you get.


Mostly Harmless

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

Reply with quote
Posted on Sun Nov 03, 2013 7:54 pm
Link to Post: Link to Post

Here is an updated version of the previous script that is ready to play once generated, now pre-scaled and includes a red ball that the sheet to wraps around. I smoothed the rings as well.

Copy everything from the first "#" down to "bpy.ops.object.select_all(action='TOGGLE')".

Code:


#
# Initial code by Zlosk (mailler@zlosk.com) 11-18-2002 for POV-Ray
# Ported by Carolides (Changed some variable names so they make sense to me
# Use as you please but not commercially
# Tweaked a bit by Levi

# Imports
import bpy
from bpy import context
from math import cos, sin, radians, atan, asin


cursor = context.scene.cursor_location

# Declare and lock layers
bpy.context.scene.layers[0] = False
bpy.context.scene.layers[2] = True


# Declare ring sizes
f_Main_Ring_Wire_Diameter = 0.0625
f_Main_Ring_Inner_Diameter = 4*1.0625 * f_Main_Ring_Wire_Diameter

i_Columns = 0
i_Rows = 0

# To make the first row stiff
bl_stiff_row = True


i_loopindex_outer = -10
i_loopindex_inner = -6
i_loopindex_inner_reset = i_loopindex_inner
i_Ring_Multiple = 10
Infinite_Dist_Multiple = 40

# Perform secondary calcs

f_Main_Ring_Wire_Diameter = i_Ring_Multiple * f_Main_Ring_Wire_Diameter
f_Main_Ring_Inner_Diameter = i_Ring_Multiple * f_Main_Ring_Inner_Diameter

f_AR = f_Main_Ring_Inner_Diameter / f_Main_Ring_Wire_Diameter

iph = f_Main_Ring_Wire_Diameter * (0.9215*f_AR-0.1566)
ipv = 2*f_Main_Ring_Wire_Diameter * (-0.0582*f_AR*f_AR*f_AR + 0.8677*f_AR*f_AR - 3.2996*f_AR+6.2401)
ang = asin(f_Main_Ring_Wire_Diameter/iph)*45/atan(1)

print ('AR: ' + str(f_AR))
print ('iph: ' + str(iph))
print ('ipv: ' + str(ipv))
print ('ang: ' + str(ang))

obj_Torus = bpy.ops.mesh.primitive_torus_add
obj_Sphere = bpy.ops.mesh.primitive_uv_sphere_add

def makeMaterial(name, diffuse, specular, alpha):
    mat = bpy.data.materials.new(name)
    mat.diffuse_color = diffuse
    mat.diffuse_shader = 'LAMBERT'
    mat.diffuse_intensity = 1.0
    mat.specular_color = specular
    mat.specular_shader = 'COOKTORR'
    mat.specular_intensity = 0.5
    mat.alpha = alpha
    mat.ambient = 1
    return mat
 
def setMaterial(ob, mat):
    me = ob.data
    me.materials.append(mat)
   
mat_red = makeMaterial('Red', (1,0,0), (1,1,1), 1)
mat_blue = makeMaterial('BlueSemi', (0,0,1), (0.5,0.5,0), 0.5)
 
while i_loopindex_outer <= i_Rows:
    while i_loopindex_inner <= i_Columns:
        if bl_stiff_row == True:
            obj_Torus(location=(i_loopindex_inner * iph - -0.55, - i_loopindex_outer * ipv + 0.55, 0.0), rotation=(0, ang, 0), minor_radius=f_Main_Ring_Wire_Diameter / 2, major_radius=(f_Main_Ring_Inner_Diameter + f_Main_Ring_Wire_Diameter) / 2)
            setMaterial(bpy.context.object, mat_red)
            bpy.ops.rigidbody.object_add(type='ACTIVE')
            bpy.ops.rigidbody.constraint_add(type='FIXED')
            bpy.ops.object.shade_smooth()
            bpy.context.object.rigid_body.collision_shape = 'MESH'
            bpy.context.object.rigid_body.collision_margin = 0.001
            bpy.context.object.rigid_body_constraint.disable_collisions = False
            bpy.context.object.rigid_body.enabled = False
            bpy.context.active_object.rotation_euler=[1.57, 0.0, -1.57]
   
            obj_Torus(location=((i_loopindex_inner + 0.5)*iph,-(i_loopindex_outer+0.5)*ipv,0.0), rotation=(0, -ang, 0), minor_radius=f_Main_Ring_Wire_Diameter / 2, major_radius=(f_Main_Ring_Inner_Diameter + f_Main_Ring_Wire_Diameter) / 2)
            setMaterial(bpy.context.object, mat_blue)
            bpy.ops.rigidbody.object_add(type='ACTIVE')
            bpy.ops.rigidbody.constraint_add(type='FIXED')
            bpy.ops.object.shade_smooth()
            bpy.context.object.rigid_body.collision_shape = 'MESH'           
            bpy.context.object.rigid_body.collision_margin = 0.001
            bpy.context.object.rigid_body.enabled = True
            bpy.context.object.rigid_body_constraint.disable_collisions = False
            bpy.context.active_object.rotation_euler=[0, 0.26, 0]
        else:               
            obj_Torus(location=(i_loopindex_inner * iph, - i_loopindex_outer * ipv, 0.0), rotation=(0, ang, 0), minor_radius=f_Main_Ring_Wire_Diameter / 2, major_radius=(f_Main_Ring_Inner_Diameter + f_Main_Ring_Wire_Diameter) / 2)
            setMaterial(bpy.context.object, mat_blue)
            bpy.ops.rigidbody.object_add(type='ACTIVE')
            bpy.ops.rigidbody.constraint_add(type='FIXED')
            bpy.ops.object.shade_smooth()
            bpy.context.object.rigid_body_constraint.disable_collisions = False
            bpy.context.object.rigid_body.collision_shape = 'MESH'
            bpy.context.object.rigid_body.collision_margin = 0.001
            bpy.context.object.rigid_body.enabled = True
            bpy.context.active_object.rotation_euler=[0, -0.26, 0]
   
            obj_Torus(location=((i_loopindex_inner + 0.5)*iph,-(i_loopindex_outer+0.5)*ipv,0.0), rotation=(0, -ang, 0), minor_radius=f_Main_Ring_Wire_Diameter / 2, major_radius=(f_Main_Ring_Inner_Diameter + f_Main_Ring_Wire_Diameter) / 2)
            setMaterial(bpy.context.object, mat_blue)
            bpy.ops.rigidbody.object_add(type='ACTIVE')
            bpy.ops.rigidbody.constraint_add(type='FIXED')
            bpy.ops.object.shade_smooth()
            bpy.context.object.rigid_body_constraint.disable_collisions = False
            bpy.context.object.rigid_body.collision_shape = 'MESH'
            bpy.context.object.rigid_body.collision_margin = 0.001
            bpy.context.object.rigid_body.enabled = True
            bpy.context.active_object.rotation_euler=[0, 0.26, 0]
        i_loopindex_inner += 1
    i_loopindex_outer += 1
    bl_stiff_row = False
    i_loopindex_inner = i_loopindex_inner_reset
    if i_loopindex_outer == 1:
        obj_Sphere(location=(-5.88,5.49,-6.41))
        setMaterial(bpy.context.object, mat_red)
        bpy.ops.rigidbody.object_add(type='ACTIVE')
        bpy.ops.object.shade_smooth()
        bpy.context.object.rigid_body.collision_shape = 'MESH'
        bpy.context.object.scale=(3,3,3)
        bpy.context.object.rigid_body.enabled = False
        bpy.ops.object.select_by_type(type='MESH')
        bpy.ops.transform.resize(value=(0.5,0.5,0.5))
        bpy.ops.transform.translate(value=(0, -10, 0))
        bpy.ops.object.select_all(action='TOGGLE')




Mostly Harmless

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

Reply with quote
Posted on Sun Nov 03, 2013 10:45 pm
Link to Post: Link to Post

Have tried the method you described previously but got no result. Will try again tomorrow and see what happens.


"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 Sun Nov 03, 2013 10:50 pm
Link to Post: Link to Post

Got it.

Can read TGA/PNG and get the RGB values.

Gimme a couple of days and i will post it.

Nice script .... When we are done experimenting on this thread perhaps we (preferably you Wink Levi) should write a tut so lorraine stays happy.

BR
C

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

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

Nice Carolides, can't wait.

Starting on the articles now.

Article 1: Making a ring, "saw-cutting" it, adding materials and modifiers.
Article 2: Making a 2 in 1 chain from a single ring.
Article 3: Making a sheet of Japanese 4 in 1 from a 2 in 1 chain.
Article 4: Using scripting to simplify the process of making sheets.
Article 5: Rendering scenes in Blender. Go ahead, push F12 and see what happens!
Article 6: Creating maille inlays with Blender. (I hope, /looks at Carolides)

I'm off to another monitor!


Mostly Harmless

Post new topic Reply to topic
Jump to:  
Page 4 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 6:30 pm
M.A.I.L. Forum Index -> Knitting Circle
Display posts from previous: