+++ /dev/null
-#include "stdafx.h"\r
-/*\r
-* Copyright (c) 2007-2010 SlimDX Group\r
-* \r
-* Permission is hereby granted, free of charge, to any person obtaining a copy\r
-* of this software and associated documentation files (the "Software"), to deal\r
-* in the Software without restriction, including without limitation the rights\r
-* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-* copies of the Software, and to permit persons to whom the Software is\r
-* furnished to do so, subject to the following conditions:\r
-* \r
-* The above copyright notice and this permission notice shall be included in\r
-* all copies or substantial portions of the Software.\r
-* \r
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
-* THE SOFTWARE.\r
-*/\r
-#include <d3d9.h>\r
-#include <d3dx9.h>\r
-\r
-#include "../ComObject.h"\r
-#include "../DataStream.h"\r
-\r
-#include "Direct3D9Exception.h"\r
-\r
-#include "Device.h"\r
-#include "Mesh.h"\r
-#include "UVAtlas.h"\r
-\r
-using namespace System;\r
-using namespace System::Runtime::InteropServices;\r
-\r
-namespace SlimDX\r
-{\r
-namespace Direct3D9\r
-{\r
- HRESULT WINAPI NativeAtlasCallback( FLOAT fPercentDone, LPVOID lpUserContext )\r
- {\r
- GCHandle handle = GCHandle::FromIntPtr( IntPtr( lpUserContext ) );\r
- Predicate<float>^ callback = safe_cast<Predicate<float>^>( handle.Target );\r
- HRESULT result;\r
-\r
- try\r
- {\r
- result = callback( fPercentDone ) ? S_OK : E_FAIL;\r
- }\r
- catch( Exception^ )\r
- {\r
- result = E_FAIL;\r
- }\r
-\r
- return result;\r
- }\r
-\r
- UVAtlasOutput^ UVAtlas::Create( Mesh^ mesh, int maxChartCount, float maxStretch, int width, int height, float gutter, int textureIndex,\r
- array<int>^ falseEdges, array<float>^ integratedMetricTensors, UVAtlasQuality quality )\r
- {\r
- return Create( mesh, maxChartCount, maxStretch, width, height, gutter, textureIndex, falseEdges, integratedMetricTensors, quality, nullptr, 0.0001f );\r
- }\r
-\r
- UVAtlasOutput^ UVAtlas::Create( Mesh^ mesh, int maxChartCount, float maxStretch, int width, int height, float gutter, int textureIndex,\r
- array<int>^ falseEdges, array<float>^ integratedMetricTensors, UVAtlasQuality quality, System::Predicate<float>^ callback, float callbackFrequency )\r
- {\r
- ID3DXMesh *meshOut;\r
- ID3DXBuffer *facePartitioning;\r
- ID3DXBuffer *vertexRemap;\r
- FLOAT maxStretchOut;\r
- UINT numChartsOut;\r
- HRESULT hr;\r
-\r
- pin_ptr<int> pinnedAdj;\r
- pin_ptr<int> pinnedFalseEdges;\r
- pin_ptr<float> pinnedIMTs;\r
-\r
- DWORD *inputAdjacencyPtr = NULL;\r
- DWORD *falseEdgesPtr = NULL;\r
- FLOAT *imtPtr = NULL;\r
-\r
- array<int>^ adj = mesh->GetAdjacency();\r
-\r
- if( adj != nullptr )\r
- {\r
- pinnedAdj = &adj[0];\r
- inputAdjacencyPtr = reinterpret_cast<DWORD*>( pinnedAdj );\r
- }\r
-\r
- if( falseEdges != nullptr )\r
- {\r
- pinnedFalseEdges = &falseEdges[0];\r
- falseEdgesPtr = reinterpret_cast<DWORD*>( pinnedFalseEdges );\r
- }\r
-\r
- if( integratedMetricTensors != nullptr )\r
- {\r
- pinnedIMTs = &integratedMetricTensors[0];\r
- imtPtr = pinnedIMTs;\r
- }\r
-\r
- if( callback != nullptr )\r
- {\r
- GCHandle handle = GCHandle::Alloc( callback, GCHandleType::Pinned );\r
-\r
- hr = D3DXUVAtlasCreate( mesh->InternalPointer, maxChartCount, maxStretch, width, height, gutter, textureIndex,\r
- inputAdjacencyPtr, falseEdgesPtr, imtPtr, NativeAtlasCallback, callbackFrequency, safe_cast<IntPtr>( handle ).ToPointer(), \r
- static_cast<DWORD>( quality ), &meshOut, &facePartitioning, &vertexRemap, &maxStretchOut, &numChartsOut );\r
-\r
- if( handle.IsAllocated )\r
- handle.Free();\r
- }\r
- else\r
- {\r
- hr = D3DXUVAtlasCreate( mesh->InternalPointer, maxChartCount, maxStretch, width, height, gutter, textureIndex,\r
- inputAdjacencyPtr, falseEdgesPtr, imtPtr, NULL, callbackFrequency, NULL, static_cast<DWORD>( quality ), &meshOut, \r
- &facePartitioning, &vertexRemap, &maxStretchOut, &numChartsOut );\r
- }\r
-\r
- if( RECORD_D3D9( hr ).IsFailure )\r
- return nullptr;\r
-\r
- return gcnew UVAtlasOutput( Mesh::FromPointer( meshOut ), gcnew DataStream( facePartitioning ), gcnew DataStream( vertexRemap ), \r
- maxStretchOut, numChartsOut );\r
- }\r
-\r
- UVAtlasOutput^ UVAtlas::Partition( Mesh^ mesh, int maxChartCount, float maxStretch, int textureIndex,\r
- array<int>^ falseEdges, array<float>^ integratedMetricTensors, UVAtlasQuality quality, [Out] DataStream^% partitionAdjacency )\r
- {\r
- return Partition( mesh, maxChartCount, maxStretch, textureIndex, falseEdges, integratedMetricTensors, quality, \r
- partitionAdjacency, nullptr, 0.0001f );\r
- }\r
-\r
- UVAtlasOutput^ UVAtlas::Partition( Mesh^ mesh, int maxChartCount, float maxStretch, int textureIndex,\r
- array<int>^ falseEdges, array<float>^ integratedMetricTensors, UVAtlasQuality quality, [Out] DataStream^% partitionAdjacency, \r
- System::Predicate<float>^ callback, float callbackFrequency )\r
- {\r
- ID3DXMesh *meshOut;\r
- ID3DXBuffer *facePartitioning;\r
- ID3DXBuffer *vertexRemap;\r
- ID3DXBuffer *partitionResult;\r
- FLOAT maxStretchOut;\r
- UINT numChartsOut;\r
- HRESULT hr;\r
-\r
- pin_ptr<int> pinnedAdj;\r
- pin_ptr<int> pinnedFalseEdges;\r
- pin_ptr<float> pinnedIMTs;\r
-\r
- DWORD *inputAdjacencyPtr = NULL;\r
- DWORD *falseEdgesPtr = NULL;\r
- FLOAT *imtPtr = NULL;\r
-\r
- array<int>^ adj = mesh->GetAdjacency();\r
-\r
- if( adj != nullptr )\r
- {\r
- pinnedAdj = &adj[0];\r
- inputAdjacencyPtr = reinterpret_cast<DWORD*>( pinnedAdj );\r
- }\r
-\r
- if( falseEdges != nullptr )\r
- {\r
- pinnedFalseEdges = &falseEdges[0];\r
- falseEdgesPtr = reinterpret_cast<DWORD*>( pinnedFalseEdges );\r
- }\r
-\r
- if( integratedMetricTensors != nullptr )\r
- {\r
- pinnedIMTs = &integratedMetricTensors[0];\r
- imtPtr = pinnedIMTs;\r
- }\r
-\r
- if( callback != nullptr )\r
- {\r
- GCHandle handle = GCHandle::Alloc( callback, GCHandleType::Pinned );\r
-\r
- hr = D3DXUVAtlasPartition( mesh->InternalPointer, maxChartCount, maxStretch, textureIndex,\r
- inputAdjacencyPtr, falseEdgesPtr, imtPtr, NativeAtlasCallback, callbackFrequency, safe_cast<IntPtr>( handle ).ToPointer(), \r
- static_cast<DWORD>( quality ), &meshOut, &facePartitioning, &vertexRemap, &partitionResult, &maxStretchOut, &numChartsOut );\r
-\r
- if( handle.IsAllocated )\r
- handle.Free();\r
- }\r
- else\r
- {\r
- hr = D3DXUVAtlasPartition( mesh->InternalPointer, maxChartCount, maxStretch, textureIndex,\r
- inputAdjacencyPtr, falseEdgesPtr, imtPtr, NULL, callbackFrequency, NULL, static_cast<DWORD>( quality ), &meshOut, \r
- &facePartitioning, &vertexRemap, &partitionResult, &maxStretchOut, &numChartsOut );\r
- }\r
-\r
- if( RECORD_D3D9( hr ).IsFailure )\r
- {\r
- partitionAdjacency = nullptr;\r
- return nullptr;\r
- }\r
-\r
- partitionAdjacency = gcnew DataStream( partitionResult );\r
-\r
- return gcnew UVAtlasOutput( Mesh::FromPointer( meshOut ), gcnew DataStream( facePartitioning ), gcnew DataStream( vertexRemap ), \r
- maxStretchOut, numChartsOut );\r
- }\r
-\r
- Result UVAtlas::Pack( Mesh^ mesh, int width, int height, float gutter, int textureIndex, array<int>^ partitionAdjacency, UVAtlasQuality quality, DataStream^ facePartitioning )\r
- {\r
- return Pack( mesh, width, height, gutter, textureIndex, partitionAdjacency, quality, facePartitioning, nullptr, 0.0001f );\r
- }\r
-\r
- Result UVAtlas::Pack( Mesh^ mesh, int width, int height, float gutter, int textureIndex, array<int>^ partitionAdjacency, \r
- UVAtlasQuality quality, DataStream^ facePartitioning, System::Predicate<float>^ callback, float callbackFrequency )\r
- {\r
- HRESULT hr;\r
- pin_ptr<int> pinnedAdj = &partitionAdjacency[0];\r
-\r
- if( callback != nullptr )\r
- {\r
- GCHandle handle = GCHandle::Alloc( callback, GCHandleType::Pinned );\r
-\r
- hr = D3DXUVAtlasPack( mesh->InternalPointer, width, height, gutter, textureIndex,\r
- reinterpret_cast<DWORD*>( pinnedAdj ), NativeAtlasCallback, callbackFrequency, safe_cast<IntPtr>( handle ).ToPointer(), \r
- static_cast<DWORD>( quality ), facePartitioning->GetD3DBuffer() );\r
-\r
- if( handle.IsAllocated )\r
- handle.Free();\r
- }\r
- else\r
- {\r
- hr = D3DXUVAtlasPack( mesh->InternalPointer, width, height, gutter, textureIndex,\r
- reinterpret_cast<DWORD*>( pinnedAdj ), NULL, callbackFrequency, NULL, \r
- static_cast<DWORD>( quality ), facePartitioning->GetD3DBuffer() );\r
- }\r
-\r
- return RECORD_D3D9( hr );\r
- }\r
-}\r
-}
\ No newline at end of file