Skip to content

Commit

Permalink
Updated morphing and other functions
Browse files Browse the repository at this point in the history
  • Loading branch information
expired6978 committed Aug 19, 2018
1 parent c398ee5 commit ac3cff2
Show file tree
Hide file tree
Showing 8 changed files with 3,530 additions and 227 deletions.
341 changes: 278 additions & 63 deletions skee/BodyMorphInterface.cpp

Large diffs are not rendered by default.

65 changes: 56 additions & 9 deletions skee/BodyMorphInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
#include "skse64/GameThreads.h"
#include "skse64/NiTypes.h"

#ifdef min
#undef min
#endif
#ifdef max
#undef max
#endif
#include "half.hpp"

#include <string>
#include <set>
#include <vector>
Expand Down Expand Up @@ -81,17 +89,25 @@ class TriShapePackedVertexDelta
SInt16 z;
};

class TriShapePackedUVDelta
{
public:
UInt16 index;
SInt16 u;
SInt16 v;
};

class TriShapeVertexData
{
public:
virtual void ApplyMorph(UInt16 vertCount, NiPoint3 * vertices, float factor) = 0;
virtual void ApplyMorph(UInt16 vertCount, void * vertices, float factor) = 0;
};
typedef std::shared_ptr<TriShapeVertexData> TriShapeVertexDataPtr;

class TriShapeFullVertexData : public TriShapeVertexData
{
public:
virtual void ApplyMorph(UInt16 vertCount, NiPoint3 * vertices, float factor);
virtual void ApplyMorph(UInt16 vertCount, void * vertices, float factor);

std::vector<TriShapeVertexDelta> m_vertexDeltas;
};
Expand All @@ -100,19 +116,43 @@ typedef std::shared_ptr<TriShapeFullVertexData> TriShapeFullVertexDataPtr;
class TriShapePackedVertexData : public TriShapeVertexData
{
public:
virtual void ApplyMorph(UInt16 vertCount, NiPoint3 * vertices, float factor);
virtual void ApplyMorph(UInt16 vertCount, void * vertices, float factor);

float m_multiplier;
std::vector<TriShapePackedVertexDelta> m_vertexDeltas;
};
typedef std::shared_ptr<TriShapePackedVertexData> TriShapePackedVertexDataPtr;

class TriShapePackedUVData : public TriShapeVertexData
{
public:
struct UVCoord
{
half_float::half u;
half_float::half v;
};

virtual void ApplyMorph(UInt16 vertCount, void * vertices, float factor);

float m_multiplier;
std::vector<TriShapePackedUVDelta> m_uvDeltas;
};
typedef std::shared_ptr<TriShapePackedUVData> TriShapePackedUVDataPtr;


class BodyMorphMap : public std::unordered_map<BSFixedString, TriShapeVertexDataPtr>
class BodyMorphMap : public std::unordered_map<BSFixedString, std::pair<TriShapeVertexDataPtr, TriShapeVertexDataPtr>>
{
friend class MorphCache;
public:
void ApplyMorphs(TESObjectREFR * refr, UInt16 vertexCount, NiPoint3* targetGeometry, NiPoint3 * storageGeometry) const;
BodyMorphMap() : m_hasUV(false) { }

void ApplyMorphs(TESObjectREFR * refr, std::function<void(const TriShapeVertexDataPtr, float)> vertexFunctor, std::function<void(const TriShapeVertexDataPtr, float)> uvFunctor) const;
bool HasMorphs(TESObjectREFR * refr) const;

bool HasUV() const { return m_hasUV; }

private:
bool m_hasUV;
};

class TriShapeMap : public std::unordered_map<BSFixedString, BodyMorphMap>
Expand All @@ -121,18 +161,25 @@ class TriShapeMap : public std::unordered_map<BSFixedString, BodyMorphMap>
TriShapeMap()
{
memoryUsage = sizeof(TriShapeMap);
accessed = 0;
}

UInt32 memoryUsage;
};

class MorphFileCache
{
friend class MorphCache;
friend class BodyMorphInterface;
public:
void ApplyMorphs(TESObjectREFR * refr, NiAVObject * rootNode, bool erase = false);
void ApplyMorph(TESObjectREFR * refr, NiAVObject * rootNode, bool erase, const std::pair<BSFixedString, BodyMorphMap> & bodyMorph);

UInt32 memoryUsage;
private:
TriShapeMap vertexMap;
std::time_t accessed;
};


class MorphCache : public SafeDataHolder<std::unordered_map<BSFixedString, TriShapeMap>>
class MorphCache : public SafeDataHolder<std::unordered_map<BSFixedString, MorphFileCache>>
{
friend class BodyMorphInterface;

Expand Down
8 changes: 4 additions & 4 deletions skee/FileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ TESRace * GetRaceByName(std::string & raceName)
if (dataHandler->races.GetNthItem(i, race)) {
BSFixedString raceStrName(raceName.c_str());
if (race->editorId == raceStrName) {
CALL_MEMBER_FN(&raceStrName, Release)();
raceStrName.Release();
return race;
}
CALL_MEMBER_FN(&raceStrName, Release)();
raceStrName.Release();
}
}
}
Expand All @@ -102,10 +102,10 @@ BGSHeadPart * GetHeadPartByName(std::string & headPartName)
if (dataHandler->headParts.GetNthItem(i, headPart)) {
BSFixedString partName(headPartName.c_str());
if (headPart->partName == partName) {
CALL_MEMBER_FN(&partName, Release)();
partName.Release();
return headPart;
}
CALL_MEMBER_FN(&partName, Release)();
partName.Release();
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions skee/OverlayInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ void OverlayInterface::InstallOverlay(const char * nodeName, const char * path,
{
NiNode * rootNode = NULL;
NiAVObject * newShape = NULL;
NiPropertyPtr alphaProperty = nullptr;
NiPropertyPtr shaderProperty = nullptr;
NiPropertyPtr alphaProperty;
NiPropertyPtr shaderProperty;

UInt8 niStreamMemory[sizeof(NiStream)];
memset(niStreamMemory, 0, sizeof(NiStream));
Expand All @@ -86,7 +86,7 @@ void OverlayInterface::InstallOverlay(const char * nodeName, const char * path,
BSFixedString overlayName(nodeName);
NiAVObject * foundGeometry = destination->GetObjectByName(&overlayName.data);
if (foundGeometry)
newShape = foundGeometry->GetAsNiGeometry();
newShape = foundGeometry->GetAsBSGeometry();

bool attachNew = false;
if(!newShape)
Expand Down Expand Up @@ -128,8 +128,11 @@ void OverlayInterface::InstallOverlay(const char * nodeName, const char * path,
if(targetShape)
{
targetShape->unk148 = source->unk148;
targetShape->m_spEffectState = shaderProperty;
targetShape->m_spPropertyState = alphaProperty;

if (shaderProperty)
targetShape->m_spEffectState = shaderProperty;
if (alphaProperty)
targetShape->m_spPropertyState = alphaProperty;

targetShape->m_localTransform = source->m_localTransform;
targetShape->m_spSkinInstance = source->m_spSkinInstance;
Expand Down
Loading

0 comments on commit ac3cff2

Please sign in to comment.