|
|
@@ -1,164 +0,0 @@
|
|
1
|
|
-# -*- coding: utf-8 -*-
|
|
2
|
|
-import bpy
|
|
3
|
|
-import math
|
|
4
|
|
-import random
|
|
5
|
|
-
|
|
6
|
|
-from mathutils import Matrix
|
|
7
|
|
-from mathutils import Vector
|
|
8
|
|
-
|
|
9
|
|
-from . import cfg
|
|
10
|
|
-
|
|
11
|
|
-
|
|
12
|
|
-def at_random_fill(min, max):
|
|
13
|
|
- first = random.uniform(min, max)
|
|
14
|
|
- second = random.uniform(min, max)
|
|
15
|
|
- if first <= second:
|
|
16
|
|
- return(first, second)
|
|
17
|
|
- else:
|
|
18
|
|
- return(second, first)
|
|
19
|
|
-
|
|
20
|
|
-
|
|
21
|
|
-def at_random(seed, totalc, totalr, mint, maxt, mins, maxs, minr, maxr, btr, bsc, brot, uniform,
|
|
22
|
|
- tr1, tr2, sc1, sc2, r1, r2, pivot, varia, valign):
|
|
23
|
|
- """Random function for translation, scale and rotation,
|
|
24
|
|
- seed : seed for random
|
|
25
|
|
- totalc : number of elements in column
|
|
26
|
|
- totalr : number of elements in row
|
|
27
|
|
- mint : minimum for translation
|
|
28
|
|
- maxt : maximum for translation
|
|
29
|
|
- mins : minimum for scale
|
|
30
|
|
- maxs : maximum for scale
|
|
31
|
|
- minr : minimum for rotation
|
|
32
|
|
- maxr : maximun for rotation
|
|
33
|
|
- btr : (boolean) use translation or not
|
|
34
|
|
- bsc : (boolean) use scale or not
|
|
35
|
|
- brot : (boolean) use rotation or not
|
|
36
|
|
- uniform : (boolean) use uniform scale or not
|
|
37
|
|
- tr1 : translation offset of the column
|
|
38
|
|
- tr2 : translation offset of the row
|
|
39
|
|
- sc1 : scale offset of the column
|
|
40
|
|
- sc2 : scale offset of the row
|
|
41
|
|
- r1 : rotation offset of the column
|
|
42
|
|
- r2 : rotation offset of the row
|
|
43
|
|
- pivot : pivot
|
|
44
|
|
- varia : variation of rows
|
|
45
|
|
- valign : Vector of align of rows
|
|
46
|
|
- """
|
|
47
|
|
- random.seed(seed)
|
|
48
|
|
- tr, sc, rot = [0, 0, 0], [0, 0, 0], [0, 0, 0]
|
|
49
|
|
- xyz_vec = (x_axis(), y_axis(), z_axis())
|
|
50
|
|
- ref_name = cfg.atools_objs[0][0]
|
|
51
|
|
- for j in range(totalr):
|
|
52
|
|
- for k in range(totalc + j*varia):
|
|
53
|
|
- elem_name = cfg.atools_objs[j][k]
|
|
54
|
|
- if elem_name == ref_name:
|
|
55
|
|
- continue
|
|
56
|
|
- elem = bpy.data.objects[elem_name]
|
|
57
|
|
- for i in range(3):
|
|
58
|
|
- tr[i] = random.uniform(mint[i], maxt[i])
|
|
59
|
|
- sc[i] = random.uniform(mins[i]/100, maxs[i]/100)
|
|
60
|
|
- rot[i] = random.uniform(minr[i], maxr[i])
|
|
61
|
|
- if uniform:
|
|
62
|
|
- sc[0] = sc[1] = sc[2]
|
|
63
|
|
- mt = Matrix.Translation(tr)
|
|
64
|
|
- ms = Matrix.Scale(sc[0], 4, (1, 0, 0)) @ Matrix.Scale(sc[1], 4, (0, 1, 0)) @ Matrix.Scale(sc[2], 4, (0, 0, 1))
|
|
65
|
|
- mr = Matrix.Rotation(rot[0], 4, (1, 0, 0)) @ Matrix.Rotation(rot[1], 4, (0, 1, 0)) @ Matrix.Rotation(rot[2], 4, (0, 0, 1))
|
|
66
|
|
-
|
|
67
|
|
- # recalculate the position...
|
|
68
|
|
- vt, vs, vr = tsr(cfg.ref_mtx, k, j, tr1, tr2, sc1, sc2, Vector(r1), Vector(r2), valign)
|
|
69
|
|
-
|
|
70
|
|
- if pivot is not None:
|
|
71
|
|
- emat = at_all_in_one(cfg.ref_mtx, vr, xyz_vec, vt, vs, pivot.location)
|
|
72
|
|
- else:
|
|
73
|
|
- emat = at_all_in_one(cfg.ref_mtx, vr, xyz_vec, vt, vs, cfg.ref_mtx.translation)
|
|
74
|
|
- elem.matrix_world = emat
|
|
75
|
|
- if btr:
|
|
76
|
|
- elem.matrix_world @= mt
|
|
77
|
|
- if bsc:
|
|
78
|
|
- elem.matrix_world @= ms
|
|
79
|
|
- if brot:
|
|
80
|
|
- elem.matrix_world @= mr
|
|
81
|
|
-
|
|
82
|
|
-def x_axis():
|
|
83
|
|
- """Get the x axis"""
|
|
84
|
|
- return Vector((1.0, 0.0, 0.0))
|
|
85
|
|
-
|
|
86
|
|
-
|
|
87
|
|
-def y_axis():
|
|
88
|
|
- """Get the y axis"""
|
|
89
|
|
- return Vector((0.0, 1.0, 0.0))
|
|
90
|
|
-
|
|
91
|
|
-
|
|
92
|
|
-def z_axis():
|
|
93
|
|
- """Get the z axis"""
|
|
94
|
|
- return Vector((0.0, 0.0, 1.0))
|
|
95
|
|
-
|
|
96
|
|
-
|
|
97
|
|
-def xyz_axis():
|
|
98
|
|
- """Get the xyz axis"""
|
|
99
|
|
- return Vector((1.0, 1.0, 1.0))
|
|
100
|
|
-
|
|
101
|
|
-
|
|
102
|
|
-def at_all_in_one(ref, angle, vecxyz, vec_tr, vec_sc, pivot):
|
|
103
|
|
- """Return the matrix of transformations"""
|
|
104
|
|
- # Matrix is composed by location @ rotation @ scale
|
|
105
|
|
- loc_ref, rot_ref, sc_ref = ref.decompose()
|
|
106
|
|
- # ref_location = bpy.data.objects[cfg.atools_objs[0][0]].location
|
|
107
|
|
-
|
|
108
|
|
- loc_ma = Matrix.Translation(loc_ref)
|
|
109
|
|
- rot_ma = rot_ref.to_matrix().to_4x4()
|
|
110
|
|
- sc_ma = Matrix.Scale(sc_ref[0], 4, (1, 0, 0)) @ Matrix.Scale(sc_ref[1], 4, (0, 1, 0)) @ Matrix.Scale(sc_ref[2], 4, (0, 0, 1))
|
|
111
|
|
-
|
|
112
|
|
- mt = Matrix.Translation(pivot - loc_ref)
|
|
113
|
|
- mr = Matrix.Rotation(angle[0], 4, vecxyz[0]) @ Matrix.Rotation(angle[1], 4, vecxyz[1]) @ Matrix.Rotation(angle[2], 4, vecxyz[2])
|
|
114
|
|
- mra = mt @ mr @ mt.inverted()
|
|
115
|
|
-
|
|
116
|
|
- trm = Matrix.Translation(vec_tr)
|
|
117
|
|
- scm = Matrix.Scale(vec_sc[0], 4, (1, 0, 0)) @ Matrix.Scale(vec_sc[1], 4, (0, 1, 0)) @ Matrix.Scale(vec_sc[2], 4, (0, 0, 1))
|
|
118
|
|
-
|
|
119
|
|
- if pivot == loc_ref:
|
|
120
|
|
- mw = loc_ma @ rot_ma @ trm @ scm @ sc_ma @ mr
|
|
121
|
|
- else:
|
|
122
|
|
- mw = loc_ma @ mra @ rot_ma @ trm @ scm @ sc_ma
|
|
123
|
|
- return mw
|
|
124
|
|
-
|
|
125
|
|
-
|
|
126
|
|
-def fill_rotation(context):
|
|
127
|
|
- prop = context.scene.arraytools_prop
|
|
128
|
|
- offset = prop.rot_offset
|
|
129
|
|
-
|
|
130
|
|
- for i in range(3):
|
|
131
|
|
- if offset[i] == 0.0:
|
|
132
|
|
- prop.rot_min[i], prop.rot_max[i] = at_random_fill(-math.pi, math.pi)
|
|
133
|
|
- else:
|
|
134
|
|
- prop.rot_min[i], prop.rot_max[i] = at_random_fill(-offset[i]*2, offset[i]*2)
|
|
135
|
|
-
|
|
136
|
|
-
|
|
137
|
|
-def sum_serie(n, factor):
|
|
138
|
|
- """Return the sum of the serie 1+2+3+4+...+n
|
|
139
|
|
- with a factor
|
|
140
|
|
- """
|
|
141
|
|
- return ((n * (n - 1)) / 2) * factor
|
|
142
|
|
-
|
|
143
|
|
-
|
|
144
|
|
-# (T)ranslate (S)cale (R)otation vector
|
|
145
|
|
-def tsr(mat, col, row, tcol, trow, scol, srow, rcol, rrow, ralign):
|
|
146
|
|
- """Retrieve the translation, scale and rotation vector according
|
|
147
|
|
- to the position in the array
|
|
148
|
|
- mat : matrix of the reference object
|
|
149
|
|
- col : position in column
|
|
150
|
|
- row : position in row
|
|
151
|
|
- tcol : translate offset in column
|
|
152
|
|
- trow : translate offset in row
|
|
153
|
|
- scol : scale offset in column
|
|
154
|
|
- srow : scale offset in row
|
|
155
|
|
- rcol : rotation offset in column
|
|
156
|
|
- rrow : rotation offset in row
|
|
157
|
|
- ralign : row align
|
|
158
|
|
- """
|
|
159
|
|
- translate = col * tcol + row * trow + row * ralign
|
|
160
|
|
- rotate = col * Vector(rcol) + row * Vector(rrow)
|
|
161
|
|
- s1 = col * (mat.to_scale() - (scol/100))
|
|
162
|
|
- s2 = row * (mat.to_scale() - (srow/100))
|
|
163
|
|
- scale = xyz_axis() - s1 - s2
|
|
164
|
|
- return translate, scale, rotate
|