#if _MSC_VER >= 1700
#pragma warning( disable: 4005 )
#endif
#include <stdio.h>
#include "DX11ViewportRenderer.h"
#include <maya/MGlobal.h>
#include <maya/MString.h>
#include <maya/MMatrix.h>
#include <maya/MDagPath.h>
#include <maya/MFnDagNode.h>
#include <maya/MFnMesh.h>
#include <maya/MItMeshPolygon.h>
#include <maya/MBoundingBox.h>
#include <maya/MImage.h>
#include <maya/MDrawTraversal.h>
#include <maya/MGeometryManager.h>
#include <maya/MGeometry.h>
#include <maya/MGeometryData.h>
#include <maya/MGeometryPrimitive.h>
#include <maya/MNodeMessage.h>
#include <maya/MPlug.h>
#include <maya/MPlugArray.h>
#include <maya/MFnSet.h>
#include <maya/MFnNumericData.h>
#include <maya/MItDependencyGraph.h>
#include <stdio.h>
#if defined(DX11_SUPPORTED)
bool D3DGeometry::Populate(
const MDagPath& dagPath, ID3D11Device* D3D)
{
HRESULT hr;
Release();
bool haveTexture = false;
int numUVsets = mesh.numUVSets();
if (numUVsets > 0)
{
mesh.getCurrentUVSetName( uvSetName );
int numCoords = mesh.numUVs( uvSetName );
if (numCoords > 0)
{
haveTexture = true;
}
}
bool haveColors = false;
int numColors = mesh.numColorSets();
if (numColors > 0)
{
haveColors = true;
mesh.getCurrentColorSetName(colorSetName);
}
bool useNormals = true;
if (useNormals)
if (haveTexture)
if (haveColors)
bool testBinormal = false;
if (testBinormal)
bool testTangent= false;
if (testTangent)
if( numPrims)
{
if( NumIndices)
{
unsigned int *idx = (
unsigned int *) prim.
data();
float * posPtr = (
float * )pos.
data();
if( !idx || !posPtr) return false;
Stride = sizeof( float) * 3;
float * normPtr = NULL;
if( useNormals)
{
normPtr = (
float * )norm.
data();
Stride += sizeof( float) * 3;
}
float *uvPtr = NULL;
if( haveTexture)
{
uvPtr = (
float *)uvs.
data();
Stride += sizeof( float) * 2;
}
Stride = sizeof(FixedFunctionVertex);
useNormals = true;
haveTexture = true;
int FloatsPerVertex = Stride / sizeof( float);
float* vertBuffer = new float[ NumVertices * FloatsPerVertex ];
float* VertexData = vertBuffer;
int StrideOffset = FloatsPerVertex - 3;
for( unsigned int i = 0; i < NumVertices; i++)
{
*VertexData++ = *posPtr++;
*VertexData++ = *posPtr++;
*VertexData++ = *posPtr++;
VertexData += StrideOffset;
}
VertexData -= NumVertices * FloatsPerVertex - 3;
if( normPtr)
{
for( unsigned int i = 0; i < NumVertices; i++)
{
*VertexData++ = *normPtr++;
*VertexData++ = *normPtr++;
*VertexData++ = *normPtr++;
VertexData += StrideOffset;
}
VertexData -= NumVertices * FloatsPerVertex - 3;
}
if( uvPtr)
{
StrideOffset = FloatsPerVertex - 2;
for( unsigned int i = 0; i < NumVertices; i++)
{
*VertexData++ = *uvPtr++;
*VertexData++ = 1.0f - *uvPtr++;
VertexData += StrideOffset;
}
VertexData -= NumVertices * FloatsPerVertex - 2;
}
D3D11_BUFFER_DESC bd;
ZeroMemory( &bd, sizeof(bd) );
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = Stride * NumVertices;
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = 0;
D3D11_SUBRESOURCE_DATA InitData;
ZeroMemory( &InitData, sizeof(InitData) );
InitData.pSysMem = vertBuffer;
hr = D3D->CreateBuffer( &bd, &InitData, &VertexBuffer );
if ( FAILED( hr ) )
{
return false;
}
delete [] vertBuffer;
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = NumIndices * sizeof( DWORD);
bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
bd.CPUAccessFlags = 0;
InitData.pSysMem = idx;
hr = D3D->CreateBuffer( &bd, &InitData, &IndexBuffer );
if ( FAILED( hr ) )
{
return false;
}
}
}
return IndexBuffer && VertexBuffer;
}
#endif