Skip to content

Commit

Permalink
RM 0.3.0 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
expired6978 committed Jan 16, 2019
1 parent 37a4e4c commit 58f565e
Show file tree
Hide file tree
Showing 69 changed files with 3,502 additions and 8,799 deletions.
78 changes: 39 additions & 39 deletions skee/BodyMorphInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,16 +304,16 @@ void TriShapeFullVertexData::ApplyMorphRaw(UInt16 vertCount, void * data, float
}
}

void TriShapeFullVertexData::ApplyMorph(UInt16 vertexCount, NiSkinPartition::TriShape * vertexData, float factor)
void TriShapeFullVertexData::ApplyMorph(UInt16 vertexCount, Layout * vertexData, float factor)
{
UInt32 offset = NiSkinPartition::GetVertexAttributeOffset(vertexData->m_VertexDesc, VertexAttribute::VA_POSITION);
UInt32 vertexSize = NiSkinPartition::GetVertexSize(vertexData->m_VertexDesc);
UInt32 offset = NiSkinPartition::GetVertexAttributeOffset(vertexData->vertexDesc, VertexAttribute::VA_POSITION);
UInt32 vertexSize = NiSkinPartition::GetVertexSize(vertexData->vertexDesc);

if (m_maxIndex < vertexCount)
{
for (const auto & vert : m_vertexDeltas)
{
DirectX::XMFLOAT4 * position = reinterpret_cast<DirectX::XMFLOAT4*>(&vertexData->m_RawVertexData[vertexSize * vert.index + offset]);
DirectX::XMFLOAT4 * position = reinterpret_cast<DirectX::XMFLOAT4*>(&vertexData->vertexData[vertexSize * vert.index + offset]);
DirectX::XMStoreFloat4(position, DirectX::XMVectorAdd(DirectX::XMLoadFloat4(position), DirectX::XMVectorScale(vert.delta, factor)));
}
}
Expand Down Expand Up @@ -345,16 +345,16 @@ void TriShapePackedVertexData::ApplyMorphRaw(UInt16 vertCount, void * data, floa
}
}

void TriShapePackedVertexData::ApplyMorph(UInt16 vertexCount, NiSkinPartition::TriShape * vertexData, float factor)
void TriShapePackedVertexData::ApplyMorph(UInt16 vertexCount, Layout * vertexData, float factor)
{
UInt32 vertexSize = NiSkinPartition::GetVertexSize(vertexData->m_VertexDesc);
UInt32 offset = NiSkinPartition::GetVertexAttributeOffset(vertexData->m_VertexDesc, VertexAttribute::VA_POSITION);
UInt32 vertexSize = NiSkinPartition::GetVertexSize(vertexData->vertexDesc);
UInt32 offset = NiSkinPartition::GetVertexAttributeOffset(vertexData->vertexDesc, VertexAttribute::VA_POSITION);

if (m_maxIndex < vertexCount)
{
for (const auto & vert : m_vertexDeltas)
{
DirectX::XMFLOAT4 * position = reinterpret_cast<DirectX::XMFLOAT4*>(&vertexData->m_RawVertexData[vertexSize * vert.index + offset]);
DirectX::XMFLOAT4 * position = reinterpret_cast<DirectX::XMFLOAT4*>(&vertexData->vertexData[vertexSize * vert.index + offset]);
DirectX::XMStoreFloat4(position, DirectX::XMVectorAdd(DirectX::XMLoadFloat4(position), DirectX::XMVectorScale(vert.delta, factor)));
}
}
Expand Down Expand Up @@ -385,18 +385,18 @@ void TriShapePackedUVData::ApplyMorphRaw(UInt16 vertCount, void * data, float fa
}
}

