-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy path1D_Scripts.py
More file actions
12283 lines (10137 loc) · 437 KB
/
1D_Scripts.py
File metadata and controls
12283 lines (10137 loc) · 437 KB
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# HISTORY
# 0-8-93 (26-10-2017) Changed default option (Sure UV)
# 0-8-94 (27-10-2017) Fixed spread type (Obj distribute by X)
# 0-8-95 (07-11-2017) Added (Loop Resolve) =Blendup cleanup
# 0-8-96 (08-11-2017) Fixed (Loop Resolve) =Blendup cleanup
# 0-8-97 (10-11-2017) New mode: EDGE (Loop Resolve) =Blendup cleanup
# 0-8-98 (20-11-2017) Added (UV/Images -> T-panel -> 1D -> Print loop)
# 0-8-99 (01.12.2017) Fixed (FEDGE, Spread Loop)
# 0-8-100(08.12.2017) Added (Make Border) =Test Zone
# 0-8-101(18.12.2017) Fixed (Mats Unclone - rename if one mat too) =Misc, Added (UV Scaler) =Test Zone
# 0-8-102(15.01.2018) Fixed (Loop Resolve, Select Chunks = vertices mode)
# 0-8-103(22.01.2018) Added (Fedge) nonquads
# 0-8-104(29.01.2018) Changed option (make border) =size +-100
# 0-8-105(31.01.2018) Added (RCS Read Camera Setup)
# 0-8-106(31.01.2018) UI (RCS Read Camera Setup)
# 0-8-107(10.02.2018) Misc (Obj switch on) - Add button OFF and modify logic
# 0-8-108(16.02.2018) Change settings default (Spread Loop => Uniform=False)
# 0-8-109(16.02.2018) Fix (Loop Resolve = relation by Dist)
# 0-8-110(16.02.2018) Fix (RCS) obj.name replace to cam.data.name
# 0-8-111(15.03.2018) Added (Naming/Instances -> Guess Active Instanes) = option Filter_mats
# 0-8-112(15.03.2018) Change settings default (Blendup cleanup) Obj verts report = 30
# 0-8-113(23.03.2018) Fix (Loop Resolve = relation by Dist) and Change settings default loopresolve_relative = True
# 0-9-0(31.03.2018) Add new Catgory: Render = [Render Nikits's Akimov], [Batch Render]
# 0-9-1(03.04.2018) Added (Render) Prew & Next camera's [Nikitron script]
# 0-9-2(06.04.2018) Change (Render = Prev/Next) - select and set active current cam
# 0-9-3(09.04.2018) Change (Naming/Instances = Select iinstances) add separate by type object: MESH, CURVE
# 0-9-4(13.04.2018) Change (Naming/Instances = Select iinstances) add message format: selected, inst, unique
# 0-9-5(15.04.2018) Change (Search instances 1 and 2) unified search logic
# 0-9-6(15.04.2018) Added (TestZone: Instance Resizer)
# 0-9-7(21.04.2018) Fix(Naming/Instances = Guess Active Instancess) select find objects
# 0-9-8(23.04.2018) Fix(Naming/Instances = Guess Chain Instancess) select find objects
# 0-9-9(28.04.2018) Change (Naming/Instances = Propagate Obname) array processing
# 0-9-10(30.04.2018) Fix (Naming/Instances = Propagate Obname) array processing
# 0-9-11(02.05.2018) Change (FEDGE) = fast check edges
# 0-9-12(09.05.2018) Added (TestZone: NJoin)
# 0-9-13(15.05.2018) Fix (TestZone: NJoin) active negative
# 0-9-14(17.05.2018) Move Panels: LoopResolve and LoopReduce, Remove button AutoUpdate, New format Name Panel with version
# 0-9-15(17.05.2018) Fix (TestZone: Instance Resizer) removed the reaction to a negative scale
# 0-9-16(19.05.2018) Fix (TestZone: Instance Resizer) correct scaling of instances
# 0-9-17(22.05.2018) Change (Multiple obj import) new func [By layers]: Import sorted by name objects to layers
# 0-9-18(23.05.2018) Change (Multiple obj import) new func [By layers]: Import into layers from the first selected
# 0-9-19(07.06.2018) Change (Naming/Instances = Propagate Obname) base objname > meshname >> all instances objname
# 0-9-20(08.06.2018) Added (Corner Edges) new CornerCross and ExtendCross
# 0-9-21(08.06.2018) Change (Blendup Cleanup = Verts project) save face after split
# 0-9-22(10.06.2018) Change (TestZone: Instance Resizer) scale apply to independent objects
# 0-9-23(14.06.2018) Fix (Blendup Cleanup = Verts project) Blender crashed after it and use f2
# 0-9-24(15.06.2018) Added (TestZone = Volume Select)
# 0-9-25(15.06.2018) Fix (TestZone = Volume Select)
# 0-9-26(15.06.2018) Fix (TestZone = Volume Select) add icon for modes
# 0-9-27(23.07.2018) Added (TestZone) Batch Remover
# 0-9-28(23.07.2018) Move Panel: Batch Remover
# 0-9-29(03.09.2018) Render(UI): Add Shortcut
# 0-9-30(08.09.2018) Change (Instances ++ replace) add: Use translation
# 0-9-31(09.09.2018) Change (Instances ++ replace) add: Selected only
# 0-9-32(11.09.2018) Change (Instances ++ replace) inactivate Selected only
# 0-9-33(02.10.2018) Change (Render) add: OpenGL Render
# 0-10-00(11.10.2018) Reformat Panel Edges/loops
# 0-10-01(19.10.2018) Upp version
# 0-10-02(19.10.2018) Bugfix
# 0-10-03(19.10.2018) Bugfix
# 0-10-04(23.10.2018) Set the panels in order
# 0-10-05(23.10.2018) Changed the order of the tools
# 0-10-06(27.10.2018) Filter on the Mesh of the functions guess_active_instance, chain_instance, obname_to_meshname, meshname_to_obname
# 0-10-07(06.11.2018) Changed (Mats sort) show in seacher
# 0-10-09(16.11.2018) Fixed panel Batch render
# 0-10-10(16.11.2018) Fixed UV Scaler
# 0-10-12(18.11.2018) Fixed (Test Zone) Polyedge select
# 0-10-13(21.11.2018) Added (Test Zone) Ssmooth
# 0-10-14(23.11.2018) Fixed (Test Zone) Ssmooth - add Shortcut
# 0-10-15(12.12.2018) Changed (Corner Edges): enable To Active edge
# 0-10-16(12.12.2018) Changed (Stairs maker): go to source object after execution
# 0-10-18(11.01.2019) Rename labels for quick search
# 0-10-19(10.02.2019) Added (Materials) Mats Showcase
# 0-10-20(18.02.2019) Changed (Materials) Mats Showcase and Colorize
# 0-10-21(18.02.2019) Changed (Materials) Mats Showcase and Colorize - old format string
# 0-10-22(31.07.2019) Fixed (Materials) mats only uncludes "." in name
bl_info = {
"name": "1D_Scripts",
"author": "Alexander Nedovizin, Paul Kotelevets aka 1D_Inc (concept design), Nikitron",
"version": (0, 10, 22),
"blender": (2, 7, 9),
"location": "View3D > Toolbar",
"category": "Mesh"
}
# https://github.com/Cfyzzz/Scripts/blob/master/1D_Scripts.py
import bpy, bmesh, mathutils, math
from mathutils import Vector, Matrix
from mathutils.geometry import intersect_line_plane, intersect_point_line, intersect_line_line
from math import sin, cos, pi, sqrt, degrees, tan, radians
from colorsys import hsv_to_rgb, rgb_to_hsv
import os, urllib
from bpy.props import (BoolProperty,
FloatProperty,
StringProperty,
EnumProperty,
IntProperty,
CollectionProperty,
FloatVectorProperty
)
from bpy_extras.io_utils import ExportHelper, ImportHelper
from bpy.types import Operator
import time
from collections import namedtuple
from operator import mul, itemgetter, add, attrgetter
from functools import reduce
from abc import abstractmethod, ABCMeta
from addon_utils import check
list_z = []
mats_idx = []
list_f = []
maloe = 1e-5
steps_smoose = 0
omsureuv_all_scale_def_glob = 1.0
def check_lukap(bm):
if hasattr(bm.verts, "ensure_lookup_table"):
bm.verts.ensure_lookup_table()
bm.edges.ensure_lookup_table()
bm.faces.ensure_lookup_table()
# ----- Module: edge fillet-------
# author this module: Zmj100
# version 0.3.0
# ref:
def a_rot(ang, rp, axis, q):
mtrx = Matrix.Rotation(ang, 3, axis)
tmp = q - rp
tmp1 = mtrx * tmp
tmp2 = tmp1 + rp
return tmp2
# ------ ------
class f_buf():
an = 0
# ------ ------
def f_edgefillet(bme, list_0, adj, n, radius, out, flip):
check_lukap(bme)
dict_0 = get_adj_v_(list_0)
list_1 = [[dict_0[i][0], i, dict_0[i][1]] for i in dict_0 if (len(dict_0[i]) == 2)][0]
list_del = [bme.verts[list_1[1]]]
list_2 = []
p = (bme.verts[list_1[1]].co).copy()
p1 = (bme.verts[list_1[0]].co).copy()
p2 = (bme.verts[list_1[2]].co).copy()
vec1 = p - p1
vec2 = p - p2
ang = vec1.angle(vec2, any)
f_buf.an = round(degrees(ang))
if f_buf.an == 180 or f_buf.an == 0.0:
pass
else:
opp = adj
if radius == False:
h = adj * (1 / cos(ang * 0.5))
d = adj
elif radius == True:
h = opp / sin(ang * 0.5)
d = opp / tan(ang * 0.5)
p3 = p - (vec1.normalized() * d)
p4 = p - (vec2.normalized() * d)
no = (vec1.cross(vec2)).normalized()
rp = a_rot(radians(90), p, (p3 - p4), (p - (no * h)))
vec3 = rp - p3
vec4 = rp - p4
axis = vec1.cross(vec2)
if out == False:
if flip == False:
rot_ang = vec3.angle(vec4)
elif flip == True:
rot_ang = vec1.angle(vec2)
elif out == True:
rot_ang = (2 * pi) - vec1.angle(vec2)
for j in range(n + 1):
if out == False:
if flip == False:
tmp2 = a_rot(rot_ang * j / n, rp, axis, p4)
elif flip == True:
tmp2 = a_rot(rot_ang * j / n, p, axis, p - (vec1.normalized() * opp))
elif out == True:
tmp2 = a_rot(rot_ang * j / n, p, axis, p - (vec2.normalized() * opp))
bme.verts.new(tmp2)
bme.verts.index_update()
check_lukap(bme)
list_2.append(bme.verts[-1].index)
check_lukap(bme)
if flip == True:
list_1[1:2] = list_2
else:
list_2.reverse()
list_1[1:2] = list_2
list_2[:] = []
n1 = len(list_1)
for t in range(n1 - 1):
bme.edges.new([bme.verts[list_1[t]], bme.verts[list_1[(t + 1) % n1]]])
bme.edges.index_update()
check_lukap(bme)
bme.verts.remove(list_del[0])
bme.verts.index_update()
check_lukap(bme)
class f_op0(bpy.types.Operator):
bl_idname = 'f.op0_id'
bl_label = 'Edge Fillet'
bl_options = {'REGISTER', 'UNDO'}
adj = FloatProperty(name='', default=0.1, min=0.00001, max=100.0, step=1, precision=3)
n = IntProperty(name='', default=3, min=1, max=100, step=1)
out = BoolProperty(name='Outside', default=False)
flip = BoolProperty(name='Flip', default=False)
radius = BoolProperty(name='Radius', default=False)
def draw(self, context):
layout = self.layout
if f_buf.an == 180 or f_buf.an == 0.0:
box = layout.box()
box.label('Info:')
box.label('Angle equal to 0 or 180,')
box.label('unable to fillet.')
else:
box = layout.box()
box.prop(self, 'radius')
row = box.split(0.35, align=True)
if self.radius == True:
row.label('Radius:')
elif self.radius == False:
row.label('Distance:')
row.prop(self, 'adj')
row1 = box.split(0.55, align=True)
row1.label('Number of sides:')
row1.prop(self, 'n', slider=True)
if self.n > 1:
row2 = box.split(0.50, align=True)
row2.prop(self, 'out')
if self.out == False:
row2.prop(self, 'flip')
def execute(self, context):
adj = self.adj
n = self.n
out = self.out
flip = self.flip
radius = self.radius
edit_mode_out()
ob_act = context.active_object
bme = bmesh.new()
bme.from_mesh(ob_act.data)
check_lukap(bme)
list_0 = [[v.index for v in e.verts] for e in bme.edges if e.select and e.is_valid]
if not list_0:
list_v = [v.index for v in bme.verts if v.select and v.is_valid]
if not list_0 and len(list_v) == 1:
connected_edges = bme.verts[list_v[0]].link_edges
list_1 = [[v.index for v in e.verts] for e in connected_edges if e.is_valid]
if len(list_1) != 2:
self.report({'INFO'}, 'Two adjacent edges or single vert must be selected.')
edit_mode_in()
return {'CANCELLED'}
if out == True:
flip = False
f_edgefillet(bme, list_1, adj, n, radius, out, flip)
elif len(list_0) != 2:
self.report({'INFO'}, 'Two adjacent edges or single vert must be selected.')
edit_mode_in()
return {'CANCELLED'}
else:
if out == True:
flip = False
f_edgefillet(bme, list_0, adj, n, radius, out, flip)
bme.to_mesh(ob_act.data)
edit_mode_in()
bpy.ops.mesh.select_all(action='DESELECT')
return {'FINISHED'}
# ----- Module: extrude along path -------
# author this module: Zmj100
# version 0.5.0.9
# ref: http://blenderartists.org/forum/showthread.php?179375-Addon-Edge-fillet-and-other-bmesh-tools-Update-Jan-11
def edit_mode_out():
bpy.ops.object.mode_set(mode='OBJECT')
def edit_mode_in():
bpy.ops.object.mode_set(mode='EDIT')
def get_adj_v_(list_):
tmp = {}
for i in list_:
try:
tmp[i[0]].append(i[1])
except KeyError:
tmp[i[0]] = [i[1]]
try:
tmp[i[1]].append(i[0])
except KeyError:
tmp[i[1]] = [i[0]]
return tmp
def f_1(frst, list_, last): # edge chain
fi = frst
tmp = [frst]
while list_ != []:
for i in list_:
if i[0] == fi:
tmp.append(i[1])
fi = i[1]
list_.remove(i)
elif i[1] == fi:
tmp.append(i[0])
fi = i[0]
list_.remove(i)
if tmp[-1] == last:
break
return tmp
def f_2(frst, list_): # edge loop
fi = frst
tmp = [frst]
while list_ != []:
for i in list_:
if i[0] == fi:
tmp.append(i[1])
fi = i[1]
list_.remove(i)
elif i[1] == fi:
tmp.append(i[0])
fi = i[0]
list_.remove(i)
if tmp[-1] == frst:
break
return tmp
def is_loop_(list_fl):
return True if len(list_fl) == 0 else False
def e_no_(bme, indx, p, p1):
if hasattr(bme.verts, "ensure_lookup_table"):
bme.verts.ensure_lookup_table()
tmp1 = (bme.verts[indx].co).copy()
tmp1[0] += 0.1
tmp1[1] += 0.1
tmp1[2] += 0.1
ip1 = intersect_point_line(tmp1, p, p1)[0]
return tmp1 - ip1
# ------ ------
def f_(bme, dict_0, list_fl, loop):
check_lukap(bme)
if loop:
list_1 = f_2(eap_buf.list_sp[0], eap_buf.list_ek)
del list_1[-1]
else:
list_1 = f_1(eap_buf.list_sp[0], eap_buf.list_ek,
list_fl[1] if eap_buf.list_sp[0] == list_fl[0] else list_fl[0])
list_2 = [v.index for v in bme.verts if v.select and v.is_valid]
n1 = len(list_2)
list_3 = list_2[:]
dict_1 = {}
for k in list_2:
dict_1[k] = [k]
n = len(list_1)
for i in range(n):
p = (bme.verts[list_1[i]].co).copy()
p1 = (bme.verts[list_1[(i - 1) % n]].co).copy()
p2 = (bme.verts[list_1[(i + 1) % n]].co).copy()
vec1 = p - p1
vec2 = p - p2
ang = vec1.angle(vec2, any)
if round(degrees(ang)) == 180.0 or round(degrees(ang)) == 0.0:
pp = p - ((e_no_(bme, list_1[i], p, p1)).normalized() * 0.1)
pn = vec1.normalized()
else:
pp = ((p - (vec1.normalized() * 0.1)) + (p - (vec2.normalized() * 0.1))) * 0.5
pn = ((vec1.cross(vec2)).cross(p - pp)).normalized()
if loop: # loop
if i == 0:
pass
else:
for j in range(n1):
v = (bme.verts[list_3[j]].co).copy()
bme.verts.new(intersect_line_plane(v, v + (vec1.normalized() * 0.1), pp, pn))
bme.verts.index_update()
if hasattr(bme.verts, "ensure_lookup_table"):
bme.verts.ensure_lookup_table()
list_3[j] = bme.verts[-1].index
dict_1[list_2[j]].append(bme.verts[-1].index)
else: # path
if i == 0:
pass
elif i == (n - 1):
pp_ = p - ((e_no_(bme, list_fl[1] if eap_buf.list_sp[0] == list_fl[0] else list_fl[0], p,
p1)).normalized() * 0.1)
pn_ = vec1.normalized()
for j in range(n1):
v = (bme.verts[list_3[j]].co).copy()
bme.verts.new(intersect_line_plane(v, v + (vec1.normalized() * 0.1), pp_, pn_))
bme.verts.index_update()
if hasattr(bme.verts, "ensure_lookup_table"):
bme.verts.ensure_lookup_table()
dict_1[list_2[j]].append(bme.verts[-1].index)
else:
for j in range(n1):
v = (bme.verts[list_3[j]].co).copy()
bme.verts.new(intersect_line_plane(v, v + (vec1.normalized() * 0.1), pp, pn))
bme.verts.index_update()
if hasattr(bme.verts, "ensure_lookup_table"):
bme.verts.ensure_lookup_table()
list_3[j] = bme.verts[-1].index
dict_1[list_2[j]].append(bme.verts[-1].index)
# -- -- -- --
list_4 = [[v.index for v in e.verts] for e in bme.edges if e.select and e.is_valid]
n2 = len(list_4)
for t in range(n2):
for o in range(n if loop else (n - 1)):
bme.faces.new([bme.verts[dict_1[list_4[t][0]][o]], bme.verts[dict_1[list_4[t][1]][o]],
bme.verts[dict_1[list_4[t][1]][(o + 1) % n]], bme.verts[dict_1[list_4[t][0]][(o + 1) % n]]])
bme.faces.index_update()
if hasattr(bme.faces, "ensure_lookup_table"):
bme.faces.ensure_lookup_table()
# ------ ------
class eap_buf():
list_ek = [] # path
list_sp = [] # start point
# ------ operator 0 ------
class eap_op0(bpy.types.Operator):
bl_idname = 'eap.op0_id'
bl_label = '....'
def execute(self, context):
edit_mode_out()
ob_act = context.active_object
bme = bmesh.new()
bme.from_mesh(ob_act.data)
check_lukap(bme)
eap_buf.list_ek[:] = []
for e in bme.edges:
if e.select and e.is_valid:
eap_buf.list_ek.append([v.index for v in e.verts])
e.select_set(0)
bme.to_mesh(ob_act.data)
edit_mode_in()
bme.free()
return {'FINISHED'}
# ------ operator 1 ------
class eap_op1(bpy.types.Operator):
bl_idname = 'eap.op1_id'
bl_label = '....'
def execute(self, context):
edit_mode_out()
ob_act = context.active_object
bme = bmesh.new()
bme.from_mesh(ob_act.data)
check_lukap(bme)
eap_buf.list_sp[:] = []
for v in bme.verts:
if v.select and v.is_valid:
eap_buf.list_sp.append(v.index)
v.select_set(0)
bme.to_mesh(ob_act.data)
edit_mode_in()
bme.free()
return {'FINISHED'}
# ------ operator 2 ------
class eap_op2(bpy.types.Operator):
bl_idname = 'eap.op2_id'
bl_label = 'Extrude Along Path'
bl_options = {'REGISTER', 'UNDO'}
def draw(self, context):
layout = self.layout
def execute(self, context):
edit_mode_out()
ob_act = context.active_object
bme = bmesh.new()
bme.from_mesh(ob_act.data)
check_lukap(bme)
dict_0 = get_adj_v_(eap_buf.list_ek)
list_fl = [i for i in dict_0 if (len(dict_0[i]) == 1)]
loop = is_loop_(list_fl)
f_(bme, dict_0, list_fl, loop)
bme.to_mesh(ob_act.data)
edit_mode_in()
bme.free()
return {'FINISHED'}
# ------ operator 3 ------
class eap_op3(bpy.types.Operator):
bl_idname = 'eap.op3_id'
bl_label = '.......'
def execute(self, context):
edit_mode_out()
ob_act = context.active_object
bme = bmesh.new()
bme.from_mesh(ob_act.data)
check_lukap(bme)
av = bm_vert_active_get(bme)
if av[1] == 'V':
eap_buf.list_sp[:] = []
v = bme.verts[av[0]]
if v.select and v.is_valid:
eap_buf.list_sp.append(v.index)
v.select_set(0)
bpy.ops.eap.op0_id()
edit_mode_in()
bme.free()
return {'FINISHED'}
# -------------- END --- extrude along path ---------
# ----- Module: Sure UVW Map v.0.5.1 -------
# author this module: Alexander Milovsky (www.milovsky.ru)
# version 0.5.1
# ref: http://blenderartists.org/forum/showthread.php?236631-Addon-Simple-Box-UVW-Map-Modifier
# globals for Box Mapping
all_scale_def = 1
tex_aspect = 1.0
x_offset_def = 0
y_offset_def = 0
z_offset_def = 0
x_rot_def = 0
y_rot_def = 0
z_rot_def = 0
# globals for Best Planar Mapping
xoffset_def = 0
yoffset_def = 0
zrot_def = 0
# Preview flag
preview_flag = True
def show_texture():
obj = bpy.context.active_object
mesh = obj.data
is_editmode = (obj.mode == 'EDIT')
# if in EDIT Mode switch to OBJECT
if is_editmode:
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
# if no UVtex - create it
if not mesh.uv_textures:
uvtex = bpy.ops.mesh.uv_texture_add()
uvtex = mesh.uv_textures.active
uvtex.active_render = True
img = None
aspect = 1.0
mat = obj.active_material
try:
if mat:
img = mat.active_texture
for f in mesh.polygons:
if not is_editmode or f.select:
uvtex.data[f.index].image = img.image
else:
img = None
except:
pass
# Back to EDIT Mode
if is_editmode:
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
def box_map():
# print('** Boxmap **')
global all_scale_def, x_offset_def, y_offset_def, z_offset_def, x_rot_def, y_rot_def, z_rot_def, tex_aspect
obj = bpy.context.active_object
mesh = obj.data
is_editmode = (obj.mode == 'EDIT')
# if in EDIT Mode switch to OBJECT
if is_editmode:
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
# if no UVtex - create it
if not mesh.uv_textures:
uvtex = bpy.ops.mesh.uv_texture_add()
uvtex = mesh.uv_textures.active
# uvtex.active_render = True
img = None
aspect = 1.0
mat = obj.active_material
try:
if mat:
img = mat.active_texture
aspect = img.image.size[0] / img.image.size[1]
except:
pass
aspect = aspect * tex_aspect
#
# Main action
#
if all_scale_def:
sc = 1.0 / all_scale_def
else:
sc = 1.0
sx = 1 * sc
sy = 1 * sc
sz = 1 * sc
ofx = x_offset_def
ofy = y_offset_def
ofz = z_offset_def
rx = x_rot_def / 180 * pi
ry = y_rot_def / 180 * pi
rz = z_rot_def / 180 * pi
crx = cos(rx)
srx = sin(rx)
cry = cos(ry)
sry = sin(ry)
crz = cos(rz)
srz = sin(rz)
ofycrx = ofy * crx
ofzsrx = ofz * srx
ofysrx = ofy * srx
ofzcrx = ofz * crx
ofxcry = ofx * cry
ofzsry = ofz * sry
ofxsry = ofx * sry
ofzcry = ofz * cry
ofxcrz = ofx * crz
ofysrz = ofy * srz
ofxsrz = ofx * srz
ofycrz = ofy * crz
# uvs = mesh.uv_loop_layers[mesh.uv_loop_layers.active_index].data
uvs = mesh.uv_layers.active.data
for i, pol in enumerate(mesh.polygons):
if not is_editmode or mesh.polygons[i].select:
for j, loop in enumerate(mesh.polygons[i].loop_indices):
v_idx = mesh.loops[loop].vertex_index
# print('before[%s]:' % v_idx)
# print(uvs[loop].uv)
n = mesh.polygons[i].normal
co = mesh.vertices[v_idx].co
x = co.x * sx
y = co.y * sy
z = co.z * sz
if abs(n[0]) > abs(n[1]) and abs(n[0]) > abs(n[2]):
# X
if n[0] >= 0:
uvs[loop].uv[0] = y * crx + z * srx - ofycrx - ofzsrx
uvs[loop].uv[1] = -y * aspect * srx + z * aspect * crx + ofysrx - ofzcrx
else:
uvs[loop].uv[0] = -y * crx + z * srx + ofycrx - ofzsrx
uvs[loop].uv[1] = y * aspect * srx + z * aspect * crx - ofysrx - ofzcrx
elif abs(n[1]) > abs(n[0]) and abs(n[1]) > abs(n[2]):
# Y
if n[1] >= 0:
uvs[loop].uv[0] = -x * cry + z * sry + ofxcry - ofzsry
uvs[loop].uv[1] = x * aspect * sry + z * aspect * cry - ofxsry - ofzcry
else:
uvs[loop].uv[0] = x * cry + z * sry - ofxcry - ofzsry
uvs[loop].uv[1] = -x * aspect * sry + z * aspect * cry + ofxsry - ofzcry
else:
# Z
if n[2] >= 0:
uvs[loop].uv[0] = x * crz + y * srz + - ofxcrz - ofysrz
uvs[loop].uv[1] = -x * aspect * srz + y * aspect * crz + ofxsrz - ofycrz
else:
uvs[loop].uv[0] = -y * srz - x * crz + ofxcrz - ofysrz
uvs[loop].uv[1] = y * aspect * crz - x * aspect * srz - ofxsrz - ofycrz
# Back to EDIT Mode
if is_editmode:
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
# Best Planar Mapping
def best_planar_map():
global all_scale_def, xoffset_def, yoffset_def, zrot_def, tex_aspect
obj = bpy.context.active_object
mesh = obj.data
is_editmode = (obj.mode == 'EDIT')
# if in EDIT Mode switch to OBJECT
if is_editmode:
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
# if no UVtex - create it
if not mesh.uv_textures:
uvtex = bpy.ops.mesh.uv_texture_add()
uvtex = mesh.uv_textures.active
# uvtex.active_render = True
img = None
aspect = 1.0
mat = obj.active_material
try:
if mat:
img = mat.active_texture
aspect = img.image.size[0] / img.image.size[1]
except:
pass
aspect = aspect * tex_aspect
#
# Main action
#
if all_scale_def:
sc = 1.0 / all_scale_def
else:
sc = 1.0
# Calculate Average Normal
v = Vector((0, 0, 0))
cnt = 0
for f in mesh.polygons:
if f.select:
cnt += 1
v = v + f.normal
zv = Vector((0, 0, 1))
q = v.rotation_difference(zv)
sx = 1 * sc
sy = 1 * sc
sz = 1 * sc
ofx = xoffset_def
ofy = yoffset_def
rz = zrot_def / 180 * pi
cosrz = cos(rz)
sinrz = sin(rz)
# uvs = mesh.uv_loop_layers[mesh.uv_loop_layers.active_index].data
uvs = mesh.uv_layers.active.data
for i, pol in enumerate(mesh.polygons):
if not is_editmode or mesh.polygons[i].select:
for j, loop in enumerate(mesh.polygons[i].loop_indices):
v_idx = mesh.loops[loop].vertex_index
n = pol.normal
co = q * mesh.vertices[v_idx].co
x = co.x * sx
y = co.y * sy
z = co.z * sz
uvs[loop].uv[0] = x * cosrz - y * sinrz + xoffset_def
uvs[loop].uv[1] = aspect * (- x * sinrz - y * cosrz) + yoffset_def
# Back to EDIT Mode
if is_editmode:
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
class SureUVWOperator(bpy.types.Operator):
bl_idname = "object.sureuvw_operator"
bl_label = "Sure UVW Map"
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_context = "data"
bl_options = {'REGISTER', 'UNDO'}
action = StringProperty()
size = FloatProperty(name="Size", default=1.0, precision=4)
rot = FloatVectorProperty(name="XYZ Rotation")
offset = FloatVectorProperty(name="XYZ offset", precision=4)
zrot = FloatProperty(name="Z rotation", default=0.0)
xoffset = FloatProperty(name="X offset", default=0.0, precision=4)
yoffset = FloatProperty(name="Y offset", default=0.0, precision=4)
texaspect = FloatProperty(name="Texture aspect", default=1.0, precision=4)
flag90 = BoolProperty()
flag90ccw = BoolProperty()
@classmethod
def poll(cls, context):
obj = context.active_object
return (obj and obj.type == 'MESH')
def execute(self, context):
# print('** execute **')
# print(self.action)
global all_scale_def, x_offset_def, y_offset_def, z_offset_def, x_rot_def, y_rot_def, z_rot_def, xoffset_def, yoffset_def, zrot_def, tex_aspect
all_scale_def = self.size
tex_aspect = self.texaspect
x_offset_def = self.offset[0]
y_offset_def = self.offset[1]
z_offset_def = self.offset[2]
x_rot_def = self.rot[0]
y_rot_def = self.rot[1]
z_rot_def = self.rot[2]
xoffset_def = self.xoffset
yoffset_def = self.yoffset
zrot_def = self.zrot
if self.flag90:
self.zrot += 90
zrot_def += 90
self.flag90 = False
if self.flag90ccw:
self.zrot += -90
zrot_def += -90
self.flag90ccw = False
if self.action == 'bestplanar':
best_planar_map()
elif self.action == 'box':
box_map()
elif self.action == 'showtex':
show_texture()
elif self.action == 'doneplanar':
best_planar_map()
elif self.action == 'donebox':
box_map()
# print('finish execute')
return {'FINISHED'}
def invoke(self, context, event):
# print('** invoke **')
# print(self.action)
global all_scale_def, x_offset_def, y_offset_def, z_offset_def, x_rot_def, y_rot_def, z_rot_def, xoffset_def, yoffset_def, zrot_def, tex_aspect
self.size = all_scale_def
self.texaspect = tex_aspect
self.offset[0] = x_offset_def
self.offset[1] = y_offset_def
self.offset[2] = z_offset_def
self.rot[0] = x_rot_def
self.rot[1] = y_rot_def
self.rot[2] = z_rot_def
self.xoffset = xoffset_def
self.yoffset = yoffset_def
self.zrot = zrot_def
if self.action == 'bestplanar':
best_planar_map()
elif self.action == 'box':
box_map()
elif self.action == 'showtex':
show_texture()
elif self.action == 'doneplanar':
best_planar_map()
elif self.action == 'donebox':
box_map()
# print('finish invoke')
return {'FINISHED'}
def draw(self, context):
if self.action == 'bestplanar' or self.action == 'rotatecw' or self.action == 'rotateccw':
self.action = 'bestplanar'
layout = self.layout
layout.label("Size - " + self.action)
layout.prop(self, 'size', text="")
layout.label("Z rotation")
col = layout.column()
col.prop(self, 'zrot', text="")
row = layout.row()
row.prop(self, 'flag90ccw', text="-90 (CCW)")
row.prop(self, 'flag90', text="+90 (CW)")
layout.label("XY offset")
col = layout.column()
col.prop(self, 'xoffset', text="")
col.prop(self, 'yoffset', text="")
layout.label("Texture aspect")
layout.prop(self, 'texaspect', text="")
# layout.prop(self,'preview_flag', text="Interactive Preview")
# layout.operator("object.sureuvw_operator",text="Done").action='doneplanar'
elif self.action == 'box':
layout = self.layout
layout.label("Size")
layout.prop(self, 'size', text="")
layout.label("XYZ rotation")
col = layout.column()
col.prop(self, 'rot', text="")
layout.label("XYZ offset")
col = layout.column()
col.prop(self, 'offset', text="")
layout.label("Texture squash (optional)")
layout.label("Always must be 1.0 !!!")
layout.prop(self, 'texaspect', text="")
# layout.prop(self,'preview_flag', text="Interactive Preview")
# layout.operator("object.sureuvw_operator",text="Done").action='donebox'
# -------------- END --- Sure UVW Map v.0.5.1 ---------
# -----------
# ------------------ Bargool_1D_tools
def is_multiuser(obj):
""" Test for instances """
return hasattr(obj.data, 'users') and obj.data.users > 1