OSDN Git Service

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