Acties:
  • 0 Henk 'm!

  • eiPionezero
  • Registratie: Augustus 2012
  • Laatst online: 25-09 14:35
Moi,

Sinds een paar dagen ben ik aan het experimenteren met ontwerpen in OpenSCAD. Voor mijn meeste 3D-ontwerpen gebruik ik Solidworks, maar voor mijn huidige projectje wil ik wat natuurlijkere vormen gaan gebruiken. Modelleren met Blender oid gaat mij te veel moeite kosten, dus heb ik mijn hoop gevestigd op de random functie in OpenSCAD om een willekeurig landschap te creëren. Dit landschap wil ik vervolgens exporteren naar STL, om vervolgens in Solidworks nog een beetje aan te passen. Uiteindelijke doel: een unieke set voor Kolonisten van Catan te designen en printen!

Voor de erts-tegel had ik een berg ontworpen, aangepast in Solidworks en deze wordt nu geprint.

Voor mijn volgende Catan-tegel, hout, wil ik in OpenSCAD een willekeurig landschap genereren, om vervolgens op willekeurige plaatsen willekeurige bomen te plaatsen. Probleem is alleen dat het samenvoegen van mijn willekeurige landschapsbasis (een polyhedron) en een ander blok niet wil, ik krijg dan een error in de vorm van:
ERROR: CGAL error in CGAL_Nef_polyhedron3(): CGAL ERROR: assertion violation! Expr: e->incident_sface() != SFace_const_handle()

Dit is mijn huidige code:
code: wood
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
// dimension settings
length = 20;
height = 4;

// functions, needed for inital matrix and smoothing
function dist(x, y) = sqrt((length/2-x)*(length/2-x)+(length/2-y)*(length/2-y));
function mp(d) = mph(d) > 0 ? mph(d) : 0;
function mph(x) = sqrt(((length*length/height+height)/2)*((length*length/height+height)/2)-4*x*x)-((length*length/height-height)/2);

// generate intial matrix
init = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length ? 0 : mp(dist(x,y))*pow(rands(1, 4, 1)[0], 4)/80]];

// smooth matrix
m1 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (init[x-1][y] + init[x][y-1] + init[x+1][y] + init[x][y+1] + 2*init[x][y])/6]];
m2 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m1[x-1][y] + m1[x][y-1] + m1[x+1][y] + m1[x][y+1] + 2*m1[x][y])/6]];
m3 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m2[x-1][y] + m2[x][y-1] + m2[x+1][y] + m2[x][y+1] + 2*m2[x][y])/6]];
m4 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m3[x-1][y] + m3[x][y-1] + m3[x+1][y] + m3[x][y+1] + 2*m3[x][y])/6]];
m5 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m4[x-1][y] + m4[x][y-1] + m4[x+1][y] + m4[x][y+1] + 2*m4[x][y])/6]];
m6 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m5[x-1][y] + m5[x][y-1] + m5[x+1][y] + m5[x][y+1] + 2*m5[x][y])/6]];
m7 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m6[x-1][y] + m6[x][y-1] + m6[x+1][y] + m6[x][y+1] + 2*m6[x][y])/6]];
m8 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m7[x-1][y] + m7[x][y-1] + m7[x+1][y] + m7[x][y+1] + 2*m7[x][y])/6]];
m9 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m8[x-1][y] + m8[x][y-1] + m8[x+1][y] + m8[x][y+1] + 2*m8[x][y])/6]];
m10 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m9[x-1][y] + m9[x][y-1] + m9[x+1][y] + m9[x][y+1] + 2*m9[x][y])/6]];
m11 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m10[x-1][y] + m10[x][y-1] + m10[x+1][y] + m10[x][y+1] + 2*m10[x][y])/6]];
m12 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m11[x-1][y] + m11[x][y-1] + m11[x+1][y] + m11[x][y+1] + 2*m11[x][y])/6]];
m13 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m12[x-1][y] + m12[x][y-1] + m12[x+1][y] + m12[x][y+1] + 2*m12[x][y])/6]];
m14 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m13[x-1][y] + m13[x][y-1] + m13[x+1][y] + m13[x][y+1] + 2*m13[x][y])/6]];
m15 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m14[x-1][y] + m14[x][y-1] + m14[x+1][y] + m14[x][y+1] + 2*m14[x][y])/6]];
m16 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m15[x-1][y] + m15[x][y-1] + m15[x+1][y] + m15[x][y+1] + 2*m15[x][y])/6]];
m17 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m16[x-1][y] + m16[x][y-1] + m16[x+1][y] + m16[x][y+1] + 2*m16[x][y])/6]];
m18 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m17[x-1][y] + m17[x][y-1] + m17[x+1][y] + m17[x][y+1] + 2*m17[x][y])/6]];
m19 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m18[x-1][y] + m18[x][y-1] + m18[x+1][y] + m18[x][y+1] + 2*m18[x][y])/6]];
m20 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m19[x-1][y] + m19[x][y-1] + m19[x+1][y] + m19[x][y+1] + 2*m19[x][y])/6]];
m21 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m20[x-1][y] + m20[x][y-1] + m20[x+1][y] + m20[x][y+1] + 2*m20[x][y])/6]];
m22 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m21[x-1][y] + m21[x][y-1] + m21[x+1][y] + m21[x][y+1] + 2*m21[x][y])/6]];
m23 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m22[x-1][y] + m22[x][y-1] + m22[x+1][y] + m22[x][y+1] + 2*m22[x][y])/6]];
m24 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m23[x-1][y] + m23[x][y-1] + m23[x+1][y] + m23[x][y+1] + 2*m23[x][y])/6]];
m25 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m24[x-1][y] + m24[x][y-1] + m24[x+1][y] + m24[x][y+1] + 2*m24[x][y])/6]];
m26 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m25[x-1][y] + m25[x][y-1] + m25[x+1][y] + m25[x][y+1] + 2*m25[x][y])/6]];
m27 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m26[x-1][y] + m26[x][y-1] + m26[x+1][y] + m26[x][y+1] + 2*m26[x][y])/6]];
m28 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m27[x-1][y] + m27[x][y-1] + m27[x+1][y] + m27[x][y+1] + 2*m27[x][y])/6]];
m29 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m28[x-1][y] + m28[x][y-1] + m28[x+1][y] + m28[x][y+1] + 2*m28[x][y])/6]];
m30 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m29[x-1][y] + m29[x][y-1] + m29[x+1][y] + m29[x][y+1] + 2*m29[x][y])/6]];
m31 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m30[x-1][y] + m30[x][y-1] + m30[x+1][y] + m30[x][y+1] + 2*m30[x][y])/6]];
m32 = [for (x = [0 : length]) [ for (y = [0 : length]) x==0 || y==0 || x==length || y==length || dist(x,y)>length/2 ? 0 : (m31[x-1][y] + m31[x][y-1] + m31[x+1][y] + m31[x][y+1] + 2*m31[x][y])/6]];

