十三、File Translator怎么写
---恢复内容开始---
1. File Translator可以将信息从maya中导入和导出。
2. 创建一个file translator需要从MPxFileTranslator继承。
3. 函数介绍:
(1)::canBeOpened()方法决定了file translator是否可以打开文件,如果只是一个importer那么就return flase,反之。
(2)importer:必须包含::haveReadMethod(), ::reader().
(3)exporter: 必须包含::haveWriteMethod(), ::writer().
4.设置translator允许访问所有的MEL命令: 在MFnPlugin::registerTranslator()函数中将requireFullMel参数值设置成true.
5. 例子, 一个polygon的exporter:
class polyExporter:public MPxFileTranslator
{
public:
polyExporter();
virtual ~polyExporter();
virtual MStatus writer (const MFileObject& file,
const MString& optionsString, MPxFileTranslator::FileAccessMode mode);
virtual bool haveWriteMethod () const;
virtual bool haveReadMethod () const;
virtual bool canBeOpened () const;
virtual MString defaultExtension () const = ;
protected:
virtual bool isVisible(MFnDagNode& fnDag, MStatus& status);
virtual MStatus exportAll(ostream& os);
virtual MStatus exportSelection(ostream& os);
virtual void writeHeader(ostream& os);
virtual void writeFooter(ostream& os);
virtual MStatus processPolyMesh(const MDagPath dagPath, ostream& os);
virtual polyWriter* createPolyWriter(const MDagPath dagPath, MStatus& status) = ;
};
6. MFnPlugin::registerFileTranslator()函数:
有6个参数,最后三个是可选的,
status = plugin.registerFileTranslator("RawText", "", polyRawExporter::creator, "", "option1=1", true);
RawText: is a name;
option1=1: default value for the option box for the translator;
true: means that you can use MGlobal::executeCommand() method in translator.
7. Reader:
如果要用reader()方法读取文件,那么haveReadMethod()方法要返回true
reader()方法读取文件的每一行,如果读取失败返回MS::kFailture
MStatus LepTranslator::reader ( const MFileObject& file,
const MString& options, MPxFileTranslator::FileAccessMode mode)
{ const MString fname = file.fullName(); MStatus rval(MS::kSuccess);
const int maxLineSize = ;
char buf[maxLineSize];
ifstream inputfile(fname.asChar(), ios::in);
if (!inputfile) {
// open failed
cerr << fname << ": could not be opened for reading\n";
return MS::kFailure;
}
if (!inputfile.getline (buf, maxLineSize)) {
cerr << "file " << fname << " contained no lines ... aborting\n";
return MS::kFailure;
}
//the first line has the magic chars.
if ( != strncmp(buf, magic.asChar(), magic.length())) {
cerr << "first line of file " << fname;
cerr << " did not contain " << magic.asChar() << " ... aborting\n";
return MS::kFailure;
}
while (inputfile.getline (buf, maxLineSize)) {
//processing each line of the file
MString cmdString;
cmdString.set(buf);
if (!MGlobal::executeCommand(cmdString))
rval = MS::kFailure;
}
inputfile.close();
return rval;
}
8. writer()方法, 类似reader()方法:
通过script editor来提供message,在这个例子中只提供export all 和export selection选项,其他的选项将输出failure message.
MStatus polyExporter::writer(const MFileObject& file,
const MString& /*options*/, MPxFileTranslator::FileAccessMode mode)
{ const MString fileName = file.fullName();
ofstream newFile(fileName.asChar(), ios::out);
if (!newFile) {
MGlobal::displayError(fileName + ": could not be opened for reading");
return MS::kFailure;
}
newFile.setf(ios::unitbuf);
writeHeader(newFile);
if (MPxFileTranslator::kExportAccessMode == mode) {
if (MStatus::kFailure == exportAll(newFile)) {
return MStatus::kFailure;
}
}
else if (MPxFileTranslator::kExportActiveAccessMode == mode) {
if (MStatus::kFailure == exportSelection(newFile)) {
return MStatus::kFailure;
}
}
else {
return MStatus::kFailure;
}
writeFooter(newFile);
newFile.flush();
newFile.close();
MGlobal::displayInfo("Export to " + fileName + " successful!");
return MS::kSuccess;
}
9. file extention:
MString polyRawExporter::defaultExtension () const
{
return MString("raw");
}
10. file access mode:
十三、File Translator怎么写的更多相关文章
- 第二十三个知识点:写一个实现蒙哥马利算法的C程序
第二十三个知识点:写一个实现蒙哥马利算法的C程序 这次博客我将通过对蒙哥马利算法的一个实际的实现,来补充我们上周蒙哥马利算法的理论方面.这个用C语言实现的蒙哥马利算法,是为一个位数为64的计算机编写的 ...
- 黑马程序员——File笔记读,写,复制
#region ReadAllBytes byte[] buffer = File.ReadAllBytes(@"C:\Users\dell\Desktop\新建文件夹.txt") ...
- Java之IO(十三)File、Filter、Piped、String和InputStreamReader与OutputStreamWriter
转载请注明原出处:http://www.cnblogs.com/lighten/p/7264196.html 1.前言 断更一段时间,计划果然赶不上变化(还是太懒...).这次一次性将剩余的5组字符流 ...
- 安卓开发笔记(三十三):Android仿写微信发现
首先我们来看看仿写之后的效果: 看到是这个界面我们首先应该思考这些按钮是怎么做出来的?有了一个整体的思路之后才知道该怎么办.最开始我想的就直接利用button控件上面直接加上png的图片就可以形成一个 ...
- python【第十三篇】可以写一个堡垒机了
前景介绍 到目前为止,很多公司对堡垒机依然不太感冒,其实是没有充分认识到堡垒机在IT管理中的重要作用的,很多人觉得,堡垒机就是跳板机,其实这个认识是不全面的,跳板功能只是堡垒机所具备的功能属性中的其中 ...
- File相关的读取和写入以及复制
import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileI ...
- 黑马程序员——【Java基础】——File类、Properties集合、IO包中的其他类
---------- android培训.java培训.期待与您交流! ---------- 一.File类 (一)概述 1.File类:文件和目录路径名的抽象表现形式 2.作用: (1)用来将文件或 ...
- input file样式修改,图片预览删除功能
本篇对input file进行了修改,改成自己需要的样式,类似验证身份上传身份证图片的功能. 效果图如下: 这里主要展示上传预览图片功能,对于删除功能的html及css写的比较粗糙,对于想要精细表现这 ...
- GO开发:用go写个日志监控系统
日志收集系统架构 1.项目背景 a. 每个系统都有日志,当系统出现问题时,需要通过日志解决问题 b. 当系统机器比较少时,登陆到服务器上查看即可满足 c. 当系统机器规模巨大,登陆到机器上查看几乎不现 ...
随机推荐
- 个人项目(JUnit单元测试)
---恢复内容开始--- 一. 题目简介 这次的单元测试我选择作了一个基本运算的程序,该程序实现了加,减,乘,除,平方,倒数的运算,该程序进行测试比较的简单,对于初步接触JUn ...
- Git服务器搭建及配置
一.部署环境 Server操作系统:CentOS release 6.7 (Final) 内核版本:2.6.32-358.el6.x86_64 git版本:1.9.0,源码下载地址如下 https:/ ...
- 【Django】Django web项目部署(Nginx+uwsgi)
一.安装uwsgi 通过pip安装uwsgi. pip install uwsgi 测试uwsgi,创建test.py文件: def application(env, start_response): ...
- C# 模拟按下回车键自动登录
private void Form1_Load(object sender, EventArgs e) { //this.Show(); this.Activate(); //this.Focus() ...
- android-APP-bluetooth
1.创建工程项目 2.工程界面(教程3) 如下目录所示:src目录下MainActivity.java是程序:res下面都是图标等资源文件,layout下的activity_main.xml是按钮等界 ...
- 王爽<<汇编语言>> 实验十四
;以"年/月/日 时:分:秒"的格式, 显示当前的日期, 时间 assume cs:code code segment main: out 70h,al ;告诉CMOS RAM将要 ...
- SpringMVC——文件上传
----------------------------------------------------------------------------spring.xml-------------- ...
- wget 递归下载整个网站
wget -r -p -np -k http://xxx.com/xxx -r, --recursive(递归) specify recursive download.(指定递归下 ...
- Eclipse搭建SSH(Struts2+Spring+Hibernate)框架教程
| 版权声明:本文为博主原创文章,未经博主允许不得转载. 前言 确实,刚创博客,对于这个陌生的东西还是有些许淡然.这是我的第一篇博文,希望能给你们有帮助,这就是我最大的乐趣! 好了下面进入正题: SS ...
- SSL安全证书-概念解析
一.关于证书 数字证书是一种认证机制.简单点说,它代表了一种由权威机构颁发授权的安全标志. 由来 在以前,传统网站采用HTTP协议进行数据传输,所有的数据几乎都用的明文,很容易发生隐私泄露.为了解决安 ...