///////////////////////////////////////// public override void GetProceduralGeneratedData(ref VertexElement[] vertexStructure, ref byte[] vertices, ref int[] indices, ref Component_Material material, ref Component_Mesh.StructureClass structure) { //!!!!!можно было бы не обновлять если такие же параметры vertexStructure = StandardVertex.MakeStructure(StandardVertex.Components.StaticOneTexCoord, true, out int vertexSize); unsafe { if (vertexSize != sizeof(StandardVertex.StaticOneTexCoord)) { Log.Fatal("vertexSize != sizeof( StandardVertexF )"); } } Vector3F[] positions; Vector3F[] normals; Vector4F[] tangents; Vector2F[] texCoords; SimpleMeshGenerator.Face[] faces; if (SphereType.Value == SphereTypeEnum.GeoSphere) { SimpleMeshGenerator.GenerateSphere(Radius, SegmentsHorizontal, SegmentsVertical, InsideOut, out positions, out normals, out tangents, out texCoords, out indices, out faces); } else { SimpleMeshGenerator.GenerateIcoSphere(Radius, Subdivisions.Value, InsideOut, out positions, out normals, out tangents, out texCoords, out indices, out faces); } if (faces != null) { structure = SimpleMeshGenerator.CreateMeshStructure(faces); } vertices = new byte[vertexSize * positions.Length]; unsafe { fixed(byte *pVertices = vertices) { StandardVertex.StaticOneTexCoord *pVertex = (StandardVertex.StaticOneTexCoord *)pVertices; for (int n = 0; n < positions.Length; n++) { pVertex->Position = positions[n]; pVertex->Normal = normals[n]; pVertex->Tangent = tangents[n]; pVertex->Color = new ColorValue(1, 1, 1, 1); pVertex->TexCoord0 = texCoords[n]; pVertex++; } } } }
// public Item(RectangleF uv) { UV = uv; EngineTime = Time.Current; var vertexStructure = StandardVertex.MakeStructure(StandardVertex.Components.StaticOneTexCoord, true, out int vertexSize); var positions = new Vector3F[] { new Vector3F(-0.5f, -0.5f, 0), new Vector3F(0.5f, -0.5f, 0), new Vector3F(0.5f, 0.5f, 0), new Vector3F(-0.5f, 0.5f, 0) }; var texCoords = new Vector2F[] { uv.LeftTop, uv.RightTop, uv.RightBottom, uv.LeftBottom }; var vertices = new byte[vertexSize * positions.Length]; unsafe { fixed(byte *pVertices = vertices) { StandardVertex.StaticOneTexCoord *pVertex = (StandardVertex.StaticOneTexCoord *)pVertices; for (int n = 0; n < positions.Length; n++) { pVertex->Position = positions[n]; pVertex->Normal = new Vector3F(0, 0, 1); pVertex->Tangent = new Vector4F(1, 0, 0, -1); pVertex->Color = new ColorValue(1, 1, 1, 1); pVertex->TexCoord0 = texCoords[n]; pVertex++; } } } var mesh = ComponentUtility.CreateComponent <Component_Mesh>(null, true, false); var geometry = mesh.CreateComponent <Component_MeshGeometry>(); geometry.VertexStructure = vertexStructure; geometry.Vertices = vertices; geometry.Indices = new int[] { 0, 1, 2, 2, 3, 0 }; mesh.Enabled = true; Mesh = mesh; }