ctx
This commit is contained in:
parent
0808672ba8
commit
72c0fdc1cb
|
@ -7,9 +7,9 @@ using namespace std;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
// 定义给Rust调用的接口函数
|
// 定义给Rust调用的接口函数
|
||||||
void fbx_parse(const char* fbx_path)
|
void fbx_parse(const FttContext* ctx)
|
||||||
{
|
{
|
||||||
printf("%s\n", fbx_path);
|
printf("%s\n", ctx->fbx_file);
|
||||||
FbxManager* lSdkManager = FbxManager::Create();
|
FbxManager* lSdkManager = FbxManager::Create();
|
||||||
if (lSdkManager){
|
if (lSdkManager){
|
||||||
printf("FbxManager created\n");
|
printf("FbxManager created\n");
|
||||||
|
@ -23,7 +23,7 @@ extern "C" {
|
||||||
printf("FbxScene creation failed.\n");
|
printf("FbxScene creation failed.\n");
|
||||||
}
|
}
|
||||||
FbxImporter* lImporter = FbxImporter::Create(lSdkManager, "");
|
FbxImporter* lImporter = FbxImporter::Create(lSdkManager, "");
|
||||||
bool s = lImporter->Initialize(fbx_path, -1, lSdkManager->GetIOSettings());
|
bool s = lImporter->Initialize(ctx->fbx_file, -1, lSdkManager->GetIOSettings());
|
||||||
if (s){
|
if (s){
|
||||||
printf("FbxImporter initialized\n");
|
printf("FbxImporter initialized\n");
|
||||||
} else{
|
} else{
|
||||||
|
@ -34,16 +34,15 @@ extern "C" {
|
||||||
|
|
||||||
FbxNode* lRootNode = lScene->GetRootNode();
|
FbxNode* lRootNode = lScene->GetRootNode();
|
||||||
if (lRootNode) {
|
if (lRootNode) {
|
||||||
each_node(lRootNode, 0);
|
each_node(ctx, lRootNode, 0);
|
||||||
} else {
|
} else {
|
||||||
printf("No root node found in the scene.\n");
|
printf("No root node found in the scene.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void load_fbx_mesh_to_db(const char* fbx_path)
|
void load_fbx_mesh_to_db(const FttContext* ctx)
|
||||||
{
|
{
|
||||||
FbxNode* root = get_fbx_root_node(fbx_path);
|
FbxNode* root = get_fbx_root_node(ctx->fbx_file);
|
||||||
|
each_node(ctx, root, 0);
|
||||||
each_node(root, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ FbxNode* get_fbx_root_node(const char* fbx_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void each_node(FbxNode* parent_node, int level)
|
void each_node(const FttContext* ctx, FbxNode* parent_node, int level)
|
||||||
{
|
{
|
||||||
// info
|
// info
|
||||||
print_node_info(parent_node, level);
|
print_node_info(parent_node, level);
|
||||||
|
@ -67,12 +67,8 @@ void each_node(FbxNode* parent_node, int level)
|
||||||
{
|
{
|
||||||
std::vector<Triangle> triangles;
|
std::vector<Triangle> triangles;
|
||||||
int count = load_triangles(attr, triangles);
|
int count = load_triangles(attr, triangles);
|
||||||
printf("triangles: %ld;", triangles.size());
|
printf("triangles: %ld\n", triangles.size());
|
||||||
std::cout << "("
|
// save data to database
|
||||||
<< get<0>(triangles[0]) << ", "
|
|
||||||
<< get<1>(triangles[0]) << ", "
|
|
||||||
<< get<2>(triangles[0]) << ")"
|
|
||||||
<< std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -83,7 +79,7 @@ void each_node(FbxNode* parent_node, int level)
|
||||||
for (int i = 0; i < parent_node->GetChildCount(); i++)
|
for (int i = 0; i < parent_node->GetChildCount(); i++)
|
||||||
{
|
{
|
||||||
FbxNode* child = parent_node->GetChild(i);
|
FbxNode* child = parent_node->GetChild(i);
|
||||||
each_node(child, level + 1);
|
each_node(ctx, child, level + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
#include <fbxsdk.h>
|
#include <fbxsdk.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <tools.h>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
using Triangle = std::tuple<int, int, int>;
|
using Triangle = std::tuple<int, int, int>;
|
||||||
|
|
||||||
struct Context {
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 递归遍历FBX节点树结构
|
* 递归遍历FBX节点树结构
|
||||||
* @param parent_node 起始父节点,从此节点开始向下遍历(若为nullptr则函数不执行任何操作)
|
* @param parent_node 起始父节点,从此节点开始向下遍历(若为nullptr则函数不执行任何操作)
|
||||||
|
@ -16,7 +14,7 @@ struct Context {
|
||||||
* @note 函数内部会递归访问parent_node的所有直接子节点和间接子节点
|
* @note 函数内部会递归访问parent_node的所有直接子节点和间接子节点
|
||||||
* @warning 若输入的parent_node无效(如野指针)可能导致程序崩溃
|
* @warning 若输入的parent_node无效(如野指针)可能导致程序崩溃
|
||||||
*/
|
*/
|
||||||
void each_node(FbxNode* parent_node, int level);
|
void each_node(const FttContext* ctx, FbxNode* parent_node, int level);
|
||||||
/**
|
/**
|
||||||
* 打印FBX节点的基本信息(含层级缩进)
|
* 打印FBX节点的基本信息(含层级缩进)
|
||||||
* @param node 待打印信息的节点指针(nullptr时输出警告日志)
|
* @param node 待打印信息的节点指针(nullptr时输出警告日志)
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char* fbx_file;
|
||||||
|
char* out_dir;
|
||||||
|
} FttContext;
|
28
src/main.rs
28
src/main.rs
|
@ -1,19 +1,39 @@
|
||||||
|
use std::{ffi::CString, os::raw::c_char};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
convert_fbx_to_3dtiles("/mnt/f/BaiduNetdiskDownload/绿科模型/绿科-三维视图-{三维}111.fbx");
|
convert_fbx_to_3dtiles("/root/data/绿科-三维视图-{三维}111.fbx", "/root/data/out");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct FttContext {
|
||||||
|
pub fbx_file: *mut c_char,
|
||||||
|
pub out_dir: *mut c_char
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
unsafe extern "C" {
|
||||||
pub unsafe fn fbx_parse(name_in: *const u8);
|
pub unsafe fn fbx_parse(name_in: *const u8);
|
||||||
pub unsafe fn load_fbx_mesh_to_db(path: *const u8);
|
pub unsafe fn load_fbx_mesh_to_db(ctx: *const FttContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_fbx_to_3dtiles(fbx_path: &str) {
|
fn convert_fbx_to_3dtiles(fbx_path: &str, out_dir: &str) {
|
||||||
|
|
||||||
|
|
||||||
|
let ctx = &FttContext{
|
||||||
|
fbx_file: CString::new(fbx_path).unwrap().into_raw(),
|
||||||
|
out_dir: CString::new(out_dir).unwrap().into_raw()
|
||||||
|
};
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
// fbx_parse(fbx_path.as_ptr() as *const u8);
|
// fbx_parse(fbx_path.as_ptr() as *const u8);
|
||||||
// 1. load to disk
|
// 1. load to disk
|
||||||
load_fbx_mesh_to_db(fbx_path.as_ptr() as *const u8);
|
// fbx_path.as_ptr() as *const u8
|
||||||
|
load_fbx_mesh_to_db(ctx);
|
||||||
|
|
||||||
|
|
||||||
|
// free
|
||||||
|
let _ = CString::from_raw(ctx.fbx_file);
|
||||||
|
let _ = CString::from_raw(ctx.out_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
// unsafe {
|
// unsafe {
|
||||||
|
|
Loading…
Reference in New Issue