// functions for generating points and faces for the polyhedron
function pts(x, y) = x <= length ? (y <= length ? concat([[x, y, m32[x][y]]], pts(x, y+1)) : pts(x+1, 0)) : [];
function fcs(i) = i < (length+1)*length ? ((i+1)%(length+1) > 0 ? concat([[i, i+1, i+length+1], [i+1, i+length+2, i+length+1]], fcs(i+1)) : fcs(i+1)) : [];
*echo(pts(0, 0)); 
*echo(fcs(0)); 

// generate polyhedron
translate([-length/2, -length/2, 0]) {
    polyhedron(concat(pts(0, 0), [[length/2, length/2, -10]]), concat([[(length+1)*(length+1), (length+1)*(length+1)-1, length], [(length+1)*(length+1), length, 0], [(length+1)*(length+1), (length+1)*(length+1)-(length+1), (length+1)*(length+1)-1], [(length+1)*(length+1), 0, (length+1)*(length+1)-(length+1)]], fcs(0)));
}
// generate some cylinder
translate([4, 3, 0]) {
    cylinder(16, 4, 4, $fn=16);
}


Ik weet het, spuuglelijk om op deze manier te itereren. Echter, omdat OpenSCAD variabelen berekend tijdens compiletime ipv tijdens runtime, is dit de enige oplossing. Weliswaar is een mooiere, recursieve oplossing ook mogelijk, maar deze zal zeer inefficiënt zijn bij compileren. Zodoende deze lelijke manier van smoothen :)

Als ik de cylinder weg laat kan ik de code perfect renderen en exporteren. Als ik de polyhedron weg laat kan ik de code perfect renderen en exporteren. Echter, als ik zowel de cylinder als de polyhedron laat staan lukt het renderen niet.

Ik heb meerdere dingen geprobeerd, iets andere locaties van beide vormen genomen (soms schijnen errors voor te komen omdat je net iets te dicht bij een x-, y- of z-as zit), een kleinere polyhedron genomen (length=20 ipv length=61) om te kijken of de polyhedron te groot was voor OpenSCAD. Beide oplossingen werken niet, ook kan ik op het internet niet een andere oplossing vinden.

Iemand die weet waar het probleem wel zit?