1 module examples.demo;
2 
3 import std.stdio;
4 import std.format;
5 
6 import beziermeshmaker.datastructures.input.polymesh;
7 import beziermeshmaker.datastructures.input.polygon;
8 import beziermeshmaker.datastructures.quadcell;
9 import beziermeshmaker.datastructures.quadmesh;
10 import beziermeshmaker.datastructures.biquarticbeziersurface;
11 
12 class Demo {
13 
14 	public static void example() {
15 		Polygon a = new Polygon([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]]);
16 		Polygon b = new Polygon([[0, 0, 0], [1, 0, 0], [1, -1, 0], [0, -1, 0]]);
17 
18 		//Optional, this is a way to track which output quads correspond to which input polygon
19 		a.metadata["name"] = "a";
20 		b.metadata["name"] = "b";
21 
22 		convert([a, b]);
23 	}
24 
25 	private static BiquarticBezierSurface[] convert(Polygon[] polys) {
26 		PolyMesh mesh = new PolyMesh();
27 
28 		foreach (Polygon poly ; polys) {
29 			mesh.addPolygon(poly);
30 		}
31 
32 		QuadMesh quadMesh = new QuadMesh(mesh);
33 
34 		BiquarticBezierSurface[] surfaces;
35 		foreach (QuadCell cell ; quadMesh.cells) {
36 			if (cell.hasAllNeighbors() ){
37 				writeln(format("Original poly %s, quad index %s", cell.metadata["name"], cell.metadata[QuadCell.VERTEX_METADATA_KEY]));
38 				surfaces ~= [cell.surfacePatch];
39 			}
40 		}
41 
42 		return surfaces;
43 	}
44 }