Example #1
0
		public BSPAccelerator (IEnumerable<RenderItem> items, SplitHeuristic sh, IEnumerable<Point3> facenormals, int maxDepth, int maxSize = 2) {
			double ta, tb;
			List<NormalInterval> fn = new List<NormalInterval>();
			foreach(Point3 normal in facenormals) {
				double tta = double.PositiveInfinity;
				double ttb = double.NegativeInfinity;
				foreach(RenderItem ri in items) {
					ri.GetFaceNormalBounds(normal, out ta, out tb);
					tta = Math.Min(tta, ta);
					ttb = Math.Max(ttb, tb);
				}
				fn.Add(new NormalInterval(normal, tta, ttb));
			}
			this.intervals = fn.ToArray();
			LinkedList<RenderItem> caches = new LinkedList<RenderItem>(items);
			this.root = Split(caches, sh, fn, maxDepth, maxSize, 0x00);
		}
Example #2
0
		private BSPNode Split (LinkedList<RenderItem> current, SplitHeuristic sh, IEnumerable<NormalInterval> facenormals, int maxDepth, int maxSize, int depth) {
			if(depth < maxDepth && maxSize < current.Count) {
				Point3 nibest = null;
				double minHeu = double.PositiveInfinity;
				double ta = double.NaN, tb = ta, tta, ttb, theu;
				foreach(NormalInterval ni in facenormals) {
					sh(current, ni.Normal, ni.T1, ni.T2, out tta, out ttb, out theu);
					if(theu < minHeu) {
						minHeu = theu;
						nibest = ni.Normal;
						ta = tta;
						tb = ttb;
					}
				}
				LinkedList<RenderItem> cachea = new LinkedList<RenderItem>(), cacheb = new LinkedList<RenderItem>();
				double tm, tM;
				Filter(current, cachea, cacheb, nibest, ta, tb, out tm, out tM);
				return new BSPNode(nibest, tm, ta, tb, tM, Split(cachea, sh, facenormals, maxDepth, maxSize, depth+1), Split(cacheb, sh, facenormals, maxDepth, maxSize, depth+1));
			}
			else {
				return new BSPNode(current.ToArray());
			}
		}
Example #3
0
		public BSPAccelerator (IEnumerable<RenderItem> items, SplitHeuristic sh, IEnumerable<Point3> facenormals) : this(items,sh,facenormals,Math.Max((int) Math.Round(Math.Log(items.Count(),2.0)),1)) {
		}
Example #4
0
		public BSPAccelerator (IEnumerable<RenderItem> items, SplitHeuristic sh) : this(items,sh,Point3.UnitDummies) {
		}