-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpolyhedron_usage6.jscad
113 lines (92 loc) · 3.1 KB
/
polyhedron_usage6.jscad
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
// EXAMPLE d'utilisation des fonctions de pontage et d'extrusion
// Gilbert Duval 03/06/2019
function creePoly (p) {
// cree un polygone avec le contenu de p [Vector3D]
return new CSG.Polygon(p.map(v=>new CSG.Vertex(new CSG.Vector3D(v))));
}
function extrudeBetweenFaces(f1, f2){
var r, i, i2, tmp;
r = [];
r.push(f2);
for(i = 0; i < f1.vertices.length; i++){
i2 = (i + 1) % f1.vertices.length;
tmp = [
f1.vertices[i].pos, f1.vertices[i2].pos,
f2.vertices[i2].pos, f2.vertices[i].pos
];
r.push(creePoly(tmp));
}
return r;
}
function ponte(f1, f2, dk = 0){
var r, i, i2, tmp;
r = [];
r.push(f1, f2);
f1vl = f1.vertices.length;
f2vl = f2.vertices.length;
for(i = 0; i < f1vl; i++){
i2 = (i + 1) % f1vl;
//j = (f2vl-1) -i;
j = ((f2vl-1) -i +dk) % f2vl;
j2 = (j + 1) % f2vl;
tmp = [
f1.vertices[i].pos, f1.vertices[i2].pos,
f2.vertices[j].pos, f2.vertices[j2].pos
];
r.push(creePoly(tmp));
}
return r;
}
function cumule(t, l){ /// ajoute le contenu de l dans t
l.forEach(function (f){ t.push(f);} );
return t;
}
function creeMur(source, v1, f1, v2, f2, d =0){
return ponte(source[v1].polygons[f1], source[v2].polygons[f2], d);
}
function affVolEtFace(vol, nFace){
return [
color("blue", CSG.fromPolygons([vol.polygons[nFace]])),
CSG.fromPolygons(vol.polygons)
];
}
function getParameterDefinitions() {
return [
{ type: 'group', caption: 'EXAMPLE Pontage et Extrusion'},
{ name: 'mode', type: 'choice', caption:'Mode ?'
,values: ['D','P']
,captions: ['dev','prod']}
];
}
function main(params){
var r = [], R = [];
var volumes = [];
volumes.push(cube({size:4, center:[true,true,false]}).scale(1).translate([0,0,2+10]));
volumes.push(cube({size:4, center:[true,true,false]}).scale(2).translate([20,0,0+10]));
volumes.push(cube({size:4, center:[true,true,false]}).scale(1).translate([20,20,2+10]));
volumes.push(cube({size:4, center:[true,true,false]}).scale(2).translate([0,20,0+10]));
R.push(creeMur(volumes, 0, 1, 1, 0));
R.push(creeMur(volumes, 1, 3, 2, 2));
R.push(creeMur(volumes, 2, 0, 3, 1));
R.push(creeMur(volumes, 3, 2, 0, 3));
volumes.forEach(function (f) {
var tmp = f.polygons[4];
var z = tmp.vertices[0].pos.z;
R.push(extrudeBetweenFaces(tmp, tmp.translate(tmp.plane.normal.times(z))));
});
switch(params.mode){
case 'D' :
cumule(r, affVolEtFace(volumes[0], 4));
cumule(r, affVolEtFace(volumes[1], 3));
cumule(r, affVolEtFace(volumes[2], 0));
cumule(r, affVolEtFace(volumes[3], 2));
R.forEach(function (f){ cumule(r, [color([1,1,1,0.3], CSG.fromPolygons(f))]); });
break;
case 'P' :
volumes.forEach(function (f){ cumule(r, f.polygons); });
R.forEach(function (f){ cumule(r, f) });
r = CSG.fromPolygons(r);
break;
}
return r;
}