#include <stdio.h>
#include "D3DViewportRenderer.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(D3D9_SUPPORTED)
bool D3DGeometry::Populate(
const MDagPath& dagPath, LPDIRECT3DDEVICE9 D3D)
{
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;
FVF = D3DFVF_XYZ;
Stride = sizeof( float) * 3;
float * normPtr = NULL;
if( useNormals)
{
normPtr = (
float * )norm.
data();
Stride += sizeof( float) * 3;
FVF |= D3DFVF_NORMAL;
}
float *uvPtr = NULL;
if( haveTexture)
{
uvPtr = (
float *)uvs.
data();
Stride += sizeof( float) * 2;
FVF |= D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE2(0);
}
unsigned int numColorComponents = 4;
float *clrPtr = NULL;
if (haveColors)
{
clrPtr = (
float *)clrs.
data();
}
else if (testBinormal)
{
clrPtr = (
float *)binorm.
data();
numColorComponents = 3;
}
else if (testTangent)
{
clrPtr = (
float *)tang.
data();
numColorComponents = 3;
}
if( D3D->CreateVertexBuffer( Stride * NumVertices, D3DUSAGE_WRITEONLY, FVF,
D3DPOOL_DEFAULT, &VertexBuffer, NULL) != D3D_OK)
{
return false;
}
float* VertexData = NULL;
int FloatsPerVertex = Stride / sizeof( float);
int StrideOffset = FloatsPerVertex - 3;
VertexBuffer->Lock( 0, 0, (void**)&VertexData, D3DLOCK_DISCARD);
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;
}
VertexBuffer->Unlock();
if( D3D->CreateIndexBuffer( NumIndices * sizeof( DWORD), 0, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &IndexBuffer, NULL) != D3D_OK)
{
return false;
}
unsigned int* IndexData = NULL;
IndexBuffer->Lock( 0, 0, (void**)&IndexData, D3DLOCK_DISCARD);
memcpy( IndexData, idx, NumIndices * sizeof(DWORD));
IndexBuffer->Unlock();
}
}
return IndexBuffer && VertexBuffer;
}
#endif