비트맵크런치 최근에 다시 짠것

 
전에 올렸던 알파에 맞춰 이미지 잘라내기  좀더 보강해서 짜봤습니다.


생존신고도 할 겸 , 성능이 쓸만한 것 같아서 올려봅니다. 
rollout vertextool "vertextool"
(
fn slicepoly obj r =
(
  
polyop.setfaceselection obj ((for i = 1 to obj.faces.count collect i) as bitarray )
 polyop.setSlicePlane obj  r 100
polyop.slice obj ((for i = 1 to obj.faces.count collect i) as bitarray ) r 
  return true
)
fn mn a b =
(
  local result = [0,0,0]
  result.x = (if a.x > b.x then b.x else a.x)
  result.y = (if a.y > b.y then b.y else a.y)
  result.z = (if a.z > b.z then b.z else a.z)
  return result
)

fn mx a b =
(
  local result = [0,0,0]
  result.x = (if a.x < b.x then b.x else a.x)
  result.y = (if a.y < b.y then b.y else a.y)
  result.z = (if a.z < b.z then b.z else a.z)
  return result
)
fn slicebygrid objs unit threshhold:0.5 =
(
  local center =[0,0,0]
  
  for obj in objs do
  (
 center+=obj.pos
  )
  center/=objs.count
  
  local b = #(center,center)
  
  for obj in objs do
  (
 local _b = nodeGetBoundingBox obj (matrix3 1)
 b[1] = mn _b[1] b[1]
 b[2] = mx _b[2] b[2]
  )
  for obj in objs do
  (
 local _b = nodeGetBoundingBox obj (matrix3 1)
  
   for i = floor b[1].z  to ceil b[2].z by unit do
 (
local r = ray [center.x,center.y,i - (mod i unit)] [0,0,1]
 
if _b[1].z +unit*threshhold > r.pos.z or _b[2].z-unit*threshhold < r.pos.z then continue

slicepoly obj r
 )
 for i = floor b[1].x to ceil b[2].x by unit do
 (
local r = ray [i - (mod i unit),center.y,center.z] [1,0,0]
if _b[1].x +unit*threshhold > r.pos.x or _b[2].x-unit*threshhold  < r.pos.x  then continue
slicepoly obj r
 )
  )
)
fn crunchobject obj tesselation expand=
(
local tex = obj.material.diffusemap.bitmap
local cm = compositetexturemap()
cm.maplist[1] = colorcorrection color:white
cm.maplist[2] = bitmaptexture bitmap:tex rgboutput:1 alphasource:1 
cm.maplist[2].coords.blur = 50
cm.maplist[2].coords.blur_Offset = 0.1
cm.maplist[2].coords.u_tile = false
cm.maplist[2].coords.v_tile = false
cm.blendmode[2]=3
 
cm = colorcorrection map:cm
cm.contrast = 50
for i =1 to tesselation do
(
local _displace = displace()
local s = snapshotasmesh obj
_displace.map = cm
_displace.strength =50
_displace.usemap = on

addmodifier obj _displace
 
 
local m = snapshotasmesh obj
deletemodifier obj _displace
local verts = #()
for j = 1 to m.verts.count do
(
local tv = getvert s j
local sv = getvert m j
if (distance tv sv) >49.5 then append verts j
)
 
obj.editablepoly.setselection #vertex (verts as bitarray)
if i<tesselation then
obj.EditablePoly.tessellate #Vertex
else 
(
for j = 1 to expand do
(
obj.editablepoly.shrinkselection()
)
obj.EditablePoly.delete #Vertex
)
free verts
)
)
fn removeinsideedges obj type:#edge =
(
obj.EditablePoly.SetSelection #Edge ((for i = 1 to obj.edges.count where finditem (polyOp.getOpenEdges obj) i==0 collect i) as bitarray)
if type == #edge then
(
obj.remove sellevel:#edge
)
else if type == #vertex then
(
obj.editablePoly.ConvertSelection#Edge #Vertex
obj.remove sellevel:#vertex
)
obj.EditablePoly.deleteIsoVerts ()
)
fn removeVertsAtDegree_2 obj deg =
(
local edges = (polyOp.getOpenEdges obj) 
for e in edges do
(
)
)
fn weldborder obj th =
(
obj.editablepoly.setselection  #edge (polyOp.getOpenEdges obj) 
obj.editablePoly.ConvertSelection#Edge #Vertex
obj.weldThreshold = th
obj.EditablePoly.weldFlaggedVertices ()
obj.EditablePoly.deleteIsoVerts ()
)
fn removeVertsAtDegree obj deg =
(
local verts = #()
local testedge = #()
local edges = (polyOp.getOpenEdges obj) 
for i = 1 to obj.verts.count do
(
if((obj.GetVertexEdgeCount i )>2 ) then continue
local e1 = obj.getvertexedge i 1
local e2 = obj.getvertexedge i 2
if finditem edges e1 == 0 or finditem edges e2 == 0 then continue
local vertsinedge =#(i)
appendifunique vertsinedge (obj.getedgevertex e1 1)
appendifunique vertsinedge (obj.getedgevertex e1 2)
appendifunique vertsinedge (obj.getedgevertex e2 1)
appendifunique vertsinedge (obj.getedgevertex e2 2)
if(vertsinedge.count != 3) then continue
appendifunique testedge e1
appendifunique testedge e2
local v1 = obj.verts[vertsinedge[1]].pos
local v2 = obj.verts[vertsinedge[2]].pos
local v3 = obj.verts[vertsinedge[3]].pos
local edgeangle = 180-acos (dot  (normalize(v1-v2)) (normalize(v1-v3)))
if edgeangle <deg  then
(
append verts i
)
free vertsinedge
)
obj.editablepoly.setselection #vertex (verts as bitarray)

obj.remove sellevel:#vertex
free verts
)
fn crunch obj expand:1 tesselation:4 weldthreshold:3 = 
(
max create mode
if superclassof obj  != geometryclass then return 0
converttopoly obj 
crunchObject obj tesselation expand
-- 인접 엣지의 각이 3도 미만이면 버텍스 삭제
removeVertsAtDegree obj  3
-- 안쪽 엣지 삭제
removeInsideEdges obj type:#vertex
-- 다시한번 인접 엣지의 각이 3도 미만이면 버텍스 삭제
removeVertsAtDegree obj  3
--다시 그리드 
-- slicebygrid #(obj) 10
weldborder obj weldthreshold
)
 )


--tesselation 이 높으면 정확도가 올라간다. 동반해서 느려지니까 잘선택. 
-- expand는 높아지면 여백이 많아진다. (tesselation 이 높으면 효과가 미미함)
-- weldthreshold수치 이하의 간격은 합쳐버린다. 


 vertextool.crunch $ tesselation:5 expand:1 weldthreshold:5




덧글

댓글 입력 영역



메모장

Junhyuck Park
(PN/pakdragon,pakk)
MALE E-mail:pakdragon57@gmail.com