|
| 1 | +using System.Numerics; |
| 2 | + |
| 3 | +namespace TestApp |
| 4 | +{ |
| 5 | + public static partial class PrimitiveShapes |
| 6 | + { |
| 7 | + public static (VertexPositionNormalTexture[], ushort[]) Plane(int width, int height, int uvUnit) |
| 8 | + { |
| 9 | + float halfWidth = width / 2; |
| 10 | + float halfHeight = height / 2; |
| 11 | + |
| 12 | + Vector2 uvScale = new Vector2(width / uvUnit, height / uvUnit); |
| 13 | + |
| 14 | + VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[] |
| 15 | + { |
| 16 | + new VertexPositionNormalTexture(new Vector3(-halfWidth, 0, -halfHeight), Vector3.UnitY, new Vector2(0, 0) * uvScale), |
| 17 | + new VertexPositionNormalTexture(new Vector3(halfWidth, 0, -halfHeight), Vector3.UnitY, new Vector2(1, 0) * uvScale), |
| 18 | + new VertexPositionNormalTexture(new Vector3(halfWidth, 0, halfHeight), Vector3.UnitY, new Vector2(1, 1) * uvScale), |
| 19 | + new VertexPositionNormalTexture(new Vector3(-halfWidth, 0, halfHeight), Vector3.UnitY, new Vector2(0, 1) * uvScale), |
| 20 | + }; |
| 21 | + |
| 22 | + ushort[] indices = new ushort[] { 0, 1, 2, 0, 2, 3 }; |
| 23 | + |
| 24 | + return (vertices, indices); |
| 25 | + } |
| 26 | + |
| 27 | + internal static (VertexPositionNormalTexture[], ushort[]) Box(float width, float height, float depth, float uvUnit) |
| 28 | + { |
| 29 | + float halfWidth = width / 2; |
| 30 | + float halfHeight = height / 2; |
| 31 | + float halfDepth = depth / 2; |
| 32 | + |
| 33 | + Vector2 uvScale = new Vector2(width / uvUnit, height / uvUnit); |
| 34 | + |
| 35 | + VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[] |
| 36 | + { |
| 37 | + // Top |
| 38 | + new VertexPositionNormalTexture(new Vector3(-halfWidth, +halfHeight, -halfDepth), new Vector3(0,1,0), new Vector2(0, 0) * uvScale), |
| 39 | + new VertexPositionNormalTexture(new Vector3(+halfWidth, +halfHeight, -halfDepth), new Vector3(0,1,0), new Vector2(1, 0) * uvScale), |
| 40 | + new VertexPositionNormalTexture(new Vector3(+halfWidth, +halfHeight, +halfDepth), new Vector3(0,1,0), new Vector2(1, 1) * uvScale), |
| 41 | + new VertexPositionNormalTexture(new Vector3(-halfWidth, +halfHeight, +halfDepth), new Vector3(0,1,0), new Vector2(0, 1) * uvScale), |
| 42 | + // Bottom |
| 43 | + new VertexPositionNormalTexture(new Vector3(-halfWidth,-halfHeight, +halfDepth), new Vector3(0,-1,0), new Vector2(0, 0) * uvScale), |
| 44 | + new VertexPositionNormalTexture(new Vector3(+halfWidth,-halfHeight, +halfDepth), new Vector3(0,-1,0), new Vector2(1, 0) * uvScale), |
| 45 | + new VertexPositionNormalTexture(new Vector3(+halfWidth,-halfHeight, -halfDepth), new Vector3(0,-1,0), new Vector2(1, 1) * uvScale), |
| 46 | + new VertexPositionNormalTexture(new Vector3(-halfWidth,-halfHeight, -halfDepth), new Vector3(0,-1,0), new Vector2(0, 1) * uvScale), |
| 47 | + // Left |
| 48 | + new VertexPositionNormalTexture(new Vector3(-halfWidth, +halfHeight, -halfDepth), new Vector3(-1,0,0), new Vector2(0, 0) * uvScale), |
| 49 | + new VertexPositionNormalTexture(new Vector3(-halfWidth, +halfHeight, +halfDepth), new Vector3(-1,0,0), new Vector2(1, 0) * uvScale), |
| 50 | + new VertexPositionNormalTexture(new Vector3(-halfWidth, -halfHeight, +halfDepth), new Vector3(-1,0,0), new Vector2(1, 1) * uvScale), |
| 51 | + new VertexPositionNormalTexture(new Vector3(-halfWidth, -halfHeight, -halfDepth), new Vector3(-1,0,0), new Vector2(0, 1) * uvScale), |
| 52 | + // Right |
| 53 | + new VertexPositionNormalTexture(new Vector3(+halfWidth, +halfHeight, +halfDepth), new Vector3(1,0,0), new Vector2(0, 0) * uvScale), |
| 54 | + new VertexPositionNormalTexture(new Vector3(+halfWidth, +halfHeight, -halfDepth), new Vector3(1,0,0), new Vector2(1, 0) * uvScale), |
| 55 | + new VertexPositionNormalTexture(new Vector3(+halfWidth, -halfHeight, -halfDepth), new Vector3(1,0,0), new Vector2(1, 1) * uvScale), |
| 56 | + new VertexPositionNormalTexture(new Vector3(+halfWidth, -halfHeight, +halfDepth), new Vector3(1,0,0), new Vector2(0, 1) * uvScale), |
| 57 | + // Back |
| 58 | + new VertexPositionNormalTexture(new Vector3(+halfWidth, +halfHeight, -halfDepth), new Vector3(0,0,-1), new Vector2(0, 0) * uvScale), |
| 59 | + new VertexPositionNormalTexture(new Vector3(-halfWidth, +halfHeight, -halfDepth), new Vector3(0,0,-1), new Vector2(1, 0) * uvScale), |
| 60 | + new VertexPositionNormalTexture(new Vector3(-halfWidth, -halfHeight, -halfDepth), new Vector3(0,0,-1), new Vector2(1, 1) * uvScale), |
| 61 | + new VertexPositionNormalTexture(new Vector3(+halfWidth, -halfHeight, -halfDepth), new Vector3(0,0,-1), new Vector2(0, 1) * uvScale), |
| 62 | + // Front |
| 63 | + new VertexPositionNormalTexture(new Vector3(-halfWidth, +halfHeight, +halfDepth), new Vector3(0,0,1), new Vector2(0, 0) * uvScale), |
| 64 | + new VertexPositionNormalTexture(new Vector3(+halfWidth, +halfHeight, +halfDepth), new Vector3(0,0,1), new Vector2(1, 0) * uvScale), |
| 65 | + new VertexPositionNormalTexture(new Vector3(+halfWidth, -halfHeight, +halfDepth), new Vector3(0,0,1), new Vector2(1, 1) * uvScale), |
| 66 | + new VertexPositionNormalTexture(new Vector3(-halfWidth, -halfHeight, +halfDepth), new Vector3(0,0,1), new Vector2(0, 1) * uvScale), |
| 67 | + }; |
| 68 | + |
| 69 | + ushort[] indices = new ushort[] |
| 70 | + { |
| 71 | + 0,1,2, 0,2,3, |
| 72 | + 4,5,6, 4,6,7, |
| 73 | + 8,9,10, 8,10,11, |
| 74 | + 12,13,14, 12,14,15, |
| 75 | + 16,17,18, 16,18,19, |
| 76 | + 20,21,22, 20,22,23, |
| 77 | + }; |
| 78 | + |
| 79 | + return (vertices, indices); |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments