Skip to content

Commit

Permalink
Now deals with pivot point when computing skin binding matrix, fixes …
Browse files Browse the repository at this point in the history
…complex1 anim
  • Loading branch information
ziriax committed May 1, 2018
1 parent a84246a commit eb00c1a
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 23 deletions.
4 changes: 2 additions & 2 deletions maya/scripts/maya2glTF_UI.mel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
proc string _quoted(string $text)
proc string _quoted(string $text)
{
string $quote = "\"";
return $quote+$text+$quote;
Expand Down Expand Up @@ -251,7 +251,7 @@ global proc maya2glTF_UI()
global string $gMainProgressBar;

// This is auto-updated by msbuild
string $maya2glTF_version = "v0.9.3-beta 9d6c7ad";
string $maya2glTF_version = "v0.9.3-beta a84246a";

if (`window -exists maya2glTF_exporter_window`)
deleteUI maya2glTF_exporter_window;
Expand Down
2 changes: 1 addition & 1 deletion src/ExportableMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ExportableMesh::ExportableMesh(
auto& resources = scene.resources();
auto& args = resources.arguments();

const auto mayaMesh = std::make_unique<Mesh>(scene, shapeDagPath, node.pivotPoint);
const auto mayaMesh = std::make_unique<Mesh>(scene, shapeDagPath, node);

if (args.dumpMaya)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "DagHelper.h"
#include "ExportableScene.h"

Mesh::Mesh(ExportableScene& scene, MDagPath dagPath, const MPoint& pivotPoint)
Mesh::Mesh(ExportableScene& scene, MDagPath dagPath, const ExportableNode& node)
{
MStatus status = dagPath.extendToShape();
THROW_ON_FAILURE(status);
Expand All @@ -24,7 +24,7 @@ Mesh::Mesh(ExportableScene& scene, MDagPath dagPath, const MPoint& pivotPoint)
if (blendShapeDeformer.isNull())
{
// Single shape
m_mainShape = std::make_unique<MainShape>(scene, fnMesh, pivotPoint, ShapeIndex::main());
m_mainShape = std::make_unique<MainShape>(scene, fnMesh, node, ShapeIndex::main());
m_allShapes.emplace_back(m_mainShape.get());
}
else
Expand Down Expand Up @@ -57,7 +57,7 @@ Mesh::Mesh(ExportableScene& scene, MDagPath dagPath, const MPoint& pivotPoint)
weightPlugs.clearWeightsExceptFor(-1);

// Reconstruct base mesh
m_mainShape = std::make_unique<MainShape>(scene, fnMesh, pivotPoint, ShapeIndex::main());
m_mainShape = std::make_unique<MainShape>(scene, fnMesh, node, ShapeIndex::main());
m_allShapes.emplace_back(m_mainShape.get());

const auto numWeights = weightPlugs.numWeights();
Expand All @@ -68,7 +68,7 @@ Mesh::Mesh(ExportableScene& scene, MDagPath dagPath, const MPoint& pivotPoint)
auto weightPlug = weightPlugs.getWeightPlug(targetIndex);
auto initialWeight = static_cast<float>(weightPlugs.getOriginalWeight(targetIndex));
auto blendShape = std::make_unique<MeshShape>(m_mainShape->indices(),
fnMesh, pivotPoint,
fnMesh, node,
args, ShapeIndex::target(targetIndex),
weightPlug, initialWeight);
m_allShapes.emplace_back(blendShape.get());
Expand Down
2 changes: 1 addition & 1 deletion src/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ typedef std::vector<MeshShape*> MeshShapes;
class Mesh
{
public:
Mesh(ExportableScene& scene, MDagPath dagPath, const MPoint& pivotPoint);
Mesh(ExportableScene& scene, MDagPath dagPath, const ExportableNode& node);
~Mesh();

void dump(IndentableStream& out, const std::string& name) const;
Expand Down
17 changes: 12 additions & 5 deletions src/MeshShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ MeshShape::MeshShape(ShapeIndex shapeIndex)
{
}

MeshShape::MeshShape(const MeshIndices& mainIndices, const MFnMesh& fnMesh, const MPoint& pivotPoint, const Arguments& args, ShapeIndex shapeIndex, const MPlug& weightPlug, const float initialWeight)
MeshShape::MeshShape(
const MeshIndices& mainIndices,
const MFnMesh& fnMesh,
const ExportableNode& node,
const Arguments& args,
ShapeIndex shapeIndex,
const MPlug& weightPlug,
const float initialWeight)
: shapeIndex(shapeIndex)
, weightPlug(weightPlug)
, initialWeight(initialWeight)
Expand All @@ -21,7 +28,7 @@ MeshShape::MeshShape(const MeshIndices& mainIndices, const MFnMesh& fnMesh, cons
THROW_ON_FAILURE(status);

m_semantics = std::make_unique<MeshSemantics>(fnMesh, nullptr, args.blendPrimitiveAttributes);
m_vertices = std::make_unique<MeshVertices>(mainIndices, nullptr, fnMesh, shapeIndex, pivotPoint, args);
m_vertices = std::make_unique<MeshVertices>(mainIndices, nullptr, fnMesh, shapeIndex, node, args);
}

MeshShape::~MeshShape() = default;
Expand All @@ -45,18 +52,18 @@ void MeshShape::dump(IndentableStream& out, const std::string& name) const
out << endl << undent << '}' << endl;
}

MainShape::MainShape(ExportableScene& scene, const MFnMesh& fnMesh, const MPoint& pivotPoint, ShapeIndex shapeIndex) : MeshShape(shapeIndex)
MainShape::MainShape(ExportableScene& scene, const MFnMesh& fnMesh, const ExportableNode& node, ShapeIndex shapeIndex) : MeshShape(shapeIndex)
{
MStatus status;
m_dagPath = fnMesh.dagPath(&status);
THROW_ON_FAILURE(status);

auto& args = scene.arguments();

m_skeleton = std::make_unique<MeshSkeleton>(scene, fnMesh);
m_skeleton = std::make_unique<MeshSkeleton>(scene, node, fnMesh);
m_semantics = std::make_unique<MeshSemantics>(fnMesh, m_skeleton.get(), args.meshPrimitiveAttributes);
m_indices = std::make_unique<MeshIndices>(m_semantics.get(), fnMesh);
m_vertices = std::make_unique<MeshVertices>(*m_indices, m_skeleton.get(), fnMesh, shapeIndex, pivotPoint, scene.arguments());
m_vertices = std::make_unique<MeshVertices>(*m_indices, m_skeleton.get(), fnMesh, shapeIndex, node, scene.arguments());
}

MainShape::~MainShape() = default;
Expand Down
4 changes: 2 additions & 2 deletions src/MeshShape.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ExportableScene;
class MeshShape
{
public:
MeshShape(const MeshIndices& mainIndices, const MFnMesh& fnMesh, const MPoint& pivotPoint, const Arguments& args, ShapeIndex shapeIndex, const MPlug& weightPlug, float initialWeight);
MeshShape(const MeshIndices& mainIndices, const MFnMesh& fnMesh, const ExportableNode& node, const Arguments& args, ShapeIndex shapeIndex, const MPlug& weightPlug, float initialWeight);
virtual ~MeshShape();

virtual void dump(class IndentableStream& out, const std::string& name) const;
Expand Down Expand Up @@ -40,7 +40,7 @@ class MeshShape
class MainShape : public MeshShape
{
public:
MainShape(ExportableScene& scene, const MFnMesh& fnMesh, const MPoint& pivotPoint, ShapeIndex shapeIndex);
MainShape(ExportableScene& scene, const MFnMesh& fnMesh, const ExportableNode& node, ShapeIndex shapeIndex);
virtual ~MainShape();

const MeshIndices& indices() const { return *m_indices; }
Expand Down
5 changes: 3 additions & 2 deletions src/MeshSkeleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ struct VertexJointAssignmentSlice
};

MeshSkeleton::MeshSkeleton(
ExportableScene& scene,
ExportableScene& scene,
const ExportableNode& node,
const MFnMesh& mesh)
: m_maxVertexJointAssignmentCount(0)
{
Expand All @@ -49,7 +50,7 @@ MeshSkeleton::MeshSkeleton(
const auto shapeDagPath = mesh.dagPath(&status);
THROW_ON_FAILURE(status);

const auto meshMatrix = shapeDagPath.inclusiveMatrix(&status);
const auto meshMatrix = node.pivotTransform * shapeDagPath.inclusiveMatrix(&status);
THROW_ON_FAILURE(status);

for (size_t index = 0; index < jointCount; ++index)
Expand Down
2 changes: 1 addition & 1 deletion src/MeshSkeleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ typedef std::vector<MeshJoint> MeshJoints;
class MeshSkeleton
{
public:
MeshSkeleton(ExportableScene& scene, const MFnMesh& mesh);
MeshSkeleton(ExportableScene& scene, const ExportableNode& node, const MFnMesh& mesh);
virtual ~MeshSkeleton();

void dump(class IndentableStream& out, const std::string& name) const;
Expand Down
6 changes: 3 additions & 3 deletions src/MeshVertices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ MeshVertices::MeshVertices(
const MeshIndices& meshIndices,
const MeshSkeleton* meshSkeleton,
const MFnMesh& mesh,
ShapeIndex shapeIndex,
const MPoint& pivotPoint,
ShapeIndex shapeIndex,
const ExportableNode& node,
const Arguments& args)
:shapeIndex(shapeIndex)
{
Expand All @@ -203,7 +203,7 @@ MeshVertices::MeshVertices(
m_positions.reserve(numPoints);

const auto positionScale = args.scaleFactor;

const MPoint pivotPoint = node.pivotPoint;
for (int i = 0; i < numPoints; ++i)
{
const auto p = (mPoints[i] - pivotPoint) * positionScale;
Expand Down
3 changes: 2 additions & 1 deletion src/MeshVertices.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ inline VertexComponents componentsAt(const VertexComponents& elements, const siz

class Arguments;
class MeshIndices;
class ExportableNode;

class MeshVertices
{
public:
MeshVertices(const MeshIndices& meshIndices, const MeshSkeleton* meshSkeleton, const MFnMesh& mesh, ShapeIndex shapeIndex, const MPoint& pivotPoint, const Arguments& args);
MeshVertices(const MeshIndices& meshIndices, const MeshSkeleton* meshSkeleton, const MFnMesh& mesh, ShapeIndex shapeIndex, const ExportableNode& node, const Arguments& args);
virtual ~MeshVertices();

const ShapeIndex shapeIndex;
Expand Down
2 changes: 1 addition & 1 deletion src/version.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#include "externals.h"

const char* version = "v0.9.3-beta 9d6c7ad";
const char* version = "v0.9.3-beta a84246a";

0 comments on commit eb00c1a

Please sign in to comment.