Remove more unused things from CryCommon and CrySystem. (#709)

Lots of unrelated removals, I basically tried to remove everything exposed via gEnv that isn't used anymore, and following the threads found a few other things to remove also.
This commit is contained in:
bosnichd
2021-05-12 08:30:15 -06:00
committed by GitHub
parent f9fb61cc5d
commit 7cec2d8b07
198 changed files with 29 additions and 28558 deletions
@@ -1,297 +0,0 @@
/*
* 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)
{
}
@@ -1,211 +0,0 @@
/*
* 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
@@ -1,57 +0,0 @@
/*
* 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);
}
@@ -1,27 +0,0 @@
/*
* 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
@@ -1,556 +0,0 @@
/*
* 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);
}
}
@@ -1,29 +0,0 @@
/*
* 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
@@ -1,32 +0,0 @@
/*
* 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
@@ -1,66 +0,0 @@
/*
* 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;
}
@@ -1,42 +0,0 @@
/*
* 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
@@ -1,83 +0,0 @@
/*
* 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
@@ -1,130 +0,0 @@
/*
* 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);
}
@@ -1,54 +0,0 @@
/*
* 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
@@ -1,215 +0,0 @@
/*
* 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());
}
@@ -1,67 +0,0 @@
/*
* 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
@@ -1,82 +0,0 @@
/*
* 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();
}
@@ -1,102 +0,0 @@
/*
* 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
@@ -1,54 +0,0 @@
/*
* 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);
}
@@ -1,36 +0,0 @@
/*
* 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
@@ -1,59 +0,0 @@
/*
* 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;
}
@@ -1,52 +0,0 @@
/*
* 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
@@ -1,36 +0,0 @@
/*
* 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];
}
@@ -1,35 +0,0 @@
/*
* 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
@@ -1,41 +0,0 @@
/*
* 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
@@ -1,96 +0,0 @@
/*
* 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
@@ -1,55 +0,0 @@
/*
* 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
@@ -1,98 +0,0 @@
/*
* 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
@@ -1,28 +0,0 @@
/*
* 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
@@ -1,35 +0,0 @@
/*
* 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
@@ -1,54 +0,0 @@
/*
* 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
@@ -1,27 +0,0 @@
/*
* 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
@@ -1,33 +0,0 @@
/*
* 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
@@ -1,36 +0,0 @@
/*
* 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
@@ -1,29 +0,0 @@
/*
* 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
@@ -1,56 +0,0 @@
/*
* 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
@@ -1,26 +0,0 @@
/*
* 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
@@ -1,69 +0,0 @@
/*
* 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();
}
@@ -1,56 +0,0 @@
/*
* 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
@@ -1,107 +0,0 @@
/*
* 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;
}
}
@@ -1,39 +0,0 @@
/*
* 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
@@ -1,138 +0,0 @@
/*
* 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
@@ -1,99 +0,0 @@
/*
* 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);
}
@@ -1,32 +0,0 @@
/*
* 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
@@ -1,914 +0,0 @@
/*
* 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
@@ -1,118 +0,0 @@
/*
* 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;
}
@@ -1,63 +0,0 @@
/*
* 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
@@ -1,55 +0,0 @@
/*
* 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;
}
@@ -1,52 +0,0 @@
/*
* 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
@@ -1,86 +0,0 @@
/*
* 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);
}
@@ -1,45 +0,0 @@
/*
* 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
@@ -1,309 +0,0 @@
/*
* 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;
}
@@ -1,116 +0,0 @@
/*
* 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
@@ -1,45 +0,0 @@
/*
* 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;
}
@@ -1,46 +0,0 @@
/*
* 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
@@ -1,119 +0,0 @@
/*
* 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
-132
View File
@@ -1,132 +0,0 @@
/*
* 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 "EULADialog.h"
#include "Win32GUI.h"
#include "ModuleHelpers.h"
#include "Richedit.h"
#include <Windows.h>
EULADialog::EULADialog()
: m_frameWindow()
, m_cancelButton(_T("Cancel"), this, &EULADialog::CancelPressed)
, m_buttonSpacer(0, 0, 2000, 0)
, m_acceptButton(_T("Accept"), this, &EULADialog::AcceptPressed)
, m_buttonLayout(Layout::DirectionHorizontal)
, m_edit()
{
Win32GUI::Initialize();
m_buttonLayout.AddComponent(&m_buttonSpacer);
m_buttonLayout.AddComponent(&m_cancelButton);
m_buttonLayout.AddComponent(&m_acceptButton);
m_frameWindow.AddComponent(&m_edit);
m_frameWindow.AddComponent(&m_buttonLayout);
}
namespace
{
class EditStreamCallbackObject
{
public:
EditStreamCallbackObject(const char* data, int size)
: data(data)
, position(0)
, size(size) {}
static DWORD WINAPI EditStreamCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG* pcb)
{
return ((EditStreamCallbackObject*)dwCookie)->EditStreamCallback_Member(dwCookie, pbBuff, cb, pcb);
}
private:
DWORD EditStreamCallback_Member(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG* pcb)
{
int bytesToRead = (std::min)(this->size - this->position, (int)cb);
std::memcpy(pbBuff, this->data + this->position, bytesToRead);
this->position += bytesToRead;
if (pcb)
{
*pcb = bytesToRead;
}
return 0;
}
const char* data;
int position;
int size;
};
}
EULADialog::UserResponse EULADialog::Run(int width, int height, TCHAR* resourceID)
{
m_frameWindow.Show(true, width, height);
// Attempt to load the resource.
HINSTANCE module = ModuleHelpers::GetCurrentModule(ModuleHelpers::CurrentModuleSpecifier_Library);
HRSRC resource = (resourceID ? FindResource(module, resourceID, RT_RCDATA) : 0);
int resourceLength = (resource ? SizeofResource(module, resource) : 0);
HGLOBAL resourceGlobal = (resource ? LoadResource(module, resource) : 0);
void* resourceData = (resourceGlobal ? LockResource(resourceGlobal) : 0);
// No need to unlock/delete data.
m_userResponse = UserResponseNone;
// Load the text.
if (resourceData && resourceLength > 0)
{
EditStreamCallbackObject callbackObject((const char*)resourceData, resourceLength);
EDITSTREAM editStream;
std::memset(&editStream, 0, sizeof(editStream));
editStream.dwCookie = (DWORD_PTR)&callbackObject;
editStream.pfnCallback = &EditStreamCallbackObject::EditStreamCallback;
SendMessage((HWND)m_edit.m_edit, EM_STREAMIN, SF_RTF, (LPARAM)&editStream);
}
MSG msg;
BOOL status;
bool waitingAcceptance = false;
while (m_userResponse == UserResponseNone && (status = GetMessage(&msg, HWND(0), UINT(0), UINT(0))) != 0)
{
if (status == -1)
{
break;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
m_frameWindow.Show(false, 0, 0);
return m_userResponse;
}
void EULADialog::CancelPressed()
{
m_userResponse = UserResponseCancel;
}
void EULADialog::AcceptPressed()
{
m_userResponse = UserResponseAccept;
}
EULADialog::UserResponse EULADialog::Show(int width, int height, TCHAR* resourceID)
{
EULADialog dlg;
return dlg.Run(width, height, resourceID);
}
-55
View File
@@ -1,55 +0,0 @@
/*
* 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_UI_EULADIALOG_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_EULADIALOG_H
#pragma once
#include "FrameWindow.h"
#include "EditControl.h"
#include "Spacer.h"
#include "Layout.h"
#include "PushButton.h"
class EULADialog
{
public:
enum UserResponse
{
UserResponseNone,
UserResponseCancel,
UserResponseAccept
};
static UserResponse Show(int width, int height, TCHAR* resourceID);
private:
EULADialog();
UserResponse Run(int width, int height, TCHAR* resourceID);
void CancelPressed();
void AcceptPressed();
FrameWindow m_frameWindow;
PushButton m_cancelButton;
Spacer m_buttonSpacer;
PushButton m_acceptButton;
Layout m_buttonLayout;
EditControl m_edit;
UserResponse m_userResponse;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_EULADIALOG_H
@@ -1,48 +0,0 @@
/*
* 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 "EditControl.h"
#include "Win32GUI.h"
#include <Windows.h>
#include <CommCtrl.h>
#include <Richedit.h>
EditControl::EditControl()
: m_edit(0)
{
}
void EditControl::CreateUI(void* window, int left, int top, int width, int height)
{
m_edit = Win32GUI::CreateControl(RICHEDIT_CLASS, ES_MULTILINE /*| ES_READONLY*/, (HWND)window, left, top, width, height);
}
void EditControl::Resize(void* window, int left, int top, int width, int height)
{
MoveWindow((HWND)m_edit, left, top, width, height, true);
}
void EditControl::DestroyUI(void* window)
{
DestroyWindow((HWND)m_edit);
m_edit = 0;
}
void EditControl::GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight)
{
minWidth = 20;
maxWidth = 2000;
minHeight = 20;
maxHeight = 2000;
}
@@ -1,36 +0,0 @@
/*
* 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_UI_EDITCONTROL_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_EDITCONTROL_H
#pragma once
#include "IUIComponent.h"
class EditControl
: public IUIComponent
{
public:
EditControl();
// IUIComponent
virtual void CreateUI(void* window, int left, int top, int width, int height);
virtual void Resize(void* window, int left, int top, int width, int height);
virtual void DestroyUI(void* window);
virtual void GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight);
void* m_edit;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_EDITCONTROL_H
@@ -1,116 +0,0 @@
/*
* 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 "FrameWindow.h"
#include "Win32GUI.h"
#include "IUIComponent.h"
#include <Windows.h>
#include <cassert>
FrameWindow::FrameWindow()
: m_hwnd(0)
, m_layout(Layout::DirectionVertical)
{
}
FrameWindow::~FrameWindow()
{
if (m_hwnd)
{
Show(false, 0, 0);
}
}
void FrameWindow::AddComponent(IUIComponent* component)
{
assert(m_hwnd == 0);
m_layout.AddComponent(component);
}
void FrameWindow::Show(bool show, int width, int height)
{
if (show)
{
assert(m_hwnd == 0);
TCHAR* className = _T("CustomFrameWindowClass212");
Win32GUI::RegisterFrameClass(className);
m_hwnd = Win32GUI::CreateFrame(className, WS_MINIMIZEBOX | WS_OVERLAPPED | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX, width, height);
Win32GUI::SetCallback<Win32GUI::EventCallbacks::GetDimensions, FrameWindow>((HWND)m_hwnd, this, &FrameWindow::CalculateExtremeDimensions);
Win32GUI::SetCallback<Win32GUI::EventCallbacks::SizeChanged, FrameWindow>((HWND)m_hwnd, this, &FrameWindow::OnSizeChanged);
std::pair<int, int> size = InitializeSize();
m_layout.CreateUI(m_hwnd, 0, 0, size.first, size.second);
ShowWindow((HWND)m_hwnd, SW_SHOWDEFAULT);
}
else
{
m_layout.DestroyUI(m_hwnd);
assert(m_hwnd != 0);
DestroyWindow((HWND)m_hwnd);
m_hwnd = 0;
}
}
void FrameWindow::SetCaption(const TCHAR* caption)
{
SendMessage((HWND)m_hwnd, WM_SETTEXT, 0, (LPARAM)caption);
}
void* FrameWindow::GetHWND()
{
return m_hwnd;
}
std::pair<int, int> FrameWindow::InitializeSize()
{
int minW, maxW, minH, maxH;
CalculateExtremeDimensions(minW, maxW, minH, maxH);
RECT rect;
GetWindowRect((HWND)m_hwnd, &rect);
int width = int((std::min)(maxW, (std::max)(minW, int(rect.right - rect.left))));
int height = int((std::min)(maxH, (std::max)(minH, int(rect.bottom - rect.top))));
MoveWindow((HWND)m_hwnd, rect.left, rect.top, width, height, false);
return std::make_pair(width, height);
}
void FrameWindow::CalculateExtremeDimensions(int& minWidth, int& maxWidth, int& minHeight, int& maxHeight)
{
int minW = 0;
int maxW = 0;
int minH = 0;
int maxH = 0;
m_layout.GetExtremeDimensions(m_hwnd, minW, maxW, minH, maxH);
// Add the space required for the window decorations.
RECT rect;
rect.left = 0, rect.top = 0, rect.right = minW, rect.bottom = minH;
unsigned style = GetWindowLong((HWND)m_hwnd, GWL_STYLE);
AdjustWindowRect(&rect, style, false);
minW = rect.right - rect.left;
minH = rect.bottom - rect.top;
rect.left = 0, rect.top = 0, rect.right = maxW, rect.bottom = maxH;
AdjustWindowRect(&rect, style, false);
maxW = rect.right - rect.left;
maxH = rect.bottom - rect.top;
minWidth = minW;
maxWidth = maxW;
minHeight = minH;
maxHeight = maxH;
}
void FrameWindow::OnSizeChanged(int width, int height)
{
m_layout.Resize(m_hwnd, 0, 0, width, height);
}
@@ -1,44 +0,0 @@
/*
* 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_UI_FRAMEWINDOW_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_FRAMEWINDOW_H
#pragma once
#include <vector>
#include "Layout.h"
class IUIComponent;
class FrameWindow
{
public:
FrameWindow();
~FrameWindow();
void AddComponent(IUIComponent* component);
void Show(bool show, int width, int height);
void SetCaption(const TCHAR* caption);
void* GetHWND();
private:
void UpdateComponentUI(bool create);
std::pair<int, int> InitializeSize();
void CalculateExtremeDimensions(int& minWidth, int& maxWidth, int& minHeight, int& maxHeight);
void OnSizeChanged(int width, int height);
void* m_hwnd;
Layout m_layout;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_FRAMEWINDOW_H
@@ -1,28 +0,0 @@
/*
* 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_UI_IUICOMPONENT_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_IUICOMPONENT_H
#pragma once
class IUIComponent
{
public:
virtual void CreateUI(void* window, int left, int top, int width, int height) = 0;
virtual void Resize(void* window, int left, int top, int width, int height) = 0;
virtual void DestroyUI(void* window) = 0;
virtual void GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight) = 0;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_IUICOMPONENT_H
-233
View File
@@ -1,233 +0,0 @@
/*
* 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 "Layout.h"
#include <cassert>
#include <Windows.h>
Layout::Layout(Direction direction)
: m_direction(direction)
{
}
void Layout::AddComponent(IUIComponent* component)
{
m_components.push_back(ComponentEntry(component));
}
void Layout::CreateUI(void* window, int left, int top, int width, int height)
{
UpdateLayout(window, left, top, width, height);
for (int componentIndex = 0, componentCount = int(m_components.size()); componentIndex < componentCount; ++componentIndex)
{
IUIComponent* component = m_components[componentIndex].component;
component->CreateUI(window, m_components[componentIndex].left, m_components[componentIndex].top, m_components[componentIndex].width, m_components[componentIndex].height);
}
}
void Layout::Resize(void* window, int left, int top, int width, int height)
{
UpdateLayout(window, left, top, width, height);
for (int componentIndex = 0, componentCount = int(m_components.size()); componentIndex < componentCount; ++componentIndex)
{
IUIComponent* component = m_components[componentIndex].component;
component->Resize(window, m_components[componentIndex].left, m_components[componentIndex].top, m_components[componentIndex].width, m_components[componentIndex].height);
}
}
void Layout::DestroyUI(void* window)
{
for (int componentIndex = 0, componentCount = int(m_components.size()); componentIndex < componentCount; ++componentIndex)
{
IUIComponent* component = m_components[componentIndex].component;
component->DestroyUI(window);
}
}
void Layout::GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight)
{
int minW = 0;
int maxW = 0;
int minH = 0;
int maxH = 0;
for (int componentIndex = 0, componentCount = int(m_components.size()); componentIndex < componentCount; ++componentIndex)
{
IUIComponent* component = m_components[componentIndex].component;
int compMinW, compMaxW, compMinH, compMaxH;
component->GetExtremeDimensions(window, compMinW, compMaxW, compMinH, compMaxH);
switch (m_direction)
{
case DirectionVertical:
minW = (minW > compMinW ? minW : compMinW);
maxW = (maxW > compMaxW ? maxW : compMaxW); // Deliberately take the larger maximum.
minH += compMinH;
maxH += compMaxH;
break;
case DirectionHorizontal:
minW += compMinW;
maxW += compMaxW;
minH = (minH > compMinH ? minH : compMinH);
maxH = (maxH > compMaxH ? maxH : compMaxH); // Deliberately take the larger maximum.
break;
}
}
// Make sure the window is at least a certain size;
minW = (minW >= 10 ? minW : 10);
maxW = (maxW >= minW ? maxW : minW);
minH = (minH >= 10 ? minH : 10);
maxH = (maxH >= minH ? maxH : minH);
minWidth = minW;
maxWidth = maxW;
minHeight = minH;
maxHeight = maxH;
}
void Layout::UpdateLayout(void* window, int left, int top, int width, int height)
{
assert(window);
int remainingToAllocate;
switch (m_direction)
{
case DirectionVertical:
remainingToAllocate = height;
break;
case DirectionHorizontal:
remainingToAllocate = width;
break;
}
int smallestAllocationAmount = INT_MAX;
int canBeExtendedCount = 0;
for (int componentIndex = 0, componentCount = int(m_components.size()); componentIndex < componentCount; ++componentIndex)
{
IUIComponent* component = m_components[componentIndex].component;
int compMinW, compMaxW, compMinH, compMaxH;
component->GetExtremeDimensions(window, compMinW, compMaxW, compMinH, compMaxH);
switch (m_direction)
{
case DirectionVertical:
{
int allocationAmount = compMaxH - compMinH;
if (allocationAmount > 0)
{
++canBeExtendedCount;
smallestAllocationAmount = (smallestAllocationAmount < allocationAmount ? smallestAllocationAmount : allocationAmount);
}
m_components[componentIndex].height = compMinH;
m_components[componentIndex].width = (width > compMaxW ? compMaxW : width);
remainingToAllocate -= m_components[componentIndex].height;
}
break;
case DirectionHorizontal:
{
int allocationAmount = compMaxW - compMinW;
if (allocationAmount > 0)
{
++canBeExtendedCount;
smallestAllocationAmount = (smallestAllocationAmount < allocationAmount ? smallestAllocationAmount : allocationAmount);
}
m_components[componentIndex].width = compMinW;
m_components[componentIndex].height = (height > compMaxH ? compMaxH : height);
remainingToAllocate -= m_components[componentIndex].width;
}
break;
}
}
while (remainingToAllocate > 0 && canBeExtendedCount > 0)
{
int equitablePerCompAllocation = remainingToAllocate / canBeExtendedCount;
int compAllocation = (equitablePerCompAllocation < smallestAllocationAmount ? equitablePerCompAllocation : smallestAllocationAmount);
compAllocation = (compAllocation > 0 ? compAllocation : 1);
canBeExtendedCount = 0;
smallestAllocationAmount = INT_MAX;
for (int componentIndex = 0, componentCount = int(m_components.size()); componentIndex < componentCount; ++componentIndex)
{
IUIComponent* component = m_components[componentIndex].component;
int compMinW, compMaxW, compMinH, compMaxH;
component->GetExtremeDimensions(window, compMinW, compMaxW, compMinH, compMaxH);
switch (m_direction)
{
case DirectionVertical:
{
int componentExpandAmount = compMaxH - m_components[componentIndex].height;
if (componentExpandAmount > 0)
{
m_components[componentIndex].height += compAllocation;
assert(m_components[componentIndex].height <= compMaxH);
componentExpandAmount -= compAllocation;
remainingToAllocate -= compAllocation;
if (componentExpandAmount > 0)
{
smallestAllocationAmount = (smallestAllocationAmount < componentExpandAmount ? smallestAllocationAmount : componentExpandAmount);
++canBeExtendedCount;
}
}
}
break;
case DirectionHorizontal:
{
int componentExpandAmount = compMaxW - m_components[componentIndex].width;
if (componentExpandAmount > 0)
{
m_components[componentIndex].width += compAllocation;
assert(m_components[componentIndex].width <= compMaxW);
componentExpandAmount -= compAllocation;
remainingToAllocate -= compAllocation;
if (componentExpandAmount > 0)
{
smallestAllocationAmount = (smallestAllocationAmount < componentExpandAmount ? smallestAllocationAmount : componentExpandAmount);
++canBeExtendedCount;
}
}
}
break;
}
}
}
switch (m_direction)
{
case DirectionVertical:
{
int posY = top;
for (int componentIndex = 0, componentCount = int(m_components.size()); componentIndex < componentCount; ++componentIndex)
{
m_components[componentIndex].left = left;
m_components[componentIndex].top = posY;
posY += m_components[componentIndex].height;
}
}
break;
case DirectionHorizontal:
{
int posX = left;
for (int componentIndex = 0, componentCount = int(m_components.size()); componentIndex < componentCount; ++componentIndex)
{
m_components[componentIndex].top = top;
m_components[componentIndex].left = posX;
posX += m_components[componentIndex].width;
}
}
break;
}
}
-61
View File
@@ -1,61 +0,0 @@
/*
* 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_UI_LAYOUT_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_LAYOUT_H
#pragma once
#include "IUIComponent.h"
#include <vector>
class Layout
: public IUIComponent
{
public:
enum Direction
{
DirectionHorizontal,
DirectionVertical
};
Layout(Direction direction);
void AddComponent(IUIComponent* component);
// IUIComponent
virtual void CreateUI(void* window, int left, int top, int width, int height);
virtual void Resize(void* window, int left, int top, int width, int height);
virtual void DestroyUI(void* window);
virtual void GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight);
private:
void UpdateLayout(void* window, int left, int top, int width, int height);
struct ComponentEntry
{
explicit ComponentEntry(IUIComponent* component)
: component(component)
, left(0)
, top(0)
, width(0)
, height(0) {}
IUIComponent* component;
int left;
int top;
int width;
int height;
};
std::vector<ComponentEntry> m_components;
Direction m_direction;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_LAYOUT_H
-96
View File
@@ -1,96 +0,0 @@
/*
* 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 "ListView.h"
#include "Win32GUI.h"
#include "resource.h"
#include "ModuleHelpers.h"
#include <Windows.h>
#include <CommCtrl.h>
#include <cstring>
ListView::ListView()
: m_list(0)
{
}
void ListView::Add(int imageIndex, const TCHAR* message)
{
int itemCount = int(SendMessage((HWND)m_list, LVM_GETITEMCOUNT, 0, 0));
LVITEM item;
std::memset(&item, 0, sizeof(item));
item.mask = LVIF_TEXT | LVIF_IMAGE;
item.iItem = itemCount;
item.iSubItem = 0;
item.pszText = (TCHAR*)message;
item.iImage = imageIndex;
SendMessage((HWND)m_list, LVM_INSERTITEM, 0, (LPARAM)&item);
}
void ListView::Clear()
{
SendMessage((HWND)m_list, LVM_DELETEALLITEMS, 0, 0);
}
void ListView::CreateUI(void* window, int left, int top, int width, int height)
{
m_list = Win32GUI::CreateControl(WC_LISTVIEW, LVS_REPORT | LVS_NOCOLUMNHEADER, (HWND)window, left, top, width, height);
LVCOLUMN column;
std::memset(&column, 0, sizeof(column));
column.mask = LVCF_TEXT | LVCF_WIDTH;
column.pszText = _T("Message");
column.cx = width;
SendMessage((HWND)m_list, LVM_INSERTCOLUMN, 0, (LPARAM)&column);
HIMAGELIST imageList = (HIMAGELIST)CreateImageList();
SendMessage((HWND)m_list, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)imageList);
}
void ListView::Resize(void* window, int left, int top, int width, int height)
{
MoveWindow((HWND)m_list, left, top, width, height, true);
SendMessage((HWND)m_list, LVM_SETCOLUMNWIDTH, 0, width);
}
void ListView::DestroyUI(void* window)
{
DestroyWindow((HWND)m_list);
m_list = 0;
}
void ListView::GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight)
{
minWidth = 20;
maxWidth = 2000;
minHeight = 20;
maxHeight = 2000;
}
void* ListView::CreateImageList()
{
HINSTANCE instance = ModuleHelpers::GetCurrentModule(ModuleHelpers::CurrentModuleSpecifier_Library);
HBITMAP image = (HBITMAP)LoadImage(instance, MAKEINTRESOURCE(IDB_LOG_ICONS), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
DIBSECTION dibSection;
GetObject(image, sizeof(dibSection), &dibSection);
int height = dibSection.dsBmih.biHeight;
int width = height;
int count = dibSection.dsBmih.biWidth / width;
HIMAGELIST imageList = ImageList_Create(16, 16, ILC_COLOR32, count, 0);
ImageList_Add(imageList, image, 0);
return imageList;
}
-42
View File
@@ -1,42 +0,0 @@
/*
* 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_UI_LISTVIEW_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_LISTVIEW_H
#pragma once
#include "IUIComponent.h"
class ListView
: public IUIComponent
{
public:
ListView();
void Add(int imageIndex, const TCHAR* message);
void Clear();
// IUIComponent
virtual void CreateUI(void* window, int left, int top, int width, int height);
virtual void Resize(void* window, int left, int top, int width, int height);
virtual void DestroyUI(void* window);
virtual void GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight);
private:
void* CreateImageList();
void* m_list;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_LISTVIEW_H
-158
View File
@@ -1,158 +0,0 @@
/*
* 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 "LogWindow.h"
LogWindow::LogWindow()
: m_mainLayout(Layout::DirectionVertical)
, m_toolbarLayout(Layout::DirectionHorizontal)
, m_filterFlags(0)
{
m_buttons.push_back(new ToggleButton(_T("Debug"), this, &LogWindow::DebugToggled));
m_buttons.push_back(new ToggleButton(_T("Info"), this, &LogWindow::InfoToggled));
m_buttons.push_back(new ToggleButton(_T("Warnings"), this, &LogWindow::WarningsToggled));
m_buttons.push_back(new ToggleButton(_T("Errors"), this, &LogWindow::ErrorsToggled));
SetFilter(ILogger::eSeverity_Error, true);
SetFilter(ILogger::eSeverity_Warning, true);
SetFilter(ILogger::eSeverity_Info, true);
SetFilter(ILogger::eSeverity_Debug, false);
m_toolbarLayout.AddComponent(m_buttons[3]);
m_toolbarLayout.AddComponent(m_buttons[2]);
m_toolbarLayout.AddComponent(m_buttons[1]);
m_toolbarLayout.AddComponent(m_buttons[0]);
m_mainLayout.AddComponent(&m_toolbarLayout);
m_mainLayout.AddComponent(&m_list);
}
LogWindow::~LogWindow()
{
for (std::vector<ToggleButton*>::iterator button = m_buttons.begin(), end = m_buttons.end(); button != end; ++button)
{
delete *button;
}
}
void LogWindow::Log(ILogger::ESeverity eSeverity, const TCHAR* message)
{
m_messages.push_back(LogMessage(eSeverity, message));
if (m_filterFlags & (1 << GetSeverityIndex(eSeverity)))
{
m_list.Add(GetImageIndex(eSeverity), message);
}
}
void LogWindow::SetFilter(ILogger::ESeverity eSeverity, bool visible)
{
int index = GetSeverityIndex(eSeverity);
if (visible)
{
m_filterFlags |= (1 << index);
}
else
{
m_filterFlags &= ~(1 << index);
}
m_buttons[index]->SetState(visible);
RefillList();
}
void LogWindow::CreateUI(void* window, int left, int top, int width, int height)
{
m_mainLayout.CreateUI(window, left, top, width, height);
}
void LogWindow::Resize(void* window, int left, int top, int width, int height)
{
m_mainLayout.Resize(window, left, top, width, height);
}
void LogWindow::DestroyUI(void* window)
{
m_mainLayout.DestroyUI(window);
}
void LogWindow::GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight)
{
m_mainLayout.GetExtremeDimensions(window, minWidth, maxWidth, minHeight, maxHeight);
}
void LogWindow::ErrorsToggled(bool value)
{
SetFilter(ILogger::eSeverity_Error, value);
}
void LogWindow::WarningsToggled(bool value)
{
SetFilter(ILogger::eSeverity_Warning, value);
}
void LogWindow::InfoToggled(bool value)
{
SetFilter(ILogger::eSeverity_Info, value);
}
void LogWindow::DebugToggled(bool value)
{
SetFilter(ILogger::eSeverity_Debug, value);
}
void LogWindow::RefillList()
{
m_list.Clear();
for (int messageIndex = 0, messageCount = int(m_messages.size()); messageIndex < messageCount; ++messageIndex)
{
if (m_filterFlags & (1 << m_messages[messageIndex].severity))
{
m_list.Add(GetImageIndex(m_messages[messageIndex].severity), m_messages[messageIndex].message.c_str());
}
}
}
int LogWindow::GetImageIndex(ILogger::ESeverity eSeverity)
{
switch (eSeverity)
{
case ILogger::eSeverity_Debug:
return 2;
case ILogger::eSeverity_Info:
return -1;
case ILogger::eSeverity_Warning:
return 1;
case ILogger::eSeverity_Error:
return 0;
default:
return 0;
}
}
int LogWindow::GetSeverityIndex(ILogger::ESeverity eSeverity)
{
switch (eSeverity)
{
case ILogger::eSeverity_Debug:
return 0;
case ILogger::eSeverity_Info:
return 1;
case ILogger::eSeverity_Warning:
return 2;
case ILogger::eSeverity_Error:
return 3;
default:
return 3;
}
}
-71
View File
@@ -1,71 +0,0 @@
/*
* 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_UI_LOGWINDOW_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_LOGWINDOW_H
#pragma once
#include "IUIComponent.h"
#include "Layout.h"
#include "ListView.h"
#include "ToggleButton.h"
#include <list>
#include "ILogger.h"
class LogWindow
: public IUIComponent
{
public:
LogWindow();
~LogWindow();
void Log(ILogger::ESeverity eSeverity, const TCHAR* message);
void SetFilter(ILogger::ESeverity eSeverity, bool visible);
// IUIComponent
virtual void CreateUI(void* window, int left, int top, int width, int height);
virtual void Resize(void* window, int left, int top, int width, int height);
virtual void DestroyUI(void* window);
virtual void GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight);
private:
struct LogMessage
{
LogMessage(ILogger::ESeverity severity, tstring message)
: severity(severity)
, message(message)
{
}
ILogger::ESeverity severity;
tstring message;
};
void ErrorsToggled(bool value);
void WarningsToggled(bool value);
void InfoToggled(bool value);
void DebugToggled(bool value);
void RefillList();
static int GetImageIndex(ILogger::ESeverity eSeverity);
static int GetSeverityIndex(ILogger::ESeverity eSeverity);
Layout m_mainLayout;
Layout m_toolbarLayout;
ListView m_list;
std::vector<ToggleButton*> m_buttons;
std::vector<LogMessage> m_messages;
unsigned m_filterFlags;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_LOGWINDOW_H
@@ -1,65 +0,0 @@
/*
* 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 "ProgressBar.h"
#include <Windows.h>
#include <CommCtrl.h>
ProgressBar::ProgressBar()
: m_progressBar(0)
{
}
void ProgressBar::CreateUI(void* window, int left, int top, int width, int height)
{
m_progressBar = CreateWindowEx(
0,
PROGRESS_CLASS,
0,
WS_CHILD | WS_VISIBLE,
left,
top,
width,
height,
(HWND)window,
(HMENU)0,
GetModuleHandle(0),
0);
SendMessage((HWND)m_progressBar, PBM_SETRANGE, 0, MAKELPARAM(0, 1000));
SendMessage((HWND)m_progressBar, PBM_SETSTEP, (WPARAM) 1, 0);
}
void ProgressBar::Resize(void* window, int left, int top, int width, int height)
{
MoveWindow((HWND)m_progressBar, left, top, width, height, true);
}
void ProgressBar::DestroyUI(void* window)
{
DestroyWindow((HWND)m_progressBar);
}
void ProgressBar::GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight)
{
minWidth = 200;
maxWidth = 2000;
minHeight = 30;
maxHeight = 30;
}
void ProgressBar::SetProgress(float progress)
{
int newPos = int(progress * 1000.0f);
SendMessage((HWND)m_progressBar, PBM_SETPOS, newPos, 0);
}
@@ -1,39 +0,0 @@
/*
* 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_UI_PROGRESSBAR_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_PROGRESSBAR_H
#pragma once
#include "IUIComponent.h"
class ProgressBar
: public IUIComponent
{
public:
ProgressBar();
void SetProgress(float progress);
// IUIComponent
virtual void CreateUI(void* window, int left, int top, int width, int height);
virtual void Resize(void* window, int left, int top, int width, int height);
virtual void DestroyUI(void* window);
virtual void GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight);
private:
void* m_progressBar;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_PROGRESSBAR_H
@@ -1,64 +0,0 @@
/*
* 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 "PushButton.h"
#include "Win32GUI.h"
PushButton::~PushButton()
{
m_callback->Release();
}
void PushButton::Enable(bool enabled)
{
m_enabled = enabled;
EnableWindow((HWND)m_button, m_enabled);
}
void PushButton::CreateUI(void* window, int left, int top, int width, int height)
{
m_button = Win32GUI::CreateControl(_T("BUTTON"), WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, (HWND)window, left, top, 40, 20);
m_font = Win32GUI::CreateFont();
SendMessage((HWND)m_button, WM_SETFONT, (WPARAM)m_font, 0);
SendMessage((HWND)m_button, WM_SETTEXT, 0, (LPARAM)m_text.c_str());
EnableWindow((HWND)m_button, m_enabled);
Win32GUI::SetCallback<Win32GUI::EventCallbacks::Pushed, PushButton>((HWND)m_button, this, &PushButton::OnPushed);
}
void PushButton::Resize(void* window, int left, int top, int width, int height)
{
MoveWindow((HWND)m_button, left, top, width, height, true);
}
void PushButton::DestroyUI(void* window)
{
DestroyWindow((HWND)m_button);
m_button = 0;
DeleteObject(m_font);
m_font = 0;
}
void PushButton::GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight)
{
minWidth = 50;
maxWidth = 50;
minHeight = 20;
maxHeight = 20;
}
void PushButton::OnPushed()
{
m_callback->Call();
}
-78
View File
@@ -1,78 +0,0 @@
/*
* 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_UI_PUSHBUTTON_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_PUSHBUTTON_H
#pragma once
#include "IUIComponent.h"
#include <string>
class PushButton
: public IUIComponent
{
public:
template <typename T>
PushButton(const TCHAR* text, T* object, void (T::* method)());
~PushButton();
void Enable(bool enabled);
// IUIComponent
virtual void CreateUI(void* window, int left, int top, int width, int height);
virtual void Resize(void* window, int left, int top, int width, int height);
virtual void DestroyUI(void* window);
virtual void GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight);
private:
PushButton(const PushButton&);
PushButton& operator=(const PushButton&);
struct ICallback
{
virtual void Release() = 0;
virtual void Call() = 0;
};
template <typename T>
struct Callback
: public ICallback
{
Callback(T* object, void (T::* method)())
: object(object)
, method(method) {}
virtual void Release() {delete this; }
virtual void Call() {(object->*method)(); }
T* object;
void (T::* method)();
};
void OnPushed();
std::basic_string<TCHAR> m_text;
void* m_button;
void* m_font;
ICallback* m_callback;
bool m_enabled;
};
template <typename T>
PushButton::PushButton(const TCHAR* text, T* object, void (T::* method)())
: m_text(text)
, m_callback(new Callback<T>(object, method))
, m_enabled(true)
{
}
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_PUSHBUTTON_H
-43
View File
@@ -1,43 +0,0 @@
/*
* 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 "Spacer.h"
Spacer::Spacer(int minWidth, int minHeight, int maxWidth, int maxHeight)
: m_minWidth(minWidth)
, m_minHeight(minHeight)
, m_maxWidth(maxWidth)
, m_maxHeight(maxHeight)
{
}
void Spacer::CreateUI(void* window, int left, int top, int width, int height)
{
}
void Spacer::Resize(void* window, int left, int top, int width, int height)
{
}
void Spacer::DestroyUI(void* window)
{
}
void Spacer::GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight)
{
minWidth = m_minWidth;
maxWidth = m_maxWidth;
minHeight = m_minHeight;
maxHeight = m_maxHeight;
}
-40
View File
@@ -1,40 +0,0 @@
/*
* 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_UI_SPACER_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_SPACER_H
#pragma once
#include "IUIComponent.h"
class Spacer
: public IUIComponent
{
public:
Spacer(int minWidth, int minHeight, int maxWidth, int maxHeight);
// IUIComponent
virtual void CreateUI(void* window, int left, int top, int width, int height);
virtual void Resize(void* window, int left, int top, int width, int height);
virtual void DestroyUI(void* window);
virtual void GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight);
private:
int m_minWidth;
int m_minHeight;
int m_maxWidth;
int m_maxHeight;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_SPACER_H
-148
View File
@@ -1,148 +0,0 @@
/*
* 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 "TaskList.h"
#include "Win32GUI.h"
#include <Windows.h>
#include <CommCtrl.h>
#include <Richedit.h>
#include <cstdlib>
TaskList::TaskList()
: m_edit(0)
{
}
void TaskList::AddTask(const std::string& id, const std::string description)
{
int taskIndex = int(m_tasks.size());
m_tasks.push_back(std::make_pair(id, description));
m_idTaskMap.insert(std::make_pair(id, taskIndex));
}
void TaskList::SetCurrentTask(const std::string& id)
{
SetText(id);
}
void TaskList::SetColor()
{
SendMessage((HWND)m_edit, EM_SETBKGNDCOLOR, 0, GetSysColor(COLOR_3DFACE));
}
void TaskList::SetText(const std::string& highlightedTask)
{
PARAFORMAT2 paragraphFormat;
std::memset(&paragraphFormat, 0, sizeof(paragraphFormat));
paragraphFormat.cbSize = sizeof(paragraphFormat);
paragraphFormat.dwMask = PFM_LINESPACING | PFM_SPACEBEFORE;
paragraphFormat.bLineSpacingRule = 5; // Specify spacing in 20ths of a line.
paragraphFormat.dyLineSpacing = 22;
paragraphFormat.dySpaceBefore = 70;
SendMessage((HWND)m_edit, EM_SETPARAFORMAT, 0, (LPARAM)&paragraphFormat);
CHARFORMAT format;
std::memset(&format, 0, sizeof(format));
format.cbSize = sizeof(format);
format.dwMask = CFM_BOLD;
format.dwEffects = 0;
SendMessage((HWND)m_edit, EM_SETCHARFORMAT, 0, (LPARAM)&format);
SETTEXTEX textEx;
std::memset(&textEx, 0, sizeof(textEx));
textEx.flags = ST_DEFAULT;
textEx.codepage = CP_ACP;
SendMessage((HWND)m_edit, EM_SETTEXTEX, (WPARAM)&textEx, (LPARAM)_T(""));
int highlightedLineStart = 0;
int highlightedLineEnd = 0;
for (std::vector<std::pair<std::string, std::string> >::const_iterator taskPos = m_tasks.begin(), taskEnd = m_tasks.end(); taskPos != taskEnd; ++taskPos)
{
textEx.flags = ST_SELECTION;
const std::string& id = (*taskPos).first;
const std::string& description = (*taskPos).second;
const char* margin = " ";
if (highlightedTask == id)
{
margin = "* ";
CHARRANGE range;
SendMessage((HWND)m_edit, EM_EXGETSEL, 0, (LPARAM)&range);
highlightedLineStart = range.cpMin;
}
SendMessageA((HWND)m_edit, EM_SETTEXTEX, (WPARAM)&textEx, (LPARAM)margin);
SendMessageA((HWND)m_edit, EM_SETTEXTEX, (WPARAM)&textEx, (LPARAM)description.c_str());
SendMessageA((HWND)m_edit, EM_SETTEXTEX, (WPARAM)&textEx, (LPARAM)"\n");
if (highlightedTask == id)
{
CHARRANGE range;
SendMessage((HWND)m_edit, EM_EXGETSEL, 0, (LPARAM)&range);
highlightedLineEnd = range.cpMin;
}
}
CHARRANGE range = {highlightedLineStart, highlightedLineEnd};
SendMessage((HWND)m_edit, EM_EXSETSEL, 0, (LPARAM)&range);
format.dwEffects = CFE_BOLD;
SendMessage((HWND)m_edit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
range.cpMin = 0;
range.cpMax = 0;
SendMessage((HWND)m_edit, EM_EXSETSEL, 0, (LPARAM)&range);
}
void TaskList::CreateUI(void* window, int left, int top, int width, int height)
{
// Create the window.
LoadLibrary(_T("Riched20.dll"));
m_edit = CreateWindowEx(
0, //DWORD dwExStyle,
RICHEDIT_CLASS, //LPCTSTR lpClassName,
0, //LPCTSTR lpWindowName,
WS_CHILD | WS_VISIBLE | ES_LEFT | ES_MULTILINE | ES_READONLY, //DWORD dwStyle,
left, //int x,
top, //int y,
width, //int nWidth,
height, //int nHeight,
(HWND)window, //HWND hWndParent,
0, //HMENU hMenu,
GetModuleHandle(0), //HINSTANCE hInstance,
0); //LPVOID lpParam);
HFONT font = Win32GUI::CreateFont();
SendMessage((HWND)m_edit, WM_SETFONT, (WPARAM)font, 0);
DeleteObject(font);
SetColor();
SetText("");
}
void TaskList::Resize(void* window, int left, int top, int width, int height)
{
MoveWindow((HWND)m_edit, left, top, width, height, true);
}
void TaskList::DestroyUI(void* window)
{
DestroyWindow((HWND)m_edit);
m_edit = 0;
}
void TaskList::GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight)
{
minWidth = 10;
maxWidth = 2000;
int height = 25 * int(m_tasks.size());
minHeight = height;
maxHeight = height;
}
-48
View File
@@ -1,48 +0,0 @@
/*
* 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_UI_TASKLIST_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_TASKLIST_H
#pragma once
#include "IUIComponent.h"
#include <map>
#include <vector>
#include <string>
class TaskList
: public IUIComponent
{
public:
TaskList();
void AddTask(const std::string& id, const std::string description);
void SetCurrentTask(const std::string& id);
// IUIComponent
virtual void CreateUI(void* window, int left, int top, int width, int height);
virtual void Resize(void* window, int left, int top, int width, int height);
virtual void DestroyUI(void* window);
virtual void GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight);
private:
void SetColor();
void SetText(const std::string& highlightedTask);
std::map<std::string, int> m_idTaskMap;
std::vector<std::pair<std::string, std::string> > m_tasks;
void* m_edit;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_TASKLIST_H
@@ -1,65 +0,0 @@
/*
* 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 "ToggleButton.h"
#include "Win32GUI.h"
ToggleButton::~ToggleButton()
{
m_callback->Release();
}
void ToggleButton::SetState(bool state)
{
m_state = state;
SendMessage((HWND)m_button, BM_SETCHECK, m_state, 0);
}
void ToggleButton::CreateUI(void* window, int left, int top, int width, int height)
{
m_button = Win32GUI::CreateControl(_T("BUTTON"), WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX | BS_NOTIFY | BS_PUSHLIKE, (HWND)window, left, top, 40, 20);
m_font = Win32GUI::CreateFont();
SendMessage((HWND)m_button, WM_SETFONT, (WPARAM)m_font, 0);
SendMessage((HWND)m_button, WM_SETTEXT, 0, (LPARAM)m_text.c_str());
SendMessage((HWND)m_button, BM_SETCHECK, m_state, 0);
Win32GUI::SetCallback<Win32GUI::EventCallbacks::Checked, ToggleButton>((HWND)m_button, this, &ToggleButton::OnChecked);
}
void ToggleButton::Resize(void* window, int left, int top, int width, int height)
{
MoveWindow((HWND)m_button, left, top, width, height, true);
}
void ToggleButton::DestroyUI(void* window)
{
DestroyWindow((HWND)m_button);
m_button = 0;
DeleteObject(m_font);
m_font = 0;
}
void ToggleButton::GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight)
{
minWidth = 50;
maxWidth = 50;
minHeight = 20;
maxHeight = 20;
}
void ToggleButton::OnChecked(bool checked)
{
m_state = checked;
m_callback->Call(checked);
}
@@ -1,78 +0,0 @@
/*
* 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_UI_TOGGLEBUTTON_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_TOGGLEBUTTON_H
#pragma once
#include "IUIComponent.h"
#include <string>
class ToggleButton
: public IUIComponent
{
public:
template <typename T>
ToggleButton(const TCHAR* text, T* object, void (T::* method)(bool value));
~ToggleButton();
void SetState(bool value);
// IUIComponent
virtual void CreateUI(void* window, int left, int top, int width, int height);
virtual void Resize(void* window, int left, int top, int width, int height);
virtual void DestroyUI(void* window);
virtual void GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight);
private:
ToggleButton(const ToggleButton&);
ToggleButton& operator=(const ToggleButton);
struct ICallback
{
virtual void Release() = 0;
virtual void Call(bool value) = 0;
};
template <typename T>
struct Callback
: public ICallback
{
Callback(T* object, void (T::* method)(bool value))
: object(object)
, method(method) {}
virtual void Release() {delete this; }
virtual void Call(bool value) {(object->*method)(value); }
T* object;
void (T::* method)(bool value);
};
void OnChecked(bool checked);
tstring m_text;
void* m_button;
void* m_font;
bool m_state;
ICallback* m_callback;
};
template <typename T>
ToggleButton::ToggleButton(const TCHAR* text, T* object, void (T::* method)(bool value))
: m_text(text)
, m_state(false)
, m_callback(new Callback<T>(object, method))
{
}
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_TOGGLEBUTTON_H
-390
View File
@@ -1,390 +0,0 @@
/*
* 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 "Win32GUI.h"
#include <cstdlib>
#include <cstring>
#include <string>
#include <map>
#include "commctrl.h"
#include "StringHelpers.h"
namespace Win32GUI
{
const int WM_REFLECT_BASE = WM_USER + 0x1c00;
const int WM_COMMAND_REFLECT = WM_REFLECT_BASE + WM_COMMAND;
const int WM_NOTIFY_REFLECT = WM_REFLECT_BASE + WM_NOTIFY;
class Window
{
public:
typedef LRESULT (Window::* WindowProcMethod)(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
Window(WindowProcMethod windowProc);
~Window();
static LRESULT CALLBACK StaticWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
LRESULT WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
LRESULT FrameWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
void Subclass(HWND window);
void Unsubclass(HWND window);
WNDPROC m_oldWndProc;
WindowProcMethod m_windowProc;
typedef std::multimap<unsigned, EventCallbacks::ICallback*> CallbackMap;
CallbackMap m_callbackMap;
};
}
void Win32GUI::Initialize()
{
InitCommonControls();
LoadLibrary(_T("riched20.dll"));
}
void Win32GUI::RegisterFrameClass(const TCHAR* name)
{
WNDCLASS cls;
std::memset(&cls, 0, sizeof(cls));
cls.style = 0;
cls.lpfnWndProc = &Window::StaticWindowProc;
cls.cbClsExtra = 0;
cls.cbWndExtra = 0;
cls.hInstance = GetModuleHandle(0);
cls.hIcon = 0;
cls.hCursor = LoadCursor(0, IDC_ARROW);
cls.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
cls.lpszMenuName = 0;
cls.lpszClassName = name;
RegisterClass(&cls);
}
HWND Win32GUI::CreateFrame(const TCHAR* className, unsigned style, int width, int height)
{
Window* window = new Window(&Window::FrameWindowProc);
HWND hwnd = CreateWindow(
className, // LPCTSTR lpClassName,
TEXT(""), // LPCTSTR lpWindowName,
style, // DWORD dwStyle,
CW_USEDEFAULT, // int x,
CW_USEDEFAULT, // int y,
width, // int nWidth,
height, // int nHeight,
0, // HWND hWndParent,
0, // HMENU hMenu,
GetModuleHandle(0), // HINSTANCE hInstance,
window); // LPVOID lpParam
return hwnd;
}
HWND Win32GUI::CreateControl(const TCHAR* className, unsigned style, HWND parent, int left, int top, int width, int height)
{
Window* window = new Window(&Window::WindowProc);
HWND hwnd = CreateWindow(
className, // LPCTSTR lpClassName,
0, // LPCTSTR lpWindowName,
style | WS_CHILD | WS_VISIBLE, // DWORD dwStyle,
left, // int x,
top, // int y,
width, // int nWidth,
height, // int nHeight,
parent, // HWND hWndParent,
0, // HMENU hMenu,
GetModuleHandle(0), // HINSTANCE hInstance,
0); // LPVOID lpParam
window->Subclass(hwnd);
return hwnd;
}
int Win32GUI::Run()
{
MSG msg;
BOOL status;
while ((status = GetMessage(&msg, HWND(0), UINT(0), UINT(0))) != 0)
{
if (status == -1)
{
return -1;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int)msg.wParam;
}
Win32GUI::Window::Window(WindowProcMethod windowProc)
: m_windowProc(windowProc)
, m_oldWndProc(0)
{
}
Win32GUI::Window::~Window()
{
for (CallbackMap::iterator callbackPos = m_callbackMap.begin(); callbackPos != m_callbackMap.end(); ++callbackPos)
{
(*callbackPos).second->Release();
}
}
LRESULT CALLBACK Win32GUI::Window::StaticWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
Window* window = 0;
{
if (uMsg == WM_CREATE)
{
CREATESTRUCT* create_struct = (CREATESTRUCT*)lParam;
window = (Window*)create_struct->lpCreateParams;
#if defined(_WIN64)
SetWindowLongPtr(hwnd, GWLP_USERDATA, LONG_PTR(window));
#else //defined(_WIN64)
SetWindowLong(hwnd, GWL_USERDATA, PtrToLong(window));
#endif //defined(_WIN64)
}
else
{
#if defined(_WIN64)
window = (Window*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
#else //defined(_WIN64)
window = (Window*)LongToPtr(GetWindowLong(hwnd, GWL_USERDATA));
#endif //defined(_WIN64)
}
}
LRESULT result = 0;
if (window)
{
result = (window->*(window->m_windowProc))(hwnd, uMsg, wParam, lParam);
}
else
{
result = DefWindowProc(hwnd, uMsg, wParam, lParam);
}
if (uMsg == WM_DESTROY)
{
delete window;
#if defined(_WIN64)
SetWindowLongPtr(hwnd, GWLP_USERDATA, 0);
#else //defined(_WIN64)
SetWindowLong(hwnd, GWL_USERDATA, 0);
#endif //defined(_WIN64)
}
return result;
}
LRESULT Win32GUI::Window::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND:
{
HWND control = (HWND)lParam;
if (control)
{
SendMessage(control, WM_COMMAND_REFLECT, wParam, lParam);
}
}
break;
case WM_NOTIFY:
{
NMHDR* notify_header = reinterpret_cast<NMHDR*>(lParam);
if (notify_header->hwndFrom)
{
SendMessage(notify_header->hwndFrom, WM_NOTIFY_REFLECT, wParam, lParam);
}
}
break;
case WM_COMMAND_REFLECT:
switch (HIWORD(wParam))
{
case EN_CHANGE:
{
std::string text = GetWindowString(hwnd);
std::pair<CallbackMap::iterator, CallbackMap::iterator> range = m_callbackMap.equal_range(EventCallbacks::TextChanged::ID);
for (CallbackMap::iterator callbackPos = range.first; callbackPos != range.second; ++callbackPos)
{
EventCallbacks::IStringCallback* callback = static_cast<EventCallbacks::IStringCallback*>((*callbackPos).second);
callback->Call(text);
}
}
break;
case BN_CLICKED:
{
if (GetWindowLong(hwnd, GWL_STYLE) & BS_CHECKBOX)
{
bool checked = (0 != SendMessage(hwnd, BM_GETCHECK, 0, 0));
std::pair<CallbackMap::iterator, CallbackMap::iterator> range = m_callbackMap.equal_range(EventCallbacks::Checked::ID);
for (CallbackMap::iterator callbackPos = range.first; callbackPos != range.second; ++callbackPos)
{
EventCallbacks::IBoolCallback* callback = static_cast<EventCallbacks::IBoolCallback*>((*callbackPos).second);
callback->Call(checked);
}
}
else
{
std::pair<CallbackMap::iterator, CallbackMap::iterator> range = m_callbackMap.equal_range(EventCallbacks::Pushed::ID);
for (CallbackMap::iterator callbackPos = range.first; callbackPos != range.second; ++callbackPos)
{
EventCallbacks::IVoidCallback* callback = static_cast<EventCallbacks::IVoidCallback*>((*callbackPos).second);
callback->Call();
}
}
}
break;
}
break;
case WM_GETMINMAXINFO:
{
int minW = 0, maxW = 0, minH = 100000, maxH = 100000;
std::pair<CallbackMap::iterator, CallbackMap::iterator> range = m_callbackMap.equal_range(EventCallbacks::GetDimensions::ID);
for (CallbackMap::iterator callbackPos = range.first; callbackPos != range.second; ++callbackPos)
{
EventCallbacks::IGetDimensionsCallback* callback = static_cast<EventCallbacks::IGetDimensionsCallback*>((*callbackPos).second);
callback->Call(minW, maxW, minH, maxH);
}
MINMAXINFO* minMaxInfo = (MINMAXINFO*)lParam;
minMaxInfo->ptMinTrackSize.x = minW;
minMaxInfo->ptMaxTrackSize.x = maxW;
minMaxInfo->ptMinTrackSize.y = minH;
minMaxInfo->ptMaxTrackSize.y = maxH;
}
break;
case WM_SIZE:
{
int width = LOWORD(lParam);
int height = HIWORD(lParam);
std::pair<CallbackMap::iterator, CallbackMap::iterator> range = m_callbackMap.equal_range(EventCallbacks::SizeChanged::ID);
for (CallbackMap::iterator callbackPos = range.first; callbackPos != range.second; ++callbackPos)
{
EventCallbacks::ISizeCallback* callback = static_cast<EventCallbacks::ISizeCallback*>((*callbackPos).second);
callback->Call(width, height);
}
}
break;
case WM_NOTIFY_REFLECT:
break;
}
LRESULT result = 0;
if (m_oldWndProc)
{
result = CallWindowProc(m_oldWndProc, hwnd, uMsg, wParam, lParam);
}
else
{
result = DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return result;
}
LRESULT Win32GUI::Window::FrameWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CLOSE:
PostQuitMessage(0);
break;
}
return WindowProc(hwnd, uMsg, wParam, lParam);
}
void Win32GUI::Window::Subclass(HWND window)
{
#if defined(_WIN64)
SetWindowLongPtr(window, GWLP_USERDATA, LONG_PTR(this));
m_oldWndProc = (WNDPROC)GetWindowLongPtr(window, GWLP_WNDPROC);
SetWindowLongPtr(window, GWLP_WNDPROC, LONG_PTR(&Window::StaticWindowProc));
#else //defined(_WIN64)
SetWindowLong(window, GWL_USERDATA, PtrToLong(this));
m_oldWndProc = (WNDPROC)LongToPtr(GetWindowLong(window, GWL_WNDPROC));
SetWindowLong(window, GWL_WNDPROC, PtrToLong(&Window::StaticWindowProc));
#endif //defined(_WIN64)
}
void Win32GUI::Window::Unsubclass(HWND window)
{
#if defined(_WIN64)
SetWindowLongPtr(window, GWLP_USERDATA, 0);
SetWindowLongPtr(window, GWLP_WNDPROC, LONG_PTR(m_oldWndProc));
#else //defined(_WIN64)
SetWindowLongPtr(window, GWL_USERDATA, 0);
SetWindowLong(window, GWLP_WNDPROC, PtrToLong(m_oldWndProc));
#endif //defined(_WIN64)
m_oldWndProc = 0;
}
std::string Win32GUI::GetWindowString(HWND hwnd)
{
LRESULT length = SendMessage(hwnd, WM_GETTEXTLENGTH, 0, 0);
std::wstring wtext(length, 0);
SendMessageW(hwnd, WM_GETTEXT, length + 1, (LPARAM)&wtext[0]);
return StringHelpers::ConvertUtf16ToAnsi(wtext.c_str(), '?');
}
void Win32GUI::SetWindowString(HWND hwnd, const std::string& text)
{
std::wstring wtext = StringHelpers::ConvertAnsiToUtf16(text.c_str());
SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)&wtext[0]);
}
HFONT Win32GUI::CreateFont()
{
HFONT hFont = 0;
HFONT hGuiFont = static_cast<HFONT>(::GetStockObject(DEFAULT_GUI_FONT));
LOGFONT lfGuiFont = { 0 };
if (::GetObject(hGuiFont, sizeof(LOGFONT), &lfGuiFont) == sizeof(LOGFONT))
{
_tcsncpy(lfGuiFont.lfFaceName, _T("MS Shell Dlg 2"), sizeof(lfGuiFont.lfFaceName) / sizeof(TCHAR));
lfGuiFont.lfFaceName[(sizeof(lfGuiFont.lfFaceName) / sizeof(TCHAR)) - 1] = '\0';
hFont = ::CreateFontIndirect(&lfGuiFont);
return hFont;
}
return 0;
}
void Win32GUI::SetCallbackObject(HWND hwnd, unsigned eventID, EventCallbacks::ICallback* callback)
{
#if defined(_WIN64)
Window* window = (Window*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
#else //defined(_WIN64)
Window* window = (Window*)LongToPtr(GetWindowLong(hwnd, GWL_USERDATA));
#endif //defined(_WIN64)
window->m_callbackMap.insert(std::make_pair(eventID, callback));
}
-216
View File
@@ -1,216 +0,0 @@
/*
* 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_UI_WIN32GUI_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_WIN32GUI_H
#pragma once
#include <Windows.h>
#include <string>
namespace Win32GUI
{
void Initialize();
void RegisterFrameClass(const TCHAR* name);
HWND CreateFrame(const TCHAR* className, unsigned style, int width, int height);
HWND CreateControl(const TCHAR* className, unsigned style, HWND parent, int left, int top, int width, int height);
int Run();
std::string GetWindowString(HWND hwnd);
void SetWindowString(HWND hwnd, const std::string& text);
HFONT CreateFont();
namespace EventCallbacks
{
class ICallback
{
public:
virtual ~ICallback() {}
virtual void Release() = 0;
};
struct IVoidCallback
: public ICallback
{
virtual void Call() = 0;
};
struct VoidCallback
{
template <typename O>
struct Callback
: public IVoidCallback
{
typedef void (O::* Signature)();
Callback(O* object, Signature method)
: m_object(object)
, m_method(method) {}
virtual void Release() {delete this; }
virtual void Call() {(m_object->*m_method)(); }
O* m_object;
Signature m_method;
};
};
struct IStringCallback
: public ICallback
{
virtual void Call(const std::string& text) = 0;
};
struct StringCallback
{
template <typename O>
struct Callback
: public IStringCallback
{
typedef void (O::* Signature)(const std::string& text);
Callback(O* object, Signature method)
: m_object(object)
, m_method(method) {}
virtual void Release() {delete this; }
virtual void Call(const std::string& text) {(m_object->*m_method)(text); }
O* m_object;
Signature m_method;
};
};
struct IGetDimensionsCallback
: public ICallback
{
virtual void Call(int& minW, int& maxW, int& minH, int& maxH) = 0;
};
struct GetDimensionsCallback
{
template <typename O>
struct Callback
: public IGetDimensionsCallback
{
typedef void (O::* Signature)(int& minW, int& maxW, int& minH, int& maxH);
Callback(O* object, Signature method)
: m_object(object)
, m_method(method) {}
virtual void Release() {delete this; }
virtual void Call(int& minW, int& maxW, int& minH, int& maxH) {(m_object->*m_method)(minW, maxW, minH, maxH); }
O* m_object;
Signature m_method;
};
};
struct ISizeCallback
: public ICallback
{
virtual void Call(int width, int height) = 0;
};
struct SizeCallback
{
template <typename O>
struct Callback
: public ISizeCallback
{
typedef void (O::* Signature)(int width, int height);
Callback(O* object, Signature method)
: m_object(object)
, m_method(method) {}
virtual void Release() {delete this; }
virtual void Call(int width, int height) {(m_object->*m_method)(width, height); }
O* m_object;
Signature m_method;
};
};
struct IBoolCallback
: public ICallback
{
virtual void Call(bool value) = 0;
};
struct BoolCallback
{
template <typename O>
struct Callback
: public IBoolCallback
{
typedef void (O::* Signature)(bool callback);
Callback(O* object, Signature method)
: m_object(object)
, m_method(method) {}
virtual void Release() {delete this; }
virtual void Call(bool value) {(m_object->*m_method)(value); }
O* m_object;
Signature m_method;
};
};
struct TextChanged
: public StringCallback
{
enum
{
ID = 0x00005001
};
};
struct GetDimensions
: public GetDimensionsCallback
{
enum
{
ID = 0x00005002
};
};
struct SizeChanged
: public SizeCallback
{
enum
{
ID = 0x00005003
};
};
struct Pushed
: public VoidCallback
{
enum
{
ID = 0x00005004
};
};
struct Checked
: public BoolCallback
{
enum
{
ID = 0x00005005
};
};
};
void SetCallbackObject(HWND hwnd, unsigned eventID, EventCallbacks::ICallback* callback);
template <typename T, typename O>
inline void SetCallback(HWND hwnd, O* object, typename T::template Callback<O>::Signature method);
}
template <typename T, typename O>
inline void Win32GUI::SetCallback(HWND hwnd, O* object, typename T::template Callback<O>::Signature method)
{
typedef T::template Callback<O> Callback;
Callback* callback = new Callback(object, method);
SetCallbackObject(hwnd, T::ID, callback);
}
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_WIN32GUI_H