Non-destructive geometry generator example.
1
2
3import coat
4import random
5
6
7
8
9
10class SimpleGenerator:
11
12 def __init__(self):
13 super().__init__()
14 self.numSpheres = 200
15 self.FigureRadius = 30
16 self.FigureRadiusVariation = 0.1
17 self.SpheresRadius = 10
18 self.SpheresRadiusVariation = 0.5
19 self.Seed = 0
20
22 self.m.Read("data/Samples/Sphere.obj")
23
24
25 def getDefaultObjectName(self) :
26 return "Spheres"
27
28
29 def ui(self) :
30 return [
31 "numSpheres,[1,1000]",
32 "FigureRadius,[1,100]",
33 "FigureRadiusVariation,[0,100]",
34 "SpheresRadius,[1,100]",
35 "SpheresRadiusVariation,[0,100]",
36 "Seed,[0,10000]"
37 ]
38
39
40 def random_var(value, variation) :
41 return random.uniform(value, value * (1.0 + variation))
42
43
44 def generate(self, v) :
45 random.seed(self.Seed)
46
48
50 for i in range(self.numSpheres) :
51
52
53 transform =
coat.mat4.Scaling(SimpleGenerator.random_var(self.SpheresRadius, self.SpheresRadiusVariation))
54
55 dv =
coat.vec3.RandNormal() * SimpleGenerator.random_var(self.FigureRadius, self.FigureRadiusVariation)
57 transform = transform * tr
58
59 summ.addTransformed(self.m, transform)
60
61 v.mergeMesh(summ, coat.mat4.Identity, coat.BoolOpType.BOOL_MERGE)
62
63
64 def GeneratePreview(self, scene) :
65
66 scene.removeSubtree()
67
68 t = scene.addChild("Simple")
69 v = t.Volume()
70
71 v.toSurface()
72
73 t.setTransform(coat.mat4.Identity)
74
75 self.generate(t.Volume())
76
77 t.setTransform(t.getTransform() * scene.getTransform())
78
79 scene.selectOne()
80
81
82 def GenerateFinalObject(self, scene) :
83
84 self.GeneratePreview(scene)
85
86
88
89
91
92if not present :
94
mat4 Scaling(float XYZ)
Definition coat.py:578
mat4 Translation(float X, float Y)
Definition coat.py:554
Randomize(int Seed)
Definition coat.py:1207
addExtension(str roomID, str section, any obj)
Add the extension (new tool) into the room.
Definition coat.py:3357
bool checkIfExtensionPresent(str extension_ID)
Check if extension named as extension_ID is present in the 3DCoat.
Definition coat.py:3362
bool cmd(str id, any fn=None)
execute some action in UI as if you pressed on some control
Definition coat.py:3186
toRoom(str name, bool Force=False)
switch to the room
Definition coat.py:3284
vec3 RandNormal()
Definition coat.py:232