X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=SlimDXc_Jun2010%28VC%2B%2B2008%29%2Fsource%2Fdirect3d9%2FSkinInfo.cpp;fp=SlimDXc_Jun2010%28VC%2B%2B2008%29%2Fsource%2Fdirect3d9%2FSkinInfo.cpp;h=0000000000000000000000000000000000000000;hb=d3453b257c2faf4db202d38666a872929ff220cd;hp=e00ba0b2e7e2e0f47e78e406fd9773cad94f574a;hpb=1c2eac207d4963c6bc170b3f7fbe0feeffcd17e0;p=dtxmania%2Fdtxmania.git diff --git a/SlimDXc_Jun2010(VC++2008)/source/direct3d9/SkinInfo.cpp b/SlimDXc_Jun2010(VC++2008)/source/direct3d9/SkinInfo.cpp deleted file mode 100644 index e00ba0b2..00000000 --- a/SlimDXc_Jun2010(VC++2008)/source/direct3d9/SkinInfo.cpp +++ /dev/null @@ -1,522 +0,0 @@ -#include "stdafx.h" -/* -* Copyright (c) 2007-2010 SlimDX Group -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -*/ -#include -#include -#include - -#include "../stack_array.h" -#include "../DataStream.h" -#include "../ComObject.h" - -#include "Device.h" -#include "IndexBuffer.h" -#include "Mesh.h" -#include "SkinInfo.h" - -#include "Direct3D9Exception.h" - -using namespace System; - -namespace SlimDX -{ -namespace Direct3D9 -{ - SkinInfo::SkinInfo( int vertexCount, array^ vertexDeclaration, int boneCount ) - { - ID3DXSkinInfo *result; - - pin_ptr pinnedDecl = &vertexDeclaration[0]; - - HRESULT hr = D3DXCreateSkinInfo( vertexCount, reinterpret_cast( pinnedDecl ), - boneCount, &result ); - - if( RECORD_D3D9( hr ).IsFailure ) - throw gcnew Direct3D9Exception( Result::Last ); - - Construct( result ); - } - - SkinInfo::SkinInfo( BaseMesh^ mesh, int boneCount, array^ boneCombinationTable ) - { - ID3DXSkinInfo *result; - - int length = boneCombinationTable->Length; - stack_array bones = stackalloc( D3DXBONECOMBINATION, length ); - for( int i = 0; i < length; i++ ) - bones[i] = boneCombinationTable[i]->ToUnmanaged(); - - HRESULT hr = D3DXCreateSkinInfoFromBlendedMesh( mesh->InternalPointer, boneCount, &bones[0], &result ); - - for( int i = 0; i < length; i++ ) - delete[] bones[i].BoneId; - - if( RECORD_D3D9( hr ).IsFailure ) - throw gcnew Direct3D9Exception( Result::Last ); - - Construct( result ); - } - - SkinInfo::SkinInfo( int vertexCount, SlimDX::Direct3D9::VertexFormat fvf, int boneCount ) - { - ID3DXSkinInfo *result; - - HRESULT hr = D3DXCreateSkinInfoFVF( vertexCount, static_cast( fvf ), - boneCount, &result ); - - if( RECORD_D3D9( hr ).IsFailure ) - throw gcnew Direct3D9Exception( Result::Last ); - - Construct( result ); - } - - SkinInfo^ SkinInfo::Clone() - { - ID3DXSkinInfo *result; - - HRESULT hr = InternalPointer->Clone( &result ); - - if( RECORD_D3D9( hr ).IsFailure ) - return nullptr; - - return gcnew SkinInfo( result, nullptr ); - } - - Mesh^ SkinInfo::ConvertToBlendedMesh( Mesh^ mesh, array^ adjacency, - [Out] array^% faceRemap, [Out] array^% vertexRemap, [Out] int% maxVertexInfluence, - [Out] array^% boneCombinationTable ) - { - ID3DXMesh *result; - ID3DXBuffer *vr; - ID3DXBuffer *bct; - DWORD mvi; - DWORD bcc; - DWORD *adjacencyIn = NULL; - - faceRemap = gcnew array( mesh->FaceCount ); - - array^ adjacencyOut = gcnew array( mesh->FaceCount * 3 ); - - pin_ptr pinnedAdjIn; - pin_ptr pinnedAdjOut = &adjacencyOut[0]; - pin_ptr pinnedFR = &faceRemap[0]; - - if( adjacency != nullptr ) - { - pinnedAdjIn = &adjacency[0]; - adjacencyIn = reinterpret_cast( pinnedAdjIn ); - } - - HRESULT hr = InternalPointer->ConvertToBlendedMesh( mesh->InternalPointer, 0, adjacencyIn, - reinterpret_cast( pinnedAdjOut ), reinterpret_cast( pinnedFR ), &vr, &mvi, &bcc, &bct, &result ); - - if( RECORD_D3D9( hr ).IsFailure ) - { - boneCombinationTable = nullptr; - maxVertexInfluence = 0; - vertexRemap = nullptr; - faceRemap = nullptr; - return nullptr; - } - - boneCombinationTable = gcnew array( bcc ); - LPD3DXBONECOMBINATION pointer = reinterpret_cast( bct->GetBufferPointer() ); - - for( DWORD i = 0; i < bcc; i++ ) - { - boneCombinationTable[i] = BoneCombination::FromUnmanaged( pointer[i] ); - boneCombinationTable[i]->BoneIds = gcnew array( mvi ); - for( DWORD j = 0; j < mvi; j++ ) - boneCombinationTable[i]->BoneIds[j] = pointer[i].BoneId[j]; - } - - Mesh^ out = Mesh::FromPointer( result ); - if( adjacency != nullptr ) - out->SetAdjacency( adjacencyOut ); - else - out->SetAdjacency( NULL ); - - maxVertexInfluence = mvi; - vertexRemap = Utilities::ReadRange( vr, result->GetNumVertices() ); - return out; - } - - Mesh^ SkinInfo::ConvertToBlendedMesh( Mesh^ mesh, array^ adjacency, - [Out] int% maxVertexInfluence, [Out] array^% boneCombinationTable ) - { - ID3DXMesh *result; - ID3DXBuffer *bct; - DWORD mvi; - DWORD bcc; - DWORD *adjacencyIn = NULL; - - array^ adjacencyOut = gcnew array( mesh->FaceCount * 3 ); - - pin_ptr pinnedAdjIn; - pin_ptr pinnedAdjOut = &adjacencyOut[0]; - - if( adjacency != nullptr ) - { - pinnedAdjIn = &adjacency[0]; - adjacencyIn = reinterpret_cast( pinnedAdjIn ); - } - - HRESULT hr = InternalPointer->ConvertToBlendedMesh( mesh->InternalPointer, 0, adjacencyIn, - reinterpret_cast( pinnedAdjOut ), NULL, NULL, &mvi, &bcc, &bct, &result ); - - if( RECORD_D3D9( hr ).IsFailure ) - { - boneCombinationTable = nullptr; - maxVertexInfluence = 0; - return nullptr; - } - - boneCombinationTable = gcnew array( bcc ); - LPD3DXBONECOMBINATION pointer = reinterpret_cast( bct->GetBufferPointer() ); - - for( DWORD i = 0; i < bcc; i++ ) - { - boneCombinationTable[i] = BoneCombination::FromUnmanaged( pointer[i] ); - boneCombinationTable[i]->BoneIds = gcnew array( mvi ); - for( DWORD j = 0; j < mvi; j++ ) - boneCombinationTable[i]->BoneIds[j] = pointer[i].BoneId[j]; - } - - Mesh^ out = Mesh::FromPointer( result ); - if( adjacency != nullptr ) - out->SetAdjacency( adjacencyOut ); - else - out->SetAdjacency( NULL ); - - maxVertexInfluence = mvi; - return out; - } - - Mesh^ SkinInfo::ConvertToIndexedBlendedMesh( Mesh^ mesh, int paletteSize, array^ adjacency, - [Out] array^% faceRemap, [Out] array^% vertexRemap, [Out] int% maxVertexInfluence, - [Out] array^% boneCombinationTable ) - { - ID3DXMesh *result; - ID3DXBuffer *vr; - ID3DXBuffer *bct; - DWORD mvi; - DWORD bcc; - DWORD *adjacencyIn = NULL; - - faceRemap = gcnew array( mesh->FaceCount ); - - array^ adjacencyOut = gcnew array( mesh->FaceCount * 3 ); - - pin_ptr pinnedAdjIn; - pin_ptr pinnedAdjOut = &adjacencyOut[0]; - - if( adjacency != nullptr ) - { - pinnedAdjIn = &adjacency[0]; - adjacencyIn = reinterpret_cast( pinnedAdjIn ); - } - - pin_ptr pinnedFR = &faceRemap[0]; - - HRESULT hr = InternalPointer->ConvertToIndexedBlendedMesh( mesh->InternalPointer, 0, paletteSize, adjacencyIn, - reinterpret_cast( pinnedAdjOut ), reinterpret_cast( pinnedFR ), &vr, &mvi, &bcc, &bct, &result ); - - if( RECORD_D3D9( hr ).IsFailure ) - { - boneCombinationTable = nullptr; - maxVertexInfluence = 0; - vertexRemap = nullptr; - faceRemap = nullptr; - return nullptr; - } - - boneCombinationTable = gcnew array( bcc ); - LPD3DXBONECOMBINATION pointer = reinterpret_cast( bct->GetBufferPointer() ); - - for( DWORD i = 0; i < bcc; i++ ) - { - boneCombinationTable[i] = BoneCombination::FromUnmanaged( pointer[i] ); - boneCombinationTable[i]->BoneIds = gcnew array( paletteSize ); - for( int j = 0; j < paletteSize; j++ ) - boneCombinationTable[i]->BoneIds[j] = pointer[i].BoneId[j]; - } - - Mesh^ out = Mesh::FromPointer( result ); - if( adjacency != nullptr ) - out->SetAdjacency( adjacencyOut ); - else - out->SetAdjacency( NULL ); - - maxVertexInfluence = mvi; - vertexRemap = Utilities::ReadRange( vr, result->GetNumVertices() ); - return out; - } - - Mesh^ SkinInfo::ConvertToIndexedBlendedMesh( Mesh^ mesh, int paletteSize, array^ adjacency, - [Out] int% maxVertexInfluence, [Out] array^% boneCombinationTable ) - { - ID3DXMesh *result; - ID3DXBuffer *bct; - DWORD mvi; - DWORD bcc; - DWORD *adjacencyIn = NULL; - - array^ adjacencyOut = gcnew array( mesh->FaceCount * 3 ); - - pin_ptr pinnedAdjIn; - pin_ptr pinnedAdjOut = &adjacencyOut[0]; - - if( adjacency != nullptr ) - { - pinnedAdjIn = &adjacency[0]; - adjacencyIn = reinterpret_cast( pinnedAdjIn ); - } - - HRESULT hr = InternalPointer->ConvertToIndexedBlendedMesh( mesh->InternalPointer, 0, paletteSize, adjacencyIn, - reinterpret_cast( pinnedAdjOut ), NULL, NULL, &mvi, &bcc, &bct, &result ); - - if( RECORD_D3D9( hr ).IsFailure ) - { - boneCombinationTable = nullptr; - maxVertexInfluence = 0; - return nullptr; - } - - boneCombinationTable = gcnew array( bcc ); - LPD3DXBONECOMBINATION pointer = reinterpret_cast( bct->GetBufferPointer() ); - - for( DWORD i = 0; i < bcc; i++ ) - { - boneCombinationTable[i] = BoneCombination::FromUnmanaged( pointer[i] ); - boneCombinationTable[i]->BoneIds = gcnew array( paletteSize ); - for( int j = 0; j < paletteSize; j++ ) - boneCombinationTable[i]->BoneIds[j] = pointer[i].BoneId[j]; - } - - Mesh^ out = Mesh::FromPointer( result ); - if( adjacency != nullptr ) - out->SetAdjacency( adjacencyOut ); - else - out->SetAdjacency( NULL ); - - maxVertexInfluence = mvi; - return out; - } - - int SkinInfo::FindBoneVertexInfluenceIndex( int bone, int vertex ) - { - DWORD influence; - - HRESULT hr = InternalPointer->FindBoneVertexInfluenceIndex( bone, vertex, &influence ); - - if( RECORD_D3D9( hr ).IsFailure ) - return 0; - - return influence; - } - - Result SkinInfo::GetBoneInfluence( int bone, [Out] array^% vertices, [Out] array^% weights ) - { - int count = GetBoneInfluenceCount( bone ); - vertices = gcnew array( count ); - weights = gcnew array( count ); - - pin_ptr pinnedVerts = &vertices[0]; - pin_ptr pinnedWeights = &weights[0]; - - HRESULT hr = InternalPointer->GetBoneInfluence( bone, reinterpret_cast( pinnedVerts ), - reinterpret_cast( pinnedWeights ) ); - - if( RECORD_D3D9( hr ).IsFailure ) - { - vertices = nullptr; - weights = nullptr; - } - - return Result::Last; - } - - Result SkinInfo::SetBoneInfluence( int bone, array^ vertices, array^ weights ) - { - pin_ptr pinnedVerts = &vertices[0]; - pin_ptr pinnedWeights = &weights[0]; - - HRESULT hr = InternalPointer->SetBoneInfluence( bone, vertices->Length, reinterpret_cast( pinnedVerts ), - reinterpret_cast( pinnedWeights ) ); - - return RECORD_D3D9( hr ); - } - - String^ SkinInfo::GetBoneName( int bone ) - { - return gcnew String( InternalPointer->GetBoneName( bone ) ); - } - - Result SkinInfo::SetBoneName( int bone, String^ name ) - { - array^ nameBytes = System::Text::ASCIIEncoding::ASCII->GetBytes( name ); - pin_ptr pinnedName = &nameBytes[0]; - - HRESULT hr = InternalPointer->SetBoneName( bone, reinterpret_cast( pinnedName ) ); - return RECORD_D3D9( hr ); - } - - Result SkinInfo::GetBoneVertexInfluence( int bone, int influence, [Out] float% weight, [Out] int% vertex ) - { - float w; - DWORD v; - - HRESULT hr = InternalPointer->GetBoneVertexInfluence( bone, influence, &w, &v ); - - if( RECORD_D3D9( hr ).IsFailure ) - { - weight = 0; - vertex = 0; - } - else - { - weight = w; - vertex = v; - } - - return Result::Last; - } - - Result SkinInfo::SetBoneVertexInfluence( int bone, int influence, float weight ) - { - HRESULT hr = InternalPointer->SetBoneVertexInfluence( bone, influence, weight ); - return RECORD_D3D9( hr ); - } - - Matrix SkinInfo::GetBoneOffsetMatrix( int bone ) - { - return Matrix::FromD3DXMATRIX( *InternalPointer->GetBoneOffsetMatrix( bone ) ); - } - - Result SkinInfo::SetBoneOffsetMatrix( int bone, Matrix matrix ) - { - HRESULT hr = InternalPointer->SetBoneOffsetMatrix( bone, reinterpret_cast( &matrix ) ); - return RECORD_D3D9( hr ); - } - - array^ SkinInfo::GetDeclaration() - { - D3DVERTEXELEMENT9 elementBuffer[MAX_FVF_DECL_SIZE]; - HRESULT hr = InternalPointer->GetDeclaration( elementBuffer ); - - if( RECORD_D3D9( hr ).IsFailure ) - return nullptr; - - // Apparently the returned decl does not include an End element. This is bizarre and confusing, - // not to mention completely unexpected. We patch it up here. - int count = D3DXGetDeclLength( elementBuffer ) + 1; - array^ elements = gcnew array( count ); - pin_ptr pinnedElements = &elements[0]; - memcpy( pinnedElements, elementBuffer, count * sizeof(D3DVERTEXELEMENT9) ); - elements[count - 1] = VertexElement::VertexDeclarationEnd; - - return elements; - } - - Result SkinInfo::SetDeclaration( array^ declaration ) - { - pin_ptr pinnedDecl = &declaration[0]; - - HRESULT hr = InternalPointer->SetDeclaration( reinterpret_cast( pinnedDecl ) ); - return RECORD_D3D9( hr ); - } - - int SkinInfo::GetMaxFaceInfluences( IndexBuffer^ indexBuffer, int faceCount ) - { - DWORD ret; - - HRESULT hr = InternalPointer->GetMaxFaceInfluences( indexBuffer->InternalPointer, faceCount, &ret ); - - if( RECORD_D3D9( hr ).IsFailure ) - return 0; - - return ret; - } - - Result SkinInfo::Remap( array^ remapData ) - { - pin_ptr pinnedData = &remapData[0]; - - HRESULT hr = InternalPointer->Remap( remapData->Length, reinterpret_cast( pinnedData ) ); - return RECORD_D3D9( hr ); - } - - Result SkinInfo::UpdateSkinnedMesh( array^ boneTransforms, array^ boneInvTransposeTransforms, DataStream^ source, DataStream^ destination ) - { - pin_ptr pinnedTransforms = &boneTransforms[0]; - pin_ptr pinnedInvTransforms = &boneInvTransposeTransforms[0]; - - HRESULT hr = InternalPointer->UpdateSkinnedMesh( reinterpret_cast( pinnedTransforms ), - reinterpret_cast( pinnedInvTransforms ), source->PositionPointer, destination->PositionPointer ); - return RECORD_D3D9( hr ); - } - - int SkinInfo::GetBoneInfluenceCount( int bone ) - { - return InternalPointer->GetNumBoneInfluences( bone ); - } - - int SkinInfo::MaximumVertexInfluences::get() - { - DWORD result; - - HRESULT hr = InternalPointer->GetMaxVertexInfluences( &result ); - - if( RECORD_D3D9( hr ).IsFailure ) - return 0; - - return result; - } - - int SkinInfo::BoneCount::get() - { - return InternalPointer->GetNumBones(); - } - - float SkinInfo::MinimumBoneInfluence::get() - { - return InternalPointer->GetMinBoneInfluence(); - } - - void SkinInfo::MinimumBoneInfluence::set( float value ) - { - HRESULT hr = InternalPointer->SetMinBoneInfluence( value ); - RECORD_D3D9( hr ); - } - - SlimDX::Direct3D9::VertexFormat SkinInfo::VertexFormat::get() - { - return static_cast( InternalPointer->GetFVF() ); - } - - void SkinInfo::VertexFormat::set( SlimDX::Direct3D9::VertexFormat value ) - { - HRESULT hr = InternalPointer->SetFVF( static_cast( value ) ); - RECORD_D3D9( hr ); - } -} -}