1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
#!BPY
""" Registration info for Blender menus: <- these words are ignored
Name: 'Unweld vertex/ices'
Blender: 234
Group: 'Mesh'
Tip: 'Unweld all faces from a (or several) selected and common vertex. Made vertex bevelling'
"""
__author__ = "Jean-Michel Soler (jms)"
__url__ = ("blender", "elysiun",
"Script's homepage, http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_faces2vertex.htm#exemple",
"Communicate problems and errors, http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender")
__version__ = "0.4.6 "
__bpydoc__ = """\
This script unwelds faces from one or several selected vertex/vertices.
Usage:
In edit mode Select at least one vertex, then run this script.
The options are:
- unbind points;<br>
a new point is added to each face connected to the selected one.
- with noise;<br>
the new points location is varied with noise
- middle face;<br>
the new point is located at the center of face to which it is connected
"""
# ------------------------------------------
# Un-Weld script 0.4.6
# name="UnWeld"
# Tip= 'Unweld all faces from a selected and common vertex.'
# date='06/08/2006'
# split all faces from one selected vertex
# (c) 2004 J-M Soler released under GPL licence
#----------------------------------------------
# Official Page :
# website = 'http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_faces2vertex.htm#exemple'
# Communicate problems and errors on:
# community = 'http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender'
#----------------------------------------------
# Blender Artistic License
# http://download.blender.org/documentation/html/x21254.html
#---------------------------------------------
# Changelog
#----------------------------------------------
# 25/05 :
# -- separate choice, normal (same place) or spread at random, middle of the face
# -- works on several vertices too
# -- Quite vertex bevelling on <<lone>> vertex : create hole in faces around this
# vertex
# 03/06 :
# -- a sort of "bevelled vertex" extrusion controled by horizontal mouse
# displacement. just a beta test to the mouse control.
# 08/08 :
# -- minor correction to completely disconnect face.
#----------------------------------------------
# Page officielle :
# http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_faces2vertex.htm#exemple
# Commsoler les problemes et erreurs sur:
# http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender
# Blender Artistic License
# http://download.blender.org/documentation/html/x21254.html
#---------------------------------------------
# Changelog
#----------------------------------------------
# 25/05 :
# -- separation du choix, normal ou dispersion hasardeuse,
# milieu de face
# -- sommets multiples /
# -- presque unvertex bevelling sur un vertex solitaire : cree
# un trou dans la facette autour du sommet
# 03/06 :
# -- une sorte de vertex extruder en biseau, controle par
# movement horizontal de la souris
# 08/08 :
# -- correction mineure pour s'assurer que les faces soient
# entierment deconnectees
#----------------------------------------------
import Blender
from Blender import Noise
from Blender.Draw import *
from Blender.BGL import *
# $Id$
NR=Noise.random
DECAL=0.03
t=[0.0,0.0,0.0]
pl=[]
orig=[]
DEBUG = 0
SUBSURF=0
DIM=Create(1.0)
def Buffer(v,t):
print dir(v)
for n in range(len(v)): t[n]=t[n]+v[n]
return t
def freeBuffer(t):
for n in range(3): t[n]=0.0
return t
def ModalBuffer(t,f):
for n in range(3): t[n]/=len(f)
return t
def applyModalValue(v,t):
for n in range(len(v)): v[n]=t[n]
return v
def docF(f0,f):
if f0 and f:
f0.mat=f.mat
if f.uv :
f0.uv=f.uv
if f.col :
f0.col=f.col
if f.image :
f0.image=f.image
f0.smooth=f.smooth
f0.mode=f.mode
f0.flag=f.flag
return f0
def connectedFacesList(me,thegood):
listf2v={}
#tri des faces connectees aux sommets selectionnes
for f in me.faces:
for v in f.v:
if v==thegood:
if v.index not in listf2v.keys():
listf2v[me.verts.index(v)]=[f]
elif f not in listf2v[me.verts.index(v)]:
listf2v[me.verts.index(v)].append(f)
return listf2v
def createAdditionalFace(me,thegood,listf2v):
global t
for f in listf2v[thegood.index]:
f0=Blender.NMesh.Face()
if result==3: t=freeBuffer(t)
for v in f.v:
if result==3: t=Buffer(v,t)
if v!=thegood:
f0.append(v)
else:
if result==2:
nv=Blender.NMesh.Vert(thegood.co[0]+NR()*DECAL,
thegood.co[1]+NR()*DECAL,
thegood.co[2]+NR()*DECAL)
else:
nv=Blender.NMesh.Vert(thegood.co[0],
thegood.co[1],
thegood.co[2])
nv.sel=1
me.verts.append(nv)
f0.append(me.verts[me.verts.index(nv)])
localise=me.verts.index(nv)
docF(f0,f)
if result==3:
t=ModalBuffer(t,f0.v)
me.verts[localise]=applyModalValue(me.verts[localise],t)
me.faces.append(f0)
del me.verts[me.verts.index(thegood)]
for f in listf2v[thegood.index]:
del me.faces[me.faces.index(f)]
return me
def collecte_edge(listf2v,me,thegood):
back=0
edgelist = []
vertlist = []
if DEBUG : print listf2v
for face in listf2v[thegood.index]:
if len(face.v) == 4:
vlist = [0,1,2,3,0]
elif len(face.v) == 3:
vlist = [0,1,2,0]
else:
vlist = [0,1]
for i in range(len(vlist)-1):
vert0 = min(face.v[vlist[i]].index,face.v[vlist[i+1]].index)
vert1 = max(face.v[vlist[i]].index,face.v[vlist[i+1]].index)
edgeinlist = 0
if vert0==thegood.index or vert1==thegood.index:
for edge in edgelist:
if ((edge[0]==vert0) and (edge[1]==vert1)):
edgeinlist = 1
edge[2] = edge[2]+1
edge.append(me.faces.index(face))
break
if edgeinlist==0:
edge = [vert0,vert1,1,me.faces.index(face)]
edgelist.append(edge)
for edge in edgelist:
#print edge
if len(edge)==4:
del edgelist[edgelist.index(edge)]
edges=len(edgelist)
if DEBUG : print 'number of edges : ',edges," Edge list : " ,edgelist
return edges, edgelist
OBJECT=Blender.Scene.getCurrent().getActiveObject()
if OBJECT and OBJECT.getType()=='Mesh':
EDITMODE=Blender.Window.EditMode()
Blender.Window.EditMode(0)
name = "Unweld %t|Unbind Points %x1|With Noise %x2|Middle Face %x3"
result = Blender.Draw.PupMenu(name)
if result:
me=OBJECT.getData()
sole=0
vSelection=[]
for v in me.verts:
if v.sel==1:
vSelection.append(v)
for v in vSelection:
thegood=v
if DEBUG : print thegood
listf2v=connectedFacesList(me,thegood)
me=createAdditionalFace(me,thegood,listf2v)
#OBJECT.link(me)
me.update()
OBJECT.makeDisplayList()
Blender.Window.EditMode(EDITMODE)
else:
name = "Nothing to do! Did you select at least one vertex?"
result = Blender.Draw.PupMenu(name)
|