/// <summary> /// Simplifies the specified mesh. /// </summary> /// <param name="mesh"> /// The mesh. /// </param> /// <param name="eps"> /// The tolerance. /// </param> /// <returns> /// A simplified mesh. /// </returns> public static MeshGeometry3D Simplify(this MeshGeometry3D mesh, DoubleOrSingle eps) { // Find common positions var dict = new Dictionary <int, int>(); // map position index to first occurence of same position for (int i = 0; i < mesh.Positions.Count; i++) { for (int j = i + 1; j < mesh.Positions.Count; j++) { if (dict.ContainsKey(j)) { continue; } var v = mesh.Positions[i] - mesh.Positions[j]; var l2 = SharedFunctions.LengthSquared(ref v); if (l2 < eps) { dict.Add(j, i); } } } var p = new Point3DCollection(); var ti = new Int32Collection(); // create new positions array var newIndex = new Dictionary <int, int>(); // map old index to new index for (int i = 0; i < mesh.Positions.Count; i++) { if (!dict.ContainsKey(i)) { newIndex.Add(i, p.Count); p.Add(mesh.Positions[i]); } } // Update triangle indices foreach (int index in mesh.TriangleIndices) { int j; ti.Add(dict.TryGetValue(index, out j) ? newIndex[j] : newIndex[index]); } #if SHARPDX var result = new MeshGeometry3D { Positions = p, TriangleIndices = new IntCollection(ti), }; #else var result = new MeshGeometry3D { Positions = p, TriangleIndices = ti }; #endif return(result); }
public void ExistsTest() { var collection = new IntCollection { 5, 8, 9, 10, 12 }; Assert.True(ListUtils.Exists(collection, item => item > 10)); Assert.True(ReadOnlyListUtils.Exists(collection, item => item > 10)); Assert.False(ListUtils.Exists(collection, item => item > 12)); Assert.False(ReadOnlyListUtils.Exists(collection, item => item > 12)); }
private static IntCollection ConvertFaceIndices(List <int> subFaces, List <int> faces) { var triangleIndices = new IntCollection(subFaces.Count * 3);// new List<int>(subFaces.Count * 3); foreach (int f in subFaces) { triangleIndices.Add(faces[f * 3]); triangleIndices.Add(faces[(f * 3) + 1]); triangleIndices.Add(faces[(f * 3) + 2]); } return(triangleIndices); }
/// <summary> /// Finds all edges where the angle between adjacent triangle normal vectors. /// is larger than minimumAngle /// </summary> /// <param name="mesh"> /// A mesh geometry. /// </param> /// <param name="minimumAngle"> /// The minimum angle between the normal vectors of two adjacent triangles (degrees). /// </param> /// <returns> /// The edge indices. /// </returns> public static Int32Collection FindSharpEdges(this MeshGeometry3D mesh, double minimumAngle) { var edgeIndices = new Int32Collection(); var edgeNormals = new Dictionary <EdgeKey, Vector3D>(); for (var i = 0; i < mesh.TriangleIndices.Count / 3; i++) { var i0 = i * 3; var p0 = mesh.Positions[mesh.TriangleIndices[i0]]; var p1 = mesh.Positions[mesh.TriangleIndices[i0 + 1]]; var p2 = mesh.Positions[mesh.TriangleIndices[i0 + 2]]; var triangleNormal = SharedFunctions.CrossProduct(p1 - p0, p2 - p0); // Handle degenerated triangles. if (SharedFunctions.LengthSquared(ref triangleNormal) < 0.001f) { continue; } triangleNormal.Normalize(); for (var j = 0; j < 3; j++) { var index0 = mesh.TriangleIndices[i0 + j]; var index1 = mesh.TriangleIndices[i0 + (j + 1) % 3]; var position0 = SharedFunctions.ToVector3D(mesh.Positions[index0]); var position1 = SharedFunctions.ToVector3D(mesh.Positions[index1]); var edgeKey = new EdgeKey(position0, position1); var reverseEdgeKey = new EdgeKey(position1, position0); if (edgeNormals.TryGetValue(edgeKey, out var value) || edgeNormals.TryGetValue(reverseEdgeKey, out value)) { var rawDot = SharedFunctions.DotProduct(ref triangleNormal, ref value); // Acos returns NaN if rawDot > 1 or rawDot < -1 var dot = Math.Max(-1, Math.Min(rawDot, 1)); var angle = 180 / Math.PI * Math.Acos(dot); if (angle > minimumAngle) { edgeIndices.Add(index0); edgeIndices.Add(index1); } } else { edgeNormals.Add(edgeKey, triangleNormal); } } } return(edgeIndices); }
/// <summary> /// Create the grid /// </summary> private void DrawGrid() { Grid = new LineGeometry3D(); var positions = new Vector3Collection(); var indices = new IntCollection(); var colors = new Color4Collection(); for (var i = 0; i < 10; i += 1) { for (var j = 0; j < 10; j += 1) { DrawGridPatch(positions, indices, colors, -50 + i * 10, -50 + j * 10); } } Grid.Positions = positions; Grid.Indices = indices; Grid.Colors = colors; Axes = new LineGeometry3D(); var axesPositions = new Vector3Collection(); var axesIndices = new IntCollection(); var axesColors = new Color4Collection(); // Draw the coordinate axes axesPositions.Add(new Vector3()); axesIndices.Add(axesPositions.Count - 1); axesPositions.Add(new Vector3(50, 0, 0)); axesIndices.Add(axesPositions.Count - 1); axesColors.Add(SharpDX.Color.Red); axesColors.Add(SharpDX.Color.Red); axesPositions.Add(new Vector3()); axesIndices.Add(axesPositions.Count - 1); axesPositions.Add(new Vector3(0, 5, 0)); axesIndices.Add(axesPositions.Count - 1); axesColors.Add(SharpDX.Color.Blue); axesColors.Add(SharpDX.Color.Blue); axesPositions.Add(new Vector3()); axesIndices.Add(axesPositions.Count - 1); axesPositions.Add(new Vector3(0, 0, -50)); axesIndices.Add(axesPositions.Count - 1); axesColors.Add(SharpDX.Color.Green); axesColors.Add(SharpDX.Color.Green); Axes.Positions = axesPositions; Axes.Indices = axesIndices; Axes.Colors = axesColors; }
private IntCollection ReadFaceList(BinaryReader reader) { int size = reader.ReadUInt16(); var faces = new IntCollection(); for (int i = 0; i < size; i++) { faces.Add(reader.ReadUInt16()); faces.Add(reader.ReadUInt16()); faces.Add(reader.ReadUInt16()); reader.ReadUInt16(); } return(faces); }
public static IntCollection Parse(string source) { IFormatProvider formatProvider = CultureInfo.InvariantCulture; var th = new TokenizerHelper(source, formatProvider); var resource = new IntCollection(); while (th.NextToken()) { var value = Convert.ToInt32(th.GetCurrentToken(), formatProvider); resource.Add(value); } return(resource); }
private static IntCollection GetTriangleIndices(DMesh3 mesh) { var tringleindices = new IntCollection(mesh.TrianglesRefCounts.count); var triangles = mesh.TrianglesBuffer; foreach (int tId in mesh.TrianglesRefCounts) { int i = tId * 3; tringleindices.Add(triangles[i]); tringleindices.Add(triangles[i + 1]); tringleindices.Add(triangles[i + 2]); } return(tringleindices); }
public void IntCollectionWithExplicitComparer(ReferenceHandling referenceHandling) { var x = new IntCollection(1); var y = new IntCollection(1); foreach (var expected in new[] { true, false }) { var comparerMock = new Mock <IEqualityComparer <IntCollection> >(MockBehavior.Strict); comparerMock.Setup(c => c.Equals(x, y)) .Returns(expected); var result = this.EqualByMethod(x, y, comparerMock.Object, referenceHandling); Assert.AreEqual(expected, result); comparerMock.Verify(c => c.Equals(It.IsAny <IntCollection>(), It.IsAny <IntCollection>()), Times.Once); } }
public void Equals_should_return_true_for_null_array() { var first = new IntCollection(); first.Collection = null; first.Count = 0; var second = new IntCollection(); second.Collection = null; second.Count = 0; var result = first.Equals(second); Assert.True(result); }
public void Equals_should_return_true_for_reference_equal_array() { var first = new IntCollection(); first.Collection = new[] { 1, 2, 3, 4, 5, 6 }; first.Count = 2; var second = new IntCollection(); second.Collection = first.Collection; second.Count = 2; var result = first.Equals(second); Assert.True(result); }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value == null) { throw GetConvertFromException(value); } var source = value as string; if (source != null) { return(IntCollection.Parse(source)); } return(base.ConvertFrom(context, culture, value)); }
/// <summary> /// /// </summary> /// <returns></returns> public MeshGeometry3D GetMesh() { var pos = new Point3DCollection(vertices.Select(x => new Point3D(x.p.X, x.p.Y, x.p.Z))); var tris = new Int32Collection(triangles.Count * 3); foreach (var tri in triangles) { tris.Add(tri.v[0]); tris.Add(tri.v[1]); tris.Add(tri.v[2]); } return(new MeshGeometry3D() { Positions = pos, TriangleIndices = tris }); }
public void Equals_should_return_false_for_fill_array_and_null_array() { var first = new IntCollection(); first.Collection = null; first.Count = 0; var second = new IntCollection(); second.Collection = new[] { 1 }; second.Count = 0; var result = first.Equals(second); Assert.False(result); }
public bool Equals(TestObject other) { return(IntValue == other.IntValue && (NullableIntValue == null && other.NullableIntValue == null) || NullableIntValue.Equals(other.NullableIntValue) && DecimalValue == other.DecimalValue && (NullableDecimalValue == null && other.NullableDecimalValue == null) || NullableDecimalValue.Equals(other.NullableDecimalValue) && (StringValue == null && other.StringValue == null) || StringValue.Equals(other.StringValue) && DateValue == other.DateValue && (NullableDateValue == null && other.NullableDateValue == null) || NullableDateValue.Equals(other.NullableDateValue) && TimeSpanValue == other.TimeSpanValue && (NullableDateValue == null && other.NullableDateValue == null) || NullableDateValue.Equals(other.NullableDateValue) && (IntArray == null && other.IntArray == null) || IntArray.SequenceEqual(other.IntArray) && (IntCollection == null && other.IntCollection == null) || IntCollection.SequenceEqual(other.IntCollection) && GuidValue == other.GuidValue && (NullableGuidValue == null && other.NullableGuidValue == null) || NullableGuidValue.Equals(other.NullableGuidValue) ); }
/// <summary> /// Returns a list of month ints that represent the months YTD based on specified month int. /// </summary> /// <param name="month"></param> /// <returns></returns> public static IntCollection MonthIntToMonthYtdIntList(int month) { //validate params if (month < 1 || month > 12) { throw new ArgumentOutOfRangeException("month", "The month int given was out of range."); } IntCollection monthList = new IntCollection(); for (int i = 0; i <= month; i++) { monthList.Add(i); } return(monthList); }
/// <summary> /// Converts a delimited string to a generic list of ints. /// </summary> /// <param name="value">A delimited string.</param> /// <param name="delimiter">The delimiter in the delimited string.</param> /// <returns>A generic list of strings: StringCollection</returns> public static IntCollection DelimitedStringToIntList(string value, char delimiter) { if (string.IsNullOrEmpty(value)) { throw new ArgumentNullException("value"); } IntCollection result = new IntCollection(); string[] valueArray = value.Split(delimiter); foreach (string val in valueArray) { result.Add(ToInt(val)); } return(result); }
private void LoadThreadFunction() { PCD wrapper = new PCD(); Points[] rawPoints = wrapper.LoadPointcloud(Location); var points = new PointGeometry3D(); var col = new Color4Collection(); var ptPos = new Vector3Collection(); var ptIdx = new IntCollection(); var ptNormals = new Vector3Collection(); var numberOfElements = rawPoints.Length; var additionalTurns = 0; foreach (var point in rawPoints) { ptIdx.Add(ptPos.Count); ptPos.Add(new Vector3(point.x, point.z, -point.y)); col.Add(new Color4(new Color3(point.r / (float)255, point.g / (float)255, point.b / (float)255))); ptNormals.Add(new Vector3(0, 1, 0)); } if ((rawPoints.Length / 3) * 3 != rawPoints.Length) { additionalTurns = ((rawPoints.Length / 3 + 1) * 3) - rawPoints.Length; } for (int i = 0; i < additionalTurns; i++) { ptIdx.Add(ptPos.Count); ptPos.Add(ptPos[ptPos.Count - 1]); col.Add(col[col.Count - 1]); ptNormals.Add(ptNormals[ptNormals.Count - 1]); } points.Positions = ptPos; points.Indices = ptIdx; points.Colors = col; //points.Normals = ptNormals; Data = points; }
public void UpdateSLAMPointCloud() { int Error = 0; var pose = new List <HelixToolkit.Wpf.SharpDX.Geometry3D.Line>(); var line = new LineBuilder(); Vector3 previousPose = new Vector3(Convert.ToSingle(poseX), Convert.ToSingle(poseY), Convert.ToSingle(poseZ)); while (IsSLAMOn) { var vc = new Vector3Collection(); var id = new IntCollection(); var cc = new Color4Collection(); var poseVect = new List <double[]>(); var colorVect = new List <double[]>(); Vector3 currentPose = new Vector3(Convert.ToSingle(poseX), Convert.ToSingle(poseY), Convert.ToSingle(poseZ)); line.AddLine(previousPose, currentPose); SLAMPoseInfo = line.ToLineGeometry3D(); previousPose = currentPose; try { RealsenseControl.GetSLAMPointCloud(ref poseVect, ref colorVect, T265ToLACCOffset.X, T265ToLACCOffset.Y, T265ToLACCOffset.Z); for (int i = 0; i < poseVect.Count; i++) { vc.Add(new Vector3(Convert.ToSingle(poseVect[i][0]), Convert.ToSingle(poseVect[i][1]), Convert.ToSingle(poseVect[i][2]))); cc.Add(new Color4(0.1f, 0.1f, 0.1f, 0.5f)); //cc.Add(new Color4(Convert.ToSingle(colorVect[i][0]), Convert.ToSingle(colorVect[i][1]), Convert.ToSingle(colorVect[i][2]), 0.5f)); id.Add(i); } SLAMPointCloud = new PointGeometry3D() { Positions = vc, Indices = id, Colors = cc }; } catch { Error++; Trace.WriteLine("Error Count is " + Error); } Thread.Sleep(50); } }
/// <summary> /// Finds all edges where the angle between adjacent triangle normal vectors. /// is larger than minimumAngle /// </summary> /// <param name="mesh"> /// A mesh geometry. /// </param> /// <param name="minimumAngle"> /// The minimum angle between the normal vectors of two adjacent triangles (degrees). /// </param> /// <returns> /// The edge indices. /// </returns> public static Int32Collection FindSharpEdges(this MeshGeometry3D mesh, double minimumAngle) { var edgeIndices = new Int32Collection(); // the keys of the dictionary are created from the triangle indices of the edge var edgeNormals = new Dictionary <ulong, Vector3D>(); for (int i = 0; i < mesh.TriangleIndices.Count / 3; i++) { int i0 = i * 3; var p0 = mesh.Positions[mesh.TriangleIndices[i0]]; var p1 = mesh.Positions[mesh.TriangleIndices[i0 + 1]]; var p2 = mesh.Positions[mesh.TriangleIndices[i0 + 2]]; var p10 = p1 - p0; var p20 = p2 - p0; var n = SharedFunctions.CrossProduct(ref p10, ref p20); n.Normalize(); for (int j = 0; j < 3; j++) { int index0 = mesh.TriangleIndices[i0 + j]; int index1 = mesh.TriangleIndices[i0 + ((j + 1) % 3)]; int minIndex = Math.Min(index0, index1); int maxIndex = Math.Max(index0, index1); ulong key = CreateKey((uint)minIndex, (uint)maxIndex); Vector3D value; if (edgeNormals.TryGetValue(key, out value)) { var n2 = value; n2.Normalize(); var angle = 180 / (DoubleOrSingle)Math.PI * (DoubleOrSingle)Math.Acos(SharedFunctions.DotProduct(ref n, ref n2)); if (angle > minimumAngle) { edgeIndices.Add(minIndex); edgeIndices.Add(maxIndex); } } else { edgeNormals.Add(key, n); } } } return(edgeIndices); }
public static IEnumerable <GroupNode> LoadMapMGEO(MGEOFile mgeo, MapData mapData, string mapPath) { foreach (MGEOObject mgeoModel in mgeo.Objects) { IntCollection indices = new IntCollection(mgeoModel.Indices.Select(x => (int)x).AsEnumerable()); Vector3Collection vertices = new Vector3Collection(mgeoModel.Vertices.Count); Vector2Collection uvs = new Vector2Collection(mgeoModel.Vertices.Count); foreach (MGEOVertex vertex in mgeoModel.Vertices) { vertices.Add(new dxVector3(vertex.Position.X, vertex.Position.Y, vertex.Position.Z)); uvs.Add(new dxVector2(vertex.DiffuseUV.X, vertex.DiffuseUV.Y)); } foreach (MGEOSubmesh submesh in mgeoModel.Submeshes) { GroupNode groupNode = new GroupNode() { Name = mgeoModel.Name }; MeshGeometry3D submeshGeometry3D = new MeshGeometry3D() { Indices = indices.GetRange((int)submesh.StartIndex, (int)submesh.IndexCount) as IntCollection, Positions = vertices, TextureCoordinates = uvs }; DiffuseMaterial diffuseMaterial = new DiffuseMaterial() { Name = submesh.Material, DiffuseMap = CreateMaterial(submesh.Material, mapData, mapPath), EnableUnLit = true }; groupNode.AddChildNode(new MeshNode() { Name = mgeoModel.Name + "|" + submesh.Material, Geometry = submeshGeometry3D, Material = diffuseMaterial }); yield return(groupNode); } } }
public void Equals_should_return_true_for_equal_collections() { var first = new IntCollection(); first.Collection = new[] { 1, 2, 3, 4, 5, 6 }; first.Count = 2; var second = new IntCollection(); second.Collection = new List <int> { 1, 2, 3, 4, 5, 6 }; second.Count = 2; var result = first.Equals(second); Assert.True(result); }
public void BinarySearchTest() { var collection = new IntCollection { 5, 8, 9, 10, 12 }; Assert.Equal(-1, ListUtils.BinarySearch(collection, 0)); Assert.Equal(-1, ReadOnlyListUtils.BinarySearch(collection, 0)); Assert.Equal(1, ListUtils.BinarySearch(collection, 8)); Assert.Equal(1, ReadOnlyListUtils.BinarySearch(collection, 8)); Assert.Equal(1, ListUtils.BinarySearch(collection, 8, s_intComparer)); Assert.Equal(1, ReadOnlyListUtils.BinarySearch(collection, 8, s_intComparer)); Assert.Equal(-2, ListUtils.BinarySearch(collection, 1, 2, 5)); Assert.Equal(-2, ReadOnlyListUtils.BinarySearch(collection, 1, 2, 5)); Assert.Equal(-4, ListUtils.BinarySearch(collection, 1, 2, 10)); Assert.Equal(-4, ReadOnlyListUtils.BinarySearch(collection, 1, 2, 10)); Assert.Equal(2, ListUtils.BinarySearch(collection, 1, 2, 9)); Assert.Equal(2, ReadOnlyListUtils.BinarySearch(collection, 1, 2, 9)); Assert.Equal(2, ListUtils.BinarySearch(collection, 1, 2, 9, s_intComparer)); Assert.Equal(2, ReadOnlyListUtils.BinarySearch(collection, 1, 2, 9, s_intComparer)); Assert.Equal(-1, ListUtils.BinarySearch(collection, 0, 0, 5)); Assert.Equal(-1, ReadOnlyListUtils.BinarySearch(collection, 0, 0, 5)); Assert.Equal(~collection.Count, ListUtils.BinarySearch(collection, collection.Count, 0, 12)); Assert.Equal(~collection.Count, ReadOnlyListUtils.BinarySearch(collection, collection.Count, 0, 12)); Assert.Throws <ArgumentOutOfRangeException>(() => ListUtils.BinarySearch(collection, -1, 1, 0)); Assert.Throws <ArgumentOutOfRangeException>(() => ReadOnlyListUtils.BinarySearch(collection, -1, 1, 0)); Assert.Throws <ArgumentOutOfRangeException>(() => ListUtils.BinarySearch(collection, 0, -1, 0)); Assert.Throws <ArgumentOutOfRangeException>(() => ReadOnlyListUtils.BinarySearch(collection, 0, -1, 0)); Assert.Throws <ArgumentException>(() => ListUtils.BinarySearch(collection, collection.Count, 1, 0)); Assert.Throws <ArgumentException>(() => ReadOnlyListUtils.BinarySearch(collection, collection.Count, 1, 0)); }
private static void IteratorTest() { Console.WriteLine("---------------------------"); Console.WriteLine("IteratorTest"); var collection = new IntCollection(); collection[0] = 0; collection[1] = 1; collection[2] = 2; collection[3] = 3; var iterator = collection.GetIterator(); while (!iterator.IsDone()) { Console.WriteLine(iterator.CurrentItem()); iterator.Next(); } Console.WriteLine("---------------------------"); }
/// <summary> /// Finds edges that are only connected to one triangle. /// </summary> /// <param name="mesh"> /// A mesh geometry. /// </param> /// <returns> /// The edge indices for the edges that are only used by one triangle. /// </returns> public static Int32Collection FindBorderEdges(this MeshGeometry3D mesh) { var dict = new Dictionary <ulong, int>(); for (var i = 0; i < mesh.TriangleIndices.Count / 3; i++) { var i0 = i * 3; for (var j = 0; j < 3; j++) { var index0 = mesh.TriangleIndices[i0 + j]; var index1 = mesh.TriangleIndices[i0 + ((j + 1) % 3)]; var minIndex = Math.Min(index0, index1); var maxIndex = Math.Max(index1, index0); var key = CreateKey((uint)minIndex, (uint)maxIndex); if (dict.ContainsKey(key)) { dict[key] = dict[key] + 1; } else { dict.Add(key, 1); } } } var edges = new Int32Collection(); foreach (var kvp in dict) { // find edges only used by 1 triangle if (kvp.Value == 1) { uint i0, i1; ReverseKey(kvp.Key, out i0, out i1); edges.Add((int)i0); edges.Add((int)i1); } } return(edges); }
/// <summary> /// Converts a month int list to a month string list. /// </summary> /// <param name="monthList"></param> /// <returns></returns> public static StringCollection MonthIntListToThreeCharacterMonthList(IntCollection monthList) { //Validate params if (monthList == null) { throw new ArgumentNullException("monthList"); } if (monthList.Count < 1) { throw new ArgumentOutOfRangeException("monthList"); } StringCollection threeCharacterMonthList = new StringCollection(); foreach (int month in monthList) { threeCharacterMonthList.Add(MonthIntToThreeCharacterMonth(month)); } return(threeCharacterMonthList); }
/// <summary> /// Converts a 3 character month string list to a month int list. /// </summary> /// <param name="monthList"></param> /// <returns></returns> public static IntCollection ThreeCharacterMonthListToMonthIntList(StringCollection threeCharacterMonthList) { //Validate params if (threeCharacterMonthList == null) { throw new ArgumentNullException("threeCharacterMonthList"); } if (threeCharacterMonthList.Count < 1) { throw new ArgumentOutOfRangeException("threeCharacterMonthList"); } IntCollection monthList = new IntCollection(); foreach (string month in threeCharacterMonthList) { monthList.Add(ThreeCharacterMonthToMonthInt(month)); } return(monthList); }
private void LoadThreadFunction() { var pt = new PotreeNode(new Uri(Location)); var points = new PointGeometry3D(); var col = new Color4Collection(); var ptPos = new Vector3Collection(); var ptIdx = new IntCollection(); var j = 0; foreach (var p in pt.Compilation.Points) { ptPos.Add(new Vector3(p.x, p.y, p.z)); ptIdx.Add(j); col.Add(new Color4(p.r / 255f, p.g / 255f, p.b / 255f, p.a / 255f)); j++; } var additionalTurns = 0; if ((pt.Compilation.Points.Count / 3) * 3 != pt.Compilation.Points.Count) { additionalTurns = ((pt.Compilation.Points.Count / 3 + 1) * 3) - pt.Compilation.Points.Count; } for (int i = 0; i < additionalTurns; i++) { ptIdx.Add(ptPos.Count); ptPos.Add(ptPos[ptPos.Count - 1]); col.Add(col[col.Count - 1]); } points.Positions = ptPos; points.Indices = ptIdx; points.Colors = col; Data = points; }
private void LoadThreadFunction() { var pt = new Potree(new Uri(Filename)); var points = new PointGeometry3D(); var col = new Color4Collection(); var ptPos = new Vector3Collection(); var ptIdx = new IntCollection(); var j = 0; foreach (var p in pt.Compilation.Points) { ptPos.Add(new Vector3(p.x, p.y, p.z)); ptIdx.Add(j); col.Add(new Color4(p.r/255f, p.g / 255f, p.b / 255f, p.a / 255f)); j++; } var additionalTurns = 0; if ((pt.Compilation.Points.Count / 3) * 3 != pt.Compilation.Points.Count) { additionalTurns = ((pt.Compilation.Points.Count / 3 + 1) * 3) - pt.Compilation.Points.Count; } for (int i = 0; i < additionalTurns; i++) { ptIdx.Add(ptPos.Count); ptPos.Add(ptPos[ptPos.Count - 1]); col.Add(col[col.Count - 1]); } points.Positions = ptPos; points.Indices = ptIdx; points.Colors = col; Data = points; }
public static PointGeometry3D ConvertToPointGeometry3D(Points[] points) { var geometry = new PointGeometry3D(); var col = new Color4Collection(); var ptPos = new Vector3Collection(); var ptIdx = new IntCollection(); var ptNormals = new Vector3Collection(); var additionalTurns = 0; foreach (var point in points) { ptIdx.Add(ptPos.Count); ptPos.Add(new Vector3(point.x, point.y, point.z)); col.Add(new Color4(new Color3(point.r / (float)255, point.g / (float)255, point.b / (float)255))); ptNormals.Add(new Vector3(0, 1, 0)); } if ((points.Length / 3) * 3 != points.Length) { additionalTurns = ((points.Length / 3 + 1) * 3) - points.Length; } for (int i = 0; i < additionalTurns; i++) { ptIdx.Add(ptPos.Count); ptPos.Add(ptPos[ptPos.Count - 1]); col.Add(col[col.Count - 1]); ptNormals.Add(ptNormals[ptNormals.Count - 1]); } geometry.Positions = ptPos; geometry.Indices = ptIdx; geometry.Colors = col; return(geometry); }
public ScintillaControl(string sciLexerDllName) { _sciLexerDllName = sciLexerDllName; // Instantiate the indexers for this instance IndicatorStyle = new Collection<IndicatorStyle>(this); IndicatorForegroundColor = new IntCollection(this); MarkerForegroundColor = new CachingIntCollection(this); MarkerBackgroundColor = new CachingIntCollection(this); Line = new ReadOnlyStringCollection(this); // setup instance-based-indexers IndicatorForegroundColor.Setup(2082, 2083); MarkerForegroundColor.Setup(2041); MarkerBackgroundColor.Setup(2042); Line.Setup(2153,2350); // Set up default encoding _encoding = Encoding.GetEncoding(this.CodePage); InitializeComponent(); }
/// <summary> /// Creates the resulting <see cref="LineGeometry3D"/>. /// </summary> /// <param name="unshareVertices"> /// If true, the resulting <see cref="LineGeometry3D"/> has no shared vertices. /// </param> /// <returns>Returns the resulting <see cref="LineGeometry3D"/>.</returns> public LineGeometry3D ToLineGeometry3D(bool unshareVertices = false) { if (unshareVertices) { var count = this.lineListIndices.Count; var pos = new Vector3Collection(count); var idx = new IntCollection(count); for (var i = 0; i < count; i++) { pos.Add(this.positions[this.lineListIndices[i]]); idx.Add(i); } return(new LineGeometry3D { Positions = pos, Indices = idx }); } return(new LineGeometry3D { Positions = this.positions, Indices = this.lineListIndices }); }
protected void ClearPageData() { streamSerialNumber = 0; pages = new List<OggPage>(); //new ArrayList (); firstPageHeader = null; lastPageHeader = null; packetToPageMap = new List<IntCollection>(); //new ArrayList(); dirtyPackets = new Dictionary<uint, ByteVector>(); //new Hashtable (); dirtyPages = new IntCollection(); currentPage = null; currentPacketPage = null; currentPackets = null; }
public override void Save() { if (IsReadOnly) { throw new ReadOnlyException(); } Mode = FileAccessMode.Write; IntCollection pageGroup = new IntCollection(); foreach (int page in dirtyPages) if (!pageGroup.IsEmpty && pageGroup[pageGroup.Count - 1] + 1 != page) { WritePageGroup(pageGroup); pageGroup.Clear(); } else pageGroup.Add(page); WritePageGroup(pageGroup); dirtyPages.Clear(); dirtyPackets.Clear(); Mode = FileAccessMode.Closed; }
private void CreateFaceModels(IFCItem item, Vector3 center) { while (item != null) { if (item.ifcID != IntPtr.Zero && item.noVerticesForFaces != 0 && item.noPrimitivesForFaces != 0) { var positions = new Vector3Collection(); var normals = new Vector3Collection(); if (item.verticesForFaces != null) { for (int i = 0; i < item.noVerticesForFaces; i++) { var point = new Vector3(item.verticesForFaces[6 * i + 0] - center.X, item.verticesForFaces[6 * i + 1] - center.Y, item.verticesForFaces[6 * i + 2] - center.Z); var normal = new Vector3(item.verticesForFaces[6 * i + 3], item.verticesForFaces[6 * i + 4], item.verticesForFaces[6 * i + 5]); positions.Add(point); normals.Add(normal); } Debug.Assert(item.verticesForFaces.Length == item.noVerticesForFaces * 6); } var indices = new IntCollection(); if (item.indicesForFaces != null) { for (int i = 0; i < 3 * item.noPrimitivesForFaces; i++) { indices.Add(item.indicesForFaces[i]); } } var meshGeometry = new MeshGeometry3D(); meshGeometry.Positions = positions; meshGeometry.Normals = normals; meshGeometry.Indices = indices; meshGeometry.TextureCoordinates = null; meshGeometry.Colors = null; meshGeometry.Tangents = null; meshGeometry.BiTangents = null; MeshGeometryModel3D mesh = new MeshGeometryModel3D() { Geometry = meshGeometry }; // var builder = new MeshBuilder(true, false); // builder.Positions.AddRange(positions); // builder.Normals.AddRange(normals); // builder.TriangleIndices.AddRange(indices); // MeshGeometryModel3D mesh = new MeshGeometryModel3D() { Geometry = builder.ToMeshGeometry3D() }; item.Mesh3d = mesh; _meshToIfcItems[mesh] = item; //#if DEBUG // OutputObj(item.ifcID.ToString(), meshGeometry); //#endif FillMeshByIfcColor(item); mesh.Tag = item.ifcType + ":" + item.ifcID; model.Add(mesh); } CreateFaceModels(item.child, center); item = item.next; } }
private void LoadThreadFunction() { PCD wrapper = new PCD(); Points[] rawPoints = wrapper.LoadPointcloud(Filename); var points = new PointGeometry3D(); var col = new Color4Collection(); var ptPos = new Vector3Collection(); var ptIdx = new IntCollection(); var ptNormals = new Vector3Collection(); var numberOfElements = rawPoints.Length; var additionalTurns = 0; foreach (var point in rawPoints) { ptIdx.Add(ptPos.Count); ptPos.Add(new Vector3(point.x, point.z, -point.y)); col.Add(new Color4(new Color3(point.r / (float)255, point.g / (float)255, point.b / (float)255))); ptNormals.Add(new Vector3(0, 1, 0)); } if ((rawPoints.Length / 3) * 3 != rawPoints.Length) { additionalTurns = ((rawPoints.Length / 3 + 1) * 3) - rawPoints.Length; } for (int i = 0; i < additionalTurns; i++) { ptIdx.Add(ptPos.Count); ptPos.Add(ptPos[ptPos.Count-1]); col.Add(col[col.Count - 1]); ptNormals.Add(ptNormals[ptNormals.Count - 1]); } points.Positions = ptPos; points.Indices = ptIdx; points.Colors = col; //points.Normals = ptNormals; Data = points; }
private static void DrawGridPatch( Vector3Collection positions, IntCollection indices, Color4Collection colors, int startX, int startY) { var c1 = (Color)ColorConverter.ConvertFromString("#c5d1d8"); c1.Clamp(); var c2 = (Color)ColorConverter.ConvertFromString("#ddeaf2"); c2.Clamp(); var darkGridColor = new Color4(new Vector4(c1.ScR,c1.ScG ,c1.ScB, 1)); var lightGridColor = new Color4(new Vector4(c2.ScR, c2.ScG, c2.ScB, 1)); const int size = 10; for (var x = startX; x <= startX + size; x++) { if (x == 0 && startY < 0) continue; var v = new Vector3(x, -.001f, startY); positions.Add(v); indices.Add(positions.Count - 1); positions.Add(new Vector3(x, -.001f, startY + size)); indices.Add(positions.Count - 1); if (x % 5 == 0) { colors.Add(darkGridColor); colors.Add(darkGridColor); } else { colors.Add(lightGridColor); colors.Add(lightGridColor); } } for (var y = startY; y <= startY + size; y++) { if (y == 0 && startX >= 0) continue; positions.Add(new Vector3(startX, -.001f, y)); indices.Add(positions.Count - 1); positions.Add(new Vector3(startX + size, -.001f, y)); indices.Add(positions.Count - 1); if (y % 5 == 0) { colors.Add(darkGridColor); colors.Add(darkGridColor); } else { colors.Add(lightGridColor); colors.Add(lightGridColor); } } }
private IntCollection ReadFaceList(BinaryReader reader) { int size = reader.ReadUInt16(); var faces = new IntCollection(); for(int i=0;i< size; i++) { faces.Add(reader.ReadUInt16()); faces.Add(reader.ReadUInt16()); faces.Add(reader.ReadUInt16()); reader.ReadUInt16(); } return faces; }
public MainViewModel() { // titles Title = "Simple Demo"; SubTitle = "WPF & SharpDX"; // camera setup Camera = new PerspectiveCamera { Position = new Point3D(3, 3, 5), LookDirection = new Vector3D(-3, -3, -5), UpDirection = new Vector3D(0, 1, 0), FarPlaneDistance = 5000000 }; // Create a custom render techniques manager that // only supports Phong and Blinn RenderTechniquesManager = new CustomRenderTechniquesManager(); RenderTechnique = RenderTechniquesManager.RenderTechniques["RenderCustom"]; EffectsManager = new CustomEffectsManager(RenderTechniquesManager); // setup lighting AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f); DirectionalLightColor = Color.White; DirectionalLightDirection = new Vector3(-2, -5, -2); // floor plane grid Grid = LineBuilder.GenerateGrid(); GridColor = Color.Black; GridTransform = new Media3D.TranslateTransform3D(-5, -1, -5); // scene model3d var b1 = new MeshBuilder(); b1.AddSphere(new Vector3(0, 0, 0), 0.5); b1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2, BoxFaces.All); var meshGeometry = b1.ToMeshGeometry3D(); meshGeometry.Colors = new Color4Collection(meshGeometry.TextureCoordinates.Select(x => x.ToColor4())); Model = meshGeometry; // lines model3d var e1 = new LineBuilder(); e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2); Lines = e1.ToLineGeometry3D(); // model transform Model1Transform = new Media3D.TranslateTransform3D(0, 0, 0); Model2Transform = new Media3D.TranslateTransform3D(-2, 0, 0); Model3Transform = new Media3D.TranslateTransform3D(+2, 0, 0); // model materials RedMaterial = PhongMaterials.Red; GreenMaterial = PhongMaterials.Green; BlueMaterial = PhongMaterials.Blue; Points = new PointGeometry3D(); var ptPos = new Vector3Collection(); var ptIdx = new IntCollection(); Text = new BillboardText3D(); for (int x = -5; x <= 5; x++) { for (int y = -5; y <= 5; y++) { ptIdx.Add(ptPos.Count); ptPos.Add(new Vector3(x, -1, y)); Text.TextInfo.Add(new TextInfo(string.Format("{0}:{1}", x, y), new Vector3(x, -1, y))); } } Points.Positions = ptPos; Points.Indices = ptIdx; }
private static void AppendSphere(Vector3 center, double radius, int thetaSteps, int phiSteps, out Vector3Collection positions, out Vector3Collection normals, out Vector2Collection textureCoordinates, out IntCollection triangleIndices) { positions = new Vector3Collection(); normals = new Vector3Collection(); textureCoordinates = new Vector2Collection(); triangleIndices = new IntCollection(); double dt = DegToRad(360.0) / thetaSteps; double dp = DegToRad(180.0) / phiSteps; for (int pi = 0; pi <= phiSteps; pi++) { double phi = pi * dp; for (int ti = 0; ti <= thetaSteps; ti++) { // we want to start the mesh on the x axis double theta = ti * dt; positions.Add(GetPosition(theta, phi, radius) + center); normals.Add(GetNormal(theta, phi)); textureCoordinates.Add(GetTextureCoordinate(theta, phi)); } } for (int pi = 0; pi < phiSteps; pi++) { for (int ti = 0; ti < thetaSteps; ti++) { int x0 = ti; int x1 = ti + 1; int y0 = pi * (thetaSteps + 1); int y1 = (pi + 1) * (thetaSteps + 1); triangleIndices.Add(x0 + y0); triangleIndices.Add(x0 + y1); triangleIndices.Add(x1 + y0); triangleIndices.Add(x1 + y0); triangleIndices.Add(x0 + y1); triangleIndices.Add(x1 + y1); } } }
/// <summary> /// Makes sure no triangles share the same vertex. /// </summary> private void NoSharedVertices() { var p = new Vector3Collection(); var ti = new IntCollection(); Vector3Collection n = null; if (this.normals != null) { n = new Vector3Collection(); } Vector2Collection tc = null; if (this.textureCoordinates != null) { tc = new Vector2Collection(); } for (int i = 0; i < this.triangleIndices.Count; i += 3) { int i0 = i; int i1 = i + 1; int i2 = i + 2; int index0 = this.triangleIndices[i0]; int index1 = this.triangleIndices[i1]; int index2 = this.triangleIndices[i2]; var p0 = this.positions[index0]; var p1 = this.positions[index1]; var p2 = this.positions[index2]; p.Add(p0); p.Add(p1); p.Add(p2); ti.Add(i0); ti.Add(i1); ti.Add(i2); if (n != null) { n.Add(this.normals[index0]); n.Add(this.normals[index1]); n.Add(this.normals[index2]); } if (tc != null) { tc.Add(this.textureCoordinates[index0]); tc.Add(this.textureCoordinates[index1]); tc.Add(this.textureCoordinates[index2]); } } this.positions = p; this.triangleIndices = ti; this.normals = n; this.textureCoordinates = tc; }
private static void ComputeNormals(Vector3Collection positions, IntCollection triangleIndices, out Vector3Collection normals) { normals = new Vector3Collection(positions.Count); normals.AddRange(Enumerable.Repeat(Vector3.Zero, positions.Count)); for (int t = 0; t < triangleIndices.Count; t += 3) { var i1 = triangleIndices[t]; var i2 = triangleIndices[t + 1]; var i3 = triangleIndices[t + 2]; var v1 = positions[i1]; var v2 = positions[i2]; var v3 = positions[i3]; var p1 = v2 - v1; var p2 = v3 - v1; var n = Vector3.Cross(p1, p2); // angle p1.Normalize(); p2.Normalize(); var a = (float)Math.Acos(Vector3.Dot(p1, p2)); n.Normalize(); normals[i1] += (a * n); normals[i2] += (a * n); normals[i3] += (a * n); } for (int i = 0; i < normals.Count; i++) { normals[i].Normalize(); } }
/// <summary> /// Initializes a new instance of the <see cref="MeshBuilder"/> class. /// </summary> /// <remarks> /// Normal and texture coordinate generation are included. /// </remarks> public MeshBuilder(bool generateNormals = true, bool generateTexCoords = true, bool tangentSpace = false) { this.positions = new Vector3Collection(); this.triangleIndices = new IntCollection(); if (generateNormals) { this.normals = new Vector3Collection(); } if (generateTexCoords) { this.textureCoordinates = new Vector2Collection(); } if (tangentSpace) { this.tangents = new Vector3Collection(); this.bitangents = new Vector3Collection(); } }
private void WritePageGroup(IntCollection page_group) { if (page_group.IsEmpty) return; ByteVectorCollection packets = new ByteVectorCollection(); // If the first page of the group isn'type dirty, append its partial content here. if (!dirtyPages.Contains(((OggPage)this.pages[page_group[0]]).FirstPacketIndex)) packets.Add(((OggPage)this.pages[page_group[0]]).Packets[0]); int previous_packet = -1; int original_size = 0; for (int i = 0; i < page_group.Count; i++) { int page = page_group[i]; uint first_packet = (uint)((OggPage)this.pages[page]).FirstPacketIndex; uint last_packet = first_packet + ((OggPage)this.pages[page]).PacketCount - 1; for (uint j = first_packet; j <= last_packet; j++) { if (i == page_group.Count - 1 && j == last_packet && !dirtyPages.Contains((int)j)) packets.Add(((OggPage)this.pages[page]).Packets[((OggPage)this.pages[page]).Packets.Count - 1]); else if ((int)j != previous_packet) { previous_packet = (int)j; packets.Add(GetPacket(j)); } } original_size += ((OggPage)this.pages[page]).Size; } bool continued = ((OggPage)this.pages[page_group[0]]).Header.FirstPacketContinued; bool completed = ((OggPage)this.pages[page_group[page_group.Count - 1]]).Header.LastPacketCompleted; // TODO: This pagination method isn'type accurate for what'field being done here. // This should account for real possibilities like non-aligned packets and such. OggPage[] pages = OggPage.Paginate(packets, PaginationStrategy.SinglePagePerGroup, streamSerialNumber, page_group[0], continued, completed); ByteVector data = new ByteVector(); foreach (OggPage p in pages) data.Add(p.Render()); // The insertion algorithms could also be improve to queue and prioritize data // on the way out. Currently it requires rewriting the file for every page // group rather than just once; however, for tagging applications there will // generally only be one page group, so it'field not worth the time for the // optimization at the moment. Insert(data, ((OggPage)this.pages[page_group[0]]).FileOffset, original_size); // Update the page index to include the pages we just created and to delete the // old pages. foreach (OggPage p in pages) { int index = p.Header.PageSequenceNumber; this.pages[index] = p; } }
/// <summary> /// Create the grid /// </summary> private void DrawGrid() { Grid = new LineGeometry3D(); var positions = new Vector3Collection(); var indices = new IntCollection(); var colors = new Color4Collection(); for(var i= 0; i < 10; i += 1) { for (var j = 0; j < 10; j += 1) { DrawGridPatch(positions, indices, colors, -50 + i * 10, -50 + j * 10); } } Grid.Positions = positions; Grid.Indices = indices; Grid.Colors = colors; Axes = new LineGeometry3D(); var axesPositions = new Vector3Collection(); var axesIndices = new IntCollection(); var axesColors = new Color4Collection(); // Draw the coordinate axes axesPositions.Add(new Vector3()); axesIndices.Add(axesPositions.Count - 1); axesPositions.Add(new Vector3(50, 0, 0)); axesIndices.Add(axesPositions.Count - 1); axesColors.Add(SharpDX.Color.Red); axesColors.Add(SharpDX.Color.Red); axesPositions.Add(new Vector3()); axesIndices.Add(axesPositions.Count - 1); axesPositions.Add(new Vector3(0, 5, 0)); axesIndices.Add(axesPositions.Count - 1); axesColors.Add(SharpDX.Color.Blue); axesColors.Add(SharpDX.Color.Blue); axesPositions.Add(new Vector3()); axesIndices.Add(axesPositions.Count - 1); axesPositions.Add(new Vector3(0, 0, -50)); axesIndices.Add(axesPositions.Count - 1); axesColors.Add(SharpDX.Color.Green); axesColors.Add(SharpDX.Color.Green); Axes.Positions = axesPositions; Axes.Indices = axesIndices; Axes.Colors = axesColors; }
/// <summary> /// /// </summary> public LineBuilder() { positions = new Vector3Collection(); // textureCoordinates = new List<Point>(); lineListIndices = new IntCollection(); }
public static PointGeometry3D ConvertToPointGeometry3D(Points[] points) { var geometry = new PointGeometry3D(); var col = new Color4Collection(); var ptPos = new Vector3Collection(); var ptIdx = new IntCollection(); var ptNormals = new Vector3Collection(); var additionalTurns = 0; foreach (var point in points) { ptIdx.Add(ptPos.Count); ptPos.Add(new Vector3(point.x, point.y, point.z)); col.Add(new Color4(new Color3(point.r / (float)255, point.g / (float)255, point.b / (float)255))); ptNormals.Add(new Vector3(0, 1, 0)); } if ((points.Length / 3) * 3 != points.Length) { additionalTurns = ((points.Length / 3 + 1) * 3) - points.Length; } for (int i = 0; i < additionalTurns; i++) { ptIdx.Add(ptPos.Count); ptPos.Add(ptPos[ptPos.Count - 1]); col.Add(col[col.Count - 1]); ptNormals.Add(ptNormals[ptNormals.Count - 1]); } geometry.Positions = ptPos; geometry.Indices = ptIdx; geometry.Colors = col; return geometry; }
private static IntCollection ConvertFaceIndices(List<int> subFaces, List<int> faces) { var triangleIndices = new IntCollection(subFaces.Count * 3);// new List<int>(subFaces.Count * 3); foreach (int f in subFaces) { triangleIndices.Add(faces[f * 3]); triangleIndices.Add(faces[(f * 3) + 1]); triangleIndices.Add(faces[(f * 3) + 2]); } return triangleIndices; }
public static MeshGeometry3D Merge(params MeshGeometry3D[] meshes) { var positions = new Vector3Collection(); var indices = new IntCollection(); var normals = meshes.All(x => x.Normals != null) ? new Vector3Collection() : null; var colors = meshes.All(x => x.Colors != null) ? new Color4Collection() : null; var textureCoods = meshes.All(x => x.TextureCoordinates != null) ? new Vector2Collection() : null; var tangents = meshes.All(x => x.Tangents != null) ? new Vector3Collection() : null; var bitangents = meshes.All(x => x.BiTangents != null) ? new Vector3Collection() : null; int index = 0; foreach (var part in meshes) { for (int i = 0; i < part.Positions.Count; i++) { positions.Add(part.Positions[i]); } for (int i = 0; i < part.Indices.Count; i++) { indices.Add(index + part.Indices[i]); } index += part.Indices.Count; } if (normals != null) { normals = new Vector3Collection(meshes.SelectMany(x => x.Normals)); } if (colors != null) { colors = new Color4Collection(meshes.SelectMany(x => x.Colors)); } if (textureCoods != null) { textureCoods = new Vector2Collection(meshes.SelectMany(x => x.TextureCoordinates)); } if (tangents != null) { tangents = new Vector3Collection(meshes.SelectMany(x => x.Tangents)); } if (bitangents != null) { bitangents = new Vector3Collection(meshes.SelectMany(x => x.BiTangents)); } var mesh = new MeshGeometry3D() { Positions = positions, Indices = indices, }; mesh.Normals = normals; mesh.Colors = colors; mesh.TextureCoordinates = textureCoods; mesh.Tangents = tangents; mesh.BiTangents = bitangents; return mesh; }
public MainViewModel() { // titles this.Title = "Simple Demo"; this.SubTitle = "WPF & SharpDX"; // camera setup this.Camera = new PerspectiveCamera { Position = new Point3D(3, 3, 5), LookDirection = new Vector3D(-3, -3, -5), UpDirection = new Vector3D(0, 1, 0), FarPlaneDistance = 5000000 }; // default render technique this.RenderTechnique = Techniques.RenderBlinn; // setup lighting this.AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f); this.DirectionalLightColor = Color.White; this.DirectionalLightDirection = new Vector3(-2, -5, -2); // floor plane grid this.Grid = LineBuilder.GenerateGrid(); this.GridColor = SharpDX.Color.Black; this.GridTransform = new Media3D.TranslateTransform3D(-5, -1, -5); // scene model3d var b1 = new MeshBuilder(); b1.AddSphere(new Vector3(0, 0, 0), 0.5); b1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2, BoxFaces.All); var meshGeometry = b1.ToMeshGeometry3D(); meshGeometry.Colors = new Color4Collection(meshGeometry.TextureCoordinates.Select(x => x.ToColor4())); this.Model = meshGeometry; // lines model3d var e1 = new LineBuilder(); e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2); this.Lines = e1.ToLineGeometry3D(); // model trafos this.Model1Transform = new Media3D.TranslateTransform3D(0, 0, 0); this.Model2Transform = new Media3D.TranslateTransform3D(-2, 0, 0); this.Model3Transform = new Media3D.TranslateTransform3D(+2, 0, 0); // model materials this.RedMaterial = PhongMaterials.Red; this.GreenMaterial = PhongMaterials.Green; this.BlueMaterial = PhongMaterials.Blue; //var diffColor = this.RedMaterial.DiffuseColor; //diffColor.Alpha = 0.5f; //this.RedMaterial.DiffuseColor = diffColor; Points = new PointGeometry3D(); var ptPos = new Vector3Collection(); var ptIdx = new IntCollection(); for (int x = 0; x < 10; x++) { for (int y = 0; y < 10; y++) { for (int z = 0; z < 10; z++) { ptIdx.Add(ptPos.Count); ptPos.Add(new Vector3(x, y, z)); } } } Points.Positions = ptPos; Points.Indices = ptIdx; Text = new BillboardText3D(); for (var i = 0; i < 50; i++) { for (var j = 0; j < 50; j++) { Text.TextInfo.Add(new TextInfo("Hello World", new Vector3(i,j,0))); } } }
/// <summary> /// Create a Mesh, with found props /// </summary> /// <param name="positions"></param> /// <param name="textureCoordinates"></param> /// <param name="triangleIndices"></param> /// <param name="normals"></param> /// <param name="tangents"></param> /// <param name="bitangents"></param> /// <param name="material"></param> private void CreateMesh(Vector3Collection positions, Vector2Collection textureCoordinates, IntCollection triangleIndices, out Vector3Collection normals, out Vector3Collection tangents, out Vector3Collection bitangents,Material material) { ComputeNormals(positions, triangleIndices, out normals); if (textureCoordinates == null) { textureCoordinates = new Vector2Collection(); foreach(var pos in positions) { textureCoordinates.Add(Vector2.One); } } MeshBuilder.ComputeTangents(positions, normals, textureCoordinates, triangleIndices, out tangents, out bitangents); MeshGeometry3D mesh = new MeshGeometry3D() { Positions = positions, Normals = normals, TextureCoordinates = textureCoordinates, Indices = triangleIndices, Tangents = tangents, BiTangents = bitangents }; Object3D ob3d = new Object3D(); ob3d.Geometry = mesh; ob3d.Material = material; ob3d.Transform = Matrix.Identity; ob3d.Name = "Default"; this.obGroup.Add(ob3d); }