Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,297 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#include "StdAfx.h"
#include "AnimationData.h"
AnimationData::AnimationData(int modelCount, float fps, float startTime)
: m_entries(modelCount)
, m_frameCount(0)
, m_startTime(startTime)
, m_fps(fps)
{
}
void AnimationData::SetFrameData(int modelIndex, int frameIndex, float translation[3], float rotation[3], float scale[3])
{
State& state = m_entries[modelIndex].samples[frameIndex];
state.translation[0] = translation[0];
state.translation[1] = translation[1];
state.translation[2] = translation[2];
state.rotation[0] = rotation[0];
state.rotation[1] = rotation[1];
state.rotation[2] = rotation[2];
state.scale[0] = scale[0];
state.scale[1] = scale[1];
state.scale[2] = scale[2];
}
void AnimationData::SetFrameCount(int frameCount)
{
m_frameCount = frameCount;
for (int modelIndex = 0, modelCount = int(m_entries.size()); modelIndex < modelCount; ++modelIndex)
{
m_entries[modelIndex].samples.resize(frameCount);
}
}
void AnimationData::SetModelFlags(int modelIndex, unsigned modelFlags)
{
m_entries[modelIndex].flags = modelFlags;
}
void AnimationData::GetFrameData(int modelIndex, int frameIndex, const float*& translation, const float*& rotation, const float*& scale) const
{
translation = m_entries[modelIndex].samples[frameIndex].translation;
rotation = m_entries[modelIndex].samples[frameIndex].rotation;
scale = m_entries[modelIndex].samples[frameIndex].scale;
}
void AnimationData::GetFrameDataPos(int modelIndex, int frameIndex, const float*& translation) const
{
translation = m_entries[modelIndex].samples[frameIndex].translation;
}
void AnimationData::GetFrameDataRot(int modelIndex, int frameIndex, const float*& rotation) const
{
rotation = m_entries[modelIndex].samples[frameIndex].rotation;
}
void AnimationData::GetFrameDataScl(int modelIndex, int frameIndex, const float*& scale) const
{
scale = m_entries[modelIndex].samples[frameIndex].scale;
}
int AnimationData::GetFrameCount() const
{
return m_frameCount;
}
unsigned AnimationData::GetModelFlags(int modelIndex) const
{
return m_entries[modelIndex].flags;
}
AnimationData::State::State()
{
translation[0] = translation[1] = translation[2] = 0.0f;
rotation[0] = rotation[1] = rotation[2] = 0.0f;
scale[0] = scale[1] = scale[2] = 1.0f;
}
AnimationData::ModelEntry::ModelEntry()
: flags(0)
{
}
///////////////////////////////////////////////////////////////////////////
NonSkeletalAnimationData::NonSkeletalAnimationData(int modelCount)
: m_entries(modelCount)
{
}
void NonSkeletalAnimationData::SetModelFlags(int modelIndex, unsigned modelFlags)
{
m_entries[modelIndex].flags = modelFlags;
}
unsigned NonSkeletalAnimationData::GetModelFlags(int modelIndex) const
{
return m_entries[modelIndex].flags;
}
void NonSkeletalAnimationData::SetFrameTimePos(int modelIndex, int frameIndex, float time)
{
State& state = m_entries[modelIndex].samplesPos[frameIndex];
state.time = time;
}
void NonSkeletalAnimationData::SetFrameDataPos(int modelIndex, int frameIndex, float translation[3])
{
State& state = m_entries[modelIndex].samplesPos[frameIndex];
state.data[0] = translation[0];
state.data[1] = translation[1];
state.data[2] = translation[2];
}
void NonSkeletalAnimationData::SetFrameCountPos(int modelIndex, int frameCount)
{
m_entries[modelIndex].samplesPos.resize(frameCount);
}
void NonSkeletalAnimationData::SetFrameTimeRot(int modelIndex, int frameIndex, float time)
{
State& state = m_entries[modelIndex].samplesRot[frameIndex];
state.time = time;
}
void NonSkeletalAnimationData::SetFrameDataRot(int modelIndex, int frameIndex, float rotation[3])
{
State& state = m_entries[modelIndex].samplesRot[frameIndex];
state.data[0] = rotation[0];
state.data[1] = rotation[1];
state.data[2] = rotation[2];
}
void NonSkeletalAnimationData::SetFrameCountRot(int modelIndex, int frameCount)
{
m_entries[modelIndex].samplesRot.resize(frameCount);
}
void NonSkeletalAnimationData::SetFrameTimeScl(int modelIndex, int frameIndex, float time)
{
State& state = m_entries[modelIndex].samplesScl[frameIndex];
state.time = time;
}
void NonSkeletalAnimationData::SetFrameDataScl(int modelIndex, int frameIndex, float scale[3])
{
State& state = m_entries[modelIndex].samplesScl[frameIndex];
state.data[0] = scale[0];
state.data[1] = scale[1];
state.data[2] = scale[2];
}
void NonSkeletalAnimationData::SetFrameCountScl(int modelIndex, int frameCount)
{
m_entries[modelIndex].samplesScl.resize(frameCount);
}
float NonSkeletalAnimationData::GetFrameTimePos(int modelIndex, int frameIndex) const
{
return m_entries[modelIndex].samplesPos[frameIndex].time;
}
void NonSkeletalAnimationData::GetFrameDataPos(int modelIndex, int frameIndex, const float*& translation) const
{
translation = m_entries[modelIndex].samplesPos[frameIndex].data;
}
int NonSkeletalAnimationData::GetFrameCountPos(int modelIndex) const
{
return int(m_entries[modelIndex].samplesPos.size());
}
float NonSkeletalAnimationData::GetFrameTimeRot(int modelIndex, int frameIndex) const
{
return m_entries[modelIndex].samplesRot[frameIndex].time;
}
void NonSkeletalAnimationData::GetFrameDataRot(int modelIndex, int frameIndex, const float*& rotation) const
{
rotation = m_entries[modelIndex].samplesRot[frameIndex].data;
}
int NonSkeletalAnimationData::GetFrameCountRot(int modelIndex) const
{
return int(m_entries[modelIndex].samplesRot.size());
}
float NonSkeletalAnimationData::GetFrameTimeScl(int modelIndex, int frameIndex) const
{
return m_entries[modelIndex].samplesScl[frameIndex].time;
}
void NonSkeletalAnimationData::GetFrameDataScl(int modelIndex, int frameIndex, const float*& scale) const
{
scale = m_entries[modelIndex].samplesScl[frameIndex].data;
}
int NonSkeletalAnimationData::GetFrameCountScl(int modelIndex) const
{
return int(m_entries[modelIndex].samplesScl.size());
}
void NonSkeletalAnimationData::SetFrameTCBPos(int modelIndex, int frameIndex, IAnimationData::TCB tcb)
{
State& state = m_entries[modelIndex].samplesPos[frameIndex];
state.tcb = tcb;
}
void NonSkeletalAnimationData::SetFrameTCBRot(int modelIndex, int frameIndex, IAnimationData::TCB tcb)
{
State& state = m_entries[modelIndex].samplesRot[frameIndex];
state.tcb = tcb;
}
void NonSkeletalAnimationData::SetFrameTCBScl(int modelIndex, int frameIndex, IAnimationData::TCB tcb)
{
State& state = m_entries[modelIndex].samplesScl[frameIndex];
state.tcb = tcb;
}
void NonSkeletalAnimationData::SetFrameEaseInOutPos(int modelIndex, int frameIndex, IAnimationData::Ease ease)
{
State& state = m_entries[modelIndex].samplesPos[frameIndex];
state.ease = ease;
}
void NonSkeletalAnimationData::SetFrameEaseInOutRot(int modelIndex, int frameIndex, IAnimationData::Ease ease)
{
State& state = m_entries[modelIndex].samplesRot[frameIndex];
state.ease = ease;
}
void NonSkeletalAnimationData::SetFrameEaseInOutScl(int modelIndex, int frameIndex, IAnimationData::Ease ease)
{
State& state = m_entries[modelIndex].samplesScl[frameIndex];
state.ease = ease;
}
void NonSkeletalAnimationData::GetFrameTCBPos(int modelIndex, int frameIndex, IAnimationData::TCB& tcb) const
{
const State& state = m_entries[modelIndex].samplesPos[frameIndex];
tcb = state.tcb;
}
void NonSkeletalAnimationData::GetFrameTCBRot(int modelIndex, int frameIndex, IAnimationData::TCB& tcb) const
{
const State& state = m_entries[modelIndex].samplesRot[frameIndex];
tcb = state.tcb;
}
void NonSkeletalAnimationData::GetFrameTCBScl(int modelIndex, int frameIndex, IAnimationData::TCB& tcb) const
{
const State& state = m_entries[modelIndex].samplesScl[frameIndex];
tcb = state.tcb;
}
void NonSkeletalAnimationData::GetFrameEaseInOutPos(int modelIndex, int frameIndex, IAnimationData::Ease& ease) const
{
const State& state = m_entries[modelIndex].samplesPos[frameIndex];
ease = state.ease;
}
void NonSkeletalAnimationData::GetFrameEaseInOutRot(int modelIndex, int frameIndex, IAnimationData::Ease& ease) const
{
const State& state = m_entries[modelIndex].samplesRot[frameIndex];
ease = state.ease;
}
void NonSkeletalAnimationData::GetFrameEaseInOutScl(int modelIndex, int frameIndex, IAnimationData::Ease& ease) const
{
const State& state = m_entries[modelIndex].samplesScl[frameIndex];
ease = state.ease;
}
NonSkeletalAnimationData::State::State()
{
time = 0.0f;
data[0] = data[1] = data[2] = 0.0f;
}
NonSkeletalAnimationData::ModelEntry::ModelEntry()
: flags(0)
{
}
@@ -0,0 +1,211 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_ANIMATIONDATA_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_ANIMATIONDATA_H
#pragma once
#include "IAnimationData.h"
#include <vector>
// Animation data class for skeletal animations
// It has a same count of samples for all models(bones)
// and always has translation/rotation/scaling data together as a set.
class AnimationData
: public IAnimationData
{
public:
AnimationData(int modelCount, float fps, float startTime);
virtual ~AnimationData() {}
// IAnimationData
virtual void SetFrameData(int modelIndex, int frameIndex, float translation[3], float rotation[3], float scale[3]);
virtual void SetFrameCount(int frameCount);
virtual void SetModelFlags(int modelIndex, unsigned modelFlags);
virtual void SetFrameTimePos(int modelIndex, int frameIndex, float time)
{ assert(0); }
virtual void SetFrameDataPos(int modelIndex, int frameIndex, float translation[3])
{ assert(0); }
virtual void SetFrameCountPos(int modelIndex, int frameCount)
{ assert(0); }
virtual void SetFrameTimeRot(int modelIndex, int frameIndex, float time)
{ assert(0); }
virtual void SetFrameDataRot(int modelIndex, int frameIndex, float rotation[3])
{ assert(0); }
virtual void SetFrameCountRot(int modelIndex, int frameCount)
{ assert(0); }
virtual void SetFrameTimeScl(int modelIndex, int frameIndex, float time)
{ assert(0); }
virtual void SetFrameDataScl(int modelIndex, int frameIndex, float scale[3])
{ assert(0); }
virtual void SetFrameCountScl(int modelIndex, int frameCount)
{ assert(0); }
virtual void GetFrameData(int modelIndex, int frameIndex, const float*& translation, const float*& rotation, const float*& scale) const;
virtual int GetFrameCount() const;
virtual unsigned GetModelFlags(int modelIndex) const;
virtual float GetFrameTimePos(int modelIndex, int frameIndex) const
{ return m_startTime + frameIndex / m_fps; }
virtual void GetFrameDataPos(int modelIndex, int frameIndex, const float*& translation) const;
virtual int GetFrameCountPos(int) const
{ return GetFrameCount(); }
virtual float GetFrameTimeRot(int modelIndex, int frameIndex) const
{ return m_startTime + frameIndex / m_fps; }
virtual void GetFrameDataRot(int modelIndex, int frameIndex, const float*& rotation) const;
virtual int GetFrameCountRot(int) const
{ return GetFrameCount(); }
virtual float GetFrameTimeScl(int modelIndex, int frameIndex) const
{ return m_startTime + frameIndex / m_fps; }
virtual void GetFrameDataScl(int modelIndex, int frameIndex, const float*& scale) const;
virtual int GetFrameCountScl(int) const
{ return GetFrameCount(); }
// TCB & Ease-In/-Out not supported for the skeletal animation.
virtual void SetFrameTCBPos(int modelIndex, int frameIndex, TCB tcb)
{ assert(0); }
virtual void SetFrameTCBRot(int modelIndex, int frameIndex, TCB tcb)
{ assert(0); }
virtual void SetFrameTCBScl(int modelIndex, int frameIndex, TCB tcb)
{ assert(0); }
virtual void SetFrameEaseInOutPos(int modelIndex, int frameIndex, Ease ease)
{ assert(0); }
virtual void SetFrameEaseInOutRot(int modelIndex, int frameIndex, Ease ease)
{ assert(0); }
virtual void SetFrameEaseInOutScl(int modelIndex, int frameIndex, Ease ease)
{ assert(0); }
virtual void GetFrameTCBPos(int modelIndex, int frameIndex, TCB& tcb) const
{ assert(0); }
virtual void GetFrameTCBRot(int modelIndex, int frameIndex, TCB& tcb) const
{ assert(0); }
virtual void GetFrameTCBScl(int modelIndex, int frameIndex, TCB& tcb) const
{ assert(0); }
virtual void GetFrameEaseInOutPos(int modelIndex, int frameIndex, Ease& ease) const
{ assert(0); }
virtual void GetFrameEaseInOutRot(int modelIndex, int frameIndex, Ease& ease) const
{ assert(0); }
virtual void GetFrameEaseInOutScl(int modelIndex, int frameIndex, Ease& ease) const
{ assert(0); }
private:
struct State
{
public:
State();
float translation[3];
float rotation[3];
float scale[3];
};
struct ModelEntry
{
ModelEntry();
unsigned flags;
std::vector<State> samples;
};
std::vector<ModelEntry> m_entries;
int m_frameCount;
float m_startTime;
float m_fps;
};
// Animation data class for non-skeletal animations
// It can have different counts of samples for each model
// and each channel of transformation data.
class NonSkeletalAnimationData
: public IAnimationData
{
public:
NonSkeletalAnimationData(int modelCount);
virtual ~NonSkeletalAnimationData() {}
// IAnimationData
virtual void SetFrameData(int modelIndex, int frameIndex, float translation[3], float rotation[3], float scale[3])
{ assert(0); }
virtual void SetFrameCount(int frameCount)
{ assert(0); }
virtual void SetModelFlags(int modelIndex, unsigned modelFlags);
virtual void SetFrameTimePos(int modelIndex, int frameIndex, float time);
virtual void SetFrameDataPos(int modelIndex, int frameIndex, float translation[3]);
virtual void SetFrameCountPos(int modelIndex, int frameCount);
virtual void SetFrameTimeRot(int modelIndex, int frameIndex, float time);
virtual void SetFrameDataRot(int modelIndex, int frameIndex, float rotation[3]);
virtual void SetFrameCountRot(int modelIndex, int frameCount);
virtual void SetFrameTimeScl(int modelIndex, int frameIndex, float time);
virtual void SetFrameDataScl(int modelIndex, int frameIndex, float scale[3]);
virtual void SetFrameCountScl(int modelIndex, int frameCount);
virtual void GetFrameData(int modelIndex, int frameIndex, const float*& translation, const float*& rotation, const float*& scale) const
{ assert(0); }
virtual int GetFrameCount() const
{
assert(0);
return 0;
}
virtual unsigned GetModelFlags(int modelIndex) const;
virtual float GetFrameTimePos(int modelIndex, int frameIndex) const;
virtual void GetFrameDataPos(int modelIndex, int frameIndex, const float*& translation) const;
virtual int GetFrameCountPos(int) const;
virtual float GetFrameTimeRot(int modelIndex, int frameIndex) const;
virtual void GetFrameDataRot(int modelIndex, int frameIndex, const float*& rotation) const;
virtual int GetFrameCountRot(int) const;
virtual float GetFrameTimeScl(int modelIndex, int frameIndex) const;
virtual void GetFrameDataScl(int modelIndex, int frameIndex, const float*& scale) const;
virtual int GetFrameCountScl(int) const;
virtual void SetFrameTCBPos(int modelIndex, int frameIndex, TCB tcb);
virtual void SetFrameTCBRot(int modelIndex, int frameIndex, TCB tcb);
virtual void SetFrameTCBScl(int modelIndex, int frameIndex, TCB tcb);
virtual void SetFrameEaseInOutPos(int modelIndex, int frameIndex, Ease ease);
virtual void SetFrameEaseInOutRot(int modelIndex, int frameIndex, Ease ease);
virtual void SetFrameEaseInOutScl(int modelIndex, int frameIndex, Ease ease);
virtual void GetFrameTCBPos(int modelIndex, int frameIndex, TCB& tcb) const;
virtual void GetFrameTCBRot(int modelIndex, int frameIndex, TCB& tcb) const;
virtual void GetFrameTCBScl(int modelIndex, int frameIndex, TCB& tcb) const;
virtual void GetFrameEaseInOutPos(int modelIndex, int frameIndex, Ease& ease) const;
virtual void GetFrameEaseInOutRot(int modelIndex, int frameIndex, Ease& ease) const;
virtual void GetFrameEaseInOutScl(int modelIndex, int frameIndex, Ease& ease) const;
private:
struct State
{
public:
State();
float time;
float data[3];
TCB tcb;
Ease ease;
};
struct ModelEntry
{
ModelEntry();
unsigned flags;
std::vector<State> samplesPos;
std::vector<State> samplesRot;
std::vector<State> samplesScl;
};
std::vector<ModelEntry> m_entries;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_ANIMATIONDATA_H
@@ -0,0 +1,57 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#include "StdAfx.h"
#include "CBAHelpers.h"
#include "../PathHelpers.h"
#include "StringHelpers.h"
static string FindRootContainingFileGoingUpwards(const char* filePath, const char* filePathToLookFor, IPakSystem* pakSystem)
{
// Here we just search upwards from the current directory, looking for a directory that
// contains a file at the relative path "Animations/Animations.cba". This is designed to
// handle root Game paths that differ from the default "Game".
string rootDirCandidate = PathHelpers::GetDirectory(filePath);
string rootDir;
while (!rootDirCandidate.empty())
{
string cbaCandidatePath = PathHelpers::Join(rootDirCandidate, filePathToLookFor);
if (PakSystemFile* file = pakSystem->Open(cbaCandidatePath.c_str(), "r"))
{
// File exists, we have found the correct root path.
pakSystem->Close(file);
rootDir = rootDirCandidate;
break;
}
string previousCandidate = rootDirCandidate;
rootDirCandidate = PathHelpers::GetDirectory(rootDirCandidate);
if (rootDirCandidate == previousCandidate)
{
break;
}
}
return (rootDir.empty() ? rootDir : PathHelpers::Join(rootDir, filePathToLookFor));
}
string CBAHelpers::FindCBAFileForFile(const char* filePath, IPakSystem* pakSystem)
{
return FindRootContainingFileGoingUpwards(filePath, "Animations/Animations.cba", pakSystem);
}
string CBAHelpers::FindSkeletonListForFile(const char* filePath, IPakSystem* pakSystem)
{
return FindRootContainingFileGoingUpwards(filePath, "Animations/SkeletonList.xml", pakSystem);
}
@@ -0,0 +1,27 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_CBAHELPERS_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_CBAHELPERS_H
#pragma once
#include "IPakSystem.h"
namespace CBAHelpers
{
string FindCBAFileForFile(const char* filePath, IPakSystem* pakSystem);
string FindSkeletonListForFile(const char* filePath, IPakSystem* pakSystem);
}
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_CBAHELPERS_H
@@ -0,0 +1,556 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#include "StdAfx.h"
#include "ColladaExportWriter.h"
#include "ColladaWriter.h"
#include "IExportSource.h"
#include "PathHelpers.h"
#include "ResourceCompilerHelper.h"
#include "SettingsManagerHelpers.h"
#include "IExportContext.h"
#include "ProgressRange.h"
#include "XMLWriter.h"
#include "XMLPakFileSink.h"
#include "ISettings.h"
#include "SingleAnimationExportSourceAdapter.h"
#include "GeometryExportSourceAdapter.h"
#include "ModelData.h"
#include "MaterialData.h"
#include "GeometryFileData.h"
#include "FileUtil.h"
#include "CBAHelpers.h"
#include "ModuleHelpers.h"
#include "PropertyHelpers.h"
#include "StringHelpers.h"
#include <ctime>
#include <list>
namespace
{
class ResourceCompilerLogListener
: public IResourceCompilerListener
{
public:
ResourceCompilerLogListener(IExportContext* context)
: m_context(context)
{
}
virtual void OnRCMessage(IResourceCompilerListener::MessageSeverity severity, const char* text)
{
ILogger::ESeverity outSeverity;
switch (severity)
{
case IResourceCompilerListener::MessageSeverity_Debug:
case IResourceCompilerListener::MessageSeverity_Info: // normal RC text should just be debug
outSeverity = ILogger::eSeverity_Debug;
break;
case IResourceCompilerListener::MessageSeverity_Warning:
outSeverity = ILogger::eSeverity_Warning;
break;
case IResourceCompilerListener::MessageSeverity_Error:
outSeverity = ILogger::eSeverity_Error;
break;
default:
outSeverity = ILogger::eSeverity_Error;
break;
}
m_context->Log(outSeverity, "%s", text);
}
private:
IExportContext* m_context;
};
}
void ColladaExportWriter::Export(IExportSource* source, IExportContext* context)
{
// Create an object to report on our progress to the export context.
ProgressRange progressRange(context, &IExportContext::SetProgress);
CResourceCompilerHelper compiler; // we need a real instance of this specific implementation.
// Log build information.
context->Log(ILogger::eSeverity_Info, "Exporter build created on " __DATE__);
#ifdef STLPORT
context->Log(ILogger::eSeverity_Info, "Using STLport C++ Standard Library implementation");
#else //STLPORT
context->Log(ILogger::eSeverity_Info, "Using Microsoft (tm) C++ Standard Library implementation");
#endif //STLPORT
#if defined(_DEBUG)
context->Log(ILogger::eSeverity_Info, "******DEBUG BUILD******");
#else //_DEBUG
context->Log(ILogger::eSeverity_Info, "Release build.");
#endif //_DEBUG
context->Log(ILogger::eSeverity_Debug, "Bit count == %d.", (sizeof(void*) * 8));
std::string exePath = StringHelpers::ConvertString<string>(ModuleHelpers::GetCurrentModulePath(ModuleHelpers::CurrentModuleSpecifier_Executable));
context->Log(ILogger::eSeverity_Debug, "Application path: %s", exePath.c_str());
std::string exporterPath = StringHelpers::ConvertString<string>(ModuleHelpers::GetCurrentModulePath(ModuleHelpers::CurrentModuleSpecifier_Library));
context->Log(ILogger::eSeverity_Debug, "Exporter path: %s", exporterPath.c_str());
bool const bExportCompressed = (GetSetting<int>(context->GetSettings(), "ExportCompressedCOLLADA", 1)) != 0;
context->Log(ILogger::eSeverity_Debug, "ExportCompressedCOLLADA key: %d", (bExportCompressed ? 1 : 0));
std::string const exportExtension = bExportCompressed ? ".dae.zip" : ".dae";
// Log the start time.
{
char buf[1024];
std::time_t t = std::time(0);
std::strftime(buf, sizeof(buf) / sizeof(buf[0]), "%H:%M:%S on %a, %d/%m/%Y", std::localtime(&t));
context->Log(ILogger::eSeverity_Info, "Export begun at %s", buf);
}
// Select the name of the directory to export to.
std::string const originalExportDirectory = source->GetExportDirectory();
if (originalExportDirectory.empty())
{
throw IExportContext::NeedSaveError("Scene must be saved before exporting.");
}
GeometryFileData geometryFileData;
std::vector<std::string> colladaGeometryFileNameList;
std::vector<std::string> assetGeometryFileNameList;
typedef std::vector<std::pair<std::pair<int, int>, std::string> > AnimationFileNameList;
AnimationFileNameList animationFileNameList;
AnimationFileNameList animationCompileFileNameList;
{
CurrentTaskScope currentTask(context, "dae");
// Choose the files to which to export all the animations.
std::list<SingleAnimationExportSourceAdapter> animationExportSources;
std::list<GeometryExportSourceAdapter> geometryExportSources;
typedef std::vector<std::pair<std::string, IExportSource*> > ExportList;
ExportList exportList;
std::vector<int> geometryFileIndices;
{
ProgressRange readProgressRange(progressRange, 0.2f);
source->ReadGeometryFiles(context, &geometryFileData);
for (int geometryFileIndex = 0; geometryFileIndex < geometryFileData.GetGeometryFileCount(); ++geometryFileIndex)
{
const std::string geometryFileName = geometryFileData.GetGeometryFileName(geometryFileIndex);
IGeometryFileData::SProperties properties = geometryFileData.GetProperties(geometryFileIndex);
if (properties.filetypeInt == CRY_FILE_TYPE_CAF)
{
// LDS: This is a temporary fix for some old hacky code that would activate a deprecated compression path during export
// It needs a proper fix by tearing out the old compression code and moving the system to the new i_caf system by default.
// See for http://docs.cryengine.com/display/SDKDOC3/Transition+from+CBA+to+AnimSettings details.
properties.filetypeInt = CRY_FILE_TYPE_INTERMEDIATE_CAF;
geometryFileData.SetProperties(geometryFileIndex, properties);
}
bool const hasGeometry = (properties.filetypeInt != CRY_FILE_TYPE_CAF &&
properties.filetypeInt != CRY_FILE_TYPE_INTERMEDIATE_CAF);
if (hasGeometry && !geometryFileName.empty())
{
geometryFileIndices.push_back(geometryFileIndex);
}
}
if (!geometryFileIndices.empty())
{
std::string name = PathHelpers::RemoveExtension(PathHelpers::GetFilename(source->GetDCCFileName()));
std::replace(name.begin(), name.end(), ' ', '_');
std::string const colladaPath = PathHelpers::Join(originalExportDirectory, name + exportExtension);
colladaGeometryFileNameList.push_back(colladaPath);
geometryExportSources.push_back(GeometryExportSourceAdapter(source, &geometryFileData, geometryFileIndices));
exportList.push_back(std::make_pair(colladaPath, &geometryExportSources.back()));
}
for (int geometryFileIndex = 0; geometryFileIndex < geometryFileData.GetGeometryFileCount(); ++geometryFileIndex)
{
std::string const geometryFileName = geometryFileData.GetGeometryFileName(geometryFileIndex);
int const fileTypeInt = geometryFileData.GetProperties(geometryFileIndex).filetypeInt;
std::string customExportPath = geometryFileData.GetProperties(geometryFileIndex).customExportPath;
bool const hasGeometry = (fileTypeInt != CRY_FILE_TYPE_CAF &&
fileTypeInt != CRY_FILE_TYPE_INTERMEDIATE_CAF);
if (hasGeometry && !geometryFileName.empty())
{
std::string extension = "missingextension";
if (fileTypeInt == CRY_FILE_TYPE_CGF)
{
extension = "cgf";
}
else if ((fileTypeInt == CRY_FILE_TYPE_CGA) || (fileTypeInt == (CRY_FILE_TYPE_CGA | CRY_FILE_TYPE_ANM)))
{
extension = "cga";
}
else if (fileTypeInt == CRY_FILE_TYPE_ANM)
{
extension = "anm";
}
else if (fileTypeInt == CRY_FILE_TYPE_CHR ||
(fileTypeInt == (CRY_FILE_TYPE_CHR | CRY_FILE_TYPE_CAF)) ||
(fileTypeInt == (CRY_FILE_TYPE_CHR | CRY_FILE_TYPE_INTERMEDIATE_CAF)))
{
extension = "chr";
}
else if (fileTypeInt == CRY_FILE_TYPE_SKIN)
{
extension = "skin";
}
std::string safeGeometryFileName = geometryFileName;
std::replace(safeGeometryFileName.begin(), safeGeometryFileName.end(), ' ', '_');
std::string finalFileName;
if (customExportPath.size() > 0)
{
if (PathHelpers::IsRelative(customExportPath))
{
std::string const assetRelativePath = PathHelpers::Join(originalExportDirectory, customExportPath);
finalFileName = PathHelpers::Join(assetRelativePath, safeGeometryFileName + "." + extension);
}
else
{
context->Log(ILogger::eSeverity_Warning, "An absolute path was specified for export of node %s (%s) - This is unlikely to be correct", geometryFileName.c_str(), customExportPath.c_str());
finalFileName = PathHelpers::Join(customExportPath, safeGeometryFileName + "." + extension);
}
}
else
{
// no relative path, just export it in the original directory.
finalFileName = PathHelpers::Join(originalExportDirectory, safeGeometryFileName + "." + extension);
}
if (finalFileName.size() > 0)
{
assetGeometryFileNameList.push_back(finalFileName);
if (!FileUtil::EnsureDirectoryExists(PathHelpers::GetDirectory(finalFileName).c_str()))
{
context->Log(ILogger::eSeverity_Error, "Unable to create directory for %s", finalFileName.c_str());
return;
}
}
}
if ((fileTypeInt & (CRY_FILE_TYPE_CAF | CRY_FILE_TYPE_INTERMEDIATE_CAF)) != 0)
{
for (int animationIndex = 0; animationIndex < source->GetAnimationCount(); ++animationIndex)
{
std::string const animationName = source->GetAnimationName(&geometryFileData, geometryFileIndex, animationIndex);
// Animations beginning with an underscore should be ignored.
bool const ignoreAnimation = animationName.empty() || (animationName[0] == '_');
if (!ignoreAnimation)
{
std::string safeAnimationName = animationName;
std::replace(safeAnimationName.begin(), safeAnimationName.end(), ' ', '_');
std::string exportPath = PathHelpers::Join(originalExportDirectory, safeAnimationName + exportExtension);
animationFileNameList.push_back(std::make_pair(std::make_pair(animationIndex, geometryFileIndex), exportPath));
if (fileTypeInt & CRY_FILE_TYPE_CAF)
{
animationCompileFileNameList.push_back(std::make_pair(std::make_pair(animationIndex, geometryFileIndex), exportPath));
}
animationExportSources.push_back(SingleAnimationExportSourceAdapter(source, &geometryFileData, geometryFileIndex, animationIndex));
exportList.push_back(std::make_pair(exportPath, &animationExportSources.back()));
}
}
}
}
}
// Export the COLLADA file to the chosen file.
{
ProgressRange exportProgressRange(progressRange, 0.6f);
size_t const daeCount = exportList.size();
float const daeProgressRangeSlice = 1.0f / (daeCount > 0 ? daeCount : 1);
for (ExportList::iterator itFile = exportList.begin(); itFile != exportList.end(); ++itFile)
{
const std::string& colladaFileName = (*itFile).first;
IExportSource* fileExportSource = (*itFile).second;
ProgressRange animationExportProgressRange(exportProgressRange, daeProgressRangeSlice);
try
{
context->Log(ILogger::eSeverity_Info, "Exporting to file '%s'", colladaFileName.c_str());
// Try to create the directory for the file.
if (!FileUtil::EnsureDirectoryExists(PathHelpers::GetDirectory(colladaFileName).c_str()))
{
context->Log(ILogger::eSeverity_Error, "Unable to create directory for %s", colladaFileName.c_str());
return;
}
bool ok;
if (bExportCompressed)
{
IPakSystem* pakSystem = (context ? context->GetPakSystem() : 0);
if (!pakSystem)
{
throw IExportContext::PakSystemError("No pak system provided.");
}
std::string const archivePath = colladaFileName;
std::string archiveRelativePath = colladaFileName.substr(0, colladaFileName.length() - exportExtension.length()) + ".dae";
archiveRelativePath = PathHelpers::GetFilename(archiveRelativePath);
XMLPakFileSink sink(pakSystem, archivePath, archiveRelativePath);
ok = ColladaWriter::Write(fileExportSource, context, &sink, animationExportProgressRange);
}
else
{
XMLFileSink fileSink(colladaFileName);
ok = ColladaWriter::Write(fileExportSource, context, &fileSink, animationExportProgressRange);
}
if (!ok)
{
// FIXME: erase the resulting file somehow
context->Log(ILogger::eSeverity_Error, "Failed to export '%s'", colladaFileName.c_str());
return;
}
}
catch (IXMLSink::OpenFailedError e)
{
context->Log(ILogger::eSeverity_Error, "Unable to open output file: %s", e.what());
return;
}
catch (...)
{
context->Log(ILogger::eSeverity_Error, "Unexpected crash in COLLADA exporter");
return;
}
}
}
}
// Get the RC path. If a custom one isn't specified then fall back to the registry method as per the default.
wchar_t resourceCompilerPath[512];
{
const std::string resourceCompilerPathString = source->GetResourceCompilerPath();
if (!resourceCompilerPathString.empty())
{
SettingsManagerHelpers::ConvertUtf8ToUtf16(resourceCompilerPathString.c_str(), SettingsManagerHelpers::CWCharBuffer(resourceCompilerPath, sizeof(resourceCompilerPath)));
}
}
// Run the resource compiler on the COLLADA file to generate uncompressed CAFs.
{
ProgressRange compilerProgressRange(progressRange, 0.075f);
CurrentTaskScope currentTask(context, "rc");
size_t const daeCount = animationFileNameList.size();
float const animationProgressRangeSlice = 1.0f / (daeCount > 0 ? daeCount : 1);
for (AnimationFileNameList::iterator itFile = animationFileNameList.begin(); itFile != animationFileNameList.end(); ++itFile)
{
std::string colladaFileName = (*itFile).second;
int geometryFileIndex = itFile->first.second;
std::string expectedCAFPath;
{
bool isIntermediateCAF = (geometryFileData.GetProperties(geometryFileIndex).filetypeInt & CRY_FILE_TYPE_INTERMEDIATE_CAF) != 0;
string nameWithoutExtension = colladaFileName.substr(0, colladaFileName.length() - exportExtension.length());
expectedCAFPath = nameWithoutExtension + (isIntermediateCAF ? ".i_caf" : ".caf");
}
if (FileUtil::FileExists(expectedCAFPath.c_str()))
{
if (!DeleteFileA(expectedCAFPath.c_str()))
{
context->Log(ILogger::eSeverity_Error, "Failed to remove existing animation file: %s", expectedCAFPath.c_str());
continue;
}
}
string arguments = "/refresh";
ProgressRange animationCompileProgressRange(compilerProgressRange, animationProgressRangeSlice);
ResourceCompilerLogListener listener(context);
context->Log(ILogger::eSeverity_Info, "Calling RC to generate uncompressed CAF file: %s", colladaFileName.c_str());
CResourceCompilerHelper::ERcCallResult result = compiler.CallResourceCompiler( // actual instance of compiler used
colladaFileName.c_str(),
arguments.c_str(),
&listener,
true, false, false, 0, resourceCompilerPath);
if (result != CResourceCompilerHelper::eRcCallResult_success)
{
context->Log(ILogger::eSeverity_Error, "%s", compiler.GetCallResultDescription(result));
continue;
}
context->Log(ILogger::eSeverity_Debug, "RC finished: %s", colladaFileName.c_str());
if (!FileUtil::FileExists(expectedCAFPath.c_str()))
{
context->Log(ILogger::eSeverity_Error, "Following Animation file is expected to be created by RC: %s", expectedCAFPath.c_str());
context->Log(ILogger::eSeverity_Error, "Do you have an old RC version?");
}
#if !defined(_DEBUG)
// Delete the Collada file.
DeleteFileA(colladaFileName.c_str());
#endif
}
}
// Run the resource compiler on the COLLADA file to generate the geometry assets.
{
ProgressRange compilerProgressRange(progressRange, 0.075f);
CurrentTaskScope currentTask(context, "rc");
size_t const daeCount = colladaGeometryFileNameList.size();
float const assetProgressRangeSlice = 1.0f / (daeCount > 0 ? daeCount : 1);
for (size_t i = 0; i < daeCount; ++i)
{
const std::string& colladaFileName = colladaGeometryFileNameList[i];
ProgressRange assetCompileProgressRange(compilerProgressRange, assetProgressRangeSlice);
ResourceCompilerLogListener listener(context);
context->Log(ILogger::eSeverity_Info, "Calling RC to generate raw asset file: %s", colladaFileName.c_str());
CResourceCompilerHelper::ERcCallResult result = compiler.CallResourceCompiler(
colladaFileName.c_str(),
"/refresh",
&listener,
true, false, false, 0, resourceCompilerPath);
#if !defined(_DEBUG)
// Delete the Collada file.
DeleteFileA(colladaFileName.c_str());
#endif
if (result == CResourceCompilerHelper::eRcCallResult_success)
{
context->Log(ILogger::eSeverity_Debug, "RC finished: %s", colladaFileName.c_str());
}
else
{
context->Log(ILogger::eSeverity_Error, "%s", compiler.GetCallResultDescription(result));
return;
}
}
}
{
// Create an RC helper - do it outside the loop, since it queries the registry on construction.
ResourceCompilerLogListener listener(context);
// Check the registry to see whether we should compress the animations or not.
int processAnimations = GetSetting<int>(context->GetSettings(), "CompressCAFs", 1);
if (!processAnimations)
{
context->Log(ILogger::eSeverity_Warning, "CompressCAFs registry key set to 0 - not compressing CAFs");
}
else
{
// Run the resource compiler again on the generated CAF files to compress/process them.
context->Log(ILogger::eSeverity_Debug, "CompressCAFs not set or set to 1 - compressing CAFs");
CurrentTaskScope currentTask(context, "compress");
ProgressRange compressRange(progressRange, 0.025f);
size_t const cafCount = animationCompileFileNameList.size();
float const animationProgressRangeSlice = 1.0f / (cafCount > 0 ? cafCount : 1);
for (AnimationFileNameList::iterator itFile = animationCompileFileNameList.begin(); itFile != animationCompileFileNameList.end(); ++itFile)
{
std::string colladaFileName = (*itFile).second;
ProgressRange animationProgressRange(compressRange, animationProgressRangeSlice);
// Assume the RC generated the CAF file using the take name and adding .CAF.
std::string cafPath = colladaFileName.substr(0, colladaFileName.length() - exportExtension.length()) + ".caf";
std::string cbaPath = StringHelpers::ConvertString<string>(CBAHelpers::FindCBAFileForFile(cafPath.c_str(), context->GetPakSystem()));
if (cbaPath.empty())
{
context->Log(ILogger::eSeverity_Error, "Unable to find CBA file for file \"%s\" (looked for a root game directory that contains a relative path of \"Animations/Animations.cba\"", cafPath.c_str());
}
else
{
char buffer[2048];
sprintf(buffer, "/file=\"%s\" /refresh /SkipDba", cafPath.c_str());
context->Log(ILogger::eSeverity_Info, "Calling RC to compress CAF file: (CBA file = %s) %s", cbaPath.c_str(), buffer);
CResourceCompilerHelper::ERcCallResult result = compiler.CallResourceCompiler(cbaPath.c_str(), buffer, &listener, true, resourceCompilerPathType, false, false, 0, resourceCompilerPath);
if (result == CResourceCompilerHelper::eRcCallResult_success)
{
context->Log(ILogger::eSeverity_Debug, "RC finished: %s %s", cbaPath.c_str(), buffer);
}
else
{
context->Log(ILogger::eSeverity_Error, "%s", compiler.GetCallResultDescription(result));
return;
}
}
}
}
// Check the registry to see whether we should optimize the geometry files or not.
int optimizeGeometry = GetSetting<int>(context->GetSettings(), "OptimizeAssets", 1);
// Run the resource compiler again on the generated geometry files to compress/process them.
// TODO: This should not be necessary, the RC should be modified so that assets are automatically
// compressed when exported from COLLADA.
if (!optimizeGeometry)
{
context->Log(ILogger::eSeverity_Warning, "OptimizeAssets registry key set to 0 - not compressing CAFs");
}
else
{
context->Log(ILogger::eSeverity_Debug, "OptimizeAssets not set or set to 1 - optimizing geometry");
CurrentTaskScope currentTask(context, "compress");
ProgressRange compressRange(progressRange, 0.025f);
size_t const assetCount = assetGeometryFileNameList.size();
float const assetProgressRangeSlice = 1.0f / (assetCount > 0 ? assetCount : 1);
for (size_t i = 0; i < assetCount; ++i)
{
const std::string& assetFileName = assetGeometryFileNameList[i];
ProgressRange animationProgressRange(compressRange, assetProgressRangeSlice);
// note: we skip some asset types because we know that they are "optimized" already
if (StringHelpers::EndsWithIgnoreCase(assetFileName, ".anm") || StringHelpers::EndsWithIgnoreCase(assetFileName, ".chr") || StringHelpers::EndsWithIgnoreCase(assetFileName, ".skin"))
{
context->Log(ILogger::eSeverity_Info, "Calling RC to optimize asset \"%s\"", assetFileName.c_str());
CResourceCompilerHelper::ERcCallResult result = compiler.CallResourceCompiler(assetFileName.c_str(), "/refresh", &listener, true, resourceCompilerPathType, false, false, 0, resourceCompilerPath);
if (result == CResourceCompilerHelper::eRcCallResult_success)
{
context->Log(ILogger::eSeverity_Debug, "RC finished: %s", assetFileName.c_str());
}
else
{
context->Log(ILogger::eSeverity_Error, "%s", compiler.GetCallResultDescription(result));
return;
}
}
}
}
}
// Log the end time.
{
char buf[1024];
std::time_t t = std::time(0);
std::strftime(buf, sizeof(buf) / sizeof(buf[0]), "%H:%M:%S on %a, %d/%m/%Y", std::localtime(&t));
context->Log(ILogger::eSeverity_Info, "Export finished at %s", buf);
}
}
@@ -0,0 +1,29 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_COLLADAEXPORTWRITER_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_COLLADAEXPORTWRITER_H
#pragma once
#include "IExportWriter.h"
class ColladaExportWriter
: public IExportWriter
{
public:
// IExportWriter
virtual void Export(IExportSource* source, IExportContext* context);
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_COLLADAEXPORTWRITER_H
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,32 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_COLLADAWRITER_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_COLLADAWRITER_H
#pragma once
#include <string>
class IExportSource;
class IExportContext;
class ProgressRange;
class IXMLSink;
class ColladaWriter
{
public:
static bool Write(IExportSource* source, IExportContext* context, IXMLSink* sink, ProgressRange& progressRange);
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_COLLADAWRITER_H
@@ -0,0 +1,66 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#include "StdAfx.h"
#include "ExportFileType.h"
#include "StringHelpers.h"
struct SFileTypeInfo
{
int type;
const char* name;
};
SFileTypeInfo s_fileTypes[] =
{
{ CRY_FILE_TYPE_CGF, "cgf" },
{ CRY_FILE_TYPE_CGA, "cga" },
{ CRY_FILE_TYPE_CHR, "chr" },
{ CRY_FILE_TYPE_CAF, "caf" },
{ CRY_FILE_TYPE_ANM, "anm" },
{ CRY_FILE_TYPE_CHR | CRY_FILE_TYPE_CAF, "chrcaf" },
{ CRY_FILE_TYPE_CGA | CRY_FILE_TYPE_ANM, "cgaanm" },
{ CRY_FILE_TYPE_SKIN, "skin" },
{ CRY_FILE_TYPE_INTERMEDIATE_CAF, "i_caf" },
};
static const int s_fileTypeCount = (sizeof(s_fileTypes) / sizeof(s_fileTypes[0]));
const char* ExportFileTypeHelpers::CryFileTypeToString(int const cryFileType)
{
for (int i = 0; i < s_fileTypeCount; ++i)
{
if (s_fileTypes[i].type == cryFileType)
{
return s_fileTypes[i].name;
}
}
return "unknown";
}
int ExportFileTypeHelpers::StringToCryFileType(const char* str)
{
if (str)
{
for (int i = 0; i < s_fileTypeCount; ++i)
{
if (_stricmp(str, s_fileTypes[i].name) == 0)
{
return s_fileTypes[i].type;
}
}
}
return CRY_FILE_TYPE_NONE;
}
@@ -0,0 +1,42 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_EXPORTFILETYPE_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_EXPORTFILETYPE_H
#pragma once
enum CryFileType
{
CRY_FILE_TYPE_NONE = 0x0000,
CRY_FILE_TYPE_CGF = 0x0001,
CRY_FILE_TYPE_CGA = 0x0002,
CRY_FILE_TYPE_CHR = 0x0004,
CRY_FILE_TYPE_CAF = 0x0008,
CRY_FILE_TYPE_ANM = 0x0010,
CRY_FILE_TYPE_SKIN = 0x0020,
CRY_FILE_TYPE_INTERMEDIATE_CAF = 0x0040,
//START: Add Skinned Geometry (.CGF) export type (for touch bending vegetation)
CRY_FILE_TYPE_SKIN_CGF = 0x0080,
//END: Add Skinned Geometry (.CGF) export type (for touch bending vegetation)
};
namespace ExportFileTypeHelpers
{
const char* CryFileTypeToString(int cryFileType);
int StringToCryFileType(const char* str);
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_EXPORTFILETYPE_H
@@ -0,0 +1,83 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_EXPORTHELPERS_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_EXPORTHELPERS_H
#pragma once
#include <cmath>
namespace ExportHelpers
{
inline void GenerateTextureCoordinates(float* const res_s, float* const res_t, const float x, const float y, const float z)
{
const float ax = ::fabs(x);
const float ay = ::fabs(y);
const float az = ::fabs(z);
float s = 0.0f;
float t = 0.0f;
if (ax > 1e-3f || ay > 1e-3f || az > 1e-3f)
{
if (ax > ay)
{
if (ax > az)
{
// X rules
s = y / ax;
t = z / ax;
}
else
{
// Z rules
s = x / az;
t = y / az;
}
}
else
{
// ax <= ay
if (ay > az)
{
// Y rules
s = x / ay;
t = z / ay;
}
else
{
// Z rules
s = x / az;
t = y / az;
}
}
}
// Now the texture coordinates are in the range [-1,1].
// We want normalized [0,1] texture coordinates.
s = (s + 1) * 0.5f;
t = (t + 1) * 0.5f;
if (res_s)
{
*res_s = s;
}
if (res_t)
{
*res_t = t;
}
}
}
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_EXPORTHELPERS_H
@@ -0,0 +1,130 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#include "StdAfx.h"
#include "ExportSourceDecoratorBase.h"
ExportSourceDecoratorBase::ExportSourceDecoratorBase(IExportSource* source)
: source(source)
{
}
void ExportSourceDecoratorBase::GetMetaData(SExportMetaData& metaData) const
{
this->source->GetMetaData(metaData);
}
std::string ExportSourceDecoratorBase::GetDCCFileName() const
{
return this->source->GetDCCFileName();
}
std::string ExportSourceDecoratorBase::GetExportDirectory() const
{
return this->source->GetExportDirectory();
}
void ExportSourceDecoratorBase::ReadGeometryFiles(IExportContext* context, IGeometryFileData* geometryFileData)
{
this->source->ReadGeometryFiles(context, geometryFileData);
}
bool ExportSourceDecoratorBase::ReadMaterials(IExportContext* context, const IGeometryFileData* const geometryFileData, IMaterialData* materialData)
{
return this->source->ReadMaterials(context, geometryFileData, materialData);
}
void ExportSourceDecoratorBase::ReadModels(const IGeometryFileData* geometryFileData, int geometryFileIndex, IModelData* modelData)
{
this->source->ReadModels(geometryFileData, geometryFileIndex, modelData);
}
void ExportSourceDecoratorBase::ReadSkinning(IExportContext* context, ISkinningData* skinningData, const IModelData* const modelData, int modelIndex, ISkeletonData* skeletonData)
{
this->source->ReadSkinning(context, skinningData, modelData, modelIndex, skeletonData);
}
bool ExportSourceDecoratorBase::ReadSkeleton(const IGeometryFileData* const geometryFileData, int geometryFileIndex, const IModelData* const modelData, int modelIndex, const IMaterialData* materialData, ISkeletonData* skeletonData)
{
return this->source->ReadSkeleton(geometryFileData, geometryFileIndex, modelData, modelIndex, materialData, skeletonData);
}
int ExportSourceDecoratorBase::GetAnimationCount() const
{
return this->source->GetAnimationCount();
}
std::string ExportSourceDecoratorBase::GetAnimationName(const IGeometryFileData* geometryFileData, int geometryFileIndex, int animationIndex) const
{
return this->source->GetAnimationName(geometryFileData, geometryFileIndex, animationIndex);
}
void ExportSourceDecoratorBase::GetAnimationTimeSpan(float& start, float& stop, int animationIndex) const
{
this->source->GetAnimationTimeSpan(start, stop, animationIndex);
}
void ExportSourceDecoratorBase::ReadAnimationFlags(IExportContext* context, IAnimationData* animationData, const IGeometryFileData* const geometryFileData, const IModelData* modelData, int modelIndex, const ISkeletonData* skeletonData, int animationIndex) const
{
this->source->ReadAnimationFlags(context, animationData, geometryFileData, modelData, modelIndex, skeletonData, animationIndex);
}
IAnimationData* ExportSourceDecoratorBase::ReadAnimation(IExportContext* context, const IGeometryFileData* const geometryFileData, const IModelData* modelData, int modelIndex, const ISkeletonData* skeletonData, int animationIndex, float fps) const
{
return this->source->ReadAnimation(context, geometryFileData, modelData, modelIndex, skeletonData, animationIndex, fps);
}
bool ExportSourceDecoratorBase::ReadGeometry(IExportContext* context, IGeometryData* geometry, const IModelData* const modelData, const IMaterialData* const materialData, int modelIndex)
{
return this->source->ReadGeometry(context, geometry, modelData, materialData, modelIndex);
}
bool ExportSourceDecoratorBase::ReadGeometryMaterialData(IExportContext* context, IGeometryMaterialData* geometryMaterialData, const IModelData* const modelData, const IMaterialData* const materialData, int modelIndex) const
{
return this->source->ReadGeometryMaterialData(context, geometryMaterialData, modelData, materialData, modelIndex);
}
bool ExportSourceDecoratorBase::ReadBoneGeometry(IExportContext* context, IGeometryData* geometry, ISkeletonData* skeletonData, int boneIndex, const IMaterialData* const materialData)
{
return this->source->ReadBoneGeometry(context, geometry, skeletonData, boneIndex, materialData);
}
bool ExportSourceDecoratorBase::ReadBoneGeometryMaterialData(IExportContext* context, IGeometryMaterialData* geometryMaterialData, ISkeletonData* skeletonData, int boneIndex, const IMaterialData* const materialData) const
{
return this->source->ReadBoneGeometryMaterialData(context, geometryMaterialData, skeletonData, boneIndex, materialData);
}
void ExportSourceDecoratorBase::ReadMorphs(IExportContext* context, IMorphData* morphData, const IModelData* const modelData, int modelIndex)
{
this->source->ReadMorphs(context, morphData, modelData, modelIndex);
}
bool ExportSourceDecoratorBase::ReadMorphGeometry(IExportContext* context, IGeometryData* geometry, const IModelData* const modelData, int modelIndex, const IMorphData* const morphData, int morphIndex, const IMaterialData* materialData)
{
return this->source->ReadMorphGeometry(context, geometry, modelData, modelIndex, morphData, morphIndex, materialData);
}
bool ExportSourceDecoratorBase::HasValidPosController(const IModelData* modelData, int modelIndex) const
{
return this->source->HasValidPosController(modelData, modelIndex);
}
bool ExportSourceDecoratorBase::HasValidRotController(const IModelData* modelData, int modelIndex) const
{
return this->source->HasValidRotController(modelData, modelIndex);
}
bool ExportSourceDecoratorBase::HasValidSclController(const IModelData* modelData, int modelIndex) const
{
return this->source->HasValidSclController(modelData, modelIndex);
}
@@ -0,0 +1,54 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_EXPORTSOURCEDECORATORBASE_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_EXPORTSOURCEDECORATORBASE_H
#pragma once
#include "IExportSource.h"
class ExportSourceDecoratorBase
: public IExportSource
{
public:
ExportSourceDecoratorBase(IExportSource* source);
virtual std::string GetResourceCompilerPath() const { return std::string(""); };
virtual void GetMetaData(SExportMetaData& metaData) const;
virtual std::string GetDCCFileName() const;
virtual std::string GetExportDirectory() const;
virtual void ReadGeometryFiles(IExportContext* context, IGeometryFileData* geometryFileData);
virtual bool ReadMaterials(IExportContext* context, const IGeometryFileData* geometryFileData, IMaterialData* materialData);
virtual void ReadModels(const IGeometryFileData* geometryFileData, int geometryFileIndex, IModelData* modelData);
virtual void ReadSkinning(IExportContext* context, ISkinningData* skinningData, const IModelData* modelData, int modelIndex, ISkeletonData* skeletonData);
virtual bool ReadSkeleton(const IGeometryFileData* geometryFileData, int geometryFileIndex, const IModelData* modelData, int modelIndex, const IMaterialData* materialData, ISkeletonData* skeletonData);
virtual int GetAnimationCount() const;
virtual std::string GetAnimationName(const IGeometryFileData* geometryFileData, int geometryFileIndex, int animationIndex) const;
virtual void GetAnimationTimeSpan(float& start, float& stop, int animationIndex) const;
virtual void ReadAnimationFlags(IExportContext* context, IAnimationData* animationData, const IGeometryFileData* geometryFileData, const IModelData* modelData, int modelIndex, const ISkeletonData* skeletonData, int animationIndex) const;
virtual IAnimationData* ReadAnimation(IExportContext* context, const IGeometryFileData* geometryFileData, const IModelData* modelData, int modelIndex, const ISkeletonData* skeletonData, int animationIndex, float fps) const;
virtual bool ReadGeometry(IExportContext* context, IGeometryData* geometry, const IModelData* modelData, const IMaterialData* materialData, int modelIndex);
virtual bool ReadGeometryMaterialData(IExportContext* context, IGeometryMaterialData* geometryMaterialData, const IModelData* modelData, const IMaterialData* materialData, int modelIndex) const;
virtual bool ReadBoneGeometry(IExportContext* context, IGeometryData* geometry, ISkeletonData* skeletonData, int boneIndex, const IMaterialData* materialData);
virtual bool ReadBoneGeometryMaterialData(IExportContext* context, IGeometryMaterialData* geometryMaterialData, ISkeletonData* skeletonData, int boneIndex, const IMaterialData* materialData) const;
virtual void ReadMorphs(IExportContext* context, IMorphData* morphData, const IModelData* modelData, int modelIndex);
virtual bool ReadMorphGeometry(IExportContext* context, IGeometryData* geometry, const IModelData* modelData, int modelIndex, const IMorphData* morphData, int morphIndex, const IMaterialData* materialData);
virtual bool HasValidPosController(const IModelData* modelData, int modelIndex) const;
virtual bool HasValidRotController(const IModelData* modelData, int modelIndex) const;
virtual bool HasValidSclController(const IModelData* modelData, int modelIndex) const;
protected:
IExportSource* source;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_EXPORTSOURCEDECORATORBASE_H
@@ -0,0 +1,215 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#include "StdAfx.h"
#include "ExportStatusWindow.h"
#include "UI/Win32GUI.h"
#include "StringHelpers.h"
#include <process.h>
#include <Windows.h>
enum
{
WM_USER_TASK_FINISHED = WM_USER + 53,
WM_USER_ACCEPTED
};
struct ThreadData
{
ExportStatusWindow* statusWindow;
void (ExportStatusWindow::* initialize)(int width, int height, const std::vector<std::pair<std::string, std::string> >& tasks);
void (ExportStatusWindow::* run)();
int width;
int height;
const std::vector<std::pair<std::string, std::string> >* tasks;
HANDLE initializedSemaphore;
};
unsigned int __stdcall ThreadFunc(void* threadDataMemory)
{
ThreadData* data = static_cast<ThreadData*>(threadDataMemory);
ExportStatusWindow* statusWindow = data->statusWindow;
void (ExportStatusWindow::* initialize)(int width, int height, const std::vector<std::pair<std::string, std::string> >& tasks) = data->initialize;
void (ExportStatusWindow::* run)() = data->run;
int width = data->width;
int height = data->height;
const std::vector<std::pair<std::string, std::string> >& tasks = *data->tasks;
HANDLE initializedSemaphore = data->initializedSemaphore;
// Initialize the data.
(statusWindow->*initialize)(width, height, tasks);
// Let the creating thread know that we have read the data - it is
// now safe for it to clear it.
ReleaseSemaphore(initializedSemaphore, 1, 0);
// Perform the main thread processing.
(statusWindow->*run)();
return 0;
}
#pragma warning(push)
#pragma warning(disable: 4355) // 'this' : used in base member initializer list
ExportStatusWindow::ExportStatusWindow(int width, int height, const std::vector<std::pair<std::string, std::string> >& tasks)
: m_threadHandle(0)
, m_warningsEncountered(false)
, m_errorsEncountered(false)
, m_waitState(WaitState_WarningsAndErrors)
, m_okButtonSpacer(0, 0, 2000, 0)
, m_okButton(_T("OK"), this, &ExportStatusWindow::OkPressed)
, m_okButtonLayout(Layout::DirectionHorizontal)
{
OutputDebugString(_T("Showing status window.\n"));
Win32GUI::Initialize();
HANDLE initializedSemaphore = CreateSemaphore(0, 0, 1, 0);
// Create a thread to handle the message pump for the window.
ThreadData threadData;
threadData.statusWindow = this;
threadData.initialize = &ExportStatusWindow::Initialize;
threadData.run = &ExportStatusWindow::Run;
threadData.width = width;
threadData.height = height;
threadData.tasks = &tasks;
threadData.initializedSemaphore = initializedSemaphore;
m_threadHandle = (HANDLE)_beginthreadex(
0, //void *security,
0, //unsigned stack_size,
ThreadFunc, //unsigned ( *start_address )( void * ),
&threadData, //void *arglist,
0, //unsigned initflag,
0); //unsigned *thrdaddr
// Wait until the thread has read the data, since once we return the data will be lost.
WaitForSingleObject(initializedSemaphore, INFINITE);
CloseHandle(initializedSemaphore);
}
#pragma warning(pop)
ExportStatusWindow::~ExportStatusWindow()
{
OutputDebugString(_T("Hiding status window.\n"));
// Tell the thread to exit and then wait for it to do so.
if (HWND hwnd = (HWND)m_frameWindow.GetHWND())
{
PostMessage(hwnd, WM_USER_TASK_FINISHED, 0, 0);
m_okButton.Enable(true);
WaitForSingleObject((HANDLE)m_threadHandle, INFINITE);
}
}
void ExportStatusWindow::Initialize(int width, int height, const std::vector<std::pair<std::string, std::string> >& tasks)
{
OutputDebugString(_T("Beginning status window thread.\n"));
for (int taskIndex = 0, taskCount = int(tasks.size()); taskIndex < taskCount; ++taskIndex)
{
m_taskList.AddTask(tasks[taskIndex].first, tasks[taskIndex].second);
}
m_okButtonLayout.AddComponent(&m_okButtonSpacer);
m_okButtonLayout.AddComponent(&m_okButton);
m_okButton.Enable(false);
m_frameWindow.AddComponent(&m_taskList);
m_frameWindow.AddComponent(&m_progressBar);
m_frameWindow.AddComponent(&m_logWindow);
m_frameWindow.AddComponent(&m_okButtonLayout);
m_frameWindow.Show(true, width, height);
}
void ExportStatusWindow::Run()
{
MSG msg;
BOOL status;
bool waitingAcceptance = false;
while ((status = GetMessage(&msg, HWND(0), UINT(0), UINT(0))) != 0)
{
if (status == -1)
{
break;
}
else if (msg.message == WM_USER_TASK_FINISHED)
{
if (m_waitState == WaitState_Always ||
(m_waitState == WaitState_WarningsAndErrors && m_warningsEncountered || m_errorsEncountered) ||
(m_waitState == WaitState_ErrorsOnly && m_errorsEncountered))
{
waitingAcceptance = true;
}
else
{
break;
}
}
else if (waitingAcceptance && msg.message == WM_USER_ACCEPTED)
{
break;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
m_frameWindow.Show(false, 0, 0);
OutputDebugString(_T("Ending status window thread.\n"));
}
void ExportStatusWindow::OkPressed()
{
if (HWND hwnd = (HWND)m_frameWindow.GetHWND())
{
PostMessage(hwnd, WM_USER_ACCEPTED, 0, 0);
}
}
void ExportStatusWindow::SetWaitState(WaitState state)
{
m_waitState = state;
}
void ExportStatusWindow::AddTask(const std::string& id, const std::string& description)
{
m_taskList.AddTask(id, description);
}
void ExportStatusWindow::SetCurrentTask(const std::string& id)
{
m_taskList.SetCurrentTask(id);
}
void ExportStatusWindow::SetProgress(float progress)
{
TCHAR buffer[2048];
_sntprintf_s(buffer, sizeof(buffer), _TRUNCATE, _T("%.1f%% complete - exporting scene."), progress * 100);
m_frameWindow.SetCaption(buffer);
m_progressBar.SetProgress(progress);
}
void ExportStatusWindow::Log(ILogger::ESeverity eSeverity, const char* message)
{
if (eSeverity == ILogger::eSeverity_Error)
{
m_errorsEncountered = true;
}
else if (eSeverity == ILogger::eSeverity_Warning)
{
m_warningsEncountered = true;
}
m_logWindow.Log(eSeverity, StringHelpers::ConvertString<tstring>(message).c_str());
}
@@ -0,0 +1,67 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_EXPORTSTATUSWINDOW_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_EXPORTSTATUSWINDOW_H
#pragma once
#include "UI/FrameWindow.h"
#include "UI/ProgressBar.h"
#include "UI/TaskList.h"
#include "UI/LogWindow.h"
#include "UI/Spacer.h"
#include "UI/Layout.h"
#include "UI/PushButton.h"
#include "ILogger.h"
class ExportStatusWindow
{
public:
enum WaitState
{
WaitState_WarningsAndErrors,
WaitState_ErrorsOnly,
WaitState_Always,
WaitState_Never,
};
ExportStatusWindow(int width, int height, const std::vector<std::pair<std::string, std::string> >& tasks);
~ExportStatusWindow();
void SetWaitState(WaitState state);
void AddTask(const std::string& id, const std::string& description);
void SetCurrentTask(const std::string& id);
void SetProgress(float progress);
void Log(ILogger::ESeverity eSeverity, const char* message);
private:
void Initialize(int width, int height, const std::vector<std::pair<std::string, std::string> >& tasks);
void Run();
void OkPressed();
FrameWindow m_frameWindow;
TaskList m_taskList;
ProgressBar m_progressBar;
Spacer m_okButtonSpacer;
PushButton m_okButton;
Layout m_okButtonLayout;
LogWindow m_logWindow;
void* m_threadHandle;
bool m_warningsEncountered;
bool m_errorsEncountered;
WaitState m_waitState;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_EXPORTSTATUSWINDOW_H
@@ -0,0 +1,82 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#include "StdAfx.h"
#include "GeometryData.h"
GeometryData::GeometryData()
{
}
int GeometryData::AddPosition(float x, float y, float z)
{
int positionIndex = int(this->positions.size());
this->positions.push_back(Vector(x, y, z));
return positionIndex;
}
int GeometryData::AddNormal(float x, float y, float z)
{
int normalIndex = int(this->normals.size());
this->normals.push_back(Vector(x, y, z));
return normalIndex;
}
int GeometryData::AddTextureCoordinate(float u, float v)
{
int textureCoordinateIndex = int(this->textureCoordinates.size());
this->textureCoordinates.push_back(TextureCoordinate(u, v));
return textureCoordinateIndex;
}
int GeometryData::AddVertexColor(float r, float g, float b, float a)
{
int vertexColorIndex = int(this->vertexColors.size());
this->vertexColors.push_back(VertexColor(r, g, b, a));
return vertexColorIndex;
}
int GeometryData::AddPolygon(const int* indices, int mtlID)
{
int polygonIndex = int(this->polygons.size());
this->polygons.push_back(Polygon(mtlID,
Polygon::Vertex(indices[0], indices[1], indices[2], indices[3]),
Polygon::Vertex(indices[4], indices[5], indices[6], indices[7]),
Polygon::Vertex(indices[8], indices[9], indices[10], indices[11])));
return polygonIndex;
}
int GeometryData::GetNumberOfPositions() const
{
return (int)this->positions.size();
}
int GeometryData::GetNumberOfNormals() const
{
return (int)this->normals.size();
}
int GeometryData::GetNumberOfTextureCoordinates() const
{
return (int)this->textureCoordinates.size();
}
int GeometryData::GetNumberOfVertexColors() const
{
return (int)this->vertexColors.size();
}
int GeometryData::GetNumberOfPolygons() const
{
return (int)this->polygons.size();
}
@@ -0,0 +1,102 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_GEOMETRYDATA_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_GEOMETRYDATA_H
#pragma once
#include "IGeometryData.h"
#include <vector>
class GeometryData
: public IGeometryData
{
public:
GeometryData();
// IGeometryData
virtual int AddPosition(float x, float y, float z);
virtual int AddNormal(float x, float y, float z);
virtual int AddTextureCoordinate(float u, float v);
virtual int AddVertexColor(float r, float g, float b, float a);
virtual int AddPolygon(const int* indices, int mtlID);
virtual int GetNumberOfPositions() const;
virtual int GetNumberOfNormals() const;
virtual int GetNumberOfTextureCoordinates() const;
virtual int GetNumberOfVertexColors() const;
virtual int GetNumberOfPolygons() const;
struct Vector
{
Vector(float x, float y, float z)
: x(x)
, y(y)
, z(z) {}
float x, y, z;
};
struct TextureCoordinate
{
TextureCoordinate(float u, float v)
: u(u)
, v(v) {}
float u, v;
};
struct VertexColor
{
VertexColor(float r, float g, float b, float a)
: r(r)
, g(g)
, b(b)
, a(a) {}
float r, g, b, a;
};
struct Polygon
{
struct Vertex
{
Vertex() {}
Vertex(int positionIndex, int normalIndex, int textureCoordinateIndex, int vertexColorIndex)
: positionIndex(positionIndex)
, normalIndex(normalIndex)
, textureCoordinateIndex(textureCoordinateIndex)
, vertexColorIndex(vertexColorIndex) {}
int positionIndex, normalIndex, textureCoordinateIndex, vertexColorIndex;
};
Polygon(int mtlID, const Vertex& v0, const Vertex& v1, const Vertex& v2)
: mtlID(mtlID)
{
v[0] = v0;
v[1] = v1;
v[2] = v2;
}
int mtlID;
Vertex v[3];
};
std::vector<Vector> positions;
std::vector<Vector> normals;
std::vector<TextureCoordinate> textureCoordinates;
std::vector<VertexColor> vertexColors;
std::vector<Polygon> polygons;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_GEOMETRYDATA_H
@@ -0,0 +1,54 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#include "StdAfx.h"
#include "GeometryExportSourceAdapter.h"
#include "IGeometryFileData.h"
#include <cassert>
GeometryExportSourceAdapter::GeometryExportSourceAdapter(IExportSource* source, IGeometryFileData* geometryFileData, const std::vector<int>& geometryFileIndices)
: ExportSourceDecoratorBase(source)
, m_geometryFileData(geometryFileData)
, m_geometryFileIndices(geometryFileIndices)
{
assert(m_geometryFileIndices.size() <= m_geometryFileData->GetGeometryFileCount());
for (size_t i = 0; i < m_geometryFileIndices.size(); ++i)
{
int const geometryFileIndex = m_geometryFileIndices[i];
assert(geometryFileIndex >= 0 && geometryFileIndex < m_geometryFileData->GetGeometryFileCount());
}
}
void GeometryExportSourceAdapter::ReadGeometryFiles(IExportContext* context, IGeometryFileData* geometryFileData)
{
for (size_t i = 0; i < m_geometryFileIndices.size(); ++i)
{
int const geometryFileIndex = m_geometryFileIndices[i];
int const newGeometryFileIndex = geometryFileData->AddGeometryFile(
m_geometryFileData->GetGeometryFileHandle(geometryFileIndex),
m_geometryFileData->GetGeometryFileName(geometryFileIndex),
m_geometryFileData->GetProperties(geometryFileIndex));
}
}
void GeometryExportSourceAdapter::ReadModels(const IGeometryFileData* geometryFileData, int geometryFileIndex, IModelData* modelData)
{
assert(geometryFileIndex >= 0 && geometryFileIndex < m_geometryFileIndices.size());
this->source->ReadModels(m_geometryFileData, m_geometryFileIndices[geometryFileIndex], modelData);
}
bool GeometryExportSourceAdapter::ReadSkeleton(const IGeometryFileData* geometryFileData, int geometryFileIndex, const IModelData* modelData, int modelIndex, const IMaterialData* materialData, ISkeletonData* skeletonData)
{
assert(geometryFileIndex >= 0 && geometryFileIndex < m_geometryFileIndices.size());
return this->source->ReadSkeleton(m_geometryFileData, m_geometryFileIndices[geometryFileIndex], modelData, modelIndex, materialData, skeletonData);
}
@@ -0,0 +1,36 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_GEOMETRYEXPORTSOURCEADAPTER_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_GEOMETRYEXPORTSOURCEADAPTER_H
#pragma once
#include "ExportSourceDecoratorBase.h"
class GeometryExportSourceAdapter
: public ExportSourceDecoratorBase
{
public:
GeometryExportSourceAdapter(IExportSource* source, IGeometryFileData* geometryFileData, const std::vector<int>& geometryFileIndices);
virtual void ReadGeometryFiles(IExportContext* context, IGeometryFileData* geometryFileData);
virtual void ReadModels(const IGeometryFileData* geometryFileData, int geometryFileIndex, IModelData* modelData);
virtual bool ReadSkeleton(const IGeometryFileData* geometryFileData, int geometryFileIndex, const IModelData* modelData, int modelIndex, const IMaterialData* materialData, ISkeletonData* skeletonData);
private:
IGeometryFileData* m_geometryFileData;
std::vector<int> m_geometryFileIndices;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_GEOMETRYEXPORTSOURCEADAPTER_H
@@ -0,0 +1,59 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#include "StdAfx.h"
#include "GeometryFileData.h"
int GeometryFileData::AddGeometryFile(const void* handle, const char* name, const SProperties& properties)
{
const int geometryFileIndex = int(m_geometryFiles.size());
m_geometryFiles.push_back(GeometryFileEntry(handle, name, properties));
return geometryFileIndex;
}
int GeometryFileData::GetGeometryFileCount() const
{
return int(m_geometryFiles.size());
}
const void* GeometryFileData::GetGeometryFileHandle(int geometryFileIndex) const
{
return m_geometryFiles[geometryFileIndex].handle;
}
const char* GeometryFileData::GetGeometryFileName(int geometryFileIndex) const
{
return m_geometryFiles[geometryFileIndex].name.c_str();
}
//////////////////////////////////////////////////////////////////////////
const IGeometryFileData::SProperties& GeometryFileData::GetProperties(int geometryFileIndex) const
{
if (size_t(geometryFileIndex) >= m_geometryFiles.size())
{
assert(0);
static SProperties badValue;
return badValue;
}
return m_geometryFiles[geometryFileIndex].properties;
}
void GeometryFileData::SetProperties(int geometryFileIndex, const IGeometryFileData::SProperties& properties)
{
if (size_t(geometryFileIndex) >= m_geometryFiles.size())
{
assert(0);
return;
}
m_geometryFiles[geometryFileIndex].properties = properties;
}
@@ -0,0 +1,52 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_GEOMETRYFILEDATA_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_GEOMETRYFILEDATA_H
#pragma once
#include "IGeometryFileData.h"
#include "STLHelpers.h"
class GeometryFileData
: public IGeometryFileData
{
public:
// IGeometryFileData
virtual int AddGeometryFile(const void* handle, const char* name, const SProperties& properties);
virtual const SProperties& GetProperties(int geometryFileIndex) const;
virtual void SetProperties(int geometryFileIndex, const SProperties& properties);
virtual int GetGeometryFileCount() const;
virtual const void* GetGeometryFileHandle(int geometryFileIndex) const;
virtual const char* GetGeometryFileName(int geometryFileIndex) const;
private:
struct GeometryFileEntry
{
GeometryFileEntry(const void* a_handle, const char* a_name, const SProperties& a_properties)
: handle(a_handle)
, name(a_name)
, properties(a_properties)
{
}
const void* handle;
std::string name;
SProperties properties;
};
std::vector<GeometryFileEntry> m_geometryFiles;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_GEOMETRYFILEDATA_H
@@ -0,0 +1,36 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#include "StdAfx.h"
#include "GeometryMaterialData.h"
void GeometryMaterialData::AddUsedMaterialIndex(int materialIndex)
{
std::map<int, int>::iterator usedMaterialPos = m_usedMaterialIndexIndexMap.find(materialIndex);
if (usedMaterialPos == m_usedMaterialIndexIndexMap.end())
{
int materialIndexIndex = int(m_usedMaterialIndices.size());
m_usedMaterialIndices.push_back(materialIndex);
m_usedMaterialIndexIndexMap.insert(std::make_pair(materialIndex, materialIndexIndex));
}
}
int GeometryMaterialData::GetUsedMaterialCount() const
{
return int(m_usedMaterialIndices.size());
}
int GeometryMaterialData::GetUsedMaterialIndex(int usedMaterialIndex) const
{
return m_usedMaterialIndices[usedMaterialIndex];
}
@@ -0,0 +1,35 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_GEOMETRYMATERIALDATA_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_GEOMETRYMATERIALDATA_H
#pragma once
#include "IGeometryMaterialData.h"
class GeometryMaterialData
: public IGeometryMaterialData
{
public:
// IGeometryMaterialData
virtual void AddUsedMaterialIndex(int materialIndex);
virtual int GetUsedMaterialCount() const;
virtual int GetUsedMaterialIndex(int usedMaterialIndex) const;
private:
std::vector<int> m_usedMaterialIndices;
std::map<int, int> m_usedMaterialIndexIndexMap;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_GEOMETRYMATERIALDATA_H
@@ -0,0 +1,41 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_HELPERDATA_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_HELPERDATA_H
#pragma once
struct SHelperData
{
public:
enum EHelperType
{
eHelperType_UNKNOWN,
eHelperType_Point,
eHelperType_Dummy
};
public:
SHelperData()
: m_eHelperType(eHelperType_UNKNOWN)
{
}
public:
EHelperType m_eHelperType;
float m_boundBoxMin[3]; // used for eHelperType_Dummy only
float m_boundBoxMax[3]; // used for eHelperType_Dummy only
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_HELPERDATA_H
@@ -0,0 +1,96 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IANIMATIONDATA_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IANIMATIONDATA_H
#pragma once
class IAnimationData
{
public:
virtual ~IAnimationData() {}
virtual void SetFrameData(int modelIndex, int frameIndex, float translation[3], float rotation[3], float scale[3]) = 0;
virtual void SetFrameCount(int frameCount) = 0;
virtual void SetFrameTimePos(int modelIndex, int frameIndex, float time) = 0;
virtual void SetFrameDataPos(int modelIndex, int frameIndex, float translation[3]) = 0;
virtual void SetFrameCountPos(int modelIndex, int frameCount) = 0;
virtual void SetFrameTimeRot(int modelIndex, int frameIndex, float time) = 0;
virtual void SetFrameDataRot(int modelIndex, int frameIndex, float rotation[3]) = 0;
virtual void SetFrameCountRot(int modelIndex, int frameCount) = 0;
virtual void SetFrameTimeScl(int modelIndex, int frameIndex, float time) = 0;
virtual void SetFrameDataScl(int modelIndex, int frameIndex, float scale[3]) = 0;
virtual void SetFrameCountScl(int modelIndex, int frameCount) = 0;
// For TCB & Ease-In/-Out support
struct TCB
{
float tension;
float continuity;
float bias;
TCB()
: tension(0)
, continuity(0)
, bias(0) {}
};
struct Ease
{
float in;
float out;
Ease()
: in(0)
, out(0) {}
};
virtual void SetFrameTCBPos(int modelIndex, int frameIndex, TCB tcb) = 0;
virtual void SetFrameTCBRot(int modelIndex, int frameIndex, TCB tcb) = 0;
virtual void SetFrameTCBScl(int modelIndex, int frameIndex, TCB tcb) = 0;
virtual void SetFrameEaseInOutPos(int modelIndex, int frameIndex, Ease ease) = 0;
virtual void SetFrameEaseInOutRot(int modelIndex, int frameIndex, Ease ease) = 0;
virtual void SetFrameEaseInOutScl(int modelIndex, int frameIndex, Ease ease) = 0;
enum ModelFlags
{
ModelFlags_NoExport = 1 << 0
};
virtual void SetModelFlags(int modelIndex, unsigned modelFlags) = 0;
virtual void GetFrameData(int modelIndex, int frameIndex, const float*& translation, const float*& rotation, const float*& scale) const = 0;
virtual int GetFrameCount() const = 0;
virtual float GetFrameTimePos(int modelIndex, int frameIndex) const = 0;
virtual void GetFrameDataPos(int modelIndex, int frameIndex, const float*& translation) const = 0;
virtual int GetFrameCountPos(int modelIndex) const = 0;
virtual float GetFrameTimeRot(int modelIndex, int frameIndex) const = 0;
virtual void GetFrameDataRot(int modelIndex, int frameIndex, const float*& rotation) const = 0;
virtual int GetFrameCountRot(int modelIndex) const = 0;
virtual float GetFrameTimeScl(int modelIndex, int frameIndex) const = 0;
virtual void GetFrameDataScl(int modelIndex, int frameIndex, const float*& scale) const = 0;
virtual int GetFrameCountScl(int modelIndex) const = 0;
// For TCB & Ease-In/-Out support
virtual void GetFrameTCBPos(int modelIndex, int frameIndex, TCB& tcb) const = 0;
virtual void GetFrameTCBRot(int modelIndex, int frameIndex, TCB& tcb) const = 0;
virtual void GetFrameTCBScl(int modelIndex, int frameIndex, TCB& tcb) const = 0;
virtual void GetFrameEaseInOutPos(int modelIndex, int frameIndex, Ease& ease) const = 0;
virtual void GetFrameEaseInOutRot(int modelIndex, int frameIndex, Ease& ease) const = 0;
virtual void GetFrameEaseInOutScl(int modelIndex, int frameIndex, Ease& ease) const = 0;
virtual unsigned GetModelFlags(int modelIndex) const = 0;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IANIMATIONDATA_H
@@ -0,0 +1,55 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IEXPORTCONTEXT_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IEXPORTCONTEXT_H
#pragma once
#include <cstdarg>
#include "Exceptions.h"
#include "ILogger.h"
struct IPakSystem;
class ISettings;
class IExportContext
: public ILogger
{
public:
// Declare an exception type to report the case where the scene must be saved before exporting.
struct NeedSaveErrorTag {};
typedef Exception<NeedSaveErrorTag> NeedSaveError;
struct PakSystemErrorTag {};
typedef Exception<PakSystemErrorTag> PakSystemError;
virtual void SetProgress(float progress) = 0;
virtual void SetCurrentTask(const std::string& id) = 0;
virtual IPakSystem* GetPakSystem() = 0;
virtual ISettings* GetSettings() = 0;
virtual void GetRootPath(char* buffer, int bufferSizeInBytes) = 0;
protected:
// ILogger
virtual void LogImpl(ILogger::ESeverity eSeverity, const char* message) = 0;
};
struct CurrentTaskScope
{
CurrentTaskScope(IExportContext* context, const std::string& id)
: context(context) {context->SetCurrentTask(id); }
~CurrentTaskScope() {context->SetCurrentTask(""); }
IExportContext* context;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IEXPORTCONTEXT_H
@@ -0,0 +1,98 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IEXPORTSOURCE_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IEXPORTSOURCE_H
#pragma once
#include "Exceptions.h"
class ISkeletonData;
class IAnimationData;
class IExportContext;
class IModelData;
class IGeometryFileData;
class IGeometryData;
class IMaterialData;
class ISkinningData;
class IMorphData;
class IGeometryMaterialData;
namespace ExportGlobal
{
const float g_defaultFrameRate = 30.f;
};
struct SExportMetaData
{
enum EAxisUp
{
X_UP,
Y_UP,
Z_UP
};
char authoring_tool[128];
char source_data[1024]; // Filename of the source.
char author[128]; // Name of the author.
char revision[64];
EAxisUp up_axis;
float fMeterUnit;
float fFramesPerSecond;
SExportMetaData()
{
fMeterUnit = 1.0f;
up_axis = Z_UP;
fFramesPerSecond = ExportGlobal::g_defaultFrameRate;
strcpy(authoring_tool, "CryENGINE Collada Exporter");
strcpy(source_data, "");
strcpy(author, "");
strcpy(revision, "1.4.1");
}
};
class IExportSource
{
public:
virtual ~IExportSource()
{
}
virtual std::string GetResourceCompilerPath() const = 0;
virtual void GetMetaData(SExportMetaData& metaData) const = 0;
virtual std::string GetDCCFileName() const = 0;
virtual float GetDCCFrameRate() const{ return ExportGlobal::g_defaultFrameRate; }
virtual std::string GetExportDirectory() const = 0;
virtual void ReadGeometryFiles(IExportContext* context, IGeometryFileData* geometryFileData) = 0;
virtual bool ReadMaterials(IExportContext* context, const IGeometryFileData* geometryFileData, IMaterialData* materialData) = 0;
virtual void ReadModels(const IGeometryFileData* geometryFileData, int geometryFileIndex, IModelData* modelData) = 0;
virtual void ReadSkinning(IExportContext* context, ISkinningData* skinningData, const IModelData* modelData, int modelIndex, ISkeletonData* skeletonData) = 0;
virtual bool ReadSkeleton(const IGeometryFileData* geometryFileData, int geometryFileIndex, const IModelData* modelData, int modelIndex, const IMaterialData* materialData, ISkeletonData* skeletonData) = 0;
virtual int GetAnimationCount() const = 0;
virtual std::string GetAnimationName(const IGeometryFileData* geometryFileData, int geometryFileIndex, int animationIndex) const = 0;
virtual void GetAnimationTimeSpan(float& start, float& stop, int animationIndex) const = 0;
virtual void ReadAnimationFlags(IExportContext* context, IAnimationData* animationData, const IGeometryFileData* geometryFileData, const IModelData* modelData, int modelIndex, const ISkeletonData* skeletonData, int animationIndex) const = 0;
virtual IAnimationData* ReadAnimation(IExportContext* context, const IGeometryFileData* geometryFileData, const IModelData* modelData, int modelIndex, const ISkeletonData* skeletonData, int animationIndex, float fps) const = 0;
virtual bool ReadGeometry(IExportContext* context, IGeometryData* geometry, const IModelData* modelData, const IMaterialData* materialData, int modelIndex) = 0;
virtual bool ReadGeometryMaterialData(IExportContext* context, IGeometryMaterialData* geometryMaterialData, const IModelData* modelData, const IMaterialData* materialData, int modelIndex) const = 0;
virtual bool ReadBoneGeometry(IExportContext* context, IGeometryData* geometry, ISkeletonData* skeletonData, int boneIndex, const IMaterialData* materialData) = 0;
virtual bool ReadBoneGeometryMaterialData(IExportContext* context, IGeometryMaterialData* geometryMaterialData, ISkeletonData* skeletonData, int boneIndex, const IMaterialData* materialData) const = 0;
virtual void ReadMorphs(IExportContext* context, IMorphData* morphData, const IModelData* modelData, int modelIndex) = 0;
virtual bool ReadMorphGeometry(IExportContext* context, IGeometryData* geometry, const IModelData* modelData, int modelIndex, const IMorphData* morphData, int morphIndex, const IMaterialData* materialData) = 0;
virtual bool HasValidPosController(const IModelData* modelData, int modelIndex) const = 0;
virtual bool HasValidRotController(const IModelData* modelData, int modelIndex) const = 0;
virtual bool HasValidSclController(const IModelData* modelData, int modelIndex) const = 0;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IEXPORTSOURCE_H
@@ -0,0 +1,28 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IEXPORTWRITER_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IEXPORTWRITER_H
#pragma once
class IExportSource;
class IExportContext;
class IExportWriter
{
public:
virtual void Export(IExportSource* source, IExportContext* context) = 0;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IEXPORTWRITER_H
@@ -0,0 +1,35 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IGEOMETRYDATA_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IGEOMETRYDATA_H
#pragma once
class IGeometryData
{
public:
virtual int AddPosition(float x, float y, float z) = 0;
virtual int AddNormal(float x, float y, float z) = 0;
virtual int AddTextureCoordinate(float u, float v) = 0;
virtual int AddVertexColor(float r, float g, float b, float a) = 0;
virtual int AddPolygon(const int* indices, int mtlID) = 0;
virtual int GetNumberOfPositions() const = 0;
virtual int GetNumberOfNormals() const = 0;
virtual int GetNumberOfTextureCoordinates() const = 0;
virtual int GetNumberOfVertexColors() const = 0;
virtual int GetNumberOfPolygons() const = 0;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IGEOMETRYDATA_H
@@ -0,0 +1,54 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IGEOMETRYFILEDATA_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IGEOMETRYFILEDATA_H
#pragma once
#include "ExportFileType.h"
#include <string>
class IGeometryFileData
{
public:
struct SProperties
{
int filetypeInt; // combination of flags from CryFileType
bool bDoNotMerge;
bool bUseCustomNormals;
bool bUseF32VertexFormat;
bool b8WeightsPerVertex;
std::string customExportPath;
SProperties()
: filetypeInt(CRY_FILE_TYPE_NONE)
, bDoNotMerge(false)
, bUseCustomNormals(false)
, bUseF32VertexFormat(false)
, b8WeightsPerVertex(false)
{
}
};
public:
virtual int AddGeometryFile(const void* handle, const char* name, const SProperties& properties) = 0;
virtual const SProperties& GetProperties(int geometryFileIndex) const = 0;
virtual int GetGeometryFileCount() const = 0;
// return an implementation-specific handle (for example a maya Dag Path string, or a MAX node name or whatever)
// its opaque to the exporter, but you can cast it yourself.
virtual const void* GetGeometryFileHandle(int geometryFileIndex) const = 0;
virtual const char* GetGeometryFileName(int geometryFileIndex) const = 0;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IGEOMETRYFILEDATA_H
@@ -0,0 +1,27 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IGEOMETRYMATERIALDATA_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IGEOMETRYMATERIALDATA_H
#pragma once
class IGeometryMaterialData
{
public:
virtual void AddUsedMaterialIndex(int materialIndex) = 0;
virtual int GetUsedMaterialCount() const = 0;
virtual int GetUsedMaterialIndex(int usedMaterialIndex) const = 0;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IGEOMETRYMATERIALDATA_H
@@ -0,0 +1,33 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IMATERIALDATA_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IMATERIALDATA_H
#pragma once
class IMaterialData
{
public:
// the handle represents an implementation specific underlying handle (like a maya pointer to a string dag name).
virtual int AddMaterial(const char* name, int id, const void* handle, const char* properties) = 0;
virtual int AddMaterial(const char* name, int id, const char* subMatName, const void* handle, const char* properties) = 0;
virtual int GetMaterialCount() const = 0;
virtual const char* GetName(int materialIndex) const = 0;
virtual int GetID(int materialIndex) const = 0;
virtual const char* GetSubMatName(int materialIndex) const = 0;
virtual const void* GetHandle(int materialIndex) const = 0;
virtual const char* GetProperties(int materialIndex) const = 0;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IMATERIALDATA_H
@@ -0,0 +1,36 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IMODELDATA_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IMODELDATA_H
#pragma once
#include "HelperData.h"
#include <string>
class IModelData
{
public:
virtual int AddModel(const void* handle, const char* modelName, int parentModelIndex, bool geometry, const SHelperData& helperData, const std::string& propertiesString) = 0;
virtual int GetModelCount() const = 0;
virtual const void* GetModelHandle(int modelIndex) const = 0;
virtual const char* GetModelName(int modelIndex) const = 0;
virtual void SetTranslationRotationScale(int modelIndex, const float* translation, const float* rotation, const float* scale) = 0;
virtual void GetTranslationRotationScale(int modelIndex, float* translation, float* rotation, float* scale) const = 0;
virtual const SHelperData& GetHelperData(int modelIndex) const = 0;
virtual const std::string& GetProperties(int modelIndex) const = 0;
virtual bool IsRoot(int modelIndex) const = 0;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IMODELDATA_H
@@ -0,0 +1,29 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IMORPHDATA_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IMORPHDATA_H
#pragma once
class IMorphData
{
public:
virtual void SetHandle(const void* handle) = 0;
virtual void AddMorph(const void* handle, const char* name, const char* fullName = NULL) = 0;
virtual const void* GetHandle() const = 0;
virtual int GetMorphCount() const = 0;
virtual const void* GetMorphHandle(int morphIndex) const = 0;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_IMORPHDATA_H
@@ -0,0 +1,56 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_ISKELETONDATA_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_ISKELETONDATA_H
#pragma once
class ISkeletonData
{
public:
enum Axis
{
AxisX,
AxisY,
AxisZ
};
enum Limit
{
LimitMin,
LimitMax
};
virtual int AddBone(const void* handle, const char* name, int parentIndex) = 0;
virtual int FindBone(const char* name) const = 0;
virtual const void* GetBoneHandle(int boneIndex) const = 0;
virtual int GetBoneParentIndex(int boneIndex) const = 0;
virtual int GetBoneCount() const = 0;
virtual void SetTranslation(int boneIndex, const float* vec) = 0;
virtual void SetRotation(int boneIndex, const float* vec) = 0;
virtual void SetScale(int boneIndex, const float* vec) = 0;
virtual void SetParentFrameTranslation(int boneIndex, const float* vec) = 0;
virtual void SetParentFrameRotation(int boneIndex, const float* vec) = 0;
virtual void SetParentFrameScale(int boneIndex, const float* vec) = 0;
virtual void SetPhysicalized(int boneIndex, bool physicalized) = 0;
virtual void SetHasGeometry(int boneIndex, bool hasGeometry) = 0;
virtual void SetBoneProperties(int boneIndex, const char* propertiesString) = 0;
virtual void SetBoneGeomProperties(int boneIndex, const char* propertiesString) = 0;
virtual void SetLimit(int boneIndex, Axis axis, Limit extreme, float limit) = 0;
virtual void SetSpringTension(int boneIndex, Axis axis, float springTension) = 0;
virtual void SetSpringAngle(int boneIndex, Axis axis, float springAngle) = 0;
virtual void SetAxisDamping(int boneIndex, Axis axis, float damping) = 0;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_ISKELETONDATA_H
@@ -0,0 +1,26 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_ISKINNINGDATA_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_ISKINNINGDATA_H
#pragma once
class ISkinningData
{
public:
virtual void SetVertexCount(int vertexCount) = 0;
virtual void AddWeight(int vertexIndex, int boneIndex, float weight) = 0;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_ISKINNINGDATA_H
@@ -0,0 +1,69 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#include "StdAfx.h"
#include "MaterialData.h"
int MaterialData::AddMaterial(const char* name, int id, const void* handle, const char* properties)
{
const int materialIndex = int(m_materials.size());
m_materials.push_back(MaterialEntry(name, id, "submat", handle, properties));
return materialIndex;
}
int MaterialData::AddMaterial(const char* name, int id, const char* subMatName, const void* handle, const char* properties)
{
const int materialIndex = int(m_materials.size());
m_materials.push_back(MaterialEntry(name, id, subMatName, handle, properties));
return materialIndex;
}
int MaterialData::GetMaterialCount() const
{
return int(m_materials.size());
}
const char* MaterialData::GetName(int materialIndex) const
{
assert(materialIndex >= 0);
assert(materialIndex < int(m_materials.size()));
return m_materials[materialIndex].name.c_str();
}
int MaterialData::GetID(int materialIndex) const
{
assert(materialIndex >= 0);
assert(materialIndex < int(m_materials.size()));
return m_materials[materialIndex].id;
}
const char* MaterialData::GetSubMatName(int materialIndex) const
{
assert(materialIndex >= 0);
assert(materialIndex < int(m_materials.size()));
return m_materials[materialIndex].subMatName.c_str();
}
const void* MaterialData::GetHandle(int materialIndex) const
{
assert(materialIndex >= 0);
assert(materialIndex < int(m_materials.size()));
return m_materials[materialIndex].handle;
}
const char* MaterialData::GetProperties(int materialIndex) const
{
assert(materialIndex >= 0);
assert(materialIndex < int(m_materials.size()));
return m_materials[materialIndex].properties.c_str();
}
@@ -0,0 +1,56 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_MATERIALDATA_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_MATERIALDATA_H
#pragma once
#include "IMaterialData.h"
class MaterialData
: public IMaterialData
{
public:
virtual int AddMaterial(const char* name, int id, const void* handle, const char* properties);
virtual int AddMaterial(const char* name, int id, const char* subMatName, const void* handle, const char* properties);
virtual int GetMaterialCount() const;
virtual const char* GetName(int materialIndex) const;
virtual int GetID(int materialIndex) const;
virtual const char* GetSubMatName(int materialIndex) const;
virtual const void* GetHandle(int materialIndex) const;
virtual const char* GetProperties(int materialIndex) const;
private:
struct MaterialEntry
{
MaterialEntry(const char* a_name, int a_id, const char* a_subMatName, const void* a_handle, const char* a_properties)
: name(a_name)
, id(a_id)
, subMatName(a_subMatName)
, handle(a_handle)
, properties(a_properties ? a_properties : "")
{
}
string name;
int id;
string subMatName;
const void* handle;
string properties;
};
std::vector<MaterialEntry> m_materials;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_MATERIALDATA_H
@@ -0,0 +1,107 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#include "StdAfx.h"
#include "MaterialHelpers.h"
#include "StringHelpers.h"
#include "PathHelpers.h"
#include "properties.h"
MaterialHelpers::MaterialInfo::MaterialInfo()
{
this->id = -1;
this->name = "";
this->physicalize = "None";
this->diffuseTexture = "";
this->diffuseColor[0] = this->diffuseColor[1] = this->diffuseColor[2] = 1.0f;
this->specularColor[0] = this->specularColor[1] = this->specularColor[2] = 1.0f;
this->emissiveColor[0] = this->emissiveColor[1] = this->emissiveColor[2] = 0.0f;
}
std::string MaterialHelpers::PhysicsIDToString(const int physicsID)
{
switch (physicsID)
{
case 1:
return "Default";
break;
case 2:
return "ProxyNoDraw";
break;
case 3:
return "NoCollide";
break;
case 4:
return "Obstruct";
break;
default:
return "None";
break;
}
}
bool MaterialHelpers::WriteMaterials(const std::string& filename, const std::vector<MaterialInfo>& materialList)
{
FILE* materialFile = fopen(filename.c_str(), "w");
if (materialFile)
{
fprintf(materialFile, "<Material MtlFlags=\"524544\" >\n");
fprintf(materialFile, " <SubMaterials>\n");
for (int i = 0; i < materialList.size(); i++)
{
const MaterialInfo& material = materialList[i];
fprintf(materialFile, " <Material Name=\"%s\" ", material.name.c_str());
if (strcmp(material.physicalize.c_str(), "ProxyNoDraw") == 0)
{
fprintf(materialFile, "MtlFlags=\"1152\" Shader=\"Nodraw\" GenMask=\"0\" ");
}
else
{
fprintf(materialFile, "MtlFlags=\"524416\" Shader=\"Illum\" GenMask=\"100000000\" ");
}
fprintf(materialFile, "SurfaceType=\"\" MatTemplate=\"\" ");
fprintf(materialFile, "Diffuse=\"%f,%f,%f\" ", material.diffuseColor[0], material.diffuseColor[1], material.diffuseColor[2]);
fprintf(materialFile, "Specular=\"%f,%f,%f\" ", material.specularColor[0], material.specularColor[1], material.specularColor[2]);
fprintf(materialFile, "Emissive=\"%f,%f,%f\" ", material.emissiveColor[0], material.emissiveColor[1], material.emissiveColor[2]);
fprintf(materialFile, "Shininess=\"10\" ");
fprintf(materialFile, "Opacity=\"1\" ");
fprintf(materialFile, ">\n");
fprintf(materialFile, " <Textures>\n");
// Write out diffuse texture.
if (material.diffuseTexture.length() > 0)
{
//fprintf( materialFile, " <Texture Map=\"Diffuse\" File=\"%s\" >\n", ProcessTexturePath( material.diffuseTexture ).c_str() );
fprintf(materialFile, " <Texture Map=\"Diffuse\" File=\"%s\" >\n", material.diffuseTexture.c_str());
fprintf(materialFile, " <TexMod />\n");
fprintf(materialFile, " </Texture>\n");
}
fprintf(materialFile, " </Textures>\n");
fprintf(materialFile, " </Material>\n");
}
fprintf(materialFile, " </SubMaterials>\n");
fprintf(materialFile, "</Material>\n");
fclose(materialFile);
return true;
}
else
{
return false;
}
}
@@ -0,0 +1,39 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_MATERIALHELPERS_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_MATERIALHELPERS_H
#pragma once
namespace MaterialHelpers
{
struct MaterialInfo
{
MaterialInfo();// : id(-1) { }
std::string name;
std::string physicalize;
int id;
float diffuseColor[3];
float specularColor[3];
float emissiveColor[3];
std::string diffuseTexture;
};
std::string PhysicsIDToString(const int physicsID);
bool WriteMaterials(const std::string& filename, const std::vector<MaterialHelpers::MaterialInfo>& materialList);
}
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_MATERIALHELPERS_H
@@ -0,0 +1,138 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_MAXHELPERS_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_MAXHELPERS_H
#pragma once
#include "CompileTimeAssert.h"
#include "PathHelpers.h"
#include "StringHelpers.h"
namespace MaxHelpers
{
enum
{
kBadChar = '_'
};
#if !defined(MAX_PRODUCT_VERSION_MAJOR)
#error MAX_PRODUCT_VERSION_MAJOR is undefined
#elif (MAX_PRODUCT_VERSION_MAJOR >= 15)
COMPILE_TIME_ASSERT(sizeof(MCHAR) == 2);
#define MAX_MCHAR_SIZE 2
typedef wstring MaxCompatibleString;
#elif (MAX_PRODUCT_VERSION_MAJOR >= 12)
COMPILE_TIME_ASSERT(sizeof(MCHAR) == 1);
#define MAX_MCHAR_SIZE 1
typedef string MaxCompatibleString;
#else
#error 3dsMax 2009 and older are not supported anymore
#endif
inline string CreateAsciiString(const char* s_ansi)
{
return StringHelpers::ConvertAnsiToAscii(s_ansi, kBadChar);
}
inline string CreateAsciiString(const wchar_t* s_utf16)
{
const string s_ansi = StringHelpers::ConvertUtf16ToAnsi(s_utf16, kBadChar);
return CreateAsciiString(s_ansi.c_str());
}
inline string CreateUtf8String(const char* s_ansi)
{
return StringHelpers::ConvertAnsiToUtf8(s_ansi);
}
inline string CreateUtf8String(const wchar_t* s_utf16)
{
return StringHelpers::ConvertUtf16ToUtf8(s_utf16);
}
inline string CreateTidyAsciiNodeName(const char* s_ansi)
{
const size_t len = strlen(s_ansi);
string res;
res.reserve(len);
for (size_t i = 0; i < len; ++i)
{
char c = s_ansi[i];
if (c < ' ' || c >= 127)
{
c = kBadChar;
}
res.append(1, c);
}
return res;
}
inline string CreateTidyAsciiNodeName(const wchar_t* s_utf16)
{
const string s_ansi = StringHelpers::ConvertUtf16ToAnsi(s_utf16, kBadChar);
return CreateTidyAsciiNodeName(s_ansi.c_str());
;
}
inline MSTR CreateMaxStringFromAscii(const char* s_ascii)
{
#if (MAX_MCHAR_SIZE == 2)
return MSTR(StringHelpers::ConvertAsciiToUtf16(s_ascii).c_str());
#else
return MSTR(s_ascii);
#endif
}
inline MaxCompatibleString CreateMaxCompatibleStringFromAscii(const char* s_ascii)
{
#if (MAX_MCHAR_SIZE == 2)
return StringHelpers::ConvertAsciiToUtf16(s_ascii);
#else
return MaxCompatibleString(s_ascii);
#endif
}
inline string GetAbsoluteAsciiPath(const char* s_ansi)
{
if (!s_ansi || !s_ansi[0])
{
return string();
}
return PathHelpers::GetAbsoluteAsciiPath(StringHelpers::ConvertAnsiToUtf16(s_ansi).c_str());
}
inline string GetAbsoluteAsciiPath(const wchar_t* s_utf16)
{
if (!s_utf16 || !s_utf16[0])
{
return string();
}
return PathHelpers::GetAbsoluteAsciiPath(s_utf16);
}
}
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_MAXHELPERS_H
@@ -0,0 +1,99 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#include "StdAfx.h"
#include "MaxUserPropertyHelpers.h"
#include "StringHelpers.h"
#include "MaxHelpers.h"
std::string MaxUserPropertyHelpers::GetNodeProperties(INode* node)
{
if (node == 0)
{
return std::string();
}
MSTR buf;
node->GetUserPropBuffer(buf);
return MaxHelpers::CreateAsciiString(buf);
}
std::string MaxUserPropertyHelpers::GetStringNodeProperty(INode* node, const char* name, const char* defaultValue)
{
if (node == 0)
{
return defaultValue;
}
MSTR val;
if (!node->GetUserPropString(MaxHelpers::CreateMaxStringFromAscii(name), val))
{
return defaultValue;
}
return MaxHelpers::CreateAsciiString(val);
}
float MaxUserPropertyHelpers::GetFloatNodeProperty(INode* node, const char* name, float defaultValue)
{
if (node == 0)
{
return defaultValue;
}
float val;
if (!node->GetUserPropFloat(MaxHelpers::CreateMaxStringFromAscii(name), val))
{
return defaultValue;
}
return val;
}
int MaxUserPropertyHelpers::GetIntNodeProperty(INode* node, const char* name, int defaultValue)
{
if (node == 0)
{
return defaultValue;
}
int val;
if (!node->GetUserPropInt(MaxHelpers::CreateMaxStringFromAscii(name), val))
{
return defaultValue;
}
return val;
}
bool MaxUserPropertyHelpers::GetBoolNodeProperty(INode* node, const char* name, bool defaultValue)
{
if (node == 0)
{
return defaultValue;
}
BOOL val;
if (!node->GetUserPropBool(MaxHelpers::CreateMaxStringFromAscii(name), val))
{
return defaultValue;
}
return (val != 0);
}
@@ -0,0 +1,32 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_MAXUSERPROPERTYHELPERS_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_MAXUSERPROPERTYHELPERS_H
#pragma once
#include <string>
class INode;
namespace MaxUserPropertyHelpers
{
std::string GetNodeProperties(INode* node);
std::string GetStringNodeProperty(INode* node, const char* name, const char* defaultValue);
float GetFloatNodeProperty(INode* node, const char* name, float defaultValue);
int GetIntNodeProperty(INode* node, const char* name, int defaultValue);
bool GetBoolNodeProperty(INode* node, const char* name, bool defaultValue);
}
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_MAXUSERPROPERTYHELPERS_H
@@ -0,0 +1,914 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_MESHUTILS_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_MESHUTILS_H
#pragma once
#include "BaseTypes.h" // uint8
#include "Cry_Vector3.h" // Vec3
#include "IIndexedMesh.h" // CMesh
namespace MeshUtils
{
struct Face
{
int vertexIndex[3];
};
struct Color
{
uint8 r;
uint8 g;
uint8 b;
};
// Stores linking of a vertex to bone(s)
class VertexLinks
{
public:
struct Link
{
int boneId;
float weight;
Vec3 offset;
Link()
: boneId(-1)
, weight(-1.0f)
, offset(0.0f, 0.0f, 0.0f)
{
}
};
enum ESort
{
eSort_ByWeight,
eSort_ByBoneId,
};
public:
std::vector<Link> links;
public:
// minWeightToDelete: links with weights <= minWeightToDelete will be deleted
const char* Normalize(ESort eSort, const float minWeightToDelete, const int maxLinkCount)
{
if (minWeightToDelete < 0 || minWeightToDelete >= 1)
{
return "Bad minWeightToDelete passed";
}
if (maxLinkCount <= 0)
{
return "Bad maxLinkCount passed";
}
// Merging links with matching bone ids
{
DeleteByWeight(0.0f);
if (links.empty())
{
return "All bone links of a vertex have zero weight";
}
std::sort(links.begin(), links.end(), CompareLinksByBoneId);
size_t dst = 0;
for (size_t i = 1; i < links.size(); ++i)
{
if (links[i].boneId == links[dst].boneId)
{
const float w0 = links[dst].weight;
const float w1 = links[i].weight;
const float a = w0 / (w0 + w1);
links[dst].offset = links[dst].offset * a + links[i].offset * (1 - a);
links[dst].weight = w0 + w1;
}
else
{
links[++dst] = links[i];
}
}
links.resize(dst + 1);
}
// Deleting links, normalizing link weights.
//
// Note: we produce meaningful results even in cases like this:
// input weights are { 0.03, 0.01 }, minWeightTodelete is 0.2.
// Output weights produced are { 0.75, 0.25 }.
{
std::sort(links.begin(), links.end(), CompareLinksByWeight);
if (links.size() > maxLinkCount)
{
links.resize(maxLinkCount);
}
NormalizeWeights();
const size_t oldSize = links.size();
DeleteByWeight(minWeightToDelete);
if (links.empty())
{
return "All bone links of a vertex are deleted (minWeightToDelete is too big)";
}
if (links.size() != oldSize)
{
NormalizeWeights();
}
}
switch (eSort)
{
case eSort_ByWeight:
// Do nothing because we already sorted links by weight (see above)
break;
case eSort_ByBoneId:
std::sort(links.begin(), links.end(), CompareLinksByBoneId);
break;
default:
assert(0);
break;
}
return 0;
}
private:
void DeleteByWeight(float minWeightToDelete)
{
for (size_t i = 0; i < links.size(); ++i)
{
if (links[i].weight <= minWeightToDelete)
{
if (i < links.size() - 1)
{
links[i] = links[links.size() - 1];
}
links.resize(links.size() - 1);
--i;
}
}
}
void NormalizeWeights()
{
assert(!links.empty() && links[0].weight > 0);
float w = 0;
for (size_t i = 0; i < links.size(); ++i)
{
w += links[i].weight;
}
w = 1 / w;
for (size_t i = 0; i < links.size(); ++i)
{
links[i].weight *= w;
}
}
static bool CompareLinksByBoneId(const Link& left, const Link& right)
{
if (left.boneId != right.boneId)
{
return left.boneId < right.boneId;
}
if (left.weight != right.weight)
{
return left.weight < right.weight;
}
return memcmp(&left.offset, &right.offset, sizeof(left.offset)) < 0;
}
static bool CompareLinksByWeight(const Link& left, const Link& right)
{
if (left.weight != right.weight)
{
return left.weight > right.weight;
}
if (left.boneId != right.boneId)
{
return left.boneId < right.boneId;
}
return memcmp(&left.offset, &right.offset, sizeof(left.offset)) < 0;
}
};
class Mesh
{
public:
// Vertex data
std::vector<Vec3> m_positions;
std::vector<int> m_topologyIds;
std::vector<Vec3> m_normals;
std::vector<std::vector<Vec2>> m_texCoords;
std::vector<Color> m_colors;
std::vector<uint8> m_alphas;
std::vector<VertexLinks> m_links;
std::vector<int> m_vertexMatIds;
size_t m_auxSizeof;
std::vector<uint8> m_aux;
// Face data
std::vector<Face> m_faces;
std::vector<int> m_faceMatIds;
// Mappings computed and filled by ComputeVertexRemapping()
std::vector<int> m_vertexOldToNew;
std::vector<int> m_vertexNewToOld;
public:
Mesh()
: m_auxSizeof(0)
{
}
int GetVertexCount() const
{
return m_positions.size();
}
int GetFaceCount() const
{
return m_faces.size();
}
//////////////////////////////////////////////////////////////////////////
// Setters
void Clear()
{
m_positions.clear();
m_topologyIds.clear();
m_normals.clear();
m_texCoords.clear();
m_colors.clear();
m_alphas.clear();
m_links.clear();
m_vertexMatIds.clear();
m_aux.clear();
m_faces.clear();
m_faceMatIds.clear();
m_vertexOldToNew.clear();
m_vertexNewToOld.clear();
}
const char* SetPositions(const float* pVec3, int count, int stride, const float scale)
{
if (count <= 0)
{
return "bad position count";
}
if (stride < 0 || (stride > 0 && stride < sizeof(Vec3)))
{
return "bad position stride";
}
m_positions.resize(count);
for (int i = 0; i < count; ++i)
{
const float* const p = (const float*)(((const char*)pVec3) + ((size_t)i * stride));
if (!_finite(p[0]) || !_finite(p[1]) || !_finite(p[2]))
{
m_positions.clear();
return "Illegal (NAN) vertex position. Fix the 3d Model.";
}
m_positions[i].x = p[0] * scale;
m_positions[i].y = p[1] * scale;
m_positions[i].z = p[2] * scale;
}
return 0;
}
const char* SetTopologyIds(const int* pTopo, int count, int stride)
{
if (count <= 0)
{
return "bad topologyId count";
}
if (stride < 0 || (stride > 0 && stride < sizeof(int)))
{
return "bad topologyId stride";
}
m_topologyIds.resize(count);
for (int i = 0; i < count; ++i)
{
const int* const p = (const int*)(((const char*)pTopo) + ((size_t)i * stride));
m_topologyIds[i] = p[0];
}
return 0;
}
const char* SetNormals(const float* pVec3, int count, int stride)
{
if (count <= 0)
{
return "bad normal count";
}
if (stride < 0 || (stride > 0 && stride < sizeof(Vec3)))
{
return "bad normal stride";
}
m_normals.resize(count);
for (int i = 0; i < count; ++i)
{
const float* const p = (const float*)(((const char*)pVec3) + ((size_t)i * stride));
if (!_finite(p[0]) || !_finite(p[1]) || !_finite(p[2]))
{
m_normals.clear();
return "Illegal (NAN) vertex normal. Fix the 3d Model.";
}
m_normals[i].x = p[0];
m_normals[i].y = p[1];
m_normals[i].z = p[2];
m_normals[i] = m_normals[i].GetNormalizedSafe(Vec3_OneZ);
}
return 0;
}
const char* SetTexCoords(const float* pVec2, int count, int stride, bool bFlipT, uint streamIndex)
{
if (count <= 0)
{
return "bad texCoord count";
}
if (stride < 0 || (stride > 0 && stride < sizeof(float) * 2))
{
return "bad texCoord stride";
}
if (m_texCoords.size() <= streamIndex)
{
m_texCoords.resize(streamIndex + 1);
}
m_texCoords[streamIndex].resize(count);
for (int i = 0; i < count; ++i)
{
const float* const p = (const float*)(((const char*)pVec2) + ((size_t)i * stride));
if (!_finite(p[0]) || !_finite(p[1]))
{
m_texCoords[streamIndex].clear();
return "Illegal (NAN) texture coordinate. Fix the 3d Model.";
}
m_texCoords[streamIndex][i].x = p[0];
m_texCoords[streamIndex][i].y = bFlipT ? 1 - p[1] : p[1];
}
return 0;
}
const char* SetColors(const uint8* pRgb, int count, int stride)
{
if (count <= 0)
{
return "bad color count";
}
if (stride < 0 || (stride > 0 && stride < 3))
{
return "bad color stride";
}
m_colors.resize(count);
for (int i = 0; i < count; ++i)
{
const uint8* const p = (((const uint8*)pRgb) + ((size_t)i * stride));
m_colors[i].r = p[0];
m_colors[i].g = p[1];
m_colors[i].b = p[2];
}
return 0;
}
const char* SetAlphas(const uint8* pAlpha, int count, int stride)
{
if (count <= 0)
{
return "bad alpha count";
}
if (stride < 0)
{
return "bad alpha stride";
}
m_alphas.resize(count);
for (int i = 0; i < count; ++i)
{
const uint8* const p = (((const uint8*)pAlpha) + ((size_t)i * stride));
m_alphas[i] = p[0];
}
return 0;
}
const char* SetFaces(const int* pVertIdx3, int count, int stride)
{
if (count <= 0)
{
return "bad face count";
}
if (stride < 0 || (stride > 0 && stride < 3 * sizeof(int)))
{
return "bad face stride";
}
m_faces.resize(count);
for (int i = 0; i < count; ++i)
{
const int* const p = (const int*)(((const char*)pVertIdx3) + ((size_t)i * stride));
for (int j = 0; j < 3; ++j)
{
if (p[j] < 0 || p[j] >= m_positions.size())
{
return "bad vertex index found in a face";
}
m_faces[i].vertexIndex[j] = p[j];
}
}
return 0;
}
const char* SetFaceMatIds(const int* pMatIds, int count, int stride, int maxMaterialId)
{
if (count <= 0)
{
return "bad face materialId count";
}
if (stride < 0 || (stride > 0 && stride < sizeof(int)))
{
return "bad face materialIdstride";
}
m_faceMatIds.resize(count);
for (int i = 0; i < count; ++i)
{
const int* const p = (const int*)(((const char*)pMatIds) + ((size_t)i * stride));
if (p[0] < 0)
{
return "negative material ID found in a face";
}
if (p[0] >= maxMaterialId)
{
return "material ID found in a face is outside of allowed ranges";
}
m_faceMatIds[i] = p[0];
}
return 0;
}
const char* SetAux(size_t auxSizeof, const void* pData, int count, int stride)
{
if (auxSizeof <= 0)
{
return "bad aux sizeof";
}
if (count <= 0)
{
return "bad aux count";
}
if (stride < 0 || (stride > 0 && stride < auxSizeof))
{
return "bad aux stride";
}
m_auxSizeof = auxSizeof;
m_aux.resize(count * m_auxSizeof);
for (int i = 0; i < count; ++i)
{
const uint8* const p = (((const uint8*)pData) + ((size_t)i * stride));
memcpy(&m_aux[i * m_auxSizeof], p, m_auxSizeof);
}
return 0;
}
//////////////////////////////////////////////////////////////////////////
// Validation
// Returns 0 if ok, or pointer to the error text
const char* Validate() const
{
const int nVerts = (int)m_positions.size();
if (nVerts <= 0)
{
return "No vertices";
}
const int nFaces = (int)m_faces.size();
if (nFaces <= 0)
{
return "No faces";
}
if (!m_topologyIds.empty() && nVerts != (int)m_topologyIds.size())
{
return "Mismatch in the number of topology IDs";
}
if (!m_normals.empty() && nVerts != (int)m_normals.size())
{
return "Mismatch in the number of normals";
}
for (uint streamIndex = 0; streamIndex < m_texCoords.size(); ++streamIndex)
{
if (!m_texCoords[streamIndex].empty() && nVerts != (int)m_texCoords[streamIndex].size())
{
return "Mismatch in the number of texture coordinates";
}
}
if (!m_colors.empty() && nVerts != (int)m_colors.size())
{
return "Mismatch in the number of colors";
}
if (!m_alphas.empty() && nVerts != (int)m_alphas.size())
{
return "Mismatch in the number of alphas";
}
if (!m_links.empty() && nVerts != (int)m_links.size())
{
return "Mismatch in the number of vertex-bone links";
}
for (size_t i = 0; i < m_links.size(); ++i)
{
if (m_links[i].links.empty())
{
return "Found a vertex without bone linking";
}
}
if (!m_vertexMatIds.empty() && nVerts != (int)m_vertexMatIds.size())
{
return "Mismatch in the number of vertex materials";
}
if (!m_aux.empty() && nVerts != (int)(m_aux.size() / m_auxSizeof))
{
return "Mismatch in the number of auxiliary elements";
}
if (!m_faceMatIds.empty() && nFaces != (int)m_faceMatIds.size())
{
return "Mismatch in the number of face materials";
}
return 0;
}
//////////////////////////////////////////////////////////////////////////
// Computation
void RemoveDegenerateFaces()
{
int writePos = 0;
for (int readPos = 0; readPos < (int)m_faces.size(); ++readPos)
{
const Face& face = m_faces[readPos];
if (face.vertexIndex[0] != face.vertexIndex[1] &&
face.vertexIndex[1] != face.vertexIndex[2] &&
face.vertexIndex[0] != face.vertexIndex[2])
{
m_faces[writePos] = m_faces[readPos];
if (!m_faceMatIds.empty())
{
m_faceMatIds[writePos] = m_faceMatIds[readPos];
}
++writePos;
}
}
m_faces.resize(writePos);
if (!m_faceMatIds.empty())
{
m_faceMatIds.resize(writePos);
}
}
int AddVertexCopy(int sourceVertexIndex)
{
if (sourceVertexIndex < 0 || sourceVertexIndex >= m_positions.size())
{
assert(0);
return -1;
}
m_positions.push_back(m_positions[sourceVertexIndex]);
if (!m_topologyIds.empty())
{
m_topologyIds.push_back(m_topologyIds[sourceVertexIndex]);
}
if (!m_normals.empty())
{
m_normals.push_back(m_normals[sourceVertexIndex]);
}
for (uint streamIndex = 0; streamIndex < m_texCoords.size(); ++streamIndex)
{
if (!m_texCoords[streamIndex].empty())
{
m_texCoords[streamIndex].push_back(m_texCoords[streamIndex][sourceVertexIndex]);
}
}
if (!m_colors.empty())
{
m_colors.push_back(m_colors[sourceVertexIndex]);
}
if (!m_alphas.empty())
{
m_alphas.push_back(m_alphas[sourceVertexIndex]);
}
if (!m_links.empty())
{
m_links.push_back(m_links[sourceVertexIndex]);
}
if (!m_vertexMatIds.empty())
{
m_vertexMatIds.push_back(m_vertexMatIds[sourceVertexIndex]);
}
if (!m_aux.empty())
{
m_aux.resize(m_aux.size() + m_auxSizeof);
memcpy(&m_aux[m_aux.size() - m_auxSizeof], &m_aux[sourceVertexIndex * m_auxSizeof], m_auxSizeof);
}
return (int)m_positions.size() - 1;
}
// Note: might create new vertices and modify vertex indices in faces
void SetVertexMaterialIdsFromFaceMaterialIds()
{
m_vertexMatIds.clear();
if (m_faceMatIds.empty())
{
return;
}
m_vertexMatIds.resize(m_positions.size(), -1);
for (size_t i = 0; i < m_faces.size(); ++i)
{
const int faceMatId = m_faceMatIds[i];
for (int j = 0; j < 3; ++j)
{
int v = m_faces[i].vertexIndex[j];
if (m_vertexMatIds[v] >= 0 && m_vertexMatIds[v] != faceMatId)
{
v = AddVertexCopy(v);
m_faces[i].vertexIndex[j] = v;
}
m_vertexMatIds[v] = faceMatId;
}
}
}
// Computes m_vertexOldToNew and m_vertexNewToOld by detecting duplicate vertices
void ComputeVertexRemapping()
{
const size_t nVerts = m_positions.size();
m_vertexNewToOld.resize(nVerts);
for (size_t i = 0; i < nVerts; ++i)
{
m_vertexNewToOld[i] = i;
}
VertexLess less(*this);
std::sort(m_vertexNewToOld.begin(), m_vertexNewToOld.end(), less);
m_vertexOldToNew.resize(nVerts);
int nVertsNew = 0;
for (size_t i = 0; i < nVerts; ++i)
{
if (i == 0 || less(m_vertexNewToOld[i - 1], m_vertexNewToOld[i]))
{
m_vertexNewToOld[nVertsNew++] = m_vertexNewToOld[i];
}
m_vertexOldToNew[m_vertexNewToOld[i]] = nVertsNew - 1;
}
m_vertexNewToOld.resize(nVertsNew);
}
// Changes order of vertices, number of vertices, vertex indices in faces
void RemoveVerticesByUsingComputedRemapping()
{
CompactVertices(m_positions, m_vertexNewToOld);
CompactVertices(m_topologyIds, m_vertexNewToOld);
CompactVertices(m_normals, m_vertexNewToOld);
for (uint streamIndex = 0; streamIndex < m_texCoords.size(); ++streamIndex)
{
CompactVertices(m_texCoords[streamIndex], m_vertexNewToOld);
}
CompactVertices(m_colors, m_vertexNewToOld);
CompactVertices(m_alphas, m_vertexNewToOld);
CompactVertices(m_links, m_vertexNewToOld);
CompactVertices(m_vertexMatIds, m_vertexNewToOld);
CompactVerticesRaw(m_aux, m_auxSizeof, m_vertexNewToOld);
for (size_t i = 0, count = m_faces.size(); i < count; ++i)
{
for (int j = 0; j < 3; ++j)
{
const int oldVertedIdx = m_faces[i].vertexIndex[j];
assert(oldVertedIdx >= 0 && (size_t)oldVertedIdx < m_vertexOldToNew.size());
const int newVertexIndex = m_vertexOldToNew[oldVertedIdx];
m_faces[i].vertexIndex[j] = newVertexIndex;
}
}
}
// Deleting degraded faces (faces with two or more vertices
// sharing same position in space)
void RemoveDegradedFaces()
{
size_t j = 0;
for (size_t i = 0, count = m_faces.size(); i < count; ++i)
{
const Vec3& p0 = m_positions[m_faces[i].vertexIndex[0]];
const Vec3& p1 = m_positions[m_faces[i].vertexIndex[1]];
const Vec3& p2 = m_positions[m_faces[i].vertexIndex[2]];
if (p0 != p1 && p1 != p2 && p2 != p0)
{
m_faces[j] = m_faces[i];
if (!m_faceMatIds.empty())
{
m_faceMatIds[j] = m_faceMatIds[i];
}
++j;
}
}
m_faces.resize(j);
if (!m_faceMatIds.empty())
{
m_faceMatIds.resize(j);
}
}
private:
//////////////////////////////////////////////////////////////////////////
// Internal helpers
template<class T>
static void CompactVertices(std::vector<T>& arr, const std::vector<int>& newToOld)
{
if (arr.empty())
{
return;
}
const size_t newCount = newToOld.size();
std::vector<T> tmp;
tmp.reserve(newCount);
for (size_t i = 0; i < newCount; ++i)
{
tmp.push_back(arr[newToOld[i]]);
}
arr.swap(tmp);
}
static void CompactVerticesRaw(std::vector<uint8>& arr, size_t elemSizeof, const std::vector<int>& newToOld)
{
if (arr.empty())
{
return;
}
const size_t newCount = newToOld.size();
std::vector<uint8> tmp;
tmp.resize(newCount * elemSizeof);
for (size_t i = 0; i < newCount; ++i)
{
memcpy(&tmp[i * elemSizeof], &arr[newToOld[i] * elemSizeof], elemSizeof);
}
arr.swap(tmp);
}
struct VertexLess
{
const Mesh& m;
VertexLess(const Mesh& mesh)
: m(mesh)
{
}
bool operator()(int a, int b) const
{
if (!m.m_topologyIds.empty())
{
const int res = m.m_topologyIds[a] - m.m_topologyIds[b];
if (res != 0)
{
return res < 0;
}
}
{
const int res = memcmp(&m.m_positions[a], &m.m_positions[b], sizeof(m.m_positions[0]));
if (res != 0)
{
return res < 0;
}
}
int res = 0;
if (res == 0 && !m.m_normals.empty())
{
res = memcmp(&m.m_normals[a], &m.m_normals[b], sizeof(m.m_normals[0]));
}
for (uint streamIndex = 0; streamIndex < m.m_texCoords.size(); ++streamIndex)
{
if (res == 0 && !m.m_texCoords[streamIndex].empty())
{
res = memcmp(&m.m_texCoords[streamIndex][a], &m.m_texCoords[streamIndex][b], sizeof(m.m_texCoords[streamIndex][0]));
}
}
if (res == 0 && !m.m_colors.empty())
{
res = memcmp(&m.m_colors[a], &m.m_colors[b], sizeof(m.m_colors[0]));
}
if (res == 0 && !m.m_alphas.empty())
{
res = (int)m.m_alphas[a] - (int)m.m_alphas[b];
}
if (res == 0 && !m.m_links.empty())
{
if (m.m_links[a].links.size() != m.m_links[b].links.size())
{
res = (m.m_links[a].links.size() < m.m_links[b].links.size()) ? -1 : +1;
}
else
{
res = memcmp(&m.m_links[a].links[0], &m.m_links[b].links[0], sizeof(m.m_links[a].links[0]) * m.m_links[a].links.size());
}
}
if (res == 0 && !m.m_vertexMatIds.empty())
{
res = m.m_vertexMatIds[a] - m.m_vertexMatIds[b];
}
if (res == 0 && !m.m_aux.empty())
{
res = memcmp(&m.m_aux[a * m.m_auxSizeof], &m.m_aux[b * m.m_auxSizeof], m.m_auxSizeof);
}
return res < 0;
}
};
};
} // namespace MeshUtils
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_MESHUTILS_H
@@ -0,0 +1,118 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#include "StdAfx.h"
#include "ModelData.h"
int ModelData::AddModel(const void* handle, const char* modelName, int parentModelIndex, bool geometry, const SHelperData& helperData, const std::string& propertiesString)
{
int modelIndex = int(m_models.size());
m_models.push_back(ModelEntry(handle, modelName, parentModelIndex, geometry, helperData, propertiesString));
if (parentModelIndex >= 0)
{
m_models[parentModelIndex].children.push_back(modelIndex);
}
else
{
m_roots.push_back(modelIndex);
}
return modelIndex;
}
const void* ModelData::GetModelHandle(int modelIndex) const
{
return m_models[modelIndex].handle;
}
const char* ModelData::GetModelName(int modelIndex) const
{
return m_models[modelIndex].name.c_str();
}
void ModelData::SetTranslationRotationScale(int const modelIndex, const float* const translation, const float* const rotation, const float* const scale)
{
for (int i = 0; i < 3; ++i)
{
m_models[modelIndex].translation[i] = translation[i];
m_models[modelIndex].rotation[i] = rotation[i];
m_models[modelIndex].scale[i] = scale[i];
}
}
void ModelData::GetTranslationRotationScale(int const modelIndex, float* const translation, float* const rotation, float* const scale) const
{
for (int i = 0; i < 3; ++i)
{
translation[i] = m_models[modelIndex].translation[i];
rotation[i] = m_models[modelIndex].rotation[i];
scale[i] = m_models[modelIndex].scale[i];
}
}
const SHelperData& ModelData::GetHelperData(int modelIndex) const
{
return m_models[modelIndex].helperData;
}
const std::string& ModelData::GetProperties(int modelIndex) const
{
return m_models[modelIndex].propertiesString;
}
bool ModelData::IsRoot(int modelIndex) const
{
return (m_models[modelIndex].parentIndex < 0);
}
int ModelData::GetModelCount() const
{
return int(m_models.size());
}
int ModelData::GetRootCount() const
{
return int(m_roots.size());
}
int ModelData::GetRootIndex(int rootIndex) const
{
return m_roots[rootIndex];
}
int ModelData::GetChildCount(int modelIndex) const
{
return int(m_models[modelIndex].children.size());
}
int ModelData::GetChildIndex(int modelIndex, int childIndexIndex) const
{
return m_models[modelIndex].children[childIndexIndex];
}
bool ModelData::HasGeometry(int modelIndex) const
{
return m_models[modelIndex].geometry;
}
ModelData::ModelEntry::ModelEntry(const void* a_handle, const std::string& a_name, int a_parentIndex, bool a_geometry, const SHelperData& a_helperData, const std::string& a_propertiesString)
: handle(a_handle)
, name(a_name)
, parentIndex(a_parentIndex)
, geometry(a_geometry)
, helperData(a_helperData)
, propertiesString(a_propertiesString)
{
translation[0] = translation[1] = translation[2] = 0.0f;
rotation[0] = rotation[1] = rotation[2] = 0.0f;
scale[0] = scale[1] = scale[2] = 1.0f;
}
@@ -0,0 +1,63 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_MODELDATA_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_MODELDATA_H
#pragma once
#include "IModelData.h"
class ModelData
: public IModelData
{
public:
// IModelData
virtual int AddModel(const void* handle, const char* name, int parentModelIndex, bool geometry, const SHelperData& helperData, const std::string& propertiesString);
virtual int GetModelCount() const;
virtual const void* GetModelHandle(int modelIndex) const;
virtual const char* GetModelName(int modelIndex) const;
virtual void SetTranslationRotationScale(int modelIndex, const float* translation, const float* rotation, const float* scale);
virtual void GetTranslationRotationScale(int modelIndex, float* translation, float* rotation, float* scale) const;
virtual const SHelperData& GetHelperData(int modelIndex) const;
virtual const std::string& GetProperties(int modelIndex) const;
virtual bool IsRoot(int modelIndex) const;
int GetRootCount() const;
int GetRootIndex(int rootIndex) const;
int GetChildCount(int modelIndex) const;
int GetChildIndex(int modelIndex, int childIndexIndex) const;
bool HasGeometry(int modelIndex) const;
private:
struct ModelEntry
{
ModelEntry(const void* handle, const std::string& name, int parentIndex, bool geometry, const SHelperData& helperData, const std::string& propertiesString);
const void* handle;
std::string name;
int parentIndex;
bool geometry;
std::vector<int> children;
float translation[3];
float rotation[3];
float scale[3];
SHelperData helperData;
std::string propertiesString;
};
std::vector<ModelEntry> m_models;
std::vector<int> m_roots;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_MODELDATA_H
@@ -0,0 +1,55 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#include "StdAfx.h"
#include "MorphData.h"
MorphData::MorphData()
: m_handle(0)
{
}
void MorphData::SetHandle(const void* handle)
{
m_handle = handle;
}
void MorphData::AddMorph(const void* handle, const char* name, const char* fullname)
{
m_morphs.push_back(Entry(handle, name, fullname ? fullname : ""));
}
const void* MorphData::GetHandle() const
{
return m_handle;
}
int MorphData::GetMorphCount() const
{
return int(m_morphs.size());
}
std::string MorphData::GetMorphName(int morphIndex) const
{
return m_morphs[morphIndex].name;
}
std::string MorphData::GetMorphFullName(int morphIndex) const
{
return m_morphs[morphIndex].fullname.length() > 0 ? m_morphs[morphIndex].fullname : m_morphs[morphIndex].name;
}
const void* MorphData::GetMorphHandle(int morphIndex) const
{
return m_morphs[morphIndex].handle;
}
@@ -0,0 +1,52 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_MORPHDATA_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_MORPHDATA_H
#pragma once
#include "IMorphData.h"
class MorphData
: public IMorphData
{
public:
MorphData();
virtual void SetHandle(const void* handle);
virtual void AddMorph(const void* handle, const char* name, const char* fullname);
virtual const void* GetHandle() const;
virtual int GetMorphCount() const;
virtual const void* GetMorphHandle(int morphIndex) const;
std::string GetMorphName(int morphIndex) const;
std::string GetMorphFullName(int morphIndex) const;
private:
struct Entry
{
Entry(const void* handle, const std::string& name, const std::string& fullname)
: handle(handle)
, name(name)
, fullname(fullname) {}
const void* handle;
std::string name;
std::string fullname;
};
const void* m_handle;
std::vector<Entry> m_morphs;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_MORPHDATA_H
@@ -0,0 +1,86 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#include "StdAfx.h"
#include "SingleAnimationExportSourceAdapter.h"
#include "IGeometryFileData.h"
#include <cassert>
SingleAnimationExportSourceAdapter::SingleAnimationExportSourceAdapter(IExportSource* source, IGeometryFileData* geometryFileData, int geometryFileIndex, int animationIndex)
: ExportSourceDecoratorBase(source)
, animationIndex(animationIndex)
, geometryFileData(geometryFileData)
, geometryFileIndex(geometryFileIndex)
{
assert(this->animationIndex < this->source->GetAnimationCount());
}
float SingleAnimationExportSourceAdapter::GetDCCFrameRate() const
{
return this->source->GetDCCFrameRate();
}
void SingleAnimationExportSourceAdapter::ReadGeometryFiles(IExportContext* context, IGeometryFileData* geometryFileData)
{
const int geometryFileIndex = geometryFileData->AddGeometryFile(
this->geometryFileData->GetGeometryFileHandle(this->geometryFileIndex),
this->geometryFileData->GetGeometryFileName(this->geometryFileIndex),
this->geometryFileData->GetProperties(this->geometryFileIndex));
}
void SingleAnimationExportSourceAdapter::ReadModels(const IGeometryFileData* geometryFileData, int geometryFileIndex, IModelData* modelData)
{
assert(geometryFileIndex == 0);
this->source->ReadModels(this->geometryFileData, this->geometryFileIndex, modelData);
}
void SingleAnimationExportSourceAdapter::ReadSkinning(IExportContext* context, ISkinningData* skinningData, const IModelData* const modelData, int modelIndex, ISkeletonData* skeletonData)
{
this->source->ReadSkinning(context, skinningData, modelData, modelIndex, skeletonData);
}
bool SingleAnimationExportSourceAdapter::ReadSkeleton(const IGeometryFileData* const geometryFileData, int geometryFileIndex, const IModelData* const modelData, int modelIndex, const IMaterialData* materialData, ISkeletonData* skeletonData)
{
assert(geometryFileIndex == 0);
return this->source->ReadSkeleton(this->geometryFileData, this->geometryFileIndex, modelData, modelIndex, materialData, skeletonData);
}
int SingleAnimationExportSourceAdapter::GetAnimationCount() const
{
return 1;
}
std::string SingleAnimationExportSourceAdapter::GetAnimationName(const IGeometryFileData* geometryFileData, int geometryFileIndex, int animationIndex) const
{
assert(geometryFileIndex == 0);
assert(animationIndex == 0);
return this->source->GetAnimationName(this->geometryFileData, this->geometryFileIndex, this->animationIndex);
}
void SingleAnimationExportSourceAdapter::GetAnimationTimeSpan(float& start, float& stop, int animationIndex) const
{
assert(animationIndex == 0);
this->source->GetAnimationTimeSpan(start, stop, this->animationIndex);
}
void SingleAnimationExportSourceAdapter::ReadAnimationFlags(IExportContext* context, IAnimationData* animationData, const IGeometryFileData* const geometryFileData, const IModelData* modelData, int modelIndex, const ISkeletonData* skeletonData, int animationIndex) const
{
assert(animationIndex == 0);
this->source->ReadAnimationFlags(context, animationData, geometryFileData, modelData, modelIndex, skeletonData, this->animationIndex);
}
IAnimationData* SingleAnimationExportSourceAdapter::ReadAnimation(IExportContext* context, const IGeometryFileData* const geometryFileData, const IModelData* modelData, int modelIndex, const ISkeletonData* skeletonData, int animationIndex, float fps) const
{
assert(animationIndex == 0);
return this->source->ReadAnimation(context, geometryFileData, modelData, modelIndex, skeletonData, this->animationIndex, fps);
}
@@ -0,0 +1,45 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_SINGLEANIMATIONEXPORTSOURCEADAPTER_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_SINGLEANIMATIONEXPORTSOURCEADAPTER_H
#pragma once
#include "ExportSourceDecoratorBase.h"
class SingleAnimationExportSourceAdapter
: public ExportSourceDecoratorBase
{
public:
SingleAnimationExportSourceAdapter(IExportSource* source, IGeometryFileData* geometryData, int geometryFileIndex, int animationIndex);
virtual float GetDCCFrameRate() const;
virtual void ReadGeometryFiles(IExportContext* context, IGeometryFileData* geometryFileData);
virtual void ReadModels(const IGeometryFileData* geometryFileData, int geometryFileIndex, IModelData* modelData);
virtual void ReadSkinning(IExportContext* context, ISkinningData* skinningData, const IModelData* modelData, int modelIndex, ISkeletonData* skeletonData);
virtual bool ReadSkeleton(const IGeometryFileData* geometryFileData, int geometryFileIndex, const IModelData* modelData, int modelIndex, const IMaterialData* materialData, ISkeletonData* skeletonData);
virtual int GetAnimationCount() const;
virtual std::string GetAnimationName(const IGeometryFileData* geometryFileData, int geometryFileIndex, int animationIndex) const;
virtual void GetAnimationTimeSpan(float& start, float& stop, int animationIndex) const;
virtual void ReadAnimationFlags(IExportContext* context, IAnimationData* animationData, const IGeometryFileData* geometryFileData, const IModelData* modelData, int modelIndex, const ISkeletonData* skeletonData, int animationIndex) const;
virtual IAnimationData* ReadAnimation(IExportContext* context, const IGeometryFileData* geometryFileData, const IModelData* modelData, int modelIndex, const ISkeletonData* skeletonData, int animationIndex, float fps) const;
private:
int animationIndex;
IGeometryFileData* geometryFileData;
int geometryFileIndex;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_SINGLEANIMATIONEXPORTSOURCEADAPTER_H
@@ -0,0 +1,309 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#include "StdAfx.h"
#include "SkeletonData.h"
#include <cctype>
int SkeletonData::AddBone(const void* handle, const char* name, int parentIndex)
{
int modelIndex = int(m_bones.size());
m_bones.push_back(BoneEntry(handle, name, parentIndex));
m_nameBoneIndexMap.insert(std::make_pair(name, modelIndex));
if (parentIndex >= 0)
{
m_bones[parentIndex].children.push_back(modelIndex);
}
else
{
m_roots.push_back(modelIndex);
}
return modelIndex;
}
int SkeletonData::FindBone(const char* name) const
{
std::map<std::string, int>::const_iterator modelPos = m_nameBoneIndexMap.find(name);
return (modelPos != m_nameBoneIndexMap.end() ? (*modelPos).second : -1);
}
const void* SkeletonData::GetBoneHandle(int boneIndex) const
{
return m_bones[boneIndex].handle;
}
int SkeletonData::GetBoneParentIndex(int boneIndex) const
{
return m_bones[boneIndex].parentIndex;
}
int SkeletonData::GetBoneCount() const
{
return int(m_bones.size());
}
void SkeletonData::SetTranslation(int modelIndex, const float* vec)
{
for (int i = 0; i < 3; ++i)
{
m_bones[modelIndex].translation[i] = vec[i];
}
}
void SkeletonData::SetRotation(int modelIndex, const float* vec)
{
for (int i = 0; i < 3; ++i)
{
m_bones[modelIndex].rotation[i] = vec[i];
}
}
void SkeletonData::SetScale(int modelIndex, const float* vec)
{
for (int i = 0; i < 3; ++i)
{
m_bones[modelIndex].scale[i] = vec[i];
}
}
void SkeletonData::SetParentFrameTranslation(int boneIndex, const float* vec)
{
EnsureParentFrameExists(boneIndex);
std::copy(vec, vec + 3, m_bones[boneIndex].parentFrameTranslation);
}
void SkeletonData::SetParentFrameRotation(int boneIndex, const float* vec)
{
EnsureParentFrameExists(boneIndex);
std::copy(vec, vec + 3, m_bones[boneIndex].parentFrameRotation);
}
void SkeletonData::SetParentFrameScale(int boneIndex, const float* vec)
{
EnsureParentFrameExists(boneIndex);
std::copy(vec, vec + 3, m_bones[boneIndex].parentFrameScale);
}
void SkeletonData::SetLimit(int boneIndex, Axis axis, Limit extreme, float limit)
{
m_bones[boneIndex].limits.insert(std::make_pair(AxisLimit(axis, extreme), limit));
}
void SkeletonData::SetSpringTension(int boneIndex, Axis axis, float springTension)
{
m_bones[boneIndex].springTensions.insert(std::make_pair(axis, springTension));
}
void SkeletonData::SetSpringAngle(int boneIndex, Axis axis, float springAngle)
{
m_bones[boneIndex].springAngles.insert(std::make_pair(axis, springAngle));
}
void SkeletonData::SetAxisDamping(int boneIndex, Axis axis, float damping)
{
m_bones[boneIndex].dampings.insert(std::make_pair(axis, damping));
}
void SkeletonData::SetPhysicalized(int boneIndex, bool physicalized)
{
m_bones[boneIndex].physicalized = physicalized;
}
void SkeletonData::SetHasGeometry(int boneIndex, bool hasGeometry)
{
m_bones[boneIndex].hasGeometry = hasGeometry;
}
void SkeletonData::SetBoneProperties(int boneIndex, const char* propertiesString)
{
m_bones[boneIndex].propertiesString = propertiesString;
}
void SkeletonData::SetBoneGeomProperties(int boneIndex, const char* propertiesString)
{
m_bones[boneIndex].geomPropertiesString = propertiesString;
}
bool SkeletonData::HasParentFrame(int boneIndex) const
{
return m_bones[boneIndex].hasParentFrame;
}
void SkeletonData::GetParentFrameTranslation(int boneIndex, float* vec) const
{
std::copy(m_bones[boneIndex].parentFrameTranslation, m_bones[boneIndex].parentFrameTranslation + 3, vec);
}
void SkeletonData::GetParentFrameRotation(int boneIndex, float* vec) const
{
std::copy(m_bones[boneIndex].parentFrameRotation, m_bones[boneIndex].parentFrameRotation + 3, vec);
}
void SkeletonData::GetParentFrameScale(int boneIndex, float* vec) const
{
std::copy(m_bones[boneIndex].parentFrameScale, m_bones[boneIndex].parentFrameScale + 3, vec);
}
bool SkeletonData::HasLimit(int boneIndex, Axis axis, Limit extreme) const
{
return m_bones[boneIndex].limits.find(AxisLimit(axis, extreme)) != m_bones[boneIndex].limits.end();
}
float SkeletonData::GetLimit(int boneIndex, Axis axis, Limit extreme) const
{
return (*m_bones[boneIndex].limits.find(AxisLimit(axis, extreme))).second;
}
bool SkeletonData::HasSpringTension(int boneIndex, Axis axis) const
{
return m_bones[boneIndex].springTensions.find(axis) != m_bones[boneIndex].springTensions.end();
}
float SkeletonData::GetSpringTension(int boneIndex, Axis axis) const
{
return (*m_bones[boneIndex].springTensions.find(axis)).second;
}
bool SkeletonData::HasSpringAngle(int boneIndex, Axis axis) const
{
return m_bones[boneIndex].springAngles.find(axis) != m_bones[boneIndex].springAngles.end();
}
float SkeletonData::GetSpringAngle(int boneIndex, Axis axis) const
{
return (*m_bones[boneIndex].springAngles.find(axis)).second;
}
bool SkeletonData::HasAxisDamping(int boneIndex, Axis axis) const
{
return m_bones[boneIndex].dampings.find(axis) != m_bones[boneIndex].dampings.end();
}
float SkeletonData::GetAxisDamping(int boneIndex, Axis axis) const
{
return (*m_bones[boneIndex].dampings.find(axis)).second;
}
bool SkeletonData::GetPhysicalized(int boneIndex) const
{
return m_bones[boneIndex].physicalized;
}
bool SkeletonData::HasGeometry(int boneIndex) const
{
return m_bones[boneIndex].hasGeometry;
}
int SkeletonData::GetRootCount() const
{
return int(m_roots.size());
}
int SkeletonData::GetRootIndex(int rootIndex) const
{
return m_roots[rootIndex];
}
int SkeletonData::GetParentIndex(int modelIndex) const
{
return m_bones[modelIndex].parentIndex;
}
const std::string SkeletonData::GetName(int modelIndex) const
{
std::string copy(m_bones[modelIndex].name);
for (int i = 0, count = int(copy.size()); i < count; ++i)
{
if (!std::isalnum(copy[i]) && copy[i] != ' ')
{
copy[i] = '_';
}
}
return copy;
}
const std::string SkeletonData::GetSafeName(int modelIndex) const
{
std::string name = GetName(modelIndex);
std::replace_if(name.begin(), name.end(), std::isspace, '_');
return name;
}
int SkeletonData::GetChildCount(int modelIndex) const
{
return int(m_bones[modelIndex].children.size());
}
int SkeletonData::GetChildIndex(int modelIndex, int childIndexIndex) const
{
return m_bones[modelIndex].children[childIndexIndex];
}
void SkeletonData::GetTranslation(float* vec, int modelIndex) const
{
for (int i = 0; i < 3; ++i)
{
vec[i] = m_bones[modelIndex].translation[i];
}
}
void SkeletonData::GetRotation(float* vec, int modelIndex) const
{
for (int i = 0; i < 3; ++i)
{
vec[i] = m_bones[modelIndex].rotation[i];
}
}
void SkeletonData::GetScale(float* vec, int modelIndex) const
{
for (int i = 0; i < 3; ++i)
{
vec[i] = m_bones[modelIndex].scale[i];
}
}
const std::string SkeletonData::GetBoneProperties(int boneIndex) const
{
return m_bones[boneIndex].propertiesString;
}
const std::string SkeletonData::GetBoneGeomProperties(int boneIndex) const
{
return m_bones[boneIndex].geomPropertiesString;
}
void SkeletonData::EnsureParentFrameExists(int boneIndex)
{
if (!m_bones[boneIndex].hasParentFrame)
{
std::fill(m_bones[boneIndex].parentFrameTranslation, m_bones[boneIndex].parentFrameTranslation + 3, 0.0f);
std::fill(m_bones[boneIndex].parentFrameRotation, m_bones[boneIndex].parentFrameRotation + 3, 0.0f);
std::fill(m_bones[boneIndex].parentFrameScale, m_bones[boneIndex].parentFrameScale + 3, 0.0f);
m_bones[boneIndex].hasParentFrame = true;
}
}
SkeletonData::BoneEntry::BoneEntry(const void* handle, const std::string& name, int parentIndex)
: handle(handle)
, name(name)
, parentIndex(parentIndex)
, hasParentFrame(false)
, physicalized(false)
, hasGeometry(hasGeometry)
{
translation[0] = translation[1] = translation[2] = 0.0f;
rotation[0] = rotation[1] = rotation[2] = 0.0f;
scale[0] = scale[1] = scale[2] = 1.0f;
}
@@ -0,0 +1,116 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_SKELETONDATA_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_SKELETONDATA_H
#pragma once
#include "ISkeletonData.h"
#include <string>
#include <vector>
#include <map>
class SkeletonData
: public ISkeletonData
{
public:
// ISkeletonData
virtual int AddBone(const void* handle, const char* name, int parentIndex);
virtual int FindBone(const char* name) const;
virtual const void* GetBoneHandle(int boneIndex) const;
virtual int GetBoneParentIndex(int boneIndex) const;
virtual int GetBoneCount() const;
virtual void SetTranslation(int boneIndex, const float* vec);
virtual void SetRotation(int boneIndex, const float* vec);
virtual void SetScale(int boneIndex, const float* vec);
virtual void SetParentFrameTranslation(int boneIndex, const float* vec);
virtual void SetParentFrameRotation(int boneIndex, const float* vec);
virtual void SetParentFrameScale(int boneIndex, const float* vec);
virtual void SetLimit(int boneIndex, Axis axis, Limit extreme, float limit);
virtual void SetSpringTension(int boneIndex, Axis axis, float springTension);
virtual void SetSpringAngle(int boneIndex, Axis axis, float springAngle);
virtual void SetAxisDamping(int boneIndex, Axis axis, float damping);
virtual void SetPhysicalized(int boneIndex, bool physicalized);
virtual void SetHasGeometry(int boneIndex, bool hasGeometry);
virtual void SetBoneProperties(int boneIndex, const char* propertiesString);
virtual void SetBoneGeomProperties(int boneIndex, const char* propertiesString);
bool HasParentFrame(int boneIndex) const;
void GetParentFrameTranslation(int boneIndex, float* vec) const;
void GetParentFrameRotation(int boneIndex, float* vec) const;
void GetParentFrameScale(int boneIndex, float* vec) const;
bool HasLimit(int boneIndex, Axis axis, Limit extreme) const;
float GetLimit(int boneIndex, Axis axis, Limit extreme) const;
bool HasSpringTension(int boneIndex, Axis axis) const;
float GetSpringTension(int boneIndex, Axis axis) const;
bool HasSpringAngle(int boneIndex, Axis axis) const;
float GetSpringAngle(int boneIndex, Axis axis) const;
bool HasAxisDamping(int boneIndex, Axis axis) const;
float GetAxisDamping(int boneIndex, Axis axis) const;
bool GetPhysicalized(int boneIndex) const;
bool HasGeometry(int boneIndex) const;
int GetRootCount() const;
int GetRootIndex(int rootIndex) const;
int GetParentIndex(int boneIndex) const;
const std::string GetName(int boneIndex) const;
const std::string GetSafeName(int boneIndex) const;
int GetChildCount(int boneIndex) const;
int GetChildIndex(int boneIndex, int childIndexIndex) const;
void GetTranslation(float* vec, int boneIndex) const;
void GetRotation(float* vec, int boneIndex) const;
void GetScale(float* vec, int boneIndex) const;
const std::string GetBoneProperties(int boneIndex) const;
const std::string GetBoneGeomProperties(int boneIndex) const;
private:
void EnsureParentFrameExists(int boneIndex);
typedef std::pair<Axis, Limit> AxisLimit;
typedef std::map<AxisLimit, float> AxisLimitLimitMap;
typedef std::map<Axis, float> AxisSpringTensionMap;
typedef std::map<Axis, float> AxisSpringAngleMap;
typedef std::map<Axis, float> AxisDampingMap;
struct BoneEntry
{
public:
BoneEntry(const void* handle, const std::string& name, int parentIndex);
const void* handle;
std::string name;
int parentIndex;
AxisLimitLimitMap limits;
AxisSpringTensionMap springTensions;
AxisSpringAngleMap springAngles;
AxisDampingMap dampings;
bool hasParentFrame;
float parentFrameTranslation[3];
float parentFrameRotation[3];
float parentFrameScale[3];
bool physicalized;
std::vector<int> children;
float translation[3];
float rotation[3];
float scale[3];
bool hasGeometry;
std::string propertiesString;
std::string geomPropertiesString;
};
std::vector<BoneEntry> m_bones;
std::vector<int> m_roots;
std::map<std::string, int> m_nameBoneIndexMap;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_SKELETONDATA_H
@@ -0,0 +1,45 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#include "StdAfx.h"
#include "SkinningData.h"
void SkinningData::SetVertexCount(int vertexCount)
{
m_weights.resize(vertexCount);
}
void SkinningData::AddWeight(int vertexIndex, int boneIndex, float weight)
{
m_weights[vertexIndex].push_back(BoneWeight(boneIndex, weight));
}
int SkinningData::GetVertexCount() const
{
return int(m_weights.size());
}
int SkinningData::GetBoneLinkCount(int vertexIndex) const
{
return int(m_weights[vertexIndex].size());
}
int SkinningData::GetBoneIndex(int vertexIndex, int linkIndex) const
{
return m_weights[vertexIndex][linkIndex].boneIndex;
}
float SkinningData::GetWeight(int vertexIndex, int linkIndex) const
{
return m_weights[vertexIndex][linkIndex].weight;
}
@@ -0,0 +1,46 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_SKINNINGDATA_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_SKINNINGDATA_H
#pragma once
#include "ISkinningData.h"
class SkinningData
: public ISkinningData
{
public:
virtual void SetVertexCount(int vertexCount);
virtual void AddWeight(int vertexIndex, int boneIndex, float weight);
int GetVertexCount() const;
int GetBoneLinkCount(int vertexIndex) const;
int GetBoneIndex(int vertexIndex, int linkIndex) const;
float GetWeight(int vertexIndex, int linkIndex) const;
private:
struct BoneWeight
{
BoneWeight(int boneIndex, float weight)
: boneIndex(boneIndex)
, weight(weight) {}
int boneIndex;
float weight;
};
std::vector<std::vector<BoneWeight> > m_weights;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_SKINNINGDATA_H
@@ -0,0 +1,119 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_TRANSFORMHELPERS_H
#define CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_TRANSFORMHELPERS_H
#pragma once
#include "Cry_Math.h"
namespace TransformHelpers
{
// Format of forwardUpAxes: "<signOfForwardAxis><forwardAxis><signOfUpAxis><upAxis>".
// Example of forwardUpAxes: "-Y+Z".
// Returns 0 if successful, or returns a pointer to an error message in case of an error.
// In case of success: X axis in res represents "forward" direction,
// Y axis represents "up" direction.
inline const char* GetForwardUpAxesMatrix(Matrix33& res, const char* forwardUpAxes)
{
Vec3 axisX(ZERO);
Vec3 axisY(ZERO);
for (int i = 0; i < 2; ++i)
{
Vec3& v = (i == 0) ? axisX : axisY;
const float val = forwardUpAxes[i * 2 + 0] == '-' ? -1.0f : +1.0f;
switch (forwardUpAxes[i * 2 + 1])
{
case 'X':
case 'x':
v.x = val;
break;
case 'Y':
case 'y':
v.y = val;
break;
case 'Z':
case 'z':
v.z = val;
break;
default:
assert(0);
return "Found a bad axis character in forwardUpAxes string";
}
}
if (axisX == axisY)
{
assert(0);
return "Forward and up axes are equal in forwardUpAxes string";
}
const Vec3 axisZ = axisX.cross(axisY);
res.SetFromVectors(axisX, axisY, axisZ);
return 0;
}
// Computes transform matrix that converts everything from forwardUpAxesSrc
// coordinate system to forwardUpAxesDst coordinate system.
// Format of forwardUpAxesXXX: "<signOfForwardAxis><forwardAxis><signOfUpAxis><upAxis>".
// Example of forwardUpAxesXXX: "-Y+Z".
// Returns 0 if successful, or returns a pointer to an error message in case of an error.
// In case of success puts computed transform into res.
// See comments to GetForwardUpAxesMatrix().
inline const char* ComputeForwardUpAxesTransform(Matrix34& res, const char* forwardUpAxesSrc, const char* forwardUpAxesDst)
{
Matrix33 srcToWorld;
Matrix33 dstToWorld;
const char* const err0 = GetForwardUpAxesMatrix(srcToWorld, forwardUpAxesSrc);
const char* const err1 = GetForwardUpAxesMatrix(dstToWorld, forwardUpAxesDst);
if (err0 || err1)
{
return err0 ? err0 : err1;
}
res = Matrix34(dstToWorld * srcToWorld.GetTransposed());
return 0;
}
inline Matrix34 ComputeOrthonormalMatrix(const Matrix34& m)
{
Vec3 x = m.GetColumn0();
x.Normalize();
Vec3 y = m.GetColumn1();
Vec3 z = x.cross(y);
z.Normalize();
y = z.cross(x);
Matrix34 result;
result.SetFromVectors(x, y, z, m.GetTranslation());
return result;
}
}
#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXPORT_TRANSFORMHELPERS_H