OSDN Git Service

convert literal tab
[tdcgexplorer/tso2mqo.git] / NvTriStrip.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.Text;\r
4 using System.Runtime.InteropServices;\r
5 \r
6 namespace Tso2MqoGui\r
7 {\r
8     public enum PrimType\r
9     {\r
10             PT_LIST,\r
11             PT_STRIP,\r
12             PT_FAN\r
13     }\r
14 \r
15     public unsafe struct PrimitiveGroup\r
16     {\r
17             public PrimType type;\r
18             public uint     numIndices;\r
19             public ushort*  indices;\r
20     }\r
21 \r
22     public unsafe class NvTriStrip\r
23     {\r
24         public static ushort[] Optimize(ushort[] triangles)\r
25         {\r
26             fixed(ushort* p= &triangles[0])\r
27             {\r
28                     SetStitchStrips(true);\r
29 \r
30                 PrimitiveGroup* pg  = null;\r
31                 ushort          num = 0;\r
32                 bool            rc  = GenerateStrips(p, (uint)triangles.Length, &pg, &num, false);\r
33 \r
34                 if(!rc)                                 throw new Exception();\r
35 \r
36                 try\r
37                 {\r
38                     if(num != 1)                        throw new Exception();\r
39                     if(pg[0].type != PrimType.PT_STRIP) throw new Exception();\r
40 \r
41                     ushort[]    nidx= new ushort[pg[0].numIndices];\r
42 \r
43                     for(int i= 0; i < nidx.Length; ++i)\r
44                         nidx[i] = pg[0].indices[i];\r
45 \r
46                     return nidx;\r
47                 } finally\r
48                 {\r
49                     DeletePrimitiveGroup(pg);\r
50                 }\r
51             }\r
52         }\r
53 \r
54       //[DllImport("NvTriStrip.dll")] public extern static int GetPicture(byte* file, int len, uint flag, out IntPtr pHBInfo, out IntPtr pHBm, void* lpPrgressCallback, uint lData); \r
55         [DllImport("NvTriStrip.dll")] public extern static void EnableRestart(uint _restartVal);\r
56         [DllImport("NvTriStrip.dll")] public extern static void DisableRestart();\r
57         [DllImport("NvTriStrip.dll")] public extern static void SetListsOnly(bool _bListsOnly);\r
58         [DllImport("NvTriStrip.dll")] public extern static void SetCacheSize(uint _cacheSize);\r
59         [DllImport("NvTriStrip.dll")] public extern static void SetStitchStrips(bool _bStitchStrips);\r
60         [DllImport("NvTriStrip.dll")] public extern static void SetMinStripSize(uint _minStripSize);\r
61       //[DllImport("NvTriStrip.dll")] public extern static void Cleanup(NvStripInfoVec& tempStrips, NvFaceInfoVec& tempFaces);\r
62         [DllImport("NvTriStrip.dll")] public extern static bool SameTriangle(ushort firstTri0, ushort firstTri1, ushort firstTri2, ushort secondTri0, ushort secondTri1, ushort secondTri2);\r
63       //[DllImport("NvTriStrip.dll")] public extern static bool TestTriangle(ushort v0, ushort v1, ushort v2, const std::vector<NvFaceInfo>* in_bins, const int NUMBINS);\r
64         [DllImport("NvTriStrip.dll")] public extern static void DeletePrimitiveGroup(PrimitiveGroup* primGroups);\r
65         [DllImport("NvTriStrip.dll")] public extern static bool GenerateStrips(ushort* in_indices, uint in_numIndices, PrimitiveGroup** primGroups, ushort* numGroups, bool validateEnabled);\r
66         [DllImport("NvTriStrip.dll")] public extern static void RemapIndices(PrimitiveGroup* in_primGroups, ushort numGroups, ushort numVerts, PrimitiveGroup** remappedGroups);\r
67     }\r
68 }\r