void TriShapePackedUVData::ApplyMorph(UInt16 vertexCount, NiSkinPartition::TriShape * vertexData, float factor)
void TriShapePackedUVData::ApplyMorph(UInt16 vertexCount, Layout * vertexData, float factor)
{
VertexFlags flags = NiSkinPartition::GetVertexFlags(vertexData->m_VertexDesc);
VertexFlags flags = NiSkinPartition::GetVertexFlags(vertexData->vertexDesc);
if ((flags & VF_UV))
{
UInt32 vertexSize = NiSkinPartition::GetVertexSize(vertexData->m_VertexDesc);
UInt32 offset = NiSkinPartition::GetVertexAttributeOffset(vertexData->m_VertexDesc, VertexAttribute::VA_TEXCOORD0);
UInt32 vertexSize = NiSkinPartition::GetVertexSize(vertexData->vertexDesc);
UInt32 offset = NiSkinPartition::GetVertexAttributeOffset(vertexData->vertexDesc, VertexAttribute::VA_TEXCOORD0);
if (m_maxIndex < vertexCount)
{
for (const auto & delta : m_uvDeltas)
{
UVCoord * texCoord = reinterpret_cast<UVCoord*>(&vertexData->m_RawVertexData[vertexSize * delta.index + offset]);
UVCoord * texCoord = reinterpret_cast<UVCoord*>(&vertexData->vertexData[vertexSize * delta.index + offset]);
texCoord->u += (float)delta.u * m_multiplier * factor;
texCoord->v += (float)delta.v * m_multiplier * factor;
}
Expand Down Expand Up @@ -599,20 +599,23 @@ void MorphFileCache::ApplyMorph(TESObjectREFR * refr, NiAVObject * rootNode, boo
auto & partition = newSkinPartition->m_pkPartitions[0];
UInt32 vertexSize = newSkinPartition->GetVertexSize(partition.vertexDesc);
UInt32 vertexCount = newSkinPartition->vertexCount;
TriShapeVertexData::Layout layout;
layout.vertexDesc = partition.shapeData->m_VertexDesc;
layout.vertexData = partition.shapeData->m_RawVertexData;

std::function<void(const TriShapeVertexDataPtr, float)> vertexMorpher = [&](const TriShapeVertexDataPtr morphData, float morphFactor)
{
if (morphFactor != 0.0f)
{
morphData->ApplyMorph(vertexCount, partition.shapeData, morphFactor);
morphData->ApplyMorph(vertexCount, &layout, morphFactor);
}
};

std::function<void(const TriShapeVertexDataPtr, float)> uvMorpher = [&](const TriShapeVertexDataPtr morphData, float morphFactor)
{
if (morphFactor != 0.0f)
{
morphData->ApplyMorph(vertexCount, partition.shapeData, morphFactor);
morphData->ApplyMorph(vertexCount, &layout, morphFactor);
}
};

Expand All @@ -626,12 +629,11 @@ void MorphFileCache::ApplyMorph(TESObjectREFR * refr, NiAVObject * rootNode, boo
memcpy(pPartition.shapeData->m_RawVertexData, partition.shapeData->m_RawVertexData, newSkinPartition->vertexCount * vertexSize);
}

skinInstance->m_spSkinPartition = newSkinPartition;
newSkinPartition->DecRef(); // DeepCopy started refcount at 1

if (mutex) mutex->lock();

auto updateTask = new NIOVTaskUpdateSkinPartition(newSkinPartition);
auto updateTask = new NIOVTaskUpdateSkinPartition(skinInstance, newSkinPartition);
newSkinPartition->DecRef(); // DeepCopy started refcount at 1, passed ownership to the task

if (deferred)
{
g_task->AddTask(updateTask);
Expand Down Expand Up @@ -1180,8 +1182,9 @@ void NIOVTaskUpdateModelWeight::Run()
}
}

NIOVTaskUpdateSkinPartition::NIOVTaskUpdateSkinPartition(NiSkinPartition * partition)
NIOVTaskUpdateSkinPartition::NIOVTaskUpdateSkinPartition(NiSkinInstance * skinInstance, NiSkinPartition * partition)
{
m_skinInstance = skinInstance;
m_partition = partition;
}

Expand All @@ -1192,8 +1195,10 @@ void NIOVTaskUpdateSkinPartition::Dispose(void)

void NIOVTaskUpdateSkinPartition::Run()
{
if (m_partition)
if (m_skinInstance && m_partition)
{
EnterCriticalSection(&g_renderManager->lock);
EnterCriticalSection(&m_skinInstance->lock);
auto & partition = m_partition->m_pkPartitions[0];
UInt32 vertexSize = m_partition->GetVertexSize(partition.vertexDesc);
UInt32 vertexCount = m_partition->vertexCount;
Expand All @@ -1206,6 +1211,10 @@ void NIOVTaskUpdateSkinPartition::Run()
auto & pPartition = m_partition->m_pkPartitions[p];
deviceContext->UpdateSubresource(pPartition.shapeData->m_VertexBuffer, 0, nullptr, pPartition.shapeData->m_RawVertexData, vertexCount * vertexSize, 0);
}

m_skinInstance->m_spSkinPartition = m_partition;
LeaveCriticalSection(&m_skinInstance->lock);
LeaveCriticalSection(&g_renderManager->lock);
}
}

Expand Down Expand Up @@ -1395,18 +1404,17 @@ bool BodyMorphInterface::ReadBodyMorphTemplates(SKEEFixedString filePath)
return true;
}

void BodyMorphInterface::GetFilteredNPCList(std::vector<TESNPC*> activeNPCs[], UInt8 modIndex, UInt16 lightIndex, UInt32 gender, TESRace * raceFilter)
void BodyMorphInterface::GetFilteredNPCList(std::vector<TESNPC*> activeNPCs[], const ModInfo * modInfo, UInt32 gender, TESRace * raceFilter)
{
for (UInt32 i = 0; i < (*g_dataHandler)->npcs.count; i++)
{
TESNPC * npc = nullptr;
if ((*g_dataHandler)->npcs.GetNthItem(i, npc))
{
bool matchMod = modIndex == 0xFF || (npc->formID >> 24) == modIndex;
bool matchLightMod = lightIndex == 0xFFFF || (((npc->formID & 0xFF000000) == 0xFE000000) && (lightIndex == ((npc->formID >> 12) & 0xFFF)));
bool matchMod = modInfo ? modInfo->IsFormInMod(npc->formID) : false;

bool matchRace = (raceFilter == nullptr || npc->race.race == raceFilter);
if (npc && npc->nextTemplate == nullptr && matchMod && matchLightMod && matchRace)
if (npc && npc->nextTemplate == nullptr && matchMod && matchRace)
{
if (gender == 0xFF)
{
Expand Down Expand Up @@ -1497,14 +1505,12 @@ bool BodyMorphInterface::ReadBodyMorphs(SKEEFixedString filePath)
paramIndex++;
}

GetFilteredNPCList(activeNPCs, 0xFF, 0xFFFF, gender, foundRace);
GetFilteredNPCList(activeNPCs, nullptr, gender, foundRace);
}
else
{
UInt8 modIndex = (*g_dataHandler)->GetLoadedModIndex(modNameText.c_str());
UInt16 lightIndex = (*g_dataHandler)->GetLoadedLightModIndex(modNameText.c_str());

if (modIndex == 0xFF && lightIndex == 0xFFFF) {
const ModInfo * modInfo = (*g_dataHandler)->LookupModByName(modNameText.c_str());
if (!modInfo || !modInfo->IsActive()) {
_WARNING("%s - Warning - Mod '%s' not a loaded mod.\tLine (%d) [%s]", __FUNCTION__, modNameText.c_str(), lineCount, filePath.c_str());
continue;
}
Expand Down Expand Up @@ -1543,7 +1549,7 @@ bool BodyMorphInterface::ReadBodyMorphs(SKEEFixedString filePath)
paramIndex++;
}

GetFilteredNPCList(activeNPCs, modIndex, lightIndex, gender, foundRace);
GetFilteredNPCList(activeNPCs, modInfo, gender, foundRace);
}
else // Fallout4.esm|XXXX[|Gender]
{
Expand All @@ -1553,20 +1559,14 @@ bool BodyMorphInterface::ReadBodyMorphs(SKEEFixedString filePath)
continue;
}

UInt32 formId = 0;
if (lightIndex != 0xFFFF)
formId = 0xFE000000 | (UInt32(lightIndex) << 12) | (formLower & 0xFFFFFF);
else
formId = UInt32(modIndex) << 24 | formLower & 0xFFFFFF;

UInt32 formId = modInfo->GetFormID(formLower);
foundForm = LookupFormByID(formId);
if (!foundForm) {
_ERROR("%s - Error - Invalid form %08X.\tLine (%d) [%s]", __FUNCTION__, formId, lineCount, filePath.c_str());
continue;
}
}


if (foundForm)
{
TESLevCharacter * levCharacter = DYNAMIC_CAST(foundForm, TESForm, TESLevCharacter);
Expand Down Expand Up @@ -1813,7 +1813,7 @@ bool BodyMorph::Load(SKSESerializationInterface * intfc, UInt32 kVersion, const
{
m_name = StringTable::ReadString(intfc, stringTable);
}
else if (kVersion >= BodyMorphInterface::kSerializationVersion2)
else if (kVersion >= BodyMorphInterface::kSerializationVersion1)
{
char * stringName = NULL;
UInt8 stringLength;
Expand Down
23 changes: 16 additions & 7 deletions skee/BodyMorphInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class NiExtraData;
class TESNPC;
class TESRace;
class NiSkinPartition;
struct ModInfo;

#define MORPH_MOD_DIRECTORY "actors\\character\\BodyGenData\\"

Expand Down Expand Up @@ -108,7 +109,14 @@ class TriShapeVertexData
{
public:
virtual void ApplyMorphRaw(UInt16 vertCount, void * vertices, float factor) = 0;
virtual void ApplyMorph(UInt16 vertexCount, NiSkinPartition::TriShape * vertexData, float factor) = 0;

struct Layout
{
UInt64 vertexDesc;
UInt8 * vertexData;
};

virtual void ApplyMorph(UInt16 vertexCount, Layout * vertexData, float factor) = 0;
};
typedef std::shared_ptr<TriShapeVertexData> TriShapeVertexDataPtr;

Expand All @@ -118,7 +126,7 @@ class TriShapeFullVertexData : public TriShapeVertexData
TriShapeFullVertexData() : m_maxIndex(0) { }

virtual void ApplyMorphRaw(UInt16 vertCount, void * vertices, float factor);
virtual void ApplyMorph(UInt16 vertexCount, NiSkinPartition::TriShape * vertexData, float factor);
virtual void ApplyMorph(UInt16 vertexCount, Layout * vertexData, float factor);

UInt32 m_maxIndex;
std::vector<TriShapeVertexDelta> m_vertexDeltas;
Expand All @@ -131,7 +139,7 @@ class TriShapePackedVertexData : public TriShapeVertexData
TriShapePackedVertexData() : m_maxIndex(0) { }

virtual void ApplyMorphRaw(UInt16 vertCount, void * vertices, float factor);
virtual void ApplyMorph(UInt16 vertexCount, NiSkinPartition::TriShape * vertexData, float factor);
virtual void ApplyMorph(UInt16 vertexCount, Layout * vertexData, float factor);

float m_multiplier;
UInt32 m_maxIndex;
Expand All @@ -151,7 +159,7 @@ class TriShapePackedUVData : public TriShapeVertexData
};

virtual void ApplyMorphRaw(UInt16 vertCount, void * vertices, float factor);
virtual void ApplyMorph(UInt16 vertexCount, NiSkinPartition::TriShape * vertexData, float factor);
virtual void ApplyMorph(UInt16 vertexCount, Layout * vertexData, float factor);

float m_multiplier;
UInt32 m_maxIndex;
Expand Down Expand Up @@ -243,10 +251,11 @@ class NIOVTaskUpdateSkinPartition : public TaskDelegate
virtual void Run();
virtual void Dispose();

NIOVTaskUpdateSkinPartition(NiSkinPartition * partition);
NIOVTaskUpdateSkinPartition(NiSkinInstance * skinInstance, NiSkinPartition * partition);

private:
NiPointer<NiSkinPartition> m_partition;
NiPointer<NiSkinPartition> m_partition;
NiPointer<NiSkinInstance> m_skinInstance;
};

class BodyGenMorphData
Expand Down Expand Up @@ -346,7 +355,7 @@ class BodyMorphInterface : public IPluginInterface
virtual void VisitActors(std::function<void(TESObjectREFR*)> functor);

protected:
void GetFilteredNPCList(std::vector<TESNPC*> activeNPCs[], UInt8 modIndex, UInt16 lightIndex, UInt32 gender, TESRace * raceFilter);
void GetFilteredNPCList(std::vector<TESNPC*> activeNPCs[], const ModInfo * modInfo, UInt32 gender, TESRace * raceFilter);

private:
ActorMorphs actorMorphs;
Expand Down
33 changes: 16 additions & 17 deletions skee/CDXBrush.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifdef FIXME

#include "CDXBrush.h"
#include "CDXMesh.h"
#include "CDXUndo.h"
#include "CDXShader.h"
#include "CDXMaterial.h"

using namespace DirectX;

double g_brushProperties[CDXBrush::kBrushTypes][CDXBrush::kBrushProperties][CDXBrush::kBrushPropertyValues];

void CDXBrush::InitGlobals()
Expand Down Expand Up @@ -143,7 +143,7 @@ float CDXBrush::CalculateFalloff(float & dist)
double y = -(1.0 - (1.0 - falloff)) * ((dist / radius) - 1.0) + (1.0 - falloff);
y = y*y*(3 - 2 * y);

return y;
return (float)y;

/*double p = 1.0f;
Expand Down Expand Up @@ -175,25 +175,26 @@ float CDXBrush::CalculateFalloff(float & dist)

CDXHitIndexMap CDXBasicHitBrush::GetHitIndices(CDXPickInfo & pickInfo, CDXEditableMesh * mesh)
{
CDXMeshVert * pVertices = mesh->LockVertices();
CDXMeshVert * pVertices = mesh->LockVertices(CDXMesh::LockMode::READ);
CDXHitIndexMap hitVertex;
for (UInt32 i = 0; i < mesh->GetVertexCount(); i++) {
for (UInt16 i = 0; i < mesh->GetVertexCount(); i++) {
if (FilterVertex(mesh, pVertices, i))
continue;
CDXVec3 vTest = pVertices[i].Position;
CDXVec3 vDiff = pickInfo.origin - vTest;
float testRadius = D3DXVec3Length(&vDiff); // Spherical radius

CDXVec vTest = XMLoadFloat3(&pVertices[i].Position);
CDXVec vDiff = XMVectorSubtract(pickInfo.origin, vTest);
float testRadius = XMVectorGetX(XMVector3Length(vDiff)); // Spherical radius
if (testRadius <= m_property[kBrushProperty_Radius][kBrushPropertyValue_Value]) {
hitVertex.emplace(i, CalculateFalloff(testRadius));
}
}
mesh->UnlockVertices();
mesh->UnlockVertices(CDXMesh::LockMode::READ);
return hitVertex;
}

bool CDXBasicHitBrush::FilterVertex(CDXEditableMesh * mesh, CDXMeshVert * pVertices, CDXMeshIndex i)
{
if (pVertices[i].Color != COLOR_UNSELECTED)
if (XMVector3NotEqual(XMLoadFloat3(&pVertices[i].Color), COLOR_UNSELECTED))
return true;

return false;
Expand Down Expand Up @@ -303,11 +304,11 @@ bool CDXInflateBrush::UpdateStroke(CDXPickInfo & pickInfo, CDXEditableMesh * mes

auto hitVertex = GetHitIndices(pickInfo, stroke->GetMesh());

CDXVec3 normal(0, 0, 0);
CDXVec normal = XMVectorZero();
for (auto i : hitVertex) {
normal += mesh->CalculateVertexNormal(i.first);
normal = XMVectorAdd(normal, mesh->CalculateVertexNormal(i.first));
}
XMVector3Normalize(&normal, &normal);
normal = XMVector3Normalize(normal);

for (auto i : hitVertex) {
CDXInflateStroke::InflateInfo strokeInfo;
Expand Down Expand Up @@ -472,15 +473,13 @@ bool CDXMoveBrush::UpdateStroke(CDXPickInfo & pickInfo, CDXEditableMesh * mesh,
DebugOut("%d - %f", strokeInfo.index, strokeInfo.falloff);
#endif*/
CDXRayInfo rayStart = moveStroke->GetRayInfo();
CDXVec3 d = pickInfo.ray.point - rayStart.point;
CDXVec d = pickInfo.ray.point - rayStart.point;
if (isMirror)
d.x = -d.x;
d = XMVectorSetX(d, -XMVectorGetX(d));
strokeInfo.offset = d;
stroke->Update(&strokeInfo);
}
}

return true;
}

#endif
4 changes: 0 additions & 4 deletions skee/CDXBrush.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#ifdef FIXME

#ifndef __CDXBRUSH__
#define __CDXBRUSH__

Expand Down Expand Up @@ -175,5 +173,3 @@ class CDXMoveBrush : public CDXBasicHitBrush
};

#endif

#endif
Loading

0 comments on commit 58f565e

Please sign in to comment.