forked from aya/aya
Initial commit
This commit is contained in:
131
engine/app/src/DataModel/CharacterMesh.cpp
Normal file
131
engine/app/src/DataModel/CharacterMesh.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
|
||||
|
||||
#include "DataModel/CharacterMesh.hpp"
|
||||
#include "Humanoid/Humanoid.hpp"
|
||||
|
||||
namespace Aya
|
||||
{
|
||||
|
||||
const char* const sCharacterMesh = "CharacterMesh";
|
||||
|
||||
|
||||
static const Reflection::EnumPropDescriptor<CharacterMesh, CharacterMesh::BodyPart> prop_bodyPart(
|
||||
"BodyPart", category_Data, &CharacterMesh::getBodyPart, &CharacterMesh::setBodyPart);
|
||||
Reflection::BoundProp<int64_t> CharacterMesh::prop_baseTextureAssetId("BaseTextureId", "Data", &CharacterMesh::baseTextureAssetId);
|
||||
Reflection::BoundProp<int64_t> CharacterMesh::prop_overlayTextureAssetId("OverlayTextureId", "Data", &CharacterMesh::overlayTextureAssetId);
|
||||
Reflection::BoundProp<int64_t> CharacterMesh::prop_meshAssetId("MeshId", "Data", &CharacterMesh::meshAssetId);
|
||||
REFLECTION_END();
|
||||
|
||||
namespace Reflection
|
||||
{
|
||||
template<>
|
||||
EnumDesc<CharacterMesh::BodyPart>::EnumDesc()
|
||||
: EnumDescriptor("BodyPart")
|
||||
|
||||
{
|
||||
addPair(CharacterMesh::HEAD, "Head");
|
||||
addPair(CharacterMesh::TORSO, "Torso");
|
||||
addPair(CharacterMesh::LEFTARM, "LeftArm");
|
||||
addPair(CharacterMesh::RIGHTARM, "RightArm");
|
||||
addPair(CharacterMesh::LEFTLEG, "LeftLeg");
|
||||
addPair(CharacterMesh::RIGHTLEG, "RightLeg");
|
||||
}
|
||||
template<>
|
||||
CharacterMesh::BodyPart& Variant::convert<CharacterMesh::BodyPart>(void)
|
||||
{
|
||||
return genericConvert<CharacterMesh::BodyPart>();
|
||||
}
|
||||
} // namespace Reflection
|
||||
|
||||
template<>
|
||||
bool StringConverter<CharacterMesh::BodyPart>::convertToValue(const std::string& text, CharacterMesh::BodyPart& value)
|
||||
{
|
||||
return Reflection::EnumDesc<CharacterMesh::BodyPart>::singleton().convertToValue(text.c_str(), value);
|
||||
}
|
||||
|
||||
CharacterMesh::CharacterMesh()
|
||||
: DescribedCreatable<CharacterMesh, CharacterAppearance, sCharacterMesh>()
|
||||
, bodyPart(HEAD)
|
||||
, baseTextureAssetId(0)
|
||||
, overlayTextureAssetId(0)
|
||||
, meshAssetId(0)
|
||||
{
|
||||
setName(sCharacterMesh);
|
||||
}
|
||||
|
||||
void CharacterMesh::onPropertyChanged(const Reflection::PropertyDescriptor& descriptor)
|
||||
{
|
||||
CharacterAppearance::apply();
|
||||
}
|
||||
|
||||
void CharacterMesh::setBodyPart(BodyPart value)
|
||||
{
|
||||
if (bodyPart != value)
|
||||
{
|
||||
bodyPart = value;
|
||||
|
||||
raisePropertyChanged(prop_bodyPart);
|
||||
}
|
||||
}
|
||||
|
||||
void CharacterMesh::applyByMyself(Humanoid* humanoid)
|
||||
{
|
||||
// re-using fireOutfitChanged. consider: own event.
|
||||
// right now, both end up doing the exact same thing, so reuse for now.
|
||||
if (PartInstance* leftLeg = humanoid->getLeftLegSlow())
|
||||
{
|
||||
leftLeg->fireOutfitChanged();
|
||||
}
|
||||
if (PartInstance* rightLeg = humanoid->getRightLegSlow())
|
||||
{
|
||||
rightLeg->fireOutfitChanged();
|
||||
}
|
||||
if (PartInstance* torso = humanoid->getTorsoSlow())
|
||||
{
|
||||
torso->fireOutfitChanged();
|
||||
}
|
||||
if (PartInstance* leftSleeve = humanoid->getLeftArmSlow())
|
||||
{
|
||||
leftSleeve->fireOutfitChanged();
|
||||
}
|
||||
if (PartInstance* rightSleeve = humanoid->getRightArmSlow())
|
||||
{
|
||||
rightSleeve->fireOutfitChanged();
|
||||
}
|
||||
}
|
||||
|
||||
TextureId CharacterMesh::getBaseTextureId() const
|
||||
{
|
||||
if (baseTextureAssetId != 0)
|
||||
{
|
||||
return TextureId(Aya::format("ayaassetid://%d", baseTextureAssetId));
|
||||
}
|
||||
else
|
||||
{
|
||||
return TextureId::nullTexture();
|
||||
}
|
||||
}
|
||||
TextureId CharacterMesh::getOverlayTextureId() const
|
||||
{
|
||||
if (overlayTextureAssetId != 0)
|
||||
{
|
||||
return TextureId(Aya::format("ayaassetid://%d", overlayTextureAssetId));
|
||||
}
|
||||
else
|
||||
{
|
||||
return TextureId::nullTexture();
|
||||
}
|
||||
}
|
||||
MeshId CharacterMesh::getMeshId() const
|
||||
{
|
||||
if (meshAssetId != 0)
|
||||
{
|
||||
return MeshId(Aya::format("ayaassetid://%d", meshAssetId));
|
||||
}
|
||||
else
|
||||
{
|
||||
return MeshId();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Aya
|
||||
Reference in New Issue
Block a user