public override IResource GetNew(IResourceSource resourceSource) { var cSource = (Source)resourceSource; var ns = cSource.NormalDirection == PlaneModelSourceNormalDirection.Positive ? 1f : -1f; var hw = cSource.HalfWidth; var hh = cSource.HalfHeight; var su = cSource.ScaleU; var sv = cSource.ScaleV; var vertices = cSource.Plane == PlaneModelSourcePlane.Xy ? new[] { new VertexPosTanNormTex(new Vector3(-hw, -hh, 0), new Vector3(1, 0, 0), new Vector3(0, 0, ns), new Vector2(0, hh * sv)), new VertexPosTanNormTex(new Vector3(-hw, hh, 0), new Vector3(1, 0, 0), new Vector3(0, 0, ns), new Vector2(0, 0)), new VertexPosTanNormTex(new Vector3(hw, hh, 0), new Vector3(1, 0, 0), new Vector3(0, 0, ns), new Vector2(hw * su, 0)), new VertexPosTanNormTex(new Vector3(hw, -hh, 0), new Vector3(1, 0, 0), new Vector3(0, 0, ns), new Vector2(hw * su, hh * sv)), } : new[] { new VertexPosTanNormTex(new Vector3(-hw, 0, hh), new Vector3(1, 0, 0), new Vector3(0, ns, 0), new Vector2(0, hh * sv)), new VertexPosTanNormTex(new Vector3(-hw, 0, -hh), new Vector3(1, 0, 0), new Vector3(0, ns, 0), new Vector2(0, 0)), new VertexPosTanNormTex(new Vector3(hw, 0, -hh), new Vector3(1, 0, 0), new Vector3(0, ns, 0), new Vector2(hw * su, 0)), new VertexPosTanNormTex(new Vector3(hw, 0, hh), new Vector3(1, 0, 0), new Vector3(0, ns, 0), new Vector2(hw * su, hh * sv)), }; var indices = cSource.NormalDirection == PlaneModelSourceNormalDirection.Positive ? new[] { 0, 1, 2, 0, 2, 3 } : new[] { 0, 2, 1, 0, 3, 2 }; return(ExplicitModel.FromVertices(vertices, indices, ExplicitModelPrimitiveTopology.TriangleList).WithSource(cSource)); }
private static IExplicitModel BuildWallModel(List <BuildingWallSegment> wallSegments) { var vertices = new VertexPosTanNormTex[wallSegments.Count * 4]; var indices = new int[wallSegments.Count * 6]; for (int i = 0; i < wallSegments.Count; i++) { var segment = wallSegments[i].Basement; var height = wallSegments[i].Height; var vertexOffset = i * 4; var indexOffset = i * 6; var tangent = (segment.Point2 - segment.Point1).Normalize(); var normal = Vector3.Cross(tangent, Vector3.UnitY).Normalize(); var texCoordWidth = Math.Max((float)Math.Round(segment.Length / 2), 1f); var texCoordHeight = Math.Max((float)Math.Round(height / 2), 1f); vertices[vertexOffset + 0] = new VertexPosTanNormTex(segment.Point1, tangent, normal, new Vector2(0, texCoordHeight)); vertices[vertexOffset + 1] = new VertexPosTanNormTex(segment.Point1 + height * Vector3.UnitY, tangent, normal, new Vector2(0, 0)); vertices[vertexOffset + 2] = new VertexPosTanNormTex(segment.Point2 + height * Vector3.UnitY, tangent, normal, new Vector2(texCoordWidth, 0)); vertices[vertexOffset + 3] = new VertexPosTanNormTex(segment.Point2, tangent, normal, new Vector2(texCoordWidth, texCoordHeight)); indices[indexOffset + 0] = vertexOffset; indices[indexOffset + 1] = vertexOffset + 1; indices[indexOffset + 2] = vertexOffset + 2; indices[indexOffset + 3] = vertexOffset; indices[indexOffset + 4] = vertexOffset + 2; indices[indexOffset + 5] = vertexOffset + 3; } return(ExplicitModel.FromVertices(vertices, indices, ExplicitModelPrimitiveTopology.TriangleList)); }
public override IResource GetNew(IResourceSource resourceSource) { var cSource = (Source)resourceSource; var verticalIndexOffset = 2 * cSource.HalfNumCircleSegments; var vertices = new VertexPosTanNormTex[verticalIndexOffset * cSource.HalfNumCircleSegments]; for (int i = 0; i < cSource.HalfNumCircleSegments; i++) { for (int j = 0; j < verticalIndexOffset; j++) { var u = (float)j / (verticalIndexOffset - 1); var v = (float)i / (cSource.HalfNumCircleSegments - 1); var phi = MathHelper.TwoPi * u + MathHelper.Pi; var psi = MathHelper.PiOver2 - MathHelper.Pi * v; var z = MathHelper.Cos(phi) * MathHelper.Cos(psi); var x = MathHelper.Sin(phi) * MathHelper.Cos(psi); var y = MathHelper.Sin(psi); var normal = new Vector3(x, y, z); var position = normal; var tangent = Vector3.Cross(Vector3.UnitY, normal).Normalize(); var texcoord = new Vector2(u, v); vertices[i * verticalIndexOffset + j] = new VertexPosTanNormTex( position, tangent, normal, texcoord); } } var indexList = new List <int>(); for (int i = 0; i < cSource.HalfNumCircleSegments - 1; i++) { for (int j = 0; j < verticalIndexOffset - 1; j++) { var topLeftIndex = i * verticalIndexOffset + j; indexList.Add(topLeftIndex); indexList.Add(topLeftIndex + 1); indexList.Add(topLeftIndex + 1 + verticalIndexOffset); indexList.Add(topLeftIndex); indexList.Add(topLeftIndex + 1 + verticalIndexOffset); indexList.Add(topLeftIndex + verticalIndexOffset); } } var indices = indexList.ToArray(); if (cSource.Inverse) { for (int i = 0; i < vertices.Length; i++) { vertices[i].Normal = -vertices[i].Normal; } for (int i = 0; i < indices.Length; i += 3) { CodingHelper.Swap(ref indices[i + 1], ref indices[i + 2]); } } return(ExplicitModel.FromVertices(vertices, indices, ExplicitModelPrimitiveTopology.TriangleList).WithSource(cSource)); }
public override IResource GetNew(IResourceSource resourceSource) { var vertices = new[] { new VertexPos(0, 0, 0, 0), new VertexPos(1, 0, 0, 1), }; return(ExplicitModel.FromVertices(vertices, null, ExplicitModelPrimitiveTopology.LineList).WithSource(resourceSource)); }
public override IResource GetNew(IResourceSource resourceSource) { var cSource = (Source)resourceSource; var vertices = Enumerable.Range(0, cSource.NumSegments) .Select(i => (float)i / cSource.NumSegments * MathHelper.TwoPi) .Select(a => new VertexPos(MathHelper.Cos(a), MathHelper.Sin(a), 0f)) .ToArray(); var indices = Enumerable.Range(0, cSource.NumSegments).Concat(0.EnumSelf()).ToArray(); return(ExplicitModel.FromVertices(vertices, indices, ExplicitModelPrimitiveTopology.LineStrip).WithSource(cSource)); }
private IExplicitModel BuildLaneModel(BuildingLane lane) { var vertices = lane.GlobalPath .Where(x => x.P0.X != x.P2.X) .Select(x => ApplyDisambiguator(x, lane.Disambiguator)) .SelectMany(x => x.ToEnumPolyline(0.01f)) .Select(x => new VertexPos(x)) .ToArray(); return(ExplicitModel.FromVertices(vertices, null, ExplicitModelPrimitiveTopology.LineStrip)); }
private static IExplicitModel BuildWallModel4(List <BuildingWallSegment> wallSegments) { var vertices = new VertexPos[wallSegments.Count * 2]; for (int i = 0; i < wallSegments.Count; i++) { var segment = wallSegments[i].Basement; var vertexOffset = i * 2; vertices[vertexOffset + 0] = new VertexPos(segment.Point1); vertices[vertexOffset + 1] = new VertexPos(segment.Point2); } return(ExplicitModel.FromVertices(vertices, null, ExplicitModelPrimitiveTopology.LineList)); }
public static IModel3D GenerateNew() { var vertices = new[] { new VertexPosTanNormTex(new Vector3(1, -1, 1), new Vector3(0, 0, -1), new Vector3(1, 0, 0), new Vector2(0, 1)), new VertexPosTanNormTex(new Vector3(1, 1, 1), new Vector3(0, 0, -1), new Vector3(1, 0, 0), new Vector2(0, 0)), new VertexPosTanNormTex(new Vector3(1, 1, -1), new Vector3(0, 0, -1), new Vector3(1, 0, 0), new Vector2(1, 0)), new VertexPosTanNormTex(new Vector3(1, -1, -1), new Vector3(0, 0, -1), new Vector3(1, 0, 0), new Vector2(1, 1)), new VertexPosTanNormTex(new Vector3(-1, 1, 1), new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector2(0, 1)), new VertexPosTanNormTex(new Vector3(-1, 1, -1), new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector2(0, 0)), new VertexPosTanNormTex(new Vector3(1, 1, -1), new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector2(1, 0)), new VertexPosTanNormTex(new Vector3(1, 1, 1), new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector2(1, 1)), new VertexPosTanNormTex(new Vector3(-1, -1, -1), new Vector3(0, 0, 1), new Vector3(-1, 0, 0), new Vector2(0, 1)), new VertexPosTanNormTex(new Vector3(-1, 1, -1), new Vector3(0, 0, 1), new Vector3(-1, 0, 0), new Vector2(0, 0)), new VertexPosTanNormTex(new Vector3(-1, 1, 1), new Vector3(0, 0, 1), new Vector3(-1, 0, 0), new Vector2(1, 0)), new VertexPosTanNormTex(new Vector3(-1, -1, 1), new Vector3(0, 0, 1), new Vector3(-1, 0, 0), new Vector2(1, 1)), new VertexPosTanNormTex(new Vector3(1, -1, 1), new Vector3(-1, 0, 0), new Vector3(0, -1, 0), new Vector2(0, 1)), new VertexPosTanNormTex(new Vector3(1, -1, -1), new Vector3(-1, 0, 0), new Vector3(0, -1, 0), new Vector2(0, 0)), new VertexPosTanNormTex(new Vector3(-1, -1, -1), new Vector3(-1, 0, 0), new Vector3(0, -1, 0), new Vector2(1, 0)), new VertexPosTanNormTex(new Vector3(-1, -1, 1), new Vector3(-1, 0, 0), new Vector3(0, -1, 0), new Vector2(1, 1)), new VertexPosTanNormTex(new Vector3(-1, -1, 1), new Vector3(1, 0, 0), new Vector3(0, 0, 1), new Vector2(0, 1)), new VertexPosTanNormTex(new Vector3(-1, 1, 1), new Vector3(1, 0, 0), new Vector3(0, 0, 1), new Vector2(0, 0)), new VertexPosTanNormTex(new Vector3(1, 1, 1), new Vector3(1, 0, 0), new Vector3(0, 0, 1), new Vector2(1, 0)), new VertexPosTanNormTex(new Vector3(1, -1, 1), new Vector3(1, 0, 0), new Vector3(0, 0, 1), new Vector2(1, 1)), new VertexPosTanNormTex(new Vector3(1, -1, -1), new Vector3(-1, 0, 0), new Vector3(0, 0, -1), new Vector2(0, 1)), new VertexPosTanNormTex(new Vector3(1, 1, -1), new Vector3(-1, 0, 0), new Vector3(0, 0, -1), new Vector2(0, 0)), new VertexPosTanNormTex(new Vector3(-1, 1, -1), new Vector3(-1, 0, 0), new Vector3(0, 0, -1), new Vector2(1, 0)), new VertexPosTanNormTex(new Vector3(-1, -1, -1), new Vector3(-1, 0, 0), new Vector3(0, 0, -1), new Vector2(1, 1)) }; var indices = new int[] { 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 13, 14, 12, 14, 15, 16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23 }; return(ExplicitModel.FromVertices(vertices, indices, ExplicitModelPrimitiveTopology.TriangleList)); }
public override IResource GetNew(IResourceSource resourceSource) { var cSource = (Source)resourceSource; var vertices = new[] { new VertexPos(-1, -1, 0), new VertexPos(-1, 1, 0), new VertexPos(1, 1, 0), new VertexPos(1, -1, 0), }; var indices = new[] { 0, 1, 2, 3, 0 }; return(ExplicitModel.FromVertices(vertices, indices, ExplicitModelPrimitiveTopology.LineStrip).WithSource(cSource)); }
public override IResource GetNew(IResourceSource resourceSource) { var cSource = (Source)resourceSource; var vertices = new[] { new VertexPosTanNormTex(new Vector3(-1, 0, 1), new Vector3(1, 0, 0), new Vector3(0, 0, 1), new Vector2(0, 1)), new VertexPosTanNormTex(new Vector3(-1, 0, -1), new Vector3(1, 0, 0), new Vector3(0, 0, 1), new Vector2(0, 0)), new VertexPosTanNormTex(new Vector3(1, 0, -1), new Vector3(1, 0, 0), new Vector3(0, 0, 1), new Vector2(1, 0)), new VertexPosTanNormTex(new Vector3(1, 0, 1), new Vector3(1, 0, 0), new Vector3(0, 0, 1), new Vector2(1, 1)), }; var indices = new int[] { 0, 1, 2, 0, 2, 3 }; return(ExplicitModel.FromVertices(vertices, indices, ExplicitModelPrimitiveTopology.TriangleList).WithSource(cSource)); }
public override IResource GetNew(IResourceSource resourceSource) { var cSource = (Source)resourceSource; var distance = 1f / MathHelper.Tan(MathHelper.Pi / 8); var vertices = new[] { new VertexPos(-1, -1, 0), new VertexPos(-1, 1, 0), new VertexPos(1, 1, 0), new VertexPos(1, -1, 0), new VertexPos(-2, -2, -distance), new VertexPos(-2, 2, -distance), new VertexPos(2, 2, -distance), new VertexPos(2, -2, -distance) }; var indices = new[] { 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 }; return(ExplicitModel.FromVertices(vertices, indices, ExplicitModelPrimitiveTopology.LineList).WithSource(cSource)); }