rollout honeycombRollout "honeycomb" ( group "honeycomb" ( dropdownlist structureType_osd "structure type:" items:#("planar: 3 (hexagonal)","planar: 4 (square)","semi-planar: 3","volume: 4 (tetraedric)","volume: 6 (cubic)") selection:1 height:6 spinner numberLinks_osd "number links: " range:[3,5000,323] type:#integer scale:1.0 fieldWidth:40 spinner nodeSize_osd "link size: " range:[1.0,10000.0,10.0] type:#float scale:1.0 fieldWidth:40 spinner varLength_osd "length var.: %" range:[0.0,250.0,0.0] type:#float scale:0.1 fieldWidth:40 spinner varAngle_osd "angle var.: deg" range:[0.0,360.0,0.0] type:#float scale:0.1 fieldWidth:40 spinner weldZone_osd "weld zone: %" range:[0.0001,75.0,60.0] type:#float scale:0.5 fieldWidth:40 button calculate_osd "create" ) progressBar pBar value:0 group "presets" ( dropdownlist preset_osd "" items:#("honeycomb","vegetable fibers (plane)","snowflake","vegetable fibers (volume)","damaged structure","vegetable sheets") selection:1 height:7 ) label lb1 "by Olivier Vandecasteele" label lb2 "email: gray@skynet.be" struct geomStructure ( node=#([0,0,0]), links=#(#()), baseVector=#([0,1,0]), basePlaneNormal=#([0,0,1]), uniqueLinks=#(), alive=#{1}, fn count = return node.count, fn addNode coord = ( append links #(); append baseVector [0,1,0]; append node coord; append alive node.count; return node.count ), fn getPos idx = return node[idx], fn setPos idx coord = node[idx]=coord, fn getLink idx = return links[idx], fn setLink idx idxOtherNode = ( if (idx<=node.count and idxOtherNode<=node.count) then (append links[idx] idxOtherNode; append links[idxOtherNode] idx; append uniqueLinks #(idx,idxOtherNode)) else false ), fn getBaseVector idx = baseVector[idx], fn setBaseVector idx v = baseVector[idx]=v, fn getBasePlane idx = basePlaneNormal[idx], fn setBasePlane idx v = basePlaneNormal[idx]=v, fn addVector fromNode v p = ( append baseVector -v append basePlaneNormal p append links #() append node (node[fromNode]+v) newNode=node.count append alive newNode append links[fromNode] newNode append links[newNode] fromNode append uniqueLinks #(fromNode,newNode) return newNode ), fn getUniqueLinksCount = return uniqueLinks.count, fn getUniqueLinks idx = return uniqueLinks[idx], fn isAlive idx = alive[idx], fn killLife idx = alive[idx]=false ) fn firstAlive structure = ( numberNodes=structure.count() count=0 for currentNode=1 to numberNodes do ( count+=1 if structure.isAlive currentNode then exit ) return count ) fn existNodeInZone structure pos delta = ( numberNodes=structure.count() existAtPos=0 for currentNode=1 to numberNodes do ( p=structure.getPos currentNode if ((abs(pos.x-p.x))<delta)and((abs(pos.y-p.y))<delta)and((abs(pos.z-p.z))<delta) do (existAtPos=currentNode;exit) ) existAtPos ) fn randomVector2Dvariation theVector varLength varAngle lengthToConform planeNormal = ( var=lengthToConform*varLength newLength=random (lengthToConform-var) (lengthToConform+var) theVector*=(newLength/(length theVector)) theVector*=quat (random -(varAngle/2.0) (varAngle/2.0) ) planeNormal ) fn randomVector3Dvariation theVector varLength varAngle lengthToConform planeNormal = ( var=lengthToConform*varLength newLength=random (lengthToConform-var) (lengthToConform+var) theVector*=(newLength/(length theVector)) theVector*=quat (random -(varAngle/2.0) (varAngle/2.0) ) planeNormal theVector*=quat (random -(varAngle/2.0) (varAngle/2.0) ) (cross theVector planeNormal) ) fn rot3d v pn rot1 rot2 = ( vbis=v*quat rot1 pn rotAxis=cross vbis pn v2=vbis*quat rot2 rotAxis p2=cross rotAxis v2 #(v2,p2) ) fn growNode structure idx str3D = ( theBaseVector=structure.getBaseVector idx thePlaneNormal=structure.getBasePlane idx lengthToConform=length (structure.getBaseVector 1) for currentStr=1 to (str3D.count-1) do ( ret=rot3d theBaseVector thePlaneNormal (str3D[currentStr][1] as float) (str3D[currentStr][2] as float) theNewVector=ret[1]; theNewPlaneNormal=ret[2] if str3D[str3D.count]=="2D" then theRealVector=randomVector2Dvariation theNewVector (varLength_osd.value/200.0) varAngle_osd.value lengthToConform theNewPlaneNormal else theRealVector=randomVector3Dvariation theNewVector (varLength_osd.value/200.0) varAngle_osd.value lengthToConform theNewPlaneNormal -- attention si le vecteur change il est normal que le plan soit également modifié pos=(structure.getPos idx)+theRealVector delta=(weldZone_osd.value/100.0)*(length theBaseVector) otherNode=existNodeInZone structure pos delta if otherNode!=0 then ( currentLinks=structure.getLink idx if (findItem currentLinks otherNode)==0 do ( structure.setLink idx otherNode p=structure.getPos otherNode structure.setPos otherNode ((pos+p)/2.0) ) ) else structure.addVector idx theRealVector theNewPlaneNormal ) structure.killLife idx ) fn createGeom structure = ( count=structure.getUniqueLinksCount() obj=SplineShape pos:[0,0,0] obj.steps=0 for idx=1 to count do ( thisLink=structure.getUniqueLinks idx splineIdx=addNewSpline obj addknot obj splineIdx #corner #line ((structure.getPos thisLink[1])*nodeSize_osd.value) addknot obj splineIdx #corner #line ((structure.getPos thisLink[2])*nodeSize_osd.value) ) updateShape obj return obj ) fn getStructure n = ( case n of ( 1:#(#(120,0),#(-120,0),"2D") 2:#(#(90,0),#(180,0),#(-90,0),"2D") 3:#(#(120,0),#(-120,0),"3D") 4:#(#(0,-109.5),#(112.2,28.13),#(-112.2,28.13),"3D") 5:#(#(90,0),#(-90,0),#(180,0),#(0,90),#(0,-90),"3D") ) ) on calculate_osd pressed do ( clearListener() myStructure=geomStructure() myStructure.addVector 1 [0,1,0] [0,0,1] securityCounter=0 actualLinks=myStructure.getUniqueLinksCount() maxLinks=numberLinks_osd.value while actualLinksmaxLinks*8 do ((messageBox("the weld value is too high program stopped") title:"honeycomb warning");exit) ) pBar.value=0 obj=createGeom myStructure )--on on preset_osd selected idx do ( case idx of ( 1: ( structureType_osd.selection=1 numberLinks_osd.value=900 varLength_osd.value=0.0 varAngle_osd.value=0.0 weldZone_osd.value=60.0 ) 2: ( structureType_osd.selection=1 numberLinks_osd.value=900 varLength_osd.value=40.0 varAngle_osd.value=40.0 weldZone_osd.value=60.0 ) 3: ( structureType_osd.selection=4 numberLinks_osd.value=200 varLength_osd.value=0.0 varAngle_osd.value=0.0 weldZone_osd.value=60.0 ) 4: ( structureType_osd.selection=4 numberLinks_osd.value=900 varLength_osd.value=30.0 varAngle_osd.value=30.0 weldZone_osd.value=60.0 ) 5: ( structureType_osd.selection=5 numberLinks_osd.value=900 varLength_osd.value=8.0 varAngle_osd.value=12.0 weldZone_osd.value=60.0 ) 6: ( structureType_osd.selection=3 numberLinks_osd.value=2500 varLength_osd.value=15.0 varAngle_osd.value=25.0 weldZone_osd.value=50.0 ) ) )--on )--rollout try (closerolloutfloater honeycombFloater)catch() honeycombFloater = newRolloutFloater "honeycomb" 162 300 addRollout honeycombRollout honeycombFloater rolledUp:false
请先
!