Notifications
Clear all
[Closed] How to optimize this code
Page 8 / 8
Prev
May 11, 2012 1:27 am
Thanks Denis. See you tomorrow.
In my country is now 3h AM.
I need to go to sleep a little
May 11, 2012 1:27 am
And this is my final FN but still don’t have selected edges
fn moveVertLocXY obj vertIdx rand =
(
movevert = polyOp.moveVert
norm = matrixFromNormal (getNormal obj.mesh vertIdx)
in coordsys norm movevert obj vertIdx (random -rand rand)
)
fn extrudeEdges obj edgeExtrudeWidth:1 edgeExtrudeHeight:2 rand:[2,2,0] divideIdx:2 =
(
edges = obj.selectededges as bitarray
if not edges.isempty do
(
vdChannel = 81
divideedge = polyOp.divideEdge
obj.edgeChamferSegments = obj.extrusionType = 1
obj.weldThreshold = edgeExtrudeWidth*4
polyOp.setVDataChannelSupport obj vdChannel on
verts = polyOp.getVertsUsingEdge obj edges
obj.constrainType = 2
for v in verts do (moveVertLocXY obj v rand)
for edge in edges do
(
for d = divideIdx to 1 by -1.0 do (divideedge obj edge (1 - 1/(d+1)))
)
edges = obj.selectededges as bitarray
verts = polyOp.getVertsUsingEdge obj edges
for v in verts do
(
polyOp.setVDataValue obj vdChannel v v
moveVertLocXY obj v (rand/2)
)
obj.constrainType = 0
faces = obj.faces as bitarray
polyOp.chamferEdges obj edges edgeExtrudeWidth
vertList = obj.verts as bitarray
obj.selectedfaces = facesToExtrude = (obj.faces as bitarray - faces)
polyop.extrudeFaces obj facesToExtrude edgeExtrudeHeight
obj.GrowSelection selLevel:#Face
for v in verts do
(
vertsToWeld = #{}
for k in (obj.verts as bitarray - vertList) where (polyop.getVDataValue obj vdChannel k) == v do append vertsToWeld k
polyOp.weldVertsByThreshold obj vertsToWeld
)
polyop.freeVData obj vdChannel
--select sharp (extruded) edges
polyOp.retriangulate obj obj.faces
polyOp.setFaceSmoothGroup obj obj.faces 0
extV = polyOp.getVertsUsedOnlyByFaces obj obj.selectedfaces
ve = polyOp.getEdgesUsingVert obj extV
ev = polyop.getEdgeVerts
extVCnt = extVerts.numberset
extE = #{}
for s in ve where ((extV-((ev obj s) as bitarray)).numberset== extVCnt-2) do append extE s
obj.selectededges = extE
--obj.setLoopShift -1 false true
--obj.setLoopShift 1 false true
)
)
with redraw off (extrudeEdges $)
May 11, 2012 1:27 am
you asked me why i pick the channel 67… probably by the same reason that you picked 81.
May 11, 2012 1:27 am
You noticed that.
At the beginning I had put 4 (1904)
But it is already taken (channels for Discreet’s use only). funny
May 11, 2012 1:27 am
here is the function that returns extruded edges:
fn extrudeEdges obj edges: edgeExtrudeWidth: edgeExtrudeHeight: =
(
if edges == unsupplied do edges = obj.selectededges as bitarray
if not edges.isempty do
(
SPLIT_CH = 67
data = #(obj.edgeChamferSegments, obj.extrusionType, obj.weldThreshold)
obj.edgeChamferSegments = 1
obj.extrusionType = 1
obj.weldThreshold = 1e9
polyop.setVDataChannelSupport obj SPLIT_CH on
obj.selectedverts = verts = polyop.getvertsusingedge obj edges
for v in verts do polyop.setVDataValue obj SPLIT_CH v v
faces = obj.faces as bitarray
polyop.chamferedges obj edges edgeExtrudeWidth
faces = obj.faces as bitarray - faces
v0 = obj.selectedverts as bitarray
polyop.extrudeFaces obj faces edgeExtrudeHeight
vlist = polyop.getvertsusingface obj faces
for v in verts do
(
vv = #{}
for k in (obj.verts as bitarray * vlist) where (polyop.getVDataValue obj SPLIT_CH k) == v do append vv k
polyop.weldvertsbythreshold obj vv
)
vlist = obj.verts as bitarray * vlist
obj.selectededges = edges = (polyop.getedgesusingvert obj vlist) - (polyop.getedgesusingvert obj v0)
obj.edgeChamferSegments = data[1]
obj.extrusionType = data[2]
obj.weldThreshold = data[3]
polyop.freeVData obj SPLIT_CH
edges
)
)
that means the function can be called in loop…
May 11, 2012 1:27 am
Thank you very much, Denis.
Now everything is much easier.
But face selection is lost. Ok my fn have this line.
I’ll try to fix that.
Thanks, again
Page 8 / 8
Prev