让USD初步支持Maya的约束


  • 网站研运

    惊讶图.jpg
    USD是一个正在发展过程中的文件格式,最基础的,能够支持网格、简单的材质、简单的光照。稍微复杂一点,就可能要借助后续的插件支持了。比如说骨骼动画,这个在USD之前的版本都是没有的,后面慢慢地得到了支持。它是通过UsdSkel这个模块支持的。这个算是和USD核心代码平级的,所以算是USD的外围插件。其实看USDSkel的发展,USDSkel其实是打算做一个动画的最小集,即仅仅支持骨骼和约束的功能,后面更加复杂的功能,通过修改UsdSkel的特性来实现。

    USD已经有一套完善的机制可以很方便地添加自定义的类型。这主要通过USD内置的usdGenSchema.py脚本来达到效果。usdGenSchema.py脚本所在的位置是:

    D:\Develop\USD\pxr\usd\lib\usd

    所以要让USD支持约束,可以选择自己通过Schema来规划一下约束这个类型,包括哪些属性。USD的说明符(specifier)包括classdefover。其中class和C++的类很相似。我们要自己写一个Schema,大致的内容是这样:

    #usda 1.0
    (
        """ This file constains schema for supporting skeletal animations in USD.
        """
        subLayers = [
            @usdGeom/schema.usda@
        ]
    )
    
    over "GLOBAL" (
        customData = {
            string libraryName              = "usdRig"
            string libraryPath              = "qtdream/usd/usdRig"
        }
    ) {
    }
    
    class Constraint "Constraint" (
        inherits = </Imageable>
    )
    {
        uniform asset target (
            doc = """Target represent affectors whom the constraint will affect to."""
        )
        uniform asset[] targets (
            doc = """The parent targets representing this constraint tied to."""
        )
        uniform float[] weights (
            doc = """Optionally, weights can control the percentage the constraint is affected."""
        )
        uniform vector3f[] targetOffsetTranslates (
            doc = """Optionally, we can specify translate offset to precisely adjust."""
        )
        uniform vector3f[] targetOffsetRotates (
            doc = """Optionally, we can specify rotate offset to precisely adjust."""
        )
        uniform vector3f rotationDecompositionTarget (
            doc = """Used in parentConsstraint."""
        )
        uniform bool useDecompositionTarget (
            doc = """Used in parentConstraint."""
        )
    }
    

    接着要根据这个schema产生一大堆的代码,于是,编写以下的脚本:

    :: 运行UsdView插件.bat
    set Path=^
    D:\Develop\Python27;^
    D:\Develop\Python27\Scripts;^
    D:\Develop\USD_Build\lib;^
    D:\Develop\USD_Build\bin;^
    D:\Develop\USD_Build\third_party\maya\lib;^
    D:\Develop\Autodesk\Maya2018\bin;^
    %Path%
    
    set MAYA_PLUG_IN_PATH=%MAYA_PLUG_IN_PATH%;^
    D:\Develop\USD_Build\third_party\maya\plugin
    
    set PYTHONPATH=%PYTHONPATH%;^
    D:\Develop\USD_Build\lib\python;^
    D:\Develop\Autodesk\Maya2018\Python\Lib\site-packages
    
    set MAYA_SCRIPT_PATH=%MAYA_SCRIPT_PATH%;^
    D:\Develop\USD_Build\third_party\maya\lib\usd\usdMaya\resources;^
    D:\Develop\USD_Build\third_party\maya\plugin\pxrUsdPreviewSurface\resources
    
    set XBMLANGPATH=%XBMLANGPATH%;^
    D:\Develop\USD_Build\third_party\maya\lib\usd\usdMaya\resources
    
    :: 需要安装Jinja2,否则会报错
    pip install Jinja2
    
    :: 开始定位到D盘目标位置上,然后执行脚本。
    pushd D:\Develop\USD\qtdream\usd\lib\usdRig
    python D:\Develop\USD\pxr\usd\lib\usd\usdGenSchema.py schema.usda .
    popd
    

    如果出现了

    Traceback (most recent call last):
    File "D:\Develop\USD\pxr\usd\lib\usd\usdGenSchema.py", line 43, in <module>
    from jinja2 import Environment, FileSystemLoader
    ImportError: No module named jinja2
    错误,那么可能要想办法让python寻找到Jinja2。于是脚本中添加了:

    pip install Jinja2
    

    最后很高兴,顺利地生成了想要的C++文件,和产生的Schema文件。


Log in to reply
 

走马观花

最近的回复

  • 诶 没有Linux吗??

    read more
  • 萌梦 男孩,女孩,和蛋

    menghome.png

    read more
  • 设计模式-工厂模式

    使用qt/qml来演示设计模式效果,便于学习理解

    1)定义创建对象的接口,封装对象的创建
    2)使具体化类的工作延迟到工厂子类中

    bg.png
    image.png

    1. 工厂类

    createProduct使用了参数来选择要创建哪个产品

    #ifndef FACTORY_H #define FACTORY_H #include <QObject> class Product; class QString; class Factory: public QObject { Q_OBJECT public: virtual ~Factory() = 0; virtual Product* createProduct(QString type) = 0; protected: Factory(); }; class ConcreteFactory: public Factory { Q_OBJECT public: ~ConcreteFactory(); ConcreteFactory(); public slots: Product* createProduct(QString type); }; #endif // FACTORY_H #include "factory.h" #include "product.h" #include <QtQml/qqml.h> Factory::~Factory() { } Factory::Factory() { qmlRegisterType<Product>("Product", 1, 0, "Product"); } ConcreteFactory::~ConcreteFactory() { } ConcreteFactory::ConcreteFactory() { } Product *ConcreteFactory::createProduct(QString type) { if(type == "boy") return static_cast<Product *>(new ConcreteProduct1()); else if(type == "girl") return static_cast<Product *>(new ConcreteProduct2()); return static_cast<Product *>(new ConcreteProduct1()); } 2 产品类

    一个产品是萌梦男,一个产品是萌梦女

    #ifndef PRODUCT_H #define PRODUCT_H #include <QObject> class Product: public QObject { Q_OBJECT public: virtual ~Product() = 0; Q_PROPERTY(QString icon READ icon NOTIFY iconChanged) QString m_icon; QString icon() const { return m_icon; } signals: void iconChanged(QString icon); protected: Product(); signals: public slots: }; class ConcreteProduct1: public Product { Q_OBJECT public: ~ConcreteProduct1(); ConcreteProduct1(); }; class ConcreteProduct2: public Product { Q_OBJECT public: ~ConcreteProduct2(); ConcreteProduct2(); }; #endif // PRODUCT_H #include "product.h" Product::~Product() { } Product::Product() { } ConcreteProduct1::~ConcreteProduct1() { } ConcreteProduct1::ConcreteProduct1() { m_icon = "qrc:/images/boy.png"; } ConcreteProduct2::~ConcreteProduct2() { } ConcreteProduct2::ConcreteProduct2() { m_icon = "qrc:/images/girl.png"; } 3. main.qml

    使用timer,canvas,listview等实现一个自动化生产的动画效果

    源代码

    Fork me on Gitee

    read more
  • blender建模 章鱼
    捕获2.PNG 😵

    read more

关注我们

微博
QQ群