-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/69-moho' into develop
- Loading branch information
Showing
9 changed files
with
161 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include "DatExporter.h" | ||
#include "animation/targetShapeSet.h" | ||
#include <boost/lexical_cast.hpp> | ||
|
||
using std::chrono::duration; | ||
using std::chrono::duration_cast; | ||
using std::string; | ||
|
||
DatExporter::DatExporter(const ShapeSet& targetShapeSet, double frameRate, bool convertToPrestonBlair) : | ||
frameRate(frameRate), | ||
convertToPrestonBlair(convertToPrestonBlair), | ||
prestonBlairShapeNames { | ||
{ Shape::A, "MBP" }, | ||
{ Shape::B, "etc" }, | ||
{ Shape::C, "E" }, | ||
{ Shape::D, "AI" }, | ||
{ Shape::E, "O" }, | ||
{ Shape::F, "U" }, | ||
{ Shape::G, "FV" }, | ||
{ Shape::H, "L" }, | ||
{ Shape::X, "rest" }, | ||
} | ||
{ | ||
// Animation works with a fixed frame rate of 100. | ||
// Downsampling to much less than 25 fps may result in dropped frames. | ||
// Upsampling to more than 100 fps doesn't make sense. | ||
const double minFrameRate = 24.0; | ||
const double maxFrameRate = 100.0; | ||
|
||
if (frameRate < minFrameRate || frameRate > maxFrameRate) { | ||
throw std::runtime_error(fmt::format("Frame rate must be between {} and {} fps.", minFrameRate, maxFrameRate)); | ||
} | ||
|
||
if (convertToPrestonBlair) { | ||
for (Shape shape : targetShapeSet) { | ||
if (prestonBlairShapeNames.find(shape) == prestonBlairShapeNames.end()) { | ||
throw std::runtime_error(fmt::format("Mouth shape {} cannot be converted to Preston Blair shape names.")); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void DatExporter::exportAnimation(const ExporterInput& input, std::ostream& outputStream) { | ||
outputStream << "MohoSwitch1" << "\n"; | ||
|
||
// Output shapes with start times | ||
int lastFrameNumber = 0; | ||
for (auto& timedShape : input.animation) { | ||
const int frameNumber = toFrameNumber(timedShape.getStart()); | ||
if (frameNumber == lastFrameNumber) continue; | ||
|
||
const string shapeName = toString(timedShape.getValue()); | ||
outputStream << frameNumber << " " << shapeName << "\n"; | ||
lastFrameNumber = frameNumber; | ||
} | ||
|
||
// Output closed mouth with end time | ||
int frameNumber = toFrameNumber(input.animation.getRange().getEnd()); | ||
if (frameNumber == lastFrameNumber) ++frameNumber; | ||
const string shapeName = toString(convertToTargetShapeSet(Shape::X, input.targetShapeSet)); | ||
outputStream << frameNumber << " " << shapeName << "\n"; | ||
} | ||
|
||
string DatExporter::toString(Shape shape) const { | ||
return convertToPrestonBlair | ||
? prestonBlairShapeNames.at(shape) | ||
: boost::lexical_cast<std::string>(shape); | ||
} | ||
|
||
int DatExporter::toFrameNumber(centiseconds time) const { | ||
return 1 + static_cast<int>(frameRate * duration_cast<duration<double>>(time).count()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include "Exporter.h" | ||
#include "core/Shape.h" | ||
#include <map> | ||
#include <string> | ||
|
||
// Exporter for Moho's switch data file format | ||
class DatExporter : public Exporter { | ||
public: | ||
DatExporter(const ShapeSet& targetShapeSet, double frameRate, bool convertToPrestonBlair); | ||
void exportAnimation(const ExporterInput& input, std::ostream& outputStream) override; | ||
|
||
private: | ||
int toFrameNumber(centiseconds time) const; | ||
std::string toString(Shape shape) const; | ||
|
||
double frameRate; | ||
bool convertToPrestonBlair; | ||
std::map<Shape, std::string> prestonBlairShapeNames; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
#include "tools/EnumConverter.h" | ||
|
||
enum class ExportFormat { | ||
Dat, | ||
Tsv, | ||
Xml, | ||
Json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters