+++ /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
-#include <vcclr.h>\r
-\r
-#include "../ComObject.h"\r
-#include "../Utilities.h"\r
-#include "../DataStream.h"\r
-\r
-#include "Device.h"\r
-#include "Texture.h"\r
-#include "IndexBuffer.h"\r
-#include "VertexBuffer.h"\r
-#include "Mesh.h"\r
-#include "SimplificationMesh.h"\r
-#include "ProgressiveMesh.h"\r
-\r
-#include "Direct3D9Exception.h"\r
-\r
-using namespace System;\r
-using namespace System::IO;\r
-using namespace System::Runtime::InteropServices;\r
-\r
-namespace SlimDX\r
-{\r
-namespace Direct3D9\r
-{\r
- SimplificationMesh::SimplificationMesh( Mesh^ mesh, array<AttributeWeights>^ vertexAttributeWeights, array<float>^ vertexWeights )\r
- {\r
- ID3DXSPMesh *result;\r
-\r
- DWORD *adjacencyIn = NULL;\r
- pin_ptr<int> pinnedAdj;\r
- array<int>^ adjacency = mesh->GetAdjacency();\r
-\r
- if( adjacency != nullptr )\r
- {\r
- pinnedAdj = &adjacency[0];\r
- adjacencyIn = reinterpret_cast<DWORD*>( pinnedAdj );\r
- }\r
-\r
- pin_ptr<AttributeWeights> pinnedVAW = &vertexAttributeWeights[0];\r
- pin_ptr<float> pinnedVW = &vertexWeights[0];\r
-\r
- HRESULT hr = D3DXCreateSPMesh( mesh->InternalPointer, adjacencyIn,\r
- reinterpret_cast<const D3DXATTRIBUTEWEIGHTS*>( pinnedVAW ), reinterpret_cast<const FLOAT *>( pinnedVW ), &result );\r
- \r
- if( RECORD_D3D9( hr ).IsFailure )\r
- throw gcnew Direct3D9Exception( Result::Last );\r
-\r
- Construct(result);\r
- }\r
-\r
- SimplificationMesh::SimplificationMesh( Mesh^ mesh, array<AttributeWeights>^ vertexAttributeWeights )\r
- {\r
- ID3DXSPMesh *result;\r
-\r
- DWORD *adjacencyIn = NULL;\r
- pin_ptr<int> pinnedAdj;\r
- array<int>^ adjacency = mesh->GetAdjacency();\r
-\r
- if( adjacency != nullptr )\r
- {\r
- pinnedAdj = &adjacency[0];\r
- adjacencyIn = reinterpret_cast<DWORD*>( pinnedAdj );\r
- }\r
-\r
- pin_ptr<AttributeWeights> pinnedVAW = &vertexAttributeWeights[0];\r
-\r
- HRESULT hr = D3DXCreateSPMesh( mesh->InternalPointer, adjacencyIn,\r
- reinterpret_cast<const D3DXATTRIBUTEWEIGHTS*>( pinnedVAW ), NULL, &result );\r
- \r
- if( RECORD_D3D9( hr ).IsFailure )\r
- throw gcnew Direct3D9Exception( Result::Last );\r
-\r
- Construct(result);\r
- }\r
-\r
- SimplificationMesh::SimplificationMesh( Mesh^ mesh, array<float>^ vertexWeights )\r
- {\r
- ID3DXSPMesh *result;\r
-\r
- DWORD *adjacencyIn = NULL;\r
- pin_ptr<int> pinnedAdj;\r
- array<int>^ adjacency = mesh->GetAdjacency();\r
-\r
- if( adjacency != nullptr )\r
- {\r
- pinnedAdj = &adjacency[0];\r
- adjacencyIn = reinterpret_cast<DWORD*>( pinnedAdj );\r
- }\r
-\r
- pin_ptr<float> pinnedVW = &vertexWeights[0];\r
-\r
- HRESULT hr = D3DXCreateSPMesh( mesh->InternalPointer, adjacencyIn,\r
- NULL, reinterpret_cast<const FLOAT *>( pinnedVW ), &result );\r
- \r
- if( RECORD_D3D9( hr ).IsFailure )\r
- throw gcnew Direct3D9Exception( Result::Last );\r
-\r
- Construct(result);\r
- }\r
-\r
- SimplificationMesh::SimplificationMesh( Mesh^ mesh )\r
- {\r
- ID3DXSPMesh *result;\r
-\r
- DWORD *adjacencyIn = NULL;\r
- pin_ptr<int> pinnedAdj;\r
- array<int>^ adjacency = mesh->GetAdjacency();\r
-\r
- if( adjacency != nullptr )\r
- {\r
- pinnedAdj = &adjacency[0];\r
- adjacencyIn = reinterpret_cast<DWORD*>( pinnedAdj );\r
- }\r
-\r
- HRESULT hr = D3DXCreateSPMesh( mesh->InternalPointer, adjacencyIn, NULL, NULL, &result );\r
- \r
- if( RECORD_D3D9( hr ).IsFailure )\r
- throw gcnew Direct3D9Exception( Result::Last );\r
-\r
- Construct(result);\r
- }\r
-\r
- Mesh^ SimplificationMesh::Clone( SlimDX::Direct3D9::Device^ device, MeshFlags options, array<VertexElement>^ vertexDeclaration, [Out] array<int>^% vertexRemap )\r
- {\r
- ID3DXMesh *result;\r
-\r
- pin_ptr<VertexElement> pinnedDecl = &vertexDeclaration[0];\r
- array<int>^ adjacencyOut = gcnew array<int>( FaceCount * 3 );\r
- pin_ptr<int> pinnedAdj = &adjacencyOut[0];\r
- vertexRemap = gcnew array<int>( VertexCount );\r
- pin_ptr<int> pinnedVR = &vertexRemap[0];\r
-\r
- HRESULT hr = InternalPointer->CloneMesh( static_cast<DWORD>( options ), reinterpret_cast<const D3DVERTEXELEMENT9*>( pinnedDecl ),\r
- device->InternalPointer, reinterpret_cast<DWORD*>( pinnedAdj ), reinterpret_cast<DWORD*>( pinnedVR ), &result );\r
- \r
- if( RECORD_D3D9( hr ).IsFailure )\r
- {\r
- vertexRemap = nullptr;\r
- return nullptr;\r
- }\r
-\r
- Mesh^ mesh = Mesh::FromPointer( result );\r
- mesh->SetAdjacency( adjacencyOut );\r
-\r
- return mesh;\r
- }\r
-\r
- Mesh^ SimplificationMesh::Clone( SlimDX::Direct3D9::Device^ device, MeshFlags options, array<VertexElement>^ vertexDeclaration )\r
- {\r
- ID3DXMesh *result;\r
-\r
- pin_ptr<VertexElement> pinnedDecl = &vertexDeclaration[0];\r
- array<int>^ adjacencyOut = gcnew array<int>( FaceCount * 3 );\r
- pin_ptr<int> pinnedAdj = &adjacencyOut[0];\r
-\r
- HRESULT hr = InternalPointer->CloneMesh( static_cast<DWORD>( options ), reinterpret_cast<const D3DVERTEXELEMENT9*>( pinnedDecl ),\r
- device->InternalPointer, reinterpret_cast<DWORD*>( pinnedAdj ), NULL, &result );\r
- \r
- if( RECORD_D3D9( hr ).IsFailure )\r
- return nullptr;\r
-\r
- Mesh^ mesh = Mesh::FromPointer( result );\r
- mesh->SetAdjacency( adjacencyOut );\r
-\r
- return mesh;\r
- }\r
-\r
- Mesh^ SimplificationMesh::Clone( SlimDX::Direct3D9::Device^ device, MeshFlags options, SlimDX::Direct3D9::VertexFormat fvf, [Out] array<int>^% vertexRemap )\r
- {\r
- ID3DXMesh *result;\r
-\r
- array<int>^ adjacencyOut = gcnew array<int>( FaceCount * 3 );\r
- pin_ptr<int> pinnedAdj = &adjacencyOut[0];\r
- vertexRemap = gcnew array<int>( VertexCount );\r
- pin_ptr<int> pinnedVR = &vertexRemap[0];\r
-\r
- HRESULT hr = InternalPointer->CloneMeshFVF( static_cast<DWORD>( options ), static_cast<DWORD>( fvf ),\r
- device->InternalPointer, reinterpret_cast<DWORD*>( pinnedAdj ), reinterpret_cast<DWORD*>( pinnedVR ), &result );\r
- \r
- if( RECORD_D3D9( hr ).IsFailure )\r
- {\r
- vertexRemap = nullptr;\r
- return nullptr;\r
- }\r
-\r
- Mesh^ mesh = Mesh::FromPointer( result );\r
- mesh->SetAdjacency( adjacencyOut );\r
-\r
- return mesh;\r
- }\r
-\r
- Mesh^ SimplificationMesh::Clone( SlimDX::Direct3D9::Device^ device, MeshFlags options, SlimDX::Direct3D9::VertexFormat fvf )\r
- {\r
- ID3DXMesh *result;\r
-\r
- array<int>^ adjacencyOut = gcnew array<int>( FaceCount * 3 );\r
- pin_ptr<int> pinnedAdj = &adjacencyOut[0];\r
-\r
- HRESULT hr = InternalPointer->CloneMeshFVF( static_cast<DWORD>( options ), static_cast<DWORD>( fvf ),\r
- device->InternalPointer, reinterpret_cast<DWORD*>( pinnedAdj ), NULL, &result );\r
- \r
- if( RECORD_D3D9( hr ).IsFailure )\r
- return nullptr;\r
-\r
- Mesh^ mesh = Mesh::FromPointer( result );\r
- mesh->SetAdjacency( adjacencyOut );\r
-\r
- return mesh;\r
- }\r
-\r
- ProgressiveMesh^ SimplificationMesh::CloneProgressive( SlimDX::Direct3D9::Device^ device, MeshFlags options, array<VertexElement>^ vertexDeclaration, [Out] array<int>^% vertexRemap, [Out] array<float>^% errorsByFace )\r
- {\r
- ID3DXPMesh *result;\r
-\r
- pin_ptr<VertexElement> pinnedDecl = &vertexDeclaration[0];\r
- vertexRemap = gcnew array<int>( VertexCount );\r
- errorsByFace = gcnew array<float>( FaceCount );\r
- pin_ptr<float> pinnedEBF = &errorsByFace[0];\r
- pin_ptr<int> pinnedVR = &vertexRemap[0];\r
-\r
- HRESULT hr = InternalPointer->ClonePMesh( static_cast<DWORD>( options ), reinterpret_cast<const D3DVERTEXELEMENT9*>( pinnedDecl ),\r
- device->InternalPointer, reinterpret_cast<DWORD*>( pinnedVR ), reinterpret_cast<FLOAT*>( pinnedEBF ), &result );\r
- \r
- if( RECORD_D3D9( hr ).IsFailure )\r
- {\r
- errorsByFace = nullptr;\r
- vertexRemap = nullptr;\r
- return nullptr;\r
- }\r
-\r
- return ProgressiveMesh::FromPointer( result );\r
- }\r
-\r
- ProgressiveMesh^ SimplificationMesh::CloneProgressive( SlimDX::Direct3D9::Device^ device, MeshFlags options, array<VertexElement>^ vertexDeclaration, [Out] array<int>^% vertexRemap )\r
- {\r
- ID3DXPMesh *result;\r
-\r
- pin_ptr<VertexElement> pinnedDecl = &vertexDeclaration[0];\r
- vertexRemap = gcnew array<int>( VertexCount );\r
- pin_ptr<int> pinnedVR = &vertexRemap[0];\r
-\r
- HRESULT hr = InternalPointer->ClonePMesh( static_cast<DWORD>( options ), reinterpret_cast<const D3DVERTEXELEMENT9*>( pinnedDecl ),\r
- device->InternalPointer, reinterpret_cast<DWORD*>( pinnedVR ), NULL, &result );\r
- \r
- if( RECORD_D3D9( hr ).IsFailure )\r
- {\r
- vertexRemap = nullptr;\r
- return nullptr;\r
- }\r
-\r
- return ProgressiveMesh::FromPointer( result );\r
- }\r
-\r
- ProgressiveMesh^ SimplificationMesh::CloneProgressive( SlimDX::Direct3D9::Device^ device, MeshFlags options, array<VertexElement>^ vertexDeclaration )\r
- {\r
- ID3DXPMesh *result;\r
-\r
- pin_ptr<VertexElement> pinnedDecl = &vertexDeclaration[0];\r
-\r
- HRESULT hr = InternalPointer->ClonePMesh( static_cast<DWORD>( options ), reinterpret_cast<const D3DVERTEXELEMENT9*>( pinnedDecl ),\r
- device->InternalPointer, NULL, NULL, &result );\r
- \r
- if( RECORD_D3D9( hr ).IsFailure )\r
- return nullptr;\r
-\r
- return ProgressiveMesh::FromPointer( result );\r
- }\r
-\r
- ProgressiveMesh^ SimplificationMesh::CloneProgressive( SlimDX::Direct3D9::Device^ device, MeshFlags options, SlimDX::Direct3D9::VertexFormat fvf, [Out] array<int>^% vertexRemap, [Out] array<float>^% errorsByFace )\r
- {\r
- ID3DXPMesh *result;\r
-\r
- vertexRemap = gcnew array<int>( VertexCount );\r
- errorsByFace = gcnew array<float>( FaceCount );\r
-\r
- pin_ptr<float> pinnedEBF = &errorsByFace[0];\r
- pin_ptr<int> pinnedVR = &vertexRemap[0];\r
-\r
- HRESULT hr = InternalPointer->ClonePMeshFVF( static_cast<DWORD>( options ), static_cast<DWORD>( fvf ),\r
- device->InternalPointer, reinterpret_cast<DWORD*>( pinnedVR ), reinterpret_cast<FLOAT*>( pinnedEBF ), &result );\r
- \r
- if( RECORD_D3D9( hr ).IsFailure )\r
- {\r
- errorsByFace = nullptr;\r
- vertexRemap = nullptr;\r
- return nullptr;\r
- }\r
-\r
- return ProgressiveMesh::FromPointer( result );\r
- }\r
-\r
- ProgressiveMesh^ SimplificationMesh::CloneProgressive( SlimDX::Direct3D9::Device^ device, MeshFlags options, SlimDX::Direct3D9::VertexFormat fvf, [Out] array<int>^% vertexRemap )\r
- {\r
- ID3DXPMesh *result;\r
-\r
- vertexRemap = gcnew array<int>( VertexCount );\r
- pin_ptr<int> pinnedVR = &vertexRemap[0];\r
-\r
- HRESULT hr = InternalPointer->ClonePMeshFVF( static_cast<DWORD>( options ), static_cast<DWORD>( fvf ),\r
- device->InternalPointer, reinterpret_cast<DWORD*>( pinnedVR ), NULL, &result );\r
- \r
- if( RECORD_D3D9( hr ).IsFailure )\r
- {\r
- vertexRemap = nullptr;\r
- return nullptr;\r
- }\r
-\r
- return ProgressiveMesh::FromPointer( result );\r
- }\r
-\r
- ProgressiveMesh^ SimplificationMesh::CloneProgressive( SlimDX::Direct3D9::Device^ device, MeshFlags options, SlimDX::Direct3D9::VertexFormat fvf )\r
- {\r
- ID3DXPMesh *result;\r
-\r
- HRESULT hr = InternalPointer->ClonePMeshFVF( static_cast<DWORD>( options ), static_cast<DWORD>( fvf ),\r
- device->InternalPointer, NULL, NULL, &result );\r
- \r
- if( RECORD_D3D9( hr ).IsFailure )\r
- return nullptr;\r
-\r
- return ProgressiveMesh::FromPointer( result );\r
- }\r
-\r
- array<VertexElement>^ SimplificationMesh::GetDeclaration()\r
- {\r
- D3DVERTEXELEMENT9 elementBuffer[MAX_FVF_DECL_SIZE];\r
- HRESULT hr = InternalPointer->GetDeclaration( elementBuffer );\r
- \r
- if( RECORD_D3D9( hr ).IsFailure )\r
- return nullptr;\r
-\r
- int count = D3DXGetDeclLength( elementBuffer ) + 1;\r
- array<VertexElement>^ elements = gcnew array<VertexElement>( count );\r
- pin_ptr<VertexElement> pinnedElements = &elements[0];\r
- memcpy( pinnedElements, elementBuffer, count * sizeof(D3DVERTEXELEMENT9) );\r
- elements[count - 1] = VertexElement::VertexDeclarationEnd;\r
-\r
- return elements;\r
- }\r
-\r
- SlimDX::Direct3D9::Device^ SimplificationMesh::Device::get()\r
- {\r
- IDirect3DDevice9* device;\r
- HRESULT hr = InternalPointer->GetDevice( &device );\r
- \r
- if( RECORD_D3D9( hr ).IsFailure )\r
- return nullptr;\r
-\r
- return SlimDX::Direct3D9::Device::FromPointer( device );\r
- }\r
-\r
- array<AttributeWeights>^ SimplificationMesh::GetVertexAttributeWeights()\r
- {\r
- array<AttributeWeights>^ results = gcnew array<AttributeWeights>( MaximumVertexCount );\r
- pin_ptr<AttributeWeights> pinnedResults = &results[0];\r
-\r
- HRESULT hr = InternalPointer->GetVertexAttributeWeights( reinterpret_cast<D3DXATTRIBUTEWEIGHTS*>( pinnedResults ) );\r
- \r
- if( RECORD_D3D9( hr ).IsFailure )\r
- return nullptr;\r
-\r
- return results;\r
- }\r
-\r
- array<float>^ SimplificationMesh::GetVertexWeights()\r
- {\r
- array<float>^ results = gcnew array<float>( MaximumVertexCount );\r
- pin_ptr<float> pinnedResults = &results[0];\r
-\r
- HRESULT hr = InternalPointer->GetVertexWeights( reinterpret_cast<FLOAT*>( pinnedResults ) );\r
- \r
- if( RECORD_D3D9( hr ).IsFailure )\r
- return nullptr;\r
-\r
- return results;\r
- }\r
-\r
- Result SimplificationMesh::ReduceFaces( int faces )\r
- {\r
- HRESULT hr = InternalPointer->ReduceFaces( faces );\r
- return RECORD_D3D9( hr );\r
- }\r
-\r
- Result SimplificationMesh::ReduceVertices( int vertices )\r
- {\r
- HRESULT hr = InternalPointer->ReduceVertices( vertices );\r
- return RECORD_D3D9( hr );\r
- }\r
-\r
- int SimplificationMesh::MaximumFaceCount::get()\r
- {\r
- return InternalPointer->GetMaxFaces();\r
- }\r
-\r
- int SimplificationMesh::MaximumVertexCount::get()\r
- {\r
- return InternalPointer->GetMaxVertices();\r
- }\r
-\r
- int SimplificationMesh::FaceCount::get()\r
- {\r
- return InternalPointer->GetNumFaces();\r
- }\r
-\r
- int SimplificationMesh::VertexCount::get()\r
- {\r
- return InternalPointer->GetNumVertices();\r
- }\r
-\r
- SlimDX::Direct3D9::VertexFormat SimplificationMesh::VertexFormat::get()\r
- {\r
- return static_cast<SlimDX::Direct3D9::VertexFormat>( InternalPointer->GetFVF() );\r
- }\r
-\r
- MeshFlags SimplificationMesh::CreationOptions::get()\r
- {\r
- return static_cast<MeshFlags>( InternalPointer->GetOptions() );\r
- }\r
-}\r
-}
\ No newline at end of file