Skip to content

Commit

Permalink
Merge pull request #2 from David-Vodhanel/master
Browse files Browse the repository at this point in the history
Added Environment Transfer Type
  • Loading branch information
colby-tafi authored Sep 21, 2020
2 parents 7bc9959 + d83df7d commit 5261246
Show file tree
Hide file tree
Showing 9 changed files with 400 additions and 34 deletions.
192 changes: 184 additions & 8 deletions Common/DzRuntimePluginAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,141 @@ DzRuntimePluginAction::~DzRuntimePluginAction()

void DzRuntimePluginAction::Export()
{
// FBX Export
Selection = dzScene->getPrimarySelection();
if (!Selection)
return;
// FBX Export
Selection = dzScene->getPrimarySelection();
if (!Selection)
return;

QMap<QString, DzNode*> PropToInstance;
if (AssetType == "Environment")
{
// Store off the original export information
QString OriginalCharacterName = CharacterName;
DzNode* OriginalSelection = Selection;

// Find all the different types of props in the scene
GetScenePropList(Selection, PropToInstance);
QMap<QString, DzNode*>::iterator iter;
for (iter = PropToInstance.begin(); iter != PropToInstance.end(); ++iter)
{
// Override the export info for exporting this prop
AssetType = "StaticMesh";
CharacterName = iter.key();
CharacterName = CharacterName.remove(QRegExp("[^A-Za-z0-9_]"));
CharacterFolder = ImportFolder + "\\" + CharacterName + "\\";
CharacterFBX = CharacterFolder + CharacterName + ".fbx";
DzNode* Node = iter.value();

// If this is a figure, send it as a skeletal mesh
if (DzSkeleton* Skeleton = Node->getSkeleton())
{
if (DzFigure* Figure = qobject_cast<DzFigure*>(Skeleton))
{
AssetType = "SkeletalMesh";
}
}

// Disconnect the asset being sent from everything else
QList<AttachmentInfo> AttachmentList;
DisconnectNode(Node, AttachmentList);

// Set the selection so this will be the exported asset
Selection = Node;

// Store the current transform and zero it out.
DzVec3 Location;
DzQuat Rotation;
DzMatrix3 Scale;

Node->getWSTransform(Location, Rotation, Scale);
Node->setWSTransform(DzVec3(0.0f, 0.0f, 0.0f), DzQuat(), DzMatrix3(true));

// Export
ExportNode(Node);

// Put the item back where it was
Node->setWSTransform(Location, Rotation, Scale);

// Reconnect all the nodes
ReconnectNodes(AttachmentList);
}

// After the props have been exported, export the environment
CharacterName = OriginalCharacterName;
CharacterFolder = ImportFolder + "\\" + CharacterName + "\\";
CharacterFBX = CharacterFolder + CharacterName + ".fbx";
Selection = OriginalSelection;
AssetType = "Environment";
ExportNode(Selection);
}
else
{
DzNode* Selection = dzScene->getPrimarySelection();
ExportNode(Selection);
}
}

void DzRuntimePluginAction::DisconnectNode(DzNode* Node, QList<AttachmentInfo>& AttachmentList)
{
AttachmentInfo ParentAttachment;
if (Node->getNodeParent())
{
// Don't disconnect a figures bones
if (DzBone* Bone = qobject_cast<DzBone*>(Node))
{

}
else
{
ParentAttachment.Parent = Node->getNodeParent();
ParentAttachment.Child = Node;
AttachmentList.append(ParentAttachment);
Node->getNodeParent()->removeNodeChild(Node);
}
}

QList<DzNode*> ChildNodes;
for (int ChildIndex = Node->getNumNodeChildren() - 1; ChildIndex >= 0; ChildIndex--)
{
DzNode* ChildNode = Node->getNodeChild(ChildIndex);
if (DzBone* Bone = qobject_cast<DzBone*>(ChildNode))
{

}
else
{
DzNode* ChildNode = Node->getNodeChild(ChildIndex);
AttachmentInfo ChildAttachment;
ChildAttachment.Parent = Node;
ChildAttachment.Child = ChildNode;
AttachmentList.append(ChildAttachment);
Node->removeNodeChild(ChildNode);
}
DisconnectNode(ChildNode, AttachmentList);
}
}

void DzRuntimePluginAction::ReconnectNodes(QList<AttachmentInfo>& AttachmentList)
{
foreach(AttachmentInfo Attachment, AttachmentList)
{
Attachment.Parent->addNodeChild(Attachment.Child);
}
}


