FBX是Autodesk公司的一种通用三维格式,很多其他软件都是解析FBX,来导入Autodesk系列软件产品生产的图纸或者模型。
FBX的SDK只有C++和Python的版本。鉴于我不会c++,所以我主要从Python入手。
1、安装Pyhon语言的FBX的sdk。
下载地址:
https://www.autodesk.com/developer-network/platform-technologies/fbx-sdk-2020-0
这里的sdk只支持Python2.7和Python3.3。我直接用Python2.7。把以下的文件复制到Python安装目录下的Lib/site-packages文件夹下。
然后Python调用FBX的sdk就搞定了。
2、C#调用cmd运行Python的实例
class Program
{
static void Main(string[] args)
{
string[] strArr = new string[2];//参数列表
string sArguments = @"main.py";//这里是python的文件名字
strArr[0] = "2";
strArr[1] = "3";
RunPythonScript(sArguments, "-u", strArr);
}
//调用python核心代码
public static void RunPythonScript(string sArgName, string args = "", params string[] teps)
{
Process p = new Process();
string path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + sArgName;// 获得python文件的绝对路径(将文件放在c#的debug文件夹中可以这样操作)
//path = @"D:\TestCode\UsePythonTest\UsePythonTest\bin\Debug\" + sArgName;//(因为我没放debug下,所以直接写的绝对路径,替换掉上面的路径了)
p.StartInfo.FileName = @"C:\Users\25403\AppData\Local\Programs\Python\Python37\python.exe";//没有配环境变量的话,可以像我这样写python.exe的绝对路径。如果配了,直接写"python.exe"即可
string sArguments = path;
foreach (string sigstr in teps)
{
sArguments += " " + sigstr;//传递参数
}
sArguments += " " + args;
p.StartInfo.Arguments = sArguments;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.BeginOutputReadLine();
p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);
Console.ReadLine();
p.WaitForExit();
}
//输出打印的信息
static void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
if (!string.IsNullOrEmpty(e.Data))
{
AppendText(e.Data + Environment.NewLine);
}
}
public delegate void AppendTextCallback(string text);
public static void AppendText(string text)
{
Console.WriteLine(text); //此处在控制台输出.py文件print的结果
}
}
其中的main.py
import numpy as np
import multi
import sys
def func(a,b):
result=np.sqrt(multi.multiplication(int(a),int(b)))
return result
if __name__ == '__main__':
print(func(sys.argv[1],sys.argv[2]))
其中的multi.py
def multiplication(a,b):
return a*b
3、用FBX的sdk里的例子做测试
把python的地址写到环境变量的path里。
然后打开cmd运行FBX的sdk里的例子。
运行结果可以看到例子里多了一个ExportScene01.fbx文件。注意修改一下里面输出文件的路径:
版权声明:本文为niuge8905原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。