-
Notifications
You must be signed in to change notification settings - Fork 3
/
sq_gorille.js
254 lines (230 loc) · 25.3 KB
/
sq_gorille.js
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
const jscad = require('@jscad/modeling')
const { curves, maths, extrusions, primitives, transforms, booleans,
colors, geometries, measurements, utils } = jscad
const { bezier } = curves
const { slice, extrudeLinear } = extrusions
const { cuboid, polygon, polyhedron } = primitives
const { intersect, subtract,union } = booleans
const { center, scale, translateX, translateY, translateZ, translate
,rotateX, rotateY, rotateZ } = transforms
const { colorize } = colors
const { geom3, poly3 } = geometries
const { vec3 } = maths
const { measureBoundingBox, measureArea } = measurements
const { degToRad } = utils
const getParameterDefinitions = () => {
return [
{name: 'g1', caption: 'Lignes', type: 'group'},
{name: 'l0', caption: '#1:', type: 'slider', min:"0", max:"100", step:"1", initial:"50"},
{name: 'l1', caption: '#2:', type: 'slider', min:"0", max:"100", step:"1", initial:"0"},
{name: 'l2', caption: '#3:', type: 'slider', min:"0", max:"100", step:"1", initial:"0"},
{name: 'l3', caption: '#4:', type: 'slider', min:"0", max:"100", step:"1", initial:"0"},
{name: 'l4', caption: '#5:', type: 'slider', min:"0", max:"100", step:"1", initial:"0"},
{name: 'l5', caption: '#6:', type: 'slider', min:"0", max:"100", step:"1", initial:"0"},
{name: 'l6', caption: '#7:', type: 'slider', min:"0", max:"100", step:"1", initial:"0"},
{name: 'l7', caption: '#8:', type: 'slider', min:"0", max:"100", step:"1", initial:"0"},
{name: 'l8', caption: '#9:', type: 'slider', min:"0", max:"100", step:"1", initial:"0"},
{name: 'l9', caption: '#10:',type: 'slider', min:"0", max:"100", step:"1", initial:"0"},
{name: 'g2', caption: 'Colonnes', type: 'group'},
{name: 'c0', caption: '#1:', type: 'slider', min:"0", max:"100", step:"1", initial:"50"},
{name: 'c1', caption: '#2:', type: 'slider', min:"0", max:"100", step:"1", initial:"0"},
{name: 'c2', caption: '#3:', type: 'slider', min:"0", max:"100", step:"1", initial:"0"},
{name: 'c3', caption: '#4:', type: 'slider', min:"0", max:"100", step:"1", initial:"0"},
{name: 'c4', caption: '#5:', type: 'slider', min:"0", max:"100", step:"1", initial:"0"},
{name: 'c5', caption: '#6:', type: 'slider', min:"0", max:"100", step:"1", initial:"0"},
{name: 'c6', caption: '#7:', type: 'slider', min:"0", max:"100", step:"1", initial:"0"},
{name: 'c7', caption: '#8:', type: 'slider', min:"0", max:"100", step:"1", initial:"0"},
{name: 'c8', caption: '#9:', type: 'slider', min:"0", max:"100", step:"1", initial:"0"},
{name: 'c9', caption: '#10:',type: 'slider', min:"0", max:"100", step:"1", initial:"0"},
{name: 'g3', caption: 'Parametres', type: 'group'},
//,{name: 'v', type:'text', caption: 'volume:', initial: 'test'}
,{name: 'ep', type:'float', caption: 'ep (mm):', initial: 6.0},
,{name: 'c3d',type:'checkbox', checked: true, initial: '1', caption: '3d ?' }
]}
volume = function () {
const faces =[[0,9,1],[1,9,2],[1,10,5],[2,6,1],[2,8,6],[2,11,8],[2,12,7],[5,49,24],[6,10,1],[6,33,10],[6,43,30],[7,11,2],[8,13,6],[8,71,13],[9,12,2],[9,21,12],[10,42,5],[12,39,7],[12,46,39],[13,43,6],[13,71,43],[21,46,12],[21,61,46],[24,25,5],[24,49,25],[30,33,6],[30,60,33],[33,42,10],[33,60,42],[42,49,5],[42,68,49],[42,77,68],[46,96,39],[49,73,25],[60,77,42],[60,108,77],[61,72,46],[61,73,68],[68,72,61],[68,73,49],[68,77,72],[71,84,43],[71,119,84],[72,96,46],[72,102,96],[77,102,72],[77,108,102],[102,122,96],[102,125,122],[108,125,102],[147,163,161],[147,170,163],[147,173,152],[152,153,147],[152,201,153],[153,170,147],[153,236,170],[161,173,147],[161,181,173],[161,198,181],[161,206,198],[163,206,161],[170,206,163],[170,235,206],[170,236,235],[173,201,152],[177,212,187],[177,215,212],[181,187,173],[181,189,187],[181,227,189],[187,189,177],[187,201,173],[187,212,201],[198,227,181],[198,237,227],[201,224,153],[201,238,224],[206,235,198],[207,215,177],[207,244,215],[212,231,201],[212,241,231],[215,241,212],[215,244,241],[224,236,153],[224,238,235],[231,238,201],[231,246,238],[231,250,246],[235,236,224],[235,237,198],[235,238,237],[237,242,227],[237,251,242],[238,246,237],[241,250,231],[244,250,241],[246,251,237],[250,251,246],[120,157,125],[122,150,145],[125,150,122],[125,157,150],[132,138,115],[132,155,138],[150,188,145],[155,180,138],[155,199,180],[157,175,150],[175,186,150],[175,203,186],[175,211,203],[177,188,186],[177,208,188],[177,227,208],[186,188,150],[186,207,177],[188,196,145],[188,240,196],[189,227,177],[196,240,234],[199,200,180],[199,211,200],[199,217,211],[203,207,186],[203,218,207],[203,229,218],[208,240,188],[208,242,240],[211,217,203],[217,229,203],[217,239,229],[218,244,207],[227,242,208],[229,243,218],[229,249,243],[239,249,229],[240,245,234],[240,247,245],[242,247,240],[242,250,247],[242,251,250],[243,244,218],[243,250,244],[247,248,245],[247,249,248],[247,250,249],[248,249,239],[249,250,243],[139,156,143],[156,160,143],[156,172,160],[156,185,172],[160,168,143],[160,191,168],[160,197,191],[172,185,183],[172,197,160],[174,204,195],[174,205,184],[183,193,184],[183,197,172],[184,197,183],[184,204,174],[184,205,197],[184,209,190],[185,193,183],[185,225,193],[190,204,184],[190,232,204],[191,213,168],[191,220,213],[193,209,184],[193,225,209],[195,205,174],[195,233,205],[197,220,191],[197,228,220],[204,210,195],[204,232,210],[205,228,197],[205,233,228],[209,223,190],[209,225,223],[210,233,195],[214,221,185],[214,222,221],[220,221,213],[220,230,221],[221,222,213],[221,225,185],[221,230,225],[223,232,190],[225,228,223],[225,230,228],[228,230,220],[228,232,223],[228,233,232],[232,233,210],[28,52,34],[28,56,52],[40,51,28],[40,83,51],[43,45,30],[43,55,45],[43,84,55],[45,60,30],[45,79,60],[51,56,28],[51,76,56],[51,83,76],[52,54,34],[52,87,54],[52,103,87],[54,97,66],[55,79,45],[55,84,70],[56,76,70],[56,91,52],[56,95,91],[56,115,95],[60,120,108],[70,76,55],[70,115,56],[76,79,55],[76,94,79],[79,120,60],[83,94,76],[83,105,94],[84,115,70],[84,119,115],[87,97,54],[87,111,97],[87,126,111],[91,103,52],[94,114,79],[94,134,114],[97,110,66],[97,128,110],[103,126,87],[105,123,94],[110,123,105],[110,128,123],[111,128,97],[114,120,79],[119,132,115],[120,125,108],[123,134,94],[126,128,111],[7,29,11],[7,44,29],[11,59,8],[29,59,11],[29,99,59],[39,44,7],[39,96,44],[44,86,29],[44,93,85],[44,96,93],[59,71,8],[59,116,71],[71,127,119],[81,86,85],[81,99,86],[81,106,98],[81,113,106],[85,86,44],[85,90,81],[85,107,90],[86,99,29],[90,107,104],[90,113,81],[93,107,85],[93,122,107],[96,122,93],[98,99,81],[98,118,99],[98,121,118],[99,116,59],[99,118,116],[104,113,90],[104,117,113],[104,129,117],[104,131,129],[106,121,98],[106,135,121],[107,131,104],[113,135,106],[116,127,71],[116,133,127],[117,124,113],[117,129,124],[118,133,116],[119,137,132],[121,130,118],[122,131,107],[124,135,113],[127,137,119],[130,133,118],[17,26,22],[17,74,26],[17,82,74],[19,31,22],[19,32,27],[19,66,31],[22,23,17],[22,31,23],[22,32,19],[23,35,17],[23,36,35],[26,32,22],[26,64,32],[26,74,64],[27,34,19],[27,40,28],[27,41,40],[28,34,27],[31,36,23],[31,50,36],[31,66,50],[32,41,27],[32,58,41],[32,64,58],[34,66,19],[35,47,17],[35,65,47],[36,65,35],[41,62,40],[47,82,17],[50,65,36],[50,78,65],[54,66,34],[58,62,41],[58,89,62],[62,83,40],[62,105,83],[64,67,65],[64,74,67],[64,78,58],[65,67,47],[65,78,64],[66,78,50],[66,89,78],[66,110,89],[67,82,47],[74,82,67],[78,89,58],[89,105,62],[89,110,105],[1,3,0],[1,5,3],[3,4,0],[3,14,4],[3,25,14],[4,9,0],[4,21,9],[4,38,21],[5,25,3],[14,16,4],[14,18,15],[14,48,18],[15,16,14],[15,38,16],[15,57,37],[16,38,4],[18,20,15],[18,63,20],[20,57,15],[20,100,57],[20,109,100],[21,69,61],[21,75,69],[25,48,14],[25,53,48],[25,73,53],[37,38,15],[37,75,38],[37,92,75],[38,75,21],[48,63,18],[48,88,63],[53,73,69],[53,80,48],[57,92,37],[57,100,92],[63,109,20],[69,73,61],[69,80,53],[75,80,69],[75,101,80],[80,88,48],[80,101,88],[88,109,63],[92,101,75],[92,112,101],[100,112,92],[101,109,88],[101,112,109],[109,112,100],[91,136,103],[95,136,91],[95,141,136],[103,136,126],[114,149,120],[115,141,95],[123,143,134],[123,146,139],[126,158,128],[128,146,123],[128,158,146],[134,149,114],[134,168,149],[136,144,126],[136,167,144],[138,141,115],[138,178,141],[138,180,178],[139,143,123],[141,167,136],[141,178,167],[143,168,134],[144,158,126],[144,192,158],[146,156,139],[146,185,156],[146,194,185],[149,157,120],[149,171,157],[157,211,175],[158,194,146],[167,192,144],[167,202,192],[168,171,149],[168,179,171],[168,213,179],[171,211,157],[178,200,179],[178,202,167],[179,200,171],[179,202,178],[179,222,202],[180,200,178],[192,194,158],[192,214,194],[194,214,185],[200,211,171],[202,214,192],[202,222,214],[213,222,179],[121,148,130],[122,140,131],[122,145,140],[124,142,135],[127,154,137],[129,142,124],[129,151,142],[130,165,133],[131,151,129],[133,154,127],[133,159,154],[133,165,159],[135,148,121],[135,162,148],[137,155,132],[137,182,155],[140,151,131],[140,164,151],[142,151,135],[145,164,140],[145,176,164],[145,196,176],[148,165,130],[151,162,135],[151,169,162],[154,182,137],[154,226,182],[159,226,154],[162,165,148],[162,169,165],[164,169,151],[164,176,169],[165,166,159],[165,169,166],[166,219,159],[169,216,166],[176,216,169],[182,199,155],[182,239,199],[196,216,176],[196,234,216],[199,239,217],[216,219,166],[216,245,219],[219,226,159],[219,248,226],[226,239,182],[226,248,239],[234,245,216],[245,248,219]]
const vertices = [[-119.34107456,-63.17424786,-73.02046592],[-116.22108326,-36.89425004,-65.76046569],[-110.58108005,-55.13424695,13.8595342],[-107.28107319,-59.99424946,-120.42046363],[-104.16108188,-90.35425198,-101.2204705],[-103.68108234,-7.13424981,-78.42046363],[-103.38107548,-19.73424923,28.31953328],[-100.80107365,-83.99424946,38.81953328],[-99.36107502,-34.43424809,73.37953179],[-99.00107822,-74.87424672,-52.92046363],[-98.46107731,-6.65424955,-21.12046535],[-97.86107502,-59.09425175,76.67953294],[-91.08108005,-78.47424901,-16.1404658],[-90.36108074,-13.19424975,68.93953317],[-89.94107685,-80.51424992,-158.46046454],[-89.88107548,-115.79424489,-200.70047004],[-88.20107708,-104.87424672,-145.68046958],[-87.0610796,114.42574871,-213.66046912],[-85.44107685,-90.95424855,-184.44046409],[-84.36108074,185.58575237,-132.12046821],[-82.5610796,-89.63424695,-213.66046912],[-82.02107868,-76.73424923,-68.10046775],[-82.02107868,171.30574596,-188.64046866],[-81.72107754,187.44574916,-206.46046454],[-80.58108005,-8.39424932,-87.18046386],[-80.52107868,-50.99424946,-134.64046866],[-80.04107914,120.54575145,-205.14045722],[-79.68107662,152.52575099,-115.68046958],[-79.20107708,127.38574779,-54.78046615],[-78.48107777,-77.09425175,85.31953614],[-78.30107937,-3.65424955,31.13953488],[-77.22107754,195.78575695,-157.08046729],[-76.20107708,162.60575283,-184.56046683],[-75.60108051,-9.17424929,15.83953517],[-75.60108051,158.2857455,-94.32046706],[-74.94107685,198.18574321,-213.66046912],[-72.84108028,205.26574504,-200.58046729],[-72.0610796,-126.53425038,-201.12046821],[-72.00107822,-116.03425038,-141.00046546],[-71.64107571,-95.21424878,23.69953483],[-71.10108051,110.34574688,-81.06046683],[-70.98107777,127.50575054,-120.8404618],[-69.12108097,-4.85424948,-22.5604654],[-69.00107822,19.74575031,65.03953546],[-68.22107754,-88.43424809,74.39953225],[-68.22107754,36.30575168,-4.98046536],[-67.98107777,-80.03425038,-15.96046598],[-66.96107731,165.84574688,-213.66046912],[-66.72107754,-85.55425084,-173.2204705],[-65.40107593,-14.51424992,-67.08046729],[-63.48107777,201.18574321,-168.24047095],[-62.52107868,120.90574825,-15.30046517],[-61.80107937,162.24575603,-12.30046517],[-61.5610796,-59.51424992,-135.30046088],[-61.08108005,175.14575374,-56.22046477],[-60.78107891,63.60575283,1.2595345],[-60.72107754,128.52575099,13.07953494],[-60.18107662,-116.45424855,-213.66046912],[-59.64107571,155.70575511,-160.80046088],[-57.72107754,-54.53425038,112.019535],[-57.00107822,3.24575067,-21.78046615],[-55.98107777,-59.33425152,-63.60046775],[-55.74107799,118.02575099,-112.50046546],[-55.68107662,-78.77425015,-190.980465],[-55.02107868,161.34574688,-187.26045997],[-54.66107616,197.40575969,-213.42046363],[-54.60108051,178.20575511,-100.74047095],[-54.48107777,164.40574825,-204.8404618],[-54.30107937,-37.55425084,-49.20046432],[-54.24107799,-75.95424855,-107.82046134],[-53.04107914,81.90574825,18.29953425],[-52.44107685,-29.63424981,107.2795295],[-52.32107983,-68.03425038,-17.6404658],[-51.72107754,-40.13424981,-87.60046775],[-51.72107754,109.20575511,-205.14045722],[-49.44107685,-122.63425267,-152.16046912],[-49.26107845,98.34574688,-31.02046592],[-49.20107708,-39.71424878,-18.24046523],[-49.02107868,181.68575466,-158.88046271],[-47.28107891,35.70574939,-42.00046546],[-46.80107937,-92.21424878,-144.78046042],[-46.68107948,-133.37424672,117.83953088],[-45.9010788,118.86574733,-213.66046912],[-44.04107914,110.82574642,-53.22046477],[-42.72107754,31.20574939,76.79953568],[-41.4010788,-122.03425038,95.03953546],[-41.04107914,-108.65425312,122.63953774],[-40.74107799,193.20575511,-0.72046544],[-40.5610796,-82.73424923,-171.00046546],[-39.48107777,141.36574733,-116.82046134],[-39.00107822,-146.99424946,75.29953568],[-37.98107777,143.46574962,47.93953317],[-35.88107834,-131.87424672,-197.94047553],[-35.64107857,-99.7142545,56.81953614],[-35.16107902,98.94574916,-59.64046294],[-34.5610796,114.84574688,41.03953546],[-33.78107891,-95.09425175,21.11953443],[-33.66107902,179.1657542,-68.58046729],[-33.54107914,-137.81424534,144.47953408],[-33.54107914,-91.91424763,143.63953774],[-33.18107948,-94.97424901,-213.6004563],[-32.16107902,-103.73425496,-162.12046821],[-31.26107845,-72.35425198,-18.72046477],[-28.5610796,174.36574733,38.45953362],[-26.76107845,-164.03425038,52.67953294],[-26.46107731,129.42574871,-67.62046821],[-26.4010788,-185.3342458,122.87953179],[-26.22107754,-134.57425129,62.39953225],[-24.66107902,-15.65424883,-41.58046443],[-24.48107777,-77.63424695,-202.8604737],[-23.46107874,163.38574779,-70.74046523],[-22.26107845,192.54575145,-30.84046466],[-21.84107885,-92.81425107,-198.8404618],[-20.16107759,-189.7142545,95.09953683],[-19.32107839,51.06575191,-72.6604634],[-18.78107891,73.50575054,56.39953225],[-17.76107845,-61.01424992,146.03953546],[-17.22107754,-200.15425312,62.99953454],[-17.04107771,-126.95424855,171.71953958],[-13.44107828,-5.33424938,103.13953774],[-10.08107791,12.42575014,-58.32046706],[-9.66107831,-180.53425038,145.19953912],[-7.50107822,-110.75424397,29.09953397],[-3.72107825,131.82574642,-53.58046729],[-3.12107811,-209.63424122,74.03953546],[-2.88107816,-51.11425221,-32.58046443],[-2.64107821,183.6657542,24.11953443],[-2.34107814,-37.97424901,137.2795295],[-0.24107822,177.12575328,-24.84046466],[-0.0010782228,-186.47424901,38.03953546],[0.5389218,-148.55425084,172.67953866],[0.89892181,-152.27424443,47.45953362],[2.63892176,24.36575019,87.59953683],[7.43892183,-115.49424946,172.79952996],[7.97892203,90.00575054,-73.44046409],[10.67892161,-190.19425404,109.55953591],[11.15892186,146.76574504,52.91953271],[11.57892146,-9.23424923,103.43953317],[12.23892155,67.50575054,62.57953637],[17.15892115,146.58575237,-57.00046546],[18.53892126,-136.07425129,55.97953408],[19.01892223,108.24575603,45.05953591],[19.25892201,-196.37424672,64.31953614],[19.67892161,126.36574733,-51.36046798],[21.47892132,176.04575145,37.6795358],[21.89892235,-99.95424855,23.87953465],[22.25892201,184.02575099,-47.94046409],[23.0989212,-100.37424672,-186.24047095],[24.41892281,-170.3342458,141.05953591],[25.25892201,49.08575237,-69.12046821],[26.45892086,-68.51424992,-23.04046495],[28.85892143,-160.49424946,53.81953614],[29.15892258,-83.57425129,-178.08046729],[29.15892258,-80.21424878,-213.54046638],[29.51892223,-50.63424695,131.519535],[29.9389204,28.02575099,83.87953179],[31.01892223,153.48575008,-97.02046592],[31.25892201,4.62575042,-48.12046821],[31.73892155,196.98576152,-2.5804655],[33.77892246,-85.19424832,142.61953729],[34.01892223,131.04575145,-103.80046088],[34.37892189,-125.87424672,-178.68046958],[35.63892212,-176.69425404,109.55953591],[37.25892201,-130.31424534,-202.50046546],[37.37892189,-132.53425038,79.019535],[37.97892132,-128.87424672,144.71953958],[39.11892166,-110.09425175,127.07953637],[39.41892281,145.92574871,46.8595342],[40.49892178,110.04575145,-48.72046477],[43.13892212,-126.53425038,101.21953958],[43.13892212,-123.23425496,-213.66046912],[43.19892063,41.64575088,-46.20046432],[43.91892281,158.46574962,-120.96046454],[45.53892269,-93.83425152,-153.00046546],[45.65892258,136.56575191,-202.80046088],[45.95892086,-11.03424966,-29.22046477],[48.71892109,-90.95424855,61.37953179],[49.49892178,-40.67425072,-79.56046683],[49.91891995,97.80574596,23.99953454],[49.91891995,109.20575511,-24.12046535],[50.63891926,63.90574825,36.29953568],[50.99892178,-92.75424969,-128.76045997],[50.99892178,-23.93424952,104.57953637],[50.99892178,180.84574688,-164.76045997],[51.05892315,184.62575328,-186.8404618],[51.77892246,172.38574779,-97.980465],[53.03892269,-39.65425026,-38.28046615],[53.87891903,-67.31425107,-125.3404618],[54.41891995,-71.63424695,-17.22046477],[54.47892132,-72.89424717,-91.20046432],[54.95892086,191.58575237,-213.66046912],[56.09892407,117.18575466,-110.40046317],[56.27892246,163.98575008,2.87953448],[57.11892452,197.58575237,-137.04046638],[57.23892155,178.80574596,-57.60046775],[57.77892246,103.80574596,-207.00046546],[58.97892132,-94.91424763,18.95953505],[60.53892269,161.46574962,-168.90046317],[61.91891995,-118.85424626,-140.94046409],[61.91891995,26.22574985,66.11953729],[62.03892269,57.8457526,-10.86046512],[62.15891972,-83.75424969,-172.20047004],[62.27892246,129.72575557,6.65953463],[63.05892315,-11.27424943,-1.44046543],[63.47892132,155.1657542,-213.54046638],[63.59892407,136.26574504,-193.92046363],[63.95892086,-127.37424672,-198.00046546],[65.69892063,-8.63424981,-34.74046523],[67.49892178,-79.01424992,-45.90046603],[67.97892132,206.58575237,-191.64046866],[68.9389204,109.14575374,-213.66046912],[70.13891926,25.14575088,-3.96046562],[70.19892063,-46.19424832,-123.24047095],[70.31892338,111.54575145,-90.42046363],[70.37891903,163.92574871,-51.6604634],[72.11892452,-9.71424949,-80.94046409],[73.85892429,-86.39424717,77.3395366],[74.57892361,12.12575042,50.87953179],[75.29892292,-2.15424955,-11.6404658],[75.41891995,-67.13424695,96.71953958],[75.59892407,151.50575054,-153.00046546],[77.33892384,156.96574962,-102.24047095],[78.77892246,127.08575237,-57.18046386],[78.77892246,199.80574596,-212.82047278],[79.07892361,-83.21424878,-192.90047462],[79.25892201,191.94574916,-131.46046454],[79.61892452,-33.29425061,90.05953591],[79.97892132,-75.29425061,-65.76046569],[81.35892429,170.22575557,-185.28046042],[84.95892086,-10.91424978,25.55953591],[85.19892063,173.2857455,-142.20047004],[85.31892338,-56.99424946,-139.02046592],[85.97892132,144.30574596,-213.6004563],[88.31892338,120.36574733,-210.6004563],[88.67892017,-89.87424672,40.43953317],[89.27892246,-116.63425267,-200.94047553],[89.81892338,-94.73424923,-213.66046912],[90.29892292,-104.93424809,-127.38046271],[90.71892109,-85.85425198,-154.32046134],[91.85892429,-5.45424962,63.23953431],[92.87891903,-78.47424901,-14.10046489],[93.53892269,-14.99424946,-99.30046088],[100.01892223,-74.45424855,-53.82046706],[100.55892315,-10.37424958,-18.0604654],[101.75891628,-5.51424956,-66.60046775],[102.2989172,-75.41424763,58.79953568],[106.55892315,-61.55425084,-122.16046912],[108.41891995,-60.29425061,3.47953444],[109.25891628,-42.53425038,52.07953637],[110.81891766,-32.69424832,1.97953462],[117.59892407,-34.67425072,-75.78046615],[119.15892544,-63.71424878,-73.14046294]]
const groups = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10]
return {faces:faces, vertices:vertices, groups:groups}
}
const main = (params) => {
const sc = 1, ep = params.ep *2
//const vv = require('./' + params.v + '.obj')
//const vv = require('./0002.obj')
const vd = volume()
const vv = polyhedron({points: vd.vertices, faces: vd.faces})
let vol = center({}, rotateX(degToRad(90), vv))
let r = [], rH = [], rV = []
let bV = measureBoundingBox(vol)
//vol = translate([-bV[0][0], -bV[0][1], -bV[0][2]], vol)
//bV = measureBoundingBox(vol)
// Recup parametres
const pv = Object.values(params)
const lH = pv.slice(0,10).filter(Number).map(x => (x-50)/100)
const lV = pv.slice(10,20).filter(Number).map(x => (x-50)/100)
console.log(pv,lH, lV)
// 1°) Traverses en X (H)
fH = bV[1][0] - bV[0][0]
mH = (bV[1][0] + bV[0][0]) / 2
var trH = cuboid( {
size: [ ep, 1+bV[1][1]- bV[0][1], 1+bV[1][2] - bV[0][2] ]} )
for (let i = 0; i < lH.length; i++){
var t = intersect(vol, translateX(fH * lH[i], trH))
if (t.polygons.length > 0)
rH.push(t)
}
// 2°) Traverses en Y (V)
fV = bV[1][1] - bV[0][1]
mV = (bV[1][1] + bV[0][1]) / 2
var trV = cuboid( {
size: [ 1+ bV[1][0] - bV[0][0], ep, 1+ bV[1][2] - bV[0][2] ]} )
for (let i = 0; i < lV.length; i++){
var t = intersect(vol, translateY(fV * lV[i], trV))
if (t.polygons.length > 0)
rV.push(t)
}
// 3°) Entrecroisement
var ur = union(intersect(union(rH), union(rV)));
var tmp = scission3d(ur)
var eS = [], eH = [], eV = [];
for(let i=0; i< tmp.length; i++){
let p = tmp[i];
let b = measureBoundingBox(p),
d = vec3.subtract(b[1], b[0]);
let c1 = translate([b[0][0], b[0][1] + ep/2, b[0][2]],
cuboid({size: [d[0], d[1]*2, d[2]]}));
let c2 = translate([b[0][0] + ep/2, b[0][1], b[1][2]],
cuboid({size: [d[0]*2, d[1], d[2]]}));
eH.push(intersect(tmp[i], c1));
eV.push(intersect(tmp[i], c2));
}
rH = rH.map(x=> subtract(x, eV));
rV = rV.map(x=> subtract(x, eH));
// 3d
console.log(params.c3d)
if(params.c3d){
r.push(colorize([0,1,0], translateX(-400, vol)));
r.push(colorize([1,0,0], translateX(32-400, rH)));
r.push(colorize([0,0,1], translateX(-32-400, rV)));
}
// 2d
console.log("haut.", fV, fH)
var dk = Math.max(fV, fH) +1
for(let ih = 0; ih < rH.length; ih++){
let b = measureBoundingBox(rH[ih]);
r.push(translate([dk *ih, dk/2], union(vol2surf(rH[ih], 'x', b[0][0]))))
//r.push(translateX(dk *ih, vol2surf(rH[ih], 'x', b[0][0])))
}
for(let iv = 0; iv < rV.length; iv++){
let b = measureBoundingBox(rV[iv]);
r.push(translate([dk *iv, -dk], union(vol2surf(rV[iv], 'y', b[0][1]))))
//r.push(translate([dk *iv, -dk], vol2surf(rV[iv], 'y', b[0][1])))
}
return r;
}
function rndColors(){return [Math.random(), Math.random(), Math.random()];}
function sortNb (E){ // returns E numerically sorted and deduplicated
return E.sort(function(a, b) {return a-b}).filter(
function(item, pos, ary) {return !pos || item != ary[pos - 1]});
}
function scission3d (geom){
var i, Pl, j, i1, j1, ok, ti, tj, z,
zz = [], P, RScission, til, tjl, tii1, zzl, zzdl;
// construit table de correspondance entre Polygones (P)
// build polygons lookup table
//P = geom.toPolygons();
P = geom.polygons;
RScission = [];
Pl = P.length;
for (i = 0; i < Pl; i++){
ti = P[i].vertices;
z = [];
for (j = 0; j < Pl; j++){
tj = P[j].vertices;
ok = false;
for (i1 = 0; i1 < ti.length; i1++){
tii1 = ti[i1];
for(j1 = 0; j1 < tj.length; j1++)
if (!ok)ok = vec3.distance(tii1, tj[j1]) < 0.01;
}
if (ok)z.push(parseInt(j));
}
z = sortNb(z);
zz.push({e:0, d:z});
}
// regroupe les correspondances des polygones se touchant
// boucle ne s'arrêtant que quand deux passages retournent le même nb de polygones
// merge lookup data from linked polygons as long as possible
ok = false;
nElOk = 0;
do {
lnElOk = nElOk;
nElOk = 0;
for (i = 0; i < zz.length; i++){
if (zz[i].e >= 0) {
nElOk++;
for (j = 0; j < zz[i].d.length; j++){
a = zz[i].d[j];
if (zz[a].e >= 0)
if (i != a) {
zz[i].d = sortNb(zz[i].d.concat(zz[a].d));
zz[a].e = -1;
}
}
}
}
ok = lnElOk == nElOk;
}while (!ok);
// construit le tableau des CSG à retourner
// build array of CSG to return
for (i = 0, zzl = zz.length; i < zzl; i++) {
if (zz[i].e >= 0) {
z = [];
for (j = 0, zzdl = zz[i].d.length; j < zzdl; j++){
z.push(P[zz[i].d[j]]);
}
if(z.length > 0) {
RScission.push(geom3.create(z));
}
}
}
return RScission;
}
function vol2surf(vol, axe, orig = 0){ // axe = 'x' | 'y' | 'z'
// retourne la surface formee par le volume avec l'axe z (à 0)
let S = [];
let X, Y, Z;
for(let n = 0; n < vol.polygons.length; n++){
let pts = [];
let P = vol.polygons[n];
let ok = true;
switch(axe){
case 'x':
X = 1; Y = 2; Z = 0;
break;
case 'y':
X = 0; Y = 2; Z = 1;
break;
case 'z':
X = 0; Y = 1; Z = 2;
break;
}
for(let i=0; (i < P.vertices.length) && ok; i++){
let pt = P.vertices[i];
if(Math.abs(pt[Z] - orig)< 0.05){
pts.push([pt[X], pt[Y]]);
} else {
ok = false;
}
}
if (ok){
if(axe == 'x'){
S.push(polygon({points:pts.reverse()}));
} else {
S.push(polygon({points:pts}));
}
}
}
return S;
}
module.exports = { main, getParameterDefinitions }