New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redpawfx #21

Open
wants to merge 470 commits into
base: master
from
Commits
Jump to file or symbol
Failed to load files and symbols.
+85 −19
Diff settings

Always

Just for now

Viewing a subset of changes. View all

Adding a working partio visualizer writer.

  • Loading branch information...
sirpalee committed Jun 1, 2017
commit d7c463af43c0d4df6e670122a4e54636d5427cb0
@@ -8,6 +8,8 @@ if (BUILD_PARTIO_USD)
endif ()
add_subdirectory(primWriter)
if (NOT BUILD_PARTIO_USD_MAYA)
install(FILES plugInfo.json
DESTINATION ./)
endif ()
@@ -8,23 +8,25 @@ link_directories(${MAYA_LIBRARY_DIR})
set(MAYA_LIBS OpenMaya Foundation OpenMayaAnim OpenMayaFX OpenMayaUI OpenMayaRender)
find_package(Boost REQUIRED)
find_package(Boost COMPONENTS regex REQUIRED)
find_package(PythonLibs REQUIRED)
find_package(TBB REQUIRED)
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
include_directories(SYSTEM ${PYTHON_INCLUDE_DIRS})
include_directories(SYSTEM ${TBB_INCLUDE_DIRS})
add_library(${PLUGIN_NAME} SHARED primWriter.cpp)
file(GLOB SRC *.cpp)
add_library(${PLUGIN_NAME} SHARED ${SRC})
set_target_properties(${PLUGIN_NAME} PROPERTIES PREFIX "")
target_link_libraries(${PLUGIN_NAME} ${Boost_LIBRARIES} ${MAYA_LIBS} tf gf sdf usd usdGeom usdMaya)
target_link_libraries(${PLUGIN_NAME} ${PARTIO_LIBRARIES} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} ${MAYA_LIBS} tf gf sdf usd usdGeom usdMaya)
install(TARGETS ${PLUGIN_NAME}
DESTINATION .)
DESTINATION plug-ins)
set(PLUGINFO_OUT ${CMAKE_CURRENT_BINARY_DIR}/plugInfo.json)
configure_file(plugInfo.json.in ${PLUGINFO_OUT})
install(FILES ${PLUGINFO_OUT}
DESTINATION ${PLUGIN_NAME}/resources)
DESTINATION .)
@@ -4,7 +4,7 @@
"Info" : {
"UsdMaya" : {
"PrimWriter" : {
"mayaPlugin": "partio4Maya",
"mayaPlugin": "partioVisualizerWriter",
"providesTranslator": [ "partioVisualizer" ]
}
},
@@ -15,10 +15,8 @@
}
}
},
"LibraryPath": "../@PLUGIN_NAME@.so",
"LibraryPath": "plug-ins/@PLUGIN_NAME@.so",
"Name": "@PLUGIN_NAME@",
"ResourcePath": "resources",
"Root": "..",
"Type": "library"
}
]
@@ -0,0 +1,11 @@
#include <maya/MFnPlugin.h>
MStatus initializePlugin(MObject obj)
{
return MS::kSuccess;
}
MStatus uninitializePlugin(MObject obj)
{
return MS::kSuccess;
}
@@ -1,32 +1,85 @@
#include <pxr/pxr.h>
#include <pxr/base/tf/fileUtils.h>
#include <usdMaya/primWriterRegistry.h>
#include <usdMaya/MayaTransformWriter.h>
PXR_NAMESPACE_USING_DIRECTIVE
#include <maya/MFnDagNode.h>
__attribute__((constructor))
static void doSomeStuff() {
std::cerr << "I'm doing stuff!" << std::endl;
}
#include <Partio.h>
#include <boost/regex.hpp>
#include <thread>
PXR_NAMESPACE_USING_DIRECTIVE
namespace {
constexpr auto _cacheDir = "cacheDir";
constexpr auto _cachePrefix = "cachePrefix";
const std::array<std::string, 3> _extensionList = {"usd", "usda", "usdc"};
template <size_t N>
std::string searchFile(const std::string& prefix, const std::string& suffix, const std::array<std::string, N>& extensions) {
for (const auto& ext : extensions) {
std::stringstream ss; ss << prefix << "result" << suffix << ext;
const auto ret = ss.str();
if (TfIsFile(ret)) {
return ret;
}
}
return "";
}
class partioVisualizerWriter : public MayaTransformWriter {
public:
partioVisualizerWriter(const MDagPath & iDag, const SdfPath& uPath, bool instanceSource, usdWriteJobCtx& jobCtx) :
MayaTransformWriter(iDag, uPath, instanceSource, jobCtx) {
static boost::regex re;
static std::once_flag once_flag;
std::call_once(once_flag, []() {
std::stringstream ss;
ss << "(.+[\\.|_])([0-9]+)([\\.|_])(";
const auto supportedFormats = PARTIO::supportedReadFormats();
assert(supportedFormats.size() != 0);
auto formatIt = supportedFormats.begin();
ss << *formatIt;
for (; formatIt != supportedFormats.end(); ++formatIt) {
ss << "|" << *formatIt;
}
ss << ")$";
re = boost::regex(ss.str().c_str());
});
MFnDagNode dgNode(iDag);
const std::string cacheFile((dgNode.findPlug(_cacheDir).asString() +
dgNode.findPlug(_cachePrefix).asString()).asChar());
boost::cmatch match;
if (boost::regex_search(cacheFile.c_str(), match, re)) {
const auto stitchPath = searchFile(match[1].str(), match[3].str(), _extensionList);
if (stitchPath.empty()) {
TF_WARN("Stitched path does not exists for cache %s", cacheFile.c_str());
} else {
mUsdPrim = getUsdStage()->DefinePrim(getUsdPath());
TF_AXIOM(mUsdPrim);
mUsdPrim.GetReferences().AppendReference(SdfReference(stitchPath, SdfPath("/points")));
}
} else {
TF_WARN("%s is not a valid path to a PartIO cache.", cacheFile.c_str());
}
}
~partioVisualizerWriter() {};
~partioVisualizerWriter() { };
};
using partioVisualizerWriterPtr = std::shared_ptr<partioVisualizerWriter>;
}
TF_REGISTRY_FUNCTION_WITH_TAG(PxrUsdMayaPrimWriterRegistry, partioVisualizerWriter) {
std::cerr << "Registering partio visualizer writer." << std::endl;
PxrUsdMayaPrimWriterRegistry::Register("partioVisualizerWriter",
PxrUsdMayaPrimWriterRegistry::Register("partioVisualizer",
[](const MDagPath& iDag,
const SdfPath& uPath, bool instanceSource,
usdWriteJobCtx& jobCtx) -> MayaPrimWriterPtr { return std::make_shared<partioVisualizerWriter>(
iDag, uPath, instanceSource, jobCtx); });
iDag, uPath, instanceSource, jobCtx); });
}
ProTip! Use n and p to navigate between commits in a pull request.