void DzRuntimePluginAction::ExportNode(DzNode* Node)
{
dzScene->selectAllNodes(false);
dzScene->setPrimarySelection(Node);

if (AssetType == "Environment")
{
QDir dir;
dir.mkpath(CharacterFolder);
WriteConfiguration();
return;
}

DzExportMgr* ExportManager = dzApp->getExportMgr();
DzExporter* Exporter = ExportManager->findExporterByClassName("DzFbxExporter");
Expand All @@ -62,7 +193,7 @@ void DzRuntimePluginAction::Export()
DzFileIOSettings ExportOptions;
ExportOptions.setBoolValue("doSelected", true);
ExportOptions.setBoolValue("doVisible", false);
if (AssetType == "SkeletalMesh" || AssetType == "StaticMesh")
if (AssetType == "SkeletalMesh" || AssetType == "StaticMesh" || AssetType == "Environment")
{
ExportOptions.setBoolValue("doFigures", true);
ExportOptions.setBoolValue("doProps", true);
Expand Down Expand Up @@ -100,10 +231,13 @@ void DzRuntimePluginAction::Export()
ExportOptions.setBoolValue("doCollapseUVTiles", false);

// get the top level node for things like clothing so we don't get dupe material names
DzNode* Parent = Selection;
while (Parent->getNodeParent() != NULL)
DzNode* Parent = Node;
if (AssetType != "Environment")
{
Parent = Parent->getNodeParent();
while (Parent->getNodeParent() != NULL)
{
Parent = Parent->getNodeParent();
}
}

// rename duplicate material names
Expand Down Expand Up @@ -164,4 +298,46 @@ void DzRuntimePluginAction::UndoRenameDuplicateMaterials(DzNode* Node, QList<QSt
}
}

void DzRuntimePluginAction::GetScenePropList(DzNode* Node, QMap<QString, DzNode*>& Types)
{
DzObject* Object = Node->getObject();
DzShape* Shape = Object ? Object->getCurrentShape() : NULL;
DzGeometry* Geometry = Shape ? Shape->getGeometry() : NULL;
DzSkeleton* Skeleton = Node->getSkeleton();
DzFigure* Figure = Skeleton ? qobject_cast<DzFigure*>(Skeleton) : NULL;
//QString AssetId = Node->getAssetId();
//IDzSceneAsset::AssetType Type = Node->getAssetType();

// Use the FileName to generate a name for the prop to be exported
QString Path = Node->getAssetFileInfo().getUri().getFilePath();
QFile File(Path);
QString FileName = File.fileName();
QStringList Items = FileName.split("/");
QStringList Parts = Items[Items.count() - 1].split(".");
QString Name = Parts[0].remove(QRegExp("[^A-Za-z0-9_]"));

if (Figure)
{
QString FigureAssetId = Figure->getAssetId();
if (!Types.contains(Name))
{
Types.insert(Name, Node);
}
}
else if (Geometry)
{
if (!Types.contains(Name))
{
Types.insert(Name, Node);
}
}

// Looks through the child nodes for more props
for (int ChildIndex = 0; ChildIndex < Node->getNumNodeChildren(); ChildIndex++)
{
DzNode* ChildNode = Node->getNodeChild(ChildIndex);
GetScenePropList(ChildNode, Types);
}
}

#include "moc_DzRuntimePluginAction.cpp"
15 changes: 15 additions & 0 deletions Common/DzRuntimePluginAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
#include "QtCore/qfile.h"
#include "QtCore/qtextstream.h"

// Struct to remember attachment info
struct AttachmentInfo
{
DzNode* Parent;
DzNode* Child;
};

class DzRuntimePluginAction : public DzAction {
Q_OBJECT
public:
Expand All @@ -32,11 +39,19 @@ class DzRuntimePluginAction : public DzAction {
virtual QString getDefaultMenuPath() const { return tr("&File/Send To"); }

virtual void Export();
virtual void ExportNode(DzNode* Node);

virtual void WriteConfiguration() = 0;
virtual void SetExportOptions(DzFileIOSettings &ExportOptions) = 0;

// Need to temporarily rename surfaces if there is a name collision
void RenameDuplicateMaterials(DzNode* Node, QList<QString>& MaterialNames, QMap<DzMaterial*, QString>& OriginalMaterialNames);
void UndoRenameDuplicateMaterials(DzNode* Node, QList<QString>& MaterialNames, QMap<DzMaterial*, QString>& OriginalMaterialNames);

// Used to find all the unique props in a scene for Environment export
void GetScenePropList(DzNode* Node, QMap<QString, DzNode*>& Types);

// During Environment export props need to get disconnected as they are exported.
void DisconnectNode(DzNode* Node, QList<AttachmentInfo>& AttachmentList);
void ReconnectNodes(QList<AttachmentInfo>& AttachmentList);
};
115 changes: 96 additions & 19 deletions Unreal/DazStudioPlugin/DzUnrealAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <QtGui/QMessageBox>
#include <QtNetwork/qudpsocket.h>
#include <QtNetwork/qabstractsocket.h>
#include <QUuid.h>

#include <dzapp.h>
#include <dzscene.h>
Expand All @@ -14,6 +15,12 @@
#include <dzimageproperty.h>
#include <dzcolorproperty.h>
#include <dpcimages.h>
#include <dzfigure.h>
#include <dzfacetmesh.h>
#include <dzbone.h>
//#include <dznodeinstance.h>
#include "idzsceneasset.h"
#include "dzuri.h"

#include "DzUnrealDialog.h"
#include "DzUnrealAction.h"
Expand Down Expand Up @@ -93,29 +100,43 @@ void DzUnrealAction::WriteConfiguration()
writer.addMember("FBX File", CharacterFBX);
writer.addMember("Import Folder", CharacterFolder);

writer.startMemberArray("Materials", true);
WriteMaterials(Selection, writer);
writer.finishArray();

writer.startMemberArray("Morphs", true);
if (ExportMorphs)
if (AssetType != "Environment")
{
for (QMap<QString, QString>::iterator i = MorphMapping.begin(); i != MorphMapping.end(); ++i)
{
writer.startObject(true);
writer.addMember("Name", i.key());
writer.addMember("Label", i.value());
writer.finishObject();
}
writer.startMemberArray("Materials", true);
WriteMaterials(Selection, writer);
writer.finishArray();

writer.startMemberArray("Morphs", true);
if (ExportMorphs)
{
for (QMap<QString, QString>::iterator i = MorphMapping.begin(); i != MorphMapping.end(); ++i)
{
writer.startObject(true);
writer.addMember("Name", i.key());
writer.addMember("Label", i.value());
writer.finishObject();
}
}

writer.finishArray();


writer.startMemberArray("Subdivisions", true);
if (ExportSubdivisions)
SubdivisionDialog->WriteSubdivisions(writer);

writer.finishArray();
}

writer.finishArray();

writer.startMemberArray("Subdivisions", true);
if (ExportSubdivisions)
SubdivisionDialog->WriteSubdivisions(writer);
if (AssetType == "Environment")
{
writer.startMemberArray("Instances", true);
QMap<QString, DzMatrix3> WritingInstances;
QList<DzGeometry*> ExportedGeometry;
WriteInstances(Selection, writer, WritingInstances, ExportedGeometry);
writer.finishArray();
}

writer.finishArray();
writer.finishObject();

DTUfile.close();
Expand Down Expand Up @@ -253,5 +274,61 @@ void DzUnrealAction::WriteMaterials(DzNode* Node, DzJsonWriter& Writer)
}
}

void DzUnrealAction::WriteInstances(DzNode* Node, DzJsonWriter& Writer, QMap<QString, DzMatrix3>& WritenInstances, QList<DzGeometry*>& ExportedGeometry, QUuid ParentID)
{
DzObject* Object = Node->getObject();
DzShape* Shape = Object ? Object->getCurrentShape() : NULL;
DzGeometry* Geometry = Shape ? Shape->getGeometry() : NULL;
DzBone* Bone = qobject_cast<DzBone*>(Node);

if (Bone == nullptr && Geometry)
{
ExportedGeometry.append(Geometry);
ParentID = WriteInstance(Node, Writer, ParentID);
}

for (int ChildIndex = 0; ChildIndex < Node->getNumNodeChildren(); ChildIndex++)
{
DzNode* ChildNode = Node->getNodeChild(ChildIndex);
WriteInstances(ChildNode, Writer, WritenInstances, ExportedGeometry, ParentID);
}
}

QUuid DzUnrealAction::WriteInstance(DzNode* Node, DzJsonWriter& Writer, QUuid ParentID)
{
QString Path = Node->getAssetFileInfo().getUri().getFilePath();
QFile File(Path);
QString FileName = File.fileName();
QStringList Items = FileName.split("/");
QStringList Parts = Items[Items.count() - 1].split(".");
QString Name = Parts[0].remove(QRegExp("[^A-Za-z0-9_]"));
QUuid Uid = QUuid::createUuid();

Writer.startObject(true);
Writer.addMember("Version", 1);
Writer.addMember("InstanceLabel", Node->getLabel());
Writer.addMember("InstanceAsset", Name);
Writer.addMember("ParentID", ParentID.toString());
Writer.addMember("Guid", Uid.toString());
Writer.addMember("TranslationX", Node->getWSPos().m_x);
Writer.addMember("TranslationY", Node->getWSPos().m_y);
Writer.addMember("TranslationZ", Node->getWSPos().m_z);

DzQuat RotationQuat = Node->getWSRot();
DzVec3 Rotation;
RotationQuat.getValue(Node->getRotationOrder(), Rotation);
Writer.addMember("RotationX", Rotation.m_x);
Writer.addMember("RotationY", Rotation.m_y);
Writer.addMember("RotationZ", Rotation.m_z);

DzMatrix3 Scale = Node->getWSScale();

Writer.addMember("ScaleX", Scale.row(0).length());
Writer.addMember("ScaleY", Scale.row(1).length());
Writer.addMember("ScaleZ", Scale.row(2).length());
Writer.finishObject();

return Uid;
}

#include "moc_DzUnrealAction.cpp"
Loading

0 comments on commit 5261246

Please sign in to comment.