summaryrefslogtreecommitdiff
path: root/trunk/users/metalab/AoI/scripts/MetaCAD.bsh
blob: d5f9a6493153a61859817ba9e0913ce41edc24ed (plain)
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
/*
<?xml version='1.0' standalone='yes' ?>
<!--  xml header for scripts & plugin manager --> 
<script>
	<name>MetaCAD</name>
	<author>Stefan Farthofer and Philipp Tiefenbacher</author>
	<version>0.1</version>
    <beta>1</beta>
	<date>23/10/2008</date>
	<description>
This script unions all selected Objects
    </description>
    <comments>
    </comments>
</script>
*/


class MetaCAD
{
	public static ObjectInfo calculateNode(ObjectInfo object)
	{
		if (object.name.equalsIgnoreCase("union"))
			return MetaCAD.Combine(object, CSGObject.UNION);
		else if (object.name.equalsIgnoreCase("intersection"))
			return MetaCAD.Combine(object, CSGObject.INTERSECTION);
		else if (object.name.equalsIgnoreCase("difference"))
			return MetaCAD.Combine(object, CSGObject.DIFFERENCE12);
		else return object;
	}

	
	public static ObjectInfo Combine(ObjectInfo object, int operation)
	{
		ObjectInfo[] children = object.getChildren();
		
		if (children == null || children.length == 0) return object;
		
		new MessageDialog(window, object.name);
		
		union = calculateNode(children[0]);
		
		//create combined object
		for(int i=1;i<children.length;i++)
		{
			union = new CSGObject(union, calculateNode(children[i]), operation);  // get the ith ObjInfo
			union = new ObjectInfo(union, new CoordinateSystem(), object.name);
		}

		object.object.copyObject(union.getObject());
		object.setCoords(new CoordinateSystem());
		object.clearCachedMeshes();		
		
		return union;
	}
}

scene=window.getScene();
sel=window.getSelectedObjects();

//new MessageDialog(window,""+sel.size());
//try {
	it = sel.iterator();
	while(it.hasNext())
	{
		MetaCAD.calculateNode(it.next());
	}
//}
//catch(Exception ex)
//{
//	new MessageDialog(window, "Exception in MetaCAD:" + ex.toString());
//}