-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbreuer.pde
406 lines (382 loc) · 16.5 KB
/
breuer.pde
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
////////////////////////////////////////////////////////////////////////////
//
// parametric breuer collection with bent steel tube and leather strips
//
////////////////////////////////////////////////////////////////////////////
int bTubeR, bCornerR, bStepLength, bShortStepLength, bStepNum, bRatioShortSteps, bRatioFabric, bFabricThickness;
boolean bExtrudeFabric = true;
boolean bClosedPipe;
class Breuer extends Furniture {
ArrayList<Line3D> segmentList;
//ArrayList<Line3D> closingSegmentList;
float tubeLength;
//ArrayList<Line3D> intersectionList;
// ArrayList<Line3D> usedSegmentList;
ArrayList<Line3D> connectionList;
ArrayList<Vec3D> connectorList;
ToxicMesh breuerMesh;
Pipe pipe;
Fabric myFabric;
Breuer() {
reset();
cx = 0;
cy = 0;
Group gBreuer = cp5.addGroup("breuer").setPosition(columnx, marginy).hideBar();
createSlider(gBreuer, "bStepNum", bStepNum, 1, 50, true, "number of steps");
cy += sh/2;
createToggle(gBreuer, "bClosedPipe", bClosedPipe, "closed pipe");
cy += sh/2;
createSlider(gBreuer, "bStepLength", bStepLength, 0, 12, true, "long step length");
createSlider(gBreuer, "bShortStepLength", bShortStepLength, 1, 10, true, "short step length");
createSlider(gBreuer, "bRatioShortSteps", bRatioShortSteps, 0, 10, true, "ratio long/short steps");
cy += sh/2;
createSlider(gBreuer, "bRatioFabric", bRatioFabric, 0, 100, true, "ratio strips");
cy += sh/2;
createSlider(gBreuer, "bTubeR", bTubeR, 5, 50, true, "tube radius");
createSlider(gBreuer, "bCornerR", bCornerR, 10, 500, true, "corner radius");
cy += sh/2;
updateControllerList.add("bCornerR");
updateControllerList.add("bTubeR");
updateControllerList.add("bClosedPipe");
}
void reset () {
bClosedPipe = false;
bTubeR = 10;
bCornerR = 60;
bStepLength = 12;
bShortStepLength = 4;
bStepNum = 25;
bRatioShortSteps = 2;
bRatioFabric = 0;
bFabricThickness = 2;
}
void update() {
pipe.cornerR = bCornerR;
pipe.tubeR = bTubeR;
for (Part thisPart : partList) {
thisPart.update();
}
}
void generate() {
gridSize = 50;
tubeLength = 0;
partList = new ArrayList<Part>();
segmentList = new ArrayList<Line3D>();
// closingSegmentList = new ArrayList<Line3D>();
// if (original) {
// if (breuerMesh == null) {
// breuerMesh = new ToxicMesh();
// breuerMesh.loadMesh("Breuer_m_binary.stl");
// breuerMesh.setLocation(new Vec3D(0, 0, -bTubeR));
// breuerMesh.setScale(1000);
// breuerMesh.offcenter = true;
// breuerMesh.material = "model";
// breuerMesh.update();
// }
// partList.add(breuerMesh);
// }
if (basics) {
pipe = new Pipe();
float stepL = bStepLength*gridSize;
float stepLL = (bStepLength+4)*gridSize;
float stepS = bShortStepLength*gridSize;
pipe.addPoint(new Vec3D(-stepLL/2, 0, 0));
pipe.addPoint(new Vec3D(-stepLL/2, -stepL/2, 0));
pipe.addPoint(new Vec3D(-stepLL/2, -stepL/2, stepL));
pipe.addPoint(new Vec3D(-stepLL/2+stepS, -stepL/2, stepL));
pipe.addPoint(new Vec3D(-stepLL/2+stepS, -stepL/2, stepL-stepS));
pipe.addPoint(new Vec3D(stepLL/2-stepS, -stepL/2, stepL-stepS));
pipe.addPoint(new Vec3D(stepLL/2-stepS, -stepL/2, stepL));
pipe.addPoint(new Vec3D(stepLL/2, -stepL/2, stepL));
pipe.addPoint(new Vec3D(stepLL/2, -stepL/2, 0));
pipe.addPoint(new Vec3D(stepLL/2, 0, 0));
pipe.addPoint(new Vec3D(stepLL/2, stepL/2, 0));
pipe.addPoint(new Vec3D(stepLL/2, stepL/2, stepL));
pipe.addPoint(new Vec3D(stepLL/2-stepS, stepL/2, stepL));
pipe.addPoint(new Vec3D(stepLL/2-stepS, stepL/2, stepL-stepS));
pipe.addPoint(new Vec3D(-stepLL/2+stepS, stepL/2, stepL-stepS));
pipe.addPoint(new Vec3D(-stepLL/2+stepS, stepL/2, stepL));
pipe.addPoint(new Vec3D(-stepLL/2, stepL/2, stepL));
pipe.addPoint(new Vec3D(-stepLL/2, stepL/2, 0));
pipe.addPoint(new Vec3D(-stepLL/2, 0, 0));
pipe.cornerR = bCornerR;
pipe.tubeR = bTubeR;
pipe.material = "metal";
partList.add(pipe);
// float pChairW = 720;
// float pChairH = 515;
// float pChairD = 640;
// float pCornerW = 140;
// float pCornerH = 170;
// pipe.addPoint(new Vec3D(-pChairW/2, 0, 0));
// pipe.addPoint(new Vec3D(-pChairW/2, -pChairD/2, 0));
//
// pipe.addPoint(new Vec3D(-pChairW/2, -pChairD/2, pChairH));
// pipe.addPoint(new Vec3D(-pChairW/2+pCornerW, -pChairD/2, pChairH));
// pipe.addPoint(new Vec3D(-pChairW/2+pCornerW, -pChairD/2, pChairH-pCornerH));
//
// pipe.addPoint(new Vec3D(+pChairW/2-pCornerW, -pChairD/2, pChairH-pCornerH));
// pipe.addPoint(new Vec3D(+pChairW/2-pCornerW, -pChairD/2, pChairH));
// pipe.addPoint(new Vec3D(+pChairW/2, -pChairD/2, pChairH));
// pipe.addPoint(new Vec3D(+pChairW/2, -pChairD/2, 0));
// pipe.addPoint(new Vec3D(+pChairW/2, 0, 0));
//
// pipe.addPoint(new Vec3D(pChairW/2, 0, 0));
// pipe.addPoint(new Vec3D(pChairW/2, pChairD/2, 0));
//
// pipe.addPoint(new Vec3D(pChairW/2, pChairD/2, pChairH));
// pipe.addPoint(new Vec3D(pChairW/2-pCornerW, pChairD/2, pChairH));
// pipe.addPoint(new Vec3D(pChairW/2-pCornerW, pChairD/2, pChairH-pCornerH));
//
// pipe.addPoint(new Vec3D(-pChairW/2+pCornerW, pChairD/2, pChairH-pCornerH));
// pipe.addPoint(new Vec3D(-pChairW/2+pCornerW, pChairD/2, pChairH));
// pipe.addPoint(new Vec3D(-pChairW/2, pChairD/2, pChairH));
//
// pipe.addPoint(new Vec3D(-pChairW/2, pChairD/2, 0));
// pipe.addPoint(new Vec3D(-pChairW/2, 0, 0));
//
// pipe.cornerR = bCornerR;
// pipe.tubeR = bTubeR;
// pipe.material = 1;
// partList.add(pipe);
for (int i =0;i<pipe.pointList.size()-1;i++) {
Line3D newSegment = new Line3D(pipe.pointList.get(i), pipe.pointList.get(i+1));
segmentList.add(newSegment);
tubeLength += newSegment.getLength();
}
}
generateRandomPipe();
generateFabrics();
generated = true;
}
void generateRandomPipe() {
pipe = new Pipe();
validated = true;
int[] lengthList = {
int(bShortStepLength * gridSize), int(bStepLength * gridSize)
};
Vec3D lastDirection = Vec3D.ZERO.copy();
Vec3D lastPoint = loc.copy();
pipe.addPoint(lastPoint.copy());
for (int i=0;i<bStepNum;i++) {
ArrayList<Vec3D> potentialPoints = new ArrayList<Vec3D>();
ArrayList<Vec3D> potentialDirections = new ArrayList<Vec3D>();
for (int j=0; j<normalList.length; j++) {
Vec3D newDirection = normalList[j].copy(); // get direction
for (int k=0; k < lengthList.length; k++) {
int newLength = lengthList[k]; // get length
// println(newDirection+" "+newLength);
if (stepIsValid(lastPoint, lastDirection, newDirection, newLength)) {
Vec3D newPoint = lastPoint.copy();
newPoint.addSelf(newDirection.scale(newLength));
potentialPoints.add(newPoint);
potentialDirections.add(newDirection);
}
}
}
if (potentialPoints.size() > 0) {
//// here we need to include ratio of short / long strips !!!
int randomPointNum = int(random(potentialPoints.size()));
Vec3D newPoint = potentialPoints.get(randomPointNum);
pipe.addPoint(newPoint.copy());
Line3D newSegment = new Line3D(lastPoint, newPoint);
segmentList.add(newSegment);
tubeLength += newSegment.getLength();
lastPoint = newPoint.copy();
lastDirection = potentialDirections.get(randomPointNum);
}
else { // we got stacked !
validated = false;
println("error");
}
}
if (bClosedPipe) {
validated = true;
while (!lastPoint.equals(loc)) {
/// loop through all lentgth/direction combinations and keep good ones
ArrayList<Vec3D> potentialPoints = new ArrayList<Vec3D>();
ArrayList<Vec3D> potentialDirections = new ArrayList<Vec3D>();
float bestDistance = lastPoint.distanceTo(loc);
Vec3D bestDirection = null;
Vec3D bestPoint = null;
for (int i=0; i<normalList.length; i++) {
for (int j=0; j< lengthList.length; j++) {
Vec3D potentialDirection = normalList[i].copy();
int stepLength = lengthList[j];
if (stepIsValid(lastPoint, lastDirection, potentialDirection, stepLength)) {
Vec3D potentialPoint = lastPoint.copy();
potentialPoint.addSelf(potentialDirection.scale(stepLength));
potentialPoints.add(potentialPoint.copy());
potentialDirections.add(potentialDirection.copy());
float potentialDistance = potentialPoint.distanceTo(loc);
if (bestDistance > potentialDistance) {
bestPoint = potentialPoint.copy();
bestDirection = potentialDirection.copy();
bestDistance = potentialDistance;
}
}
}
}
if (bestPoint == null) { // no points get us closer to target :(
if (potentialPoints.size() > 0) { // check there are at least one potential point to try a different path
int randomPoint = int(random(potentialPoints.size()));
bestPoint = potentialPoints.get(randomPoint);
bestDirection = potentialDirections.get(randomPoint);
}
}
if (bestPoint != null) { // ok we got a point !
pipe.addPoint(bestPoint);
Line3D newSegment = new Line3D(lastPoint, bestPoint);
segmentList.add(newSegment);
tubeLength += newSegment.getLength();
//
//closingSegmentList.add(newSegment);
lastDirection = bestDirection.copy();
lastPoint = bestPoint.copy();
}
else { // we got stacked :(
validated = false;
break;
}
}
}
if (pipe.pointList.size()>0) {
printConsole("!"+tubeLength+" mm tube longitute in "+segmentList.size()+" segments ");
partList.add(pipe);
pipe.cornerR = bCornerR;
pipe.tubeR = bTubeR;
pipe.material = "metal";
}
}
boolean stepIsValid(Vec3D lastPoint, Vec3D lastStepDirection, Vec3D stepDirection, float stepLength) {
// check if direction is same or opposite
if (stepDirection.equals(lastStepDirection)) { // || stepDirection.equals(lastStepDirection.getInverted()) ) {
return false;
}
Vec3D newPoint = lastPoint.copy();
newPoint.addSelf(stepDirection.scale(stepLength));
// check if new point is within boundaries
if (!newPoint.isInAABB(worldBox)) {
return false;
}
// check intersections
Line3D newSegment = new Line3D(lastPoint, newPoint);
for (Line3D thisSegment : segmentList) {
if (checkLinesCollision(newSegment, thisSegment)) {
return false;
}
}
return true;
}
void generateFabrics() {
// usedSegmentList = new ArrayList<Line3D>();
connectorList = new ArrayList<Vec3D>();
connectionList = new ArrayList<Line3D>();
// iterate over all segments of the piece in order to place fabrics
ArrayList<Vec3D> thisPointList = new ArrayList();
ArrayList<Vec3D> otherPointList = new ArrayList();
for (Line3D thisSegment : segmentList) {
for (Line3D otherSegment : segmentList) {
ArrayList<Line3D> thisConnectionList = new ArrayList();
if (!thisSegment.equals(otherSegment) && // check we are not connecting the same segments
checkLinesParallel(thisSegment, otherSegment) && // check to connect only parallel segments
!checkLinesCoincident(thisSegment, otherSegment) && // check segments are not coincident
!(thisSegment.a.z == 0 && thisSegment.b.z == 0 && otherSegment.a.z == 0 && otherSegment.b.z == 0)) { // check both segments are not on the floor
// calculate points on segment that might potentially be connected
thisPointList = new ArrayList<Vec3D>();
otherPointList = new ArrayList<Vec3D>();
for (Vec3D thisPoint : thisSegment.splitIntoSegments(null,gridSize,false)) { // false to ignore first point
if (!thisPoint.equals(thisSegment.b)) { // and this to ignore last point
thisPointList.add(thisPoint.copy());
connectorList.add(thisPoint.copy()); // for displaying connectors only...
}
}
for (Vec3D otherPoint : otherSegment.splitIntoSegments(null,gridSize,false)) {
if (!otherPoint.equals(otherSegment.b)) { // to avoid including last point
otherPointList.add(otherPoint.copy());
connectorList.add(otherPoint.copy()); // for displaying connectors only...
}
}
// calculate all possible connections between the points
for (Vec3D thisPoint : thisPointList) {
// we look for the closest point on this point to the other line (which will connect always with a perpendicular line)
Vec3D closestPoint = otherSegment.closestPointTo(thisPoint);
Line3D closestLine = new Line3D(thisPoint, closestPoint);
Vec3D closestDirection = closestLine.getDirection().normalize();
for (Vec3D otherPoint : otherPointList) {
Line3D thisLine = new Line3D (thisPoint, otherPoint);
Vec3D thisDirection = thisLine.getDirection().normalize();
// and we only add connections that are parallel to the closest line (so they are perpendicular and never skewed or crossing)
if (thisDirection.equals(closestDirection)) {
thisConnectionList.add(thisLine);
connectionList.add(thisLine); // for displaying posible connections only...
}
}
}
// we have all possible connections betwen every pair of parallel segment, let's place the pieces of fabric where appropriate
// check if segment is free
// boolean free = true;
// for (Line3D currentSegment : usedSegmentList) {
// if (currentSegment.equals(thisSegment) || currentSegment.equals(otherSegment)) {
// free = false;
// break;
// }
// }
// usedSegmentList.add(thisSegment);
// usedSegmentList.add(otherSegment);
for (int i=0;i<(thisConnectionList.size()/2);i++) {
if (random(100)<bRatioFabric) {
Fabric newFabric = new Fabric();
Line3D firstConnection = thisConnectionList.get((i*2));
Line3D lastConnection = thisConnectionList.get((i*2)+1); // thisConnectionList.size()-1
newFabric.a = firstConnection.a;
newFabric.b = firstConnection.b;
newFabric.c = lastConnection.b;
newFabric.d = lastConnection.a;
newFabric.thickness = bFabricThickness;
partList.add(newFabric);
newFabric.material = "leather";
}
}
}
}
}
}
void display() {
for (Part thisPart : partList) {
thisPart.display();
}
if (details) {
for (Line3D thisSegment :segmentList) {
stroke(color(0, 0, strokeColor), strokeAlpha);
strokeWeight(thickStroke);
fx.line(thisSegment);
}
// for (Line3D thisSegment : segmentList) {
// for (Line3D otherSegment : segmentList) {
// stroke(color(0, 0, strokeColor), strokeAlpha);
// strokeWeight(thinStroke);
// if (!thisSegment.equals(otherSegment) && checkLinesCollision(thisSegment, otherSegment)) {
// stroke(color(strokeColor, 0, 0), strokeAlpha);
// strokeWeight(thickStroke);
// fx.line(thisSegment);
// fx.line(otherSegment);
// }
// fx.line(thisSegment);
// }
// }
for (Line3D thisLine : connectionList) {
stroke(color(strokeColor, 0, 0), strokeAlpha/2);
strokeWeight(thinStroke);
// fx.line(thisLine);
}
}
if (dots) {
for (Vec3D thisPoint : connectorList) {
stroke(blueColor);
strokeWeight(markerStroke);
drawMarker(thisPoint);
}
}
}
}