protected override void OnResultCompile() { if (Result == null) { GpuTexture result = null; PixelFormat createFormatV = CreateFormat; if (createFormatV != PixelFormat.Unknown) { //create Vector2I size = CreateSize; if (size.X > 0 && size.Y > 0) { //!!!!!что еще проверить? //!!!!3d support TypeEnum type = CreateType; bool mipmaps = CreateMipmaps; int arrayLayers = CreateArrayLayers; Usages usage = CreateUsage; int fsaa = CreateFSAA; int depth; if (type == TypeEnum._2D) { depth = 1; } else if (type == TypeEnum.Cube) { depth = 6; } else { depth = CreateDepth; } GpuTexture.Usages gpuUsage = 0; if ((usage & Usages.Dynamic) != 0) { gpuUsage |= GpuTexture.Usages.Dynamic; } else { gpuUsage |= GpuTexture.Usages.Static; } if ((usage & Usages.WriteOnly) != 0) { gpuUsage |= GpuTexture.Usages.WriteOnly; } if ((usage & Usages.AutoMipmaps) != 0) { gpuUsage |= GpuTexture.Usages.AutoMipmap; } if ((usage & Usages.RenderTarget) != 0) { gpuUsage |= GpuTexture.Usages.RenderTarget; } if ((usage & Usages.ReadBack) != 0) { gpuUsage |= GpuTexture.Usages.ReadBack; } if ((usage & Usages.BlitDestination) != 0) { gpuUsage |= GpuTexture.Usages.BlitDestination; } //!!!!!почему для других не Discardable? if ((gpuUsage & GpuTexture.Usages.Dynamic) != 0 && (gpuUsage & GpuTexture.Usages.WriteOnly) != 0) { gpuUsage |= GpuTexture.Usages.DynamicWriteOnlyDiscardable; } result = new GpuTexture(type, size, depth, mipmaps, arrayLayers, createFormatV, gpuUsage, fsaa, out var error2); if (!string.IsNullOrEmpty(error2)) { result.Dispose(); result = null; Log.Warning("Unable to create texture. " + error2); } } } else { //load //!!!!3d support //!!!!!проверять наличие файла. если нет, то он по дефолту создает 512 512 Unknown формат. это какая-то хрень. надо разрулить //!!!!threading //!!!!!каждый раз проверять будет если нет файла. где еще так? string[] loadCubeMap6Files = null; string loadFromOneFile = null; if (AnyCubemapSideIsSpecified()) { if (AllCubemapSidesAreaSpecified()) { loadCubeMap6Files = new string[6]; for (int n = 0; n < 6; n++) { var v = GetLoadCubeSide(n); if (v != null) { loadCubeMap6Files[n] = v.ResourceName; } if (string.IsNullOrEmpty(loadCubeMap6Files[n]) || !VirtualFile.Exists(loadCubeMap6Files[n])) { loadCubeMap6Files = null; break; } } } } else { var v = LoadFile.Value; loadFromOneFile = v != null ? v.ResourceName : ""; if (string.IsNullOrEmpty(loadFromOneFile) || !VirtualFile.Exists(loadFromOneFile)) { loadFromOneFile = null; } } //!!!! //bool RenderToTexture = false; //if( RenderToTexture ) // result = RenderToTextureTest(); //else if (loadFromOneFile != null) { result = LoadOneTexture(loadFromOneFile); } else if (loadCubeMap6Files != null) { result = LoadCubeTexture(loadCubeMap6Files); } } Result = result; } }
public static Component_Mesh.StructureClass CreateMeshStructure(Face[] faces) { var result = new Component_Mesh.StructureClass(); int vertexMaxIndex = 0; //faces result.Faces = new Component_Mesh.StructureClass.Face[faces.Length]; for (int nFace = 0; nFace < faces.Length; nFace++) { var face = faces[nFace]; var triangles2 = new Component_Mesh.StructureClass.FaceVertex[face.Triangles.Length]; for (int n = 0; n < triangles2.Length; n++) { var faceVertex = face.Triangles[n]; triangles2[n] = new Component_Mesh.StructureClass.FaceVertex(faceVertex.Vertex, 0, faceVertex.RawVertex); vertexMaxIndex = Math.Max(vertexMaxIndex, faceVertex.Vertex); } result.Faces[nFace] = new Component_Mesh.StructureClass.Face(triangles2, null, 0); } //edges var edges = new ESet <Vector2I>(vertexMaxIndex * 3); for (int nFace = 0; nFace < faces.Length; nFace++) { var face = faces[nFace]; var edgeCounts = new Dictionary <Vector2I, int>(face.Triangles.Length); for (int nTriangle = 0; nTriangle < face.Triangles.Length / 3; nTriangle++) { var faceVertex0 = face.Triangles[nTriangle * 3 + 0]; var faceVertex1 = face.Triangles[nTriangle * 3 + 1]; var faceVertex2 = face.Triangles[nTriangle * 3 + 2]; void AddEdge(int vertex1, int vertex2) { int v1, v2; if (vertex1 > vertex2) { v1 = vertex2; v2 = vertex1; } else { v1 = vertex1; v2 = vertex2; } var key = new Vector2I(v1, v2); edgeCounts.TryGetValue(key, out var count); edgeCounts[key] = count + 1; } AddEdge(faceVertex0.Vertex, faceVertex1.Vertex); AddEdge(faceVertex1.Vertex, faceVertex2.Vertex); AddEdge(faceVertex2.Vertex, faceVertex0.Vertex); } foreach (var pair in edgeCounts) { if (pair.Value == 1) { var edge = pair.Key; edges.AddWithCheckAlreadyContained(new Vector2I(edge.X, edge.Y)); } } //for( int nTriangle = 0; nTriangle < face.Triangles.Length / 3; nTriangle++ ) //{ // var faceVertex0 = face.Triangles[ nTriangle * 3 + 0 ]; // var faceVertex1 = face.Triangles[ nTriangle * 3 + 1 ]; // var faceVertex2 = face.Triangles[ nTriangle * 3 + 2 ]; // void AddEdge( int vertex1, int vertex2 ) // { // int v1, v2; // if( vertex1 > vertex2 ) // { // v1 = vertex2; // v2 = vertex1; // } // else // { // v1 = vertex1; // v2 = vertex2; // } // edges.AddWithCheckAlreadyContained( new Vector2I( v1, v2 ) ); // } // AddEdge( faceVertex0.Vertex, faceVertex1.Vertex ); // AddEdge( faceVertex1.Vertex, faceVertex2.Vertex ); // AddEdge( faceVertex2.Vertex, faceVertex0.Vertex ); //} } result.Edges = edges.Select(e => new Component_Mesh.StructureClass.Edge(e.X, e.Y)).ToArray(); //vertices result.Vertices = new Component_Mesh.StructureClass.Vertex[vertexMaxIndex + 1]; return(result); }