public static ImmutableGeometryData BuildGeoBox(AxisAlignedBox box) { var indx = new List <int>(); var dic = new Dictionary <Vector3, int>(); var corners = box.GetCornersBox(); var index = 0; dic.Add(corners.FarBottomLeft, index); dic.Add(corners.FarBottomRight, ++index); dic.Add(corners.FarTopRight, ++index); dic.Add(corners.FarTopLeft, ++index); dic.Add(corners.NearBottomLeft, ++index); dic.Add(corners.NearBottomRight, ++index); dic.Add(corners.NearTopRight, ++index); dic.Add(corners.NearTopLeft, ++index); indx.AddRange(new[] { //top dic[corners.FarTopRight], dic[corners.FarTopLeft], dic[corners.NearTopRight], dic[corners.NearTopLeft], dic[corners.NearTopRight], dic[corners.FarTopLeft], //Bottom dic[corners.FarBottomRight], dic[corners.NearBottomRight], dic[corners.FarBottomLeft], dic[corners.NearBottomLeft], dic[corners.FarBottomLeft], dic[corners.NearBottomRight], //left dic[corners.NearTopLeft], dic[corners.FarTopLeft], dic[corners.FarBottomLeft], dic[corners.NearBottomLeft], dic[corners.NearTopLeft], dic[corners.FarBottomLeft], //right dic[corners.NearTopRight], dic[corners.NearBottomRight], dic[corners.FarTopRight], dic[corners.NearBottomRight], dic[corners.FarBottomRight], dic[corners.FarTopRight], //near dic[corners.NearBottomLeft], dic[corners.NearBottomRight], dic[corners.NearTopRight], dic[corners.NearBottomLeft], dic[corners.NearTopRight], dic[corners.NearTopLeft], //far dic[corners.FarBottomLeft], dic[corners.FarTopRight], dic[corners.FarBottomRight], dic[corners.FarBottomLeft], dic[corners.FarTopLeft], dic[corners.FarTopRight], }); return(new ImmutableGeometryData(dic.Keys.ToList().AsReadOnly(), indx.AsReadOnly())); }
public static Vector3[] BuildBox(AxisAlignedBox box) { var pos = new List <Vector3>(); var corners = box.GetCornersBox(); pos.Add(corners.FarBottomLeft); pos.Add(corners.FarBottomRight); pos.Add(corners.FarBottomRight); pos.Add(corners.FarTopRight); pos.Add(corners.FarTopRight); pos.Add(corners.FarTopLeft); pos.Add(corners.FarTopLeft); pos.Add(corners.FarBottomLeft); pos.Add(corners.NearBottomLeft); pos.Add(corners.NearBottomRight); pos.Add(corners.NearBottomRight); pos.Add(corners.NearTopRight); pos.Add(corners.NearTopRight); pos.Add(corners.NearTopLeft); pos.Add(corners.NearTopLeft); pos.Add(corners.NearBottomLeft); pos.Add(corners.NearBottomLeft); pos.Add(corners.FarBottomLeft); pos.Add(corners.NearBottomRight); pos.Add(corners.FarBottomRight); pos.Add(corners.NearTopRight); pos.Add(corners.FarTopRight); pos.Add(corners.NearTopLeft); pos.Add(corners.FarTopLeft); return(pos.ToArray()); }
public static VisualPolylineObject CreateBox(IContextState context, ElementTag tag, AxisAlignedBox box, Vector4 color) { var indeces = new List <int>(); var pos = new List <Vector3>(); var xbox = box.GetCornersBox(); var NearBottomLeft = xbox.NearBottomLeft; var NearBottomRight = xbox.NearBottomRight; var NearTopLeft = xbox.NearTopLeft; var NearTopRight = xbox.NearTopRight; var FarBottomLeft = xbox.FarBottomLeft; var FarBottomRight = xbox.FarBottomRight; var FarTopLeft = xbox.FarTopLeft; var FarTopRight = xbox.FarTopRight; //top pos.Add(NearBottomLeft); pos.Add(NearBottomRight); pos.Add(NearBottomRight); pos.Add(NearTopRight); pos.Add(NearTopRight); pos.Add(NearTopLeft); pos.Add(NearTopLeft); pos.Add(NearBottomLeft); //side pos.Add(NearBottomLeft); pos.Add(FarBottomLeft); pos.Add(NearBottomRight); pos.Add(FarBottomRight); pos.Add(NearTopRight); pos.Add(FarTopRight); pos.Add(NearTopLeft); pos.Add(FarTopLeft); //bottom pos.Add(FarBottomLeft); pos.Add(FarBottomRight); pos.Add(FarBottomRight); pos.Add(FarTopRight); pos.Add(FarTopRight); pos.Add(FarTopLeft); pos.Add(FarTopLeft); pos.Add(FarBottomLeft); for (var i = 0; i < pos.Count; i++) { indeces.AddRange(new[] { i, i }); } var manager = context.GetEntityManager(); var geo = context.GetGeometryPool() .AddGeometry(new ImmutableGeometryData(pos.ToArray(), indeces.ToArray())); manager .CreateEntity(tag) .AddComponent(geo) .AddComponent(TransformComponent.Identity()) .AddComponent(ColorComponent.CreateDiffuse(color)) .AddComponent(RenderableComponent.AsLineList()); return(new VisualPolylineObject(tag)); }