protected override void CreateGeosphereInternal(Device device, float radius, SubdivisionCount numSubdivisions) { var geosphere = GeometryGenerator.CreateGeosphere(radius, numSubdivisions); InitFromMeshData(device, geosphere); _meshCount = 1; }
public static BasicModel CreateGeosphere(Device device, float radius, SubdivisionCount numSubdivisions) { var model = new BasicModel(); model.CreateGeosphereInternal(device, radius, numSubdivisions); return(model); }
public static MeshData CreateGeosphere(float radius, SubdivisionCount numSubdivisions) { var tempMesh = new MeshData(); tempMesh.Vertices = IcosahedronVertices.Select(p => new Vertex { Position = p }).ToList(); tempMesh.Indices = IcosahedronIndices; var mh = new Subdivider(); for (var i = 0; i < (int)numSubdivisions; i++) { mh.Subdivide4(tempMesh); } // Project vertices onto sphere and scale. for (var i = 0; i < tempMesh.Vertices.Count; i++) { // Project onto unit sphere. var n = Vector3.Normalize(tempMesh.Vertices[i].Position); // Project onto sphere. var p = radius * n; // Derive texture coordinates from spherical coordinates. var theta = MathF.AngleFromXY(tempMesh.Vertices[i].Position.X, tempMesh.Vertices[i].Position.Z); var phi = MathF.Acos(tempMesh.Vertices[i].Position.Y / radius); var texC = new Vector2(theta / (2 * MathF.PI), phi / MathF.PI); // Partial derivative of P with respect to theta var tangent = new Vector3( -radius * MathF.Sin(phi) * MathF.Sin(theta), 0, radius * MathF.Sin(phi) * MathF.Cos(theta) ); tangent.Normalize(); tempMesh.Vertices[i] = new Vertex(p, n, tangent, texC); } return(tempMesh); }
public static MeshData CreateGeosphere(float radius, SubdivisionCount numSubdivisions) { var tempMesh = new MeshBuilder { VerticesBuffer = IcosahedronVertices.Select(p => new Vertex(p)).ToArray(), IndicesBuffer = IcosahedronIndices }; for (var i = 0; i < (int)numSubdivisions; i++) { Subdivide4(tempMesh); } // Project vertices onto sphere and scale. for (var i = 0; i < tempMesh.VerticesCount; i++) { // Project onto unit sphere. var n = Vector3.Normalize(tempMesh.VerticesBuffer[i].Position); // Project onto sphere. var p = radius * n; // Derive texture coordinates from spherical coordinates. var theta = MathF.AngleFromXY(tempMesh.VerticesBuffer[i].Position.X, tempMesh.VerticesBuffer[i].Position.Z); var phi = (tempMesh.VerticesBuffer[i].Position.Y / radius).Acos(); var texC = new Vector2(theta / (2 * MathF.PI), phi / MathF.PI); // Partial derivative of P with respect to theta var tangent = new Vector3( -radius * phi.Sin() * theta.Sin(), 0, radius * phi.Sin() * theta.Cos()); tangent.Normalize(); tempMesh.VerticesBuffer[i] = new Vertex(p, n, texC, tangent); } return(tempMesh.Seal()); }
protected abstract void CreateGeosphereInternal(Device device, float radius, SubdivisionCount subdivisionCount);
public static MeshData CreateGeosphere(float radius, SubdivisionCount numSubdivisions) { var tempMesh = new MeshData { Vertices = IcosahedronVertices.Select(p => new Vertex {Position = p}).ToList(), Indices = IcosahedronIndices }; var mh = new Subdivider(); for (var i = 0; i < (int)numSubdivisions; i++) { mh.Subdivide4(tempMesh); } // Project vertices onto sphere and scale. for (var i = 0; i < tempMesh.Vertices.Count; i++) { // Project onto unit sphere. var n = Vector3.Normalize(tempMesh.Vertices[i].Position); // Project onto sphere. var p = radius * n; // Derive texture coordinates from spherical coordinates. var theta = MathF.AngleFromXY(tempMesh.Vertices[i].Position.X, tempMesh.Vertices[i].Position.Z); var phi = MathF.Acos(tempMesh.Vertices[i].Position.Y / radius); var texC = new Vector2(theta / (2 * MathF.PI), phi / MathF.PI); // Partial derivative of P with respect to theta var tangent = new Vector3( -radius * MathF.Sin(phi) * MathF.Sin(theta), 0, radius * MathF.Sin(phi) * MathF.Cos(theta) ); tangent.Normalize(); tempMesh.Vertices[i] = new Vertex(p, n, tangent, texC); } return tempMesh; }