#ifndef _CacheWriter_h_
#define _CacheWriter_h_
#include "gpuCacheGeometry.h"
#include "gpuCacheMaterial.h"
#include <maya/MMatrix.h>
#include <maya/MFnTransform.h>
#include <maya/MTime.h>
#include <maya/MString.h>
#include <maya/MFileObject.h>
#include <memory>
#include <vector>
class CacheXformSampler;
class CacheMeshSampler;
class CacheWriter
{
public:
static std::shared_ptr<CacheWriter> create(
const MString& impl,
typedef std::shared_ptr<CacheWriter> CreateFunction(
const MFileObject& file,
char compressLevel,
const MString& dataFormat);
static void registerWriter(
const MString& impl, CreateFunction func);
virtual ~CacheWriter() {}
virtual bool valid() const = 0;
virtual void writeSubNodeHierarchy(
const GPUCache::SubNode::Ptr& topNode,
double secondsPerSample, double startTimeInSeconds) = 0;
virtual void writeMaterials(
const GPUCache::MaterialGraphMap::Ptr& materialGraphMap,
double secondsPerSample, double startTimeInSeconds) = 0;
protected:
CacheWriter() {}
private:
CacheWriter(const CacheWriter&);
const CacheWriter& operator=(const CacheWriter&);
static std::map<std::string,void*> fsRegistry;
};
class CacheXformSampler
{
public:
static std::shared_ptr<CacheXformSampler> create(
const MObject& xformObject);
~CacheXformSampler();
void addSample();
bool isAnimated() const {
return fXformAnimated || fVisibilityAnimated; }
std::shared_ptr<const GPUCache::XformSample> getSample(double timeInSeconds);
private:
CacheXformSampler(
const MObject& xformObject);
GPUCACHE_DECLARE_MAKE_SHARED_FRIEND;
bool fIsFirstSample;
bool fXformAnimated;
bool fVisibilitySample;
bool fVisibilityAnimated;
};
class CacheMeshSampler
{
public:
static std::shared_ptr<CacheMeshSampler> create(bool needUVs);
~CacheMeshSampler();
bool addSample(
MObject meshObject,
bool visibility);
bool addSampleFromMesh(
MFnMesh& mesh);
bool isAnimated() const
{
return fIsAnimated;
}
void enableUVs()
{
fNeedUVs = true;
}
void setUseBaseTessellation()
{
fUseBaseTessellation = true;
}
std::shared_ptr<const GPUCache::ShapeSample>
getSample(
double timeInSeconds,
const MColor& diffuseColor);
private:
CacheMeshSampler(bool needUVs);
GPUCACHE_DECLARE_MAKE_SHARED_FRIEND;
struct AttributeSet
{
size_t fNumWires;
size_t fNumTriangles;
size_t fNumVerts;
std::shared_ptr<GPUCache::IndexBuffer> fWireVertIndices;
std::vector<std::shared_ptr<GPUCache::IndexBuffer> > fTriangleVertIndices;
std::shared_ptr<GPUCache::VertexBuffer> fPositions;
std::shared_ptr<GPUCache::VertexBuffer> fNormals;
std::shared_ptr<GPUCache::VertexBuffer> fUVs;
bool fVisibility;
AttributeSet()
: fNumWires(0), fNumTriangles(0), fNumVerts(0), fVisibility(true)
{}
AttributeSet(
MObject meshObject,
bool visibility,
bool needUVs);
AttributeSet(
MFnMesh& mesh,
bool needUVs,
bool useBaseTessellation);
bool updateAnimatedChannels(
bool& animated, const AttributeSet& newer);
};
bool fNeedUVs;
bool fUseBaseTessellation;
bool fIsAnimated;
AttributeSet fAttributeSet;
};
#endif