logo

TAPE GUNNED

Gallery details

Quick & Dirty Mock Up for prototype idea
Code creates variable thickness Tape Based on Structural Analysis Information – Algor – Python Research V.2 [12.March.2013] – via Python + Algor
“”” The input is a Text File containing XYZ info as well as deformation values. The code rebuilds the geometry from scratch based on XYZ coordinates, these coordinates are used to re-create the mesh in 3D and paint the vertices based on the value range. This is very useful in recreating and making the structural color maps as drivers in actual geometry instead of simple Textures

. Process
. Create Geometry
. Export STL, Bring into ALGOR run Analysis . Create a base curve to create contour curves which run along surface or mesh
. Use Code to Create variable thickness bands based on analysis info

CODE

"""Script Written By Luis Quinones
Script Copywritten by complicitMatter + computationalMatter

www.complicitmatter.com
www.computationalmatter.com
Script Version Wednesday, June 29, 2011"""
import rhinoscriptsyntax as rs
from System.Drawing import Color 

def ColorAction(centroid,eval,ave):
    index = rs.PointArrayClosestPoint(centroid,eval)
    closestTest = centroid[index]  
    result = ave[index]
    #print result
    return result
def Main():
    strLayer = rs.AddLayer("OffsetMesh",Color.White)
    strLayer2 = rs.AddLayer("BaseMesh",Color.White)    
    strLayer4 = rs.AddLayer("BaseCrvs",Color.White)
    strLayer5 = rs.AddLayer("Construction_Curves")
    strLayer6 = rs.AddLayer("Profile_Curves")    
    strip = []    
    scaleFactor = rs.RealBox("Set The Scale",4,"SCALE DOMINATION")
    scaleFactor2 = rs.RealBox("Multiplier_# for color value",1,"DONT DO IT")
    offsetFactor = rs.RealBox("OffsetValue for MeshOffset",-5,"OFFSET")    
    newMeshBase = rs.GetObject("BaseMesh_To_Offset",rs.filter.mesh)
    rs.ObjectLayer(newMeshBase,strLayer2)
    offsetMesh = rs.MeshOffset(newMeshBase,offsetFactor)
    rs.ObjectLayer(offsetMesh,strLayer)
    newCrvBase = rs.GetObjects("GetCrvs",rs.filter.curve)
    rs.ObjectLayer(newCrvBase,strLayer4)  
    strObject = rs.GetObject("Select Painted Mesh",rs.filter.mesh)
    strLayerAA = rs.AddLayer("PTSTORE")   
    arrFaces = rs.MeshFaces(strObject,True)
    color = rs.MeshVertexColors(strObject)    
    faceVerts = [0]
    centroid = []
    ave = []
    if arrFaces:        
        i = 0
        count2 = 0        
        while(i < len(arrFaces)):            
            arrFace = arrFaces[i],arrFaces[i+1],arrFaces[i+2],arrFaces[i+3]            
            if arrFace[2][0] == arrFace[3][0] and arrFace[2][1] == arrFace[3][1] and arrFace[2][2] == arrFace[3][2] :                
                arrHLS = rs.ColorRGBToHLS(color[count2]),rs.ColorRGBToHLS(color[count2+1]),rs.ColorRGBToHLS(color[count2+2]),rs.ColorRGBToHLS(color[count2+2])                
                sum = arrHLS[0][2] + arrHLS[1][2] + arrHLS[2][2] 
                ave2 = (sum/3)
                if ave2 < 0.2:
                    ave2 = 0.2
                ave.append(ave2)                
                faceVerts[0] = [0,1,2,2]               
                meshVerts = arrFace                
                mesh = rs.AddMesh(meshVerts,faceVerts)               
                if mesh :
                    centroid.append(rs.MeshAreaCentroid(mesh))
                else:
                    print "did not make mesh"                
                rs.DeleteObject(mesh)             
                count2 += 3                
            else:              
                arrHLS = rs.ColorRGBToHLS(color[count2]),rs.ColorRGBToHLS(color[count2+1]),rs.ColorRGBToHLS(color[count2+2]),rs.ColorRGBToHLS(color[count2+3])               
                sum = arrHLS[0][2] + arrHLS[1][2] + arrHLS[2][2] + arrHLS[3][2]
                ave2 = (sum/4)
                if ave2 < 0.2:
                    ave2 = 0.2
                ave.append(ave2)                
                faceVerts[0] = [0,1,2,3]
                meshVerts = arrFace
                mesh = rs.AddMesh(meshVerts,faceVerts)                
                if mesh:
                    centroid.append(rs.MeshAreaCentroid(mesh))
                else:
                    print "did not make mesh"                
                rs.DeleteObject(mesh)               
                count2 += 4
            i +=4            
    if len(centroid) != len(ave):
        print "# of aves does != # of points"   
    meshFaceVerts99 = [0]   
    for w in range(len(newCrvBase)):
        threshMult = []
        strip = []      
        strLayer3 = rs.AddLayer('MeshStrips_'+ str(w),Color.White)
        crvPTS = rs.CurvePoints(newCrvBase[w])        
        for y in range(len(crvPTS)-1):           
            dblParam = rs.CurveClosestPoint(newCrvBase[w],crvPTS[y])
            eval = rs.EvaluateCurve(newCrvBase[w],dblParam)            
            if eval:                
                arrData = rs.CurveCurvature(newCrvBase[w],dblParam)              
                if arrData:                    
                    arrTangent = arrData[1]
                    arrEnd = eval[0]+arrTangent[0],eval[1]+arrTangent[1],eval[2]+arrTangent[2]
                    newVec = rs.VectorCreate(arrEnd,eval)
                    newVec = rs.VectorUnitize(newVec)
                    rs.AddPoint(newVec)                   
                    tangLine = rs.AddLine(arrEnd,eval)
                    rs.ObjectLayer(tangLine,strLayer6)                  
                else:                                       
                    arrTangent = crvPTS[y+1][0],crvPTS[y+1][1],crvPTS[y+1][2]
                    arrEnd = eval[0]+arrTangent[0],eval[1]+arrTangent[1],eval[2]+arrTangent[2]
                    newVec = rs.VectorCreate(arrTangent,eval)
                    newVec = rs.VectorUnitize(newVec)
                    rs.AddPoint(newVec)                    
                    print "USED THE NEXT POINT AS REFERENCE"                    
            meshClosest = rs.MeshClosestPoint(offsetMesh,eval)
            constLine = rs.AddLine(meshClosest[0],eval)
            rs.ObjectLayer(constLine,strLayer5)
            endPt = rs.CurveEndPoint(constLine)
            midPt = rs.CurveMidPoint(tangLine)
            translation = endPt-midPt
            rs.MoveObject(tangLine,translation)            
            rotVec = rs.VectorCreate(meshClosest[0],eval)
            rs.RotateObject(tangLine,endPt,90,rotVec)
            rs.ScaleObject(tangLine,endPt,[scaleFactor,scaleFactor,scaleFactor])          
            threshMult.append(ColorAction(centroid,eval,ave))            
            if threshMult[y] <= 0.2 :
                threshMult[y] == 0.1                
            strip.append(rs.ScaleObject(tangLine,endPt,[threshMult[y],threshMult[y],threshMult[y]]))
        for x in range(len(strip)-1):           
            arrCrvs = strip[x],strip[x+1]
            newSrf = rs.AddLoftSrf(arrCrvs)           
            meshFaceVerts99[0] = [0,1,2,3]          
            if not newSrf:                
                print "negative"               
            else:             
                surfPts = rs.SurfacePoints(newSrf[0])
                verts99 = surfPts[0],surfPts[1],surfPts[7],surfPts[6]              
                newMeshSet = rs.AddMesh(verts99,meshFaceVerts99)                
                if not newMeshSet:                    
                    print "negative again"                    
                else:                    
                    rs.DeleteObject(newSrf[0])   
    rs.LayerVisible(strLayer,False)
    rs.LayerVisible(strLayer5,False)
    rs.LayerVisible(strLayer4,False)
    rs.LayerVisible(strLayer6,False)
Main()
Update

 

 

 

  • Share

Leave a reply

Your email address will not be published.