Results 1 to 10 of 10
  1. #1

    [Updated]WireFrame Mesh and Curve/Path to mesh script.

    Hi
    Update! Combined both old scripts in one .Also changed/improved some code.And added new script which uses meta capsules for wire mesh creation .

    Use and Purpose:

    If run on mesh object this script makes Wire like mesh out of wireframe of mesh and if run on curve it makes a closed wire mesh out of it.

    Input fields
    Thickness=0.05 # Wire Thickness
    Resolution=4 # Wire resolution. 0 to 32


    gvrDI.png


    Code:
    #                 WireFrameMesh Script for blender 2.6x
    #    This script makes WireMesh from Wireframe of solid Meshes and make closed
    #    tubular mesh from path/curve.
    #    
    #    Copyright (C) 2011  Author: Anand S ,email: mail.anand.in@gmail.com
    #
    #    This program is free software: you can redistribute it and/or modify
    #    it under the terms of the GNU General Public License as published by
    #    the Free Software Foundation, either version 3 of the License, or
    #    (at your option) any later version.
    #
    #    This program is distributed in the hope that it will be useful,
    #    but WITHOUT ANY WARRANTY; without even the implied warranty of
    #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    #    GNU General Public License for more details.
    #
    #    You should have received a copy of the GNU General Public License
    #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    #
    #-------------------------Do Not Modify Anything Above This Line----------------------
    
    Thickness=0.05  # Wire Thickness
    Resolution=4   # Wire resolution. 0 to 32
    #-------------------------------------------------------------------------------------
    
    import bpy
    from mathutils import Vector
    
    def sealends(): # closes non-manifold tube ends
        current_mode = bpy.context.active_object.mode
        if current_mode == 'OBJECT' and bpy.context.active_object.type=='MESH':
            bpy.ops.object.mode_set(mode='EDIT')
            bpy.ops.mesh.select_all(action='DESELECT')
            bpy.ops.wm.context_set_value(data_path="tool_settings.mesh_select_mode", value="(False, True, False)")
            bpy.ops.mesh.select_non_manifold()
            bpy.ops.mesh.extrude_region_move()
            bpy.ops.mesh.merge(type='COLLAPSE', uvs=False)
    
        bpy.ops.object.mode_set(mode=current_mode)
    
    if bpy.context.active_object==None:pass
    else:
        if bpy.context.active_object.mode is not 'OBJECT':
            bpy.ops.object.mode_set(mode='OBJECT')
    
        if bpy.context.active_object.type=='MESH':
            bpy.ops.object.duplicate()
            bpy.ops.wm.context_set_value(data_path="tool_settings.mesh_select_mode", value="(False, True, False)")
    
            obj = bpy.context.active_object
            obj.select=True
            bpy.ops.object.mode_set(mode='EDIT')
            bpy.ops.mesh.delete(type='ONLY_FACE')
            bpy.ops.object.mode_set(mode='OBJECT')
            
            for indx in range(len(obj.data.edges)):
    
                obj.data.edges[indx].select = True
    
                bpy.ops.object.mode_set(mode='EDIT')
        
                bpy.ops.mesh.split()
    
                bpy.ops.object.mode_set(mode='OBJECT')
                obj.data.edges[indx].select = False 
    
            bpy.ops.object.convert(target='CURVE', keep_original=False)
            obj.data.fill_mode='FULL'
            obj.data.bevel_resolution=Resolution
            obj.data.bevel_depth=Thickness
    
            bpy.ops.object.convert(target='MESH', keep_original=False)
    
        elif bpy.context.active_object.type=='CURVE':
      
            obj=bpy.context.active_object
            obj.select=True
        
            def1=obj.data.fill_mode
            def2=obj.data.bevel_resolution
            def3=obj.data.bevel_depth    
        
            obj.data.fill_mode='FULL'
            obj.data.bevel_resolution=Resolution
            obj.data.bevel_depth=Thickness    
            bpy.ops.object.convert(target='MESH', keep_original=True)
        
            obj.data.fill_mode=def1           #reverting
            obj.data.bevel_resolution=def2
            obj.data.bevel_depth=def3
    
        sealends()
    tdnDQ.png

    Above is Meta WireMesh preview! New script below

    Code:
    #                 WireFrame MetaMesh Script for blender 2.6x
    #    This script make wiremesh from Wireframe of solid Meshes and it uses
    #    MetaObject(Capsules) to do so.
    #    
    #    Copyright (C) 2011  Author: Anand S ,email: mail.anand.in@gmail.com
    #
    #    This program is free software: you can redistribute it and/or modify
    #    it under the terms of the GNU General Public License as published by
    #    the Free Software Foundation, either version 3 of the License, or
    #    (at your option) any later version.
    #
    #    This program is distributed in the hope that it will be useful,
    #    but WITHOUT ANY WARRANTY; without even the implied warranty of
    #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    #    GNU General Public License for more details.
    #
    #    You should have received a copy of the GNU General Public License
    #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    #
    #-------------------------Do Not Modify Anything Above This Line----------------------
    
    Thickness  = 0.05
    Resolution = 1     #between 0.05 to 1  LOWER IS SLOWER 
    
    #---------------------------------------------------------------------------------------
    import bpy
    import math
    import  mathutils
    from mathutils import Vector
    
    def glb_co(localco,obj):
        wmtx = obj.matrix_world
        worldco = wmtx*localco
        return worldco
    
    def AlignX(v1,v2):
        dvec=v2-v1
        rotation_quat = dvec.to_track_quat('X', 'Y')
        return rotation_quat
    
    def dist3d(Vec1,Vec2):
        dist = math.sqrt((Vec2.x-Vec1.x)**2 + (Vec2.y-Vec1.y)**2 + (Vec2.z-Vec1.z)**2)
        return dist
    
    def midpt3d(Vec1,Vec2):
        mx=(Vec1.x+Vec2.x)/2
        my=(Vec1.y+Vec2.y)/2
        mz=(Vec1.z+Vec2.z)/2
        return Vector((mx,my,mz))
    
    if bpy.context.active_object==None:pass
    else:
        if bpy.context.active_object.mode is not 'OBJECT':
            bpy.ops.object.mode_set(mode='OBJECT')
    
        if bpy.context.active_object.type=='MESH':
    
            ob_act=bpy.context.active_object
            location=ob_act.location
            scale   =ob_act.scale
            rotation=ob_act.rotation_euler
    
            edgecount=len(ob_act.data.edges)
            edge_mid=[]
            edge_len=[]
            edge_align=[]
    #----------------------------------------------
            for e in range(edgecount):
                vert1=ob_act.data.edges[e].vertices[0]
                vert2=ob_act.data.edges[e].vertices[1]
    
                v_loc1=ob_act.data.vertices[vert1].co
                v_loc2=ob_act.data.vertices[vert2].co
        
                v_glb1=glb_co(v_loc1,ob_act)
                v_glb2=glb_co(v_loc2,ob_act)
        
                len=dist3d(v_glb1,v_glb2)
                mid=midpt3d(v_glb1,v_glb2)
                qua=AlignX(v_glb1,v_glb2)
                edge_mid.append(mid)
                edge_len.append(len)
                edge_align.append(qua)
    #---------------------------------------------
            bpy.ops.object.metaball_add(type='CAPSULE', view_align=False, enter_editmode=False, location=location, rotation=(0.0, 0.0, 0.0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
            obj=bpy.context.active_object
            scl=Thickness
            obj.scale=(scl,scl,scl)
            obj.data.resolution=Resolution
            obj.data.update_method='NEVER'
            bpy.ops.object.mode_set(mode='EDIT')
            bpy.ops.mball.delete_metaelems()
    
            for i in range(edgecount):
                bpy.ops.object.metaball_add(type='CAPSULE', view_align=False, enter_editmode=False, location=edge_mid[i], rotation=(0.0, 0.0, 0.0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
                rsize=(edge_len[i]/scl)/2
                bpy.ops.transform.resize(value=(rsize,rsize,rsize), constraint_axis=(True, False, False))
                obj.data.elements.active.rotation=edge_align[i]
    
            bpy.ops.object.mode_set(mode='OBJECT')
    
            obj.data.update_method='UPDATE_ALWAYS'



  2. #2
    Member flokkievids's Avatar
    Join Date
    Apr 2011
    Location
    Scharnegoutum, the Netherlands
    Posts
    371
    your script has a few small problems. first of all, never base an if statement on whether a certain mode is active, but always use
    Code:
    if bpy.context.active_object.mode is not 'EDIT' #or another mode.
    if you don't do this the script will give an error when ran from edit mode.

    second: something to check if the object that's currently selected is a curve object is handy. to do that use something like:
    Code:
    if bpy.context.active_object.type is not 'CURVE': # stop the script
    otherwise you'll get an error when it's run on a mesh object.

    except for those small mistakes it's quite handy, thanks for sharing



  3. #3
    Originally Posted by flokkievids View Post
    your script has a few small problems. first of all, never base an if statement on whether a certain mode is active, but always use
    Code:
    if bpy.context.active_object.mode is not 'EDIT' #or another mode.
    if you don't do this the script will give an error when ran from edit mode.

    second: something to check if the object that's currently selected is a curve object is handy. to do that use something like:
    Code:
    if bpy.context.active_object.type is not 'CURVE': # stop the script
    otherwise you'll get an error when it's run on a mesh object.

    except for those small mistakes it's quite handy, thanks for sharing
    Thank you very much for feedback.In future i will keep those in mind.I think i will build upon your second point and combine both scripts,so that if curve it will use second script or else if mesh it uses first script.



  4. #4
    Added new script and improved and combined both old ones
    New script uses MetaObject(Capsules) to create WireMesh.Using meta objects has an upside and one downside. Upside being perrrfect closed meshes! Downside is it makes too many faces ! but do try it as i kept defaults at lowest resolution .



  5. #5
    Member
    Join Date
    Mar 2002
    Location
    California
    Posts
    2,109
    Ok, can I assume that you run this from a blender text window. Since I have to copy and paste the code I am assuming that it is not a standard addon
    At some point in life you stop being the man you are and start being the man you always wanted to be. ------ Bruce Springsteen.



  6. #6



  7. #7
    I'm actually having difficulty getting this working for me - I'm on Blender 2.6 for Mac and I get float not callable errors.

    Can you help?



  8. #8
    Looks great,it works in Bmesh!can you convert it to addon, please?Thanks!



  9. #9
    In 2.64 there is Wireframe tool which is very good.All it lacks it proper cylindrical wireframe. But still its leaves no rips and distortions which is great.



  10. #10
    ok, thanks!



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •