lo48576 / fbxcel-dom

FBX DOM library for Rust. // See https://github.com/lo48576/fbx-viewer for working example application // rework (total rewrite) is planned
Apache License 2.0
24 stars 10 forks source link

Getting transformation data of an node #13

Closed const-volatile closed 2 years ago

const-volatile commented 2 years ago

In FBX-SDK we can get the transformation data of an node like this:

const FbxVector4 lT = pNode->GetGeometricTranslation(FbxNode::eSourcePivot);
const FbxVector4 lR = pNode->GetGeometricRotation(FbxNode::eSourcePivot);
const FbxVector4 lS = pNode->GetGeometricScaling(FbxNode::eSourcePivot);

Is there any way to access the same using fbxcel-dom? I searched the documentation and examples, but could not find an equivalent. Without being able to access the transformation of an MeshHandle, the pivot of all objects in the scene becomes the same (0, 0, 0) and hence submeshes can not be translated/rotated to their global position correctly.

lo48576 commented 2 years ago

I'm afraid I can do quite little things about this, but could you try the code below? The retrieved values might be (or might not be) useful to calculate the values you need. (And modify .expect() if the absense of properties or errors should be safely ignored.)

use fbxcel_dom::v7400::object::property::loaders::F32Arr3Loader;

let obj_props = object_handle.properties_by_native_typename("KFbxNode");
let local_trans: [f32; 3] = obj_props
    .get_property("GeometricTranslation")
    .expect("geometric translation not set")
    .load_value(F32Arr3Loader)
    .expect("type mismatch (expected vec3)");
let local_rot: [f32; 3] = obj_props
    .get_property("GeometricRotation")
    .expect("geometric rotation not set")
    .load_value(F32Arr3Loader)
    .expect("type mismatch (expected vec3)");
let local_scaling: [f32; 3] = obj_props
    .get_property("GeometricScaling")
    .expect("geometric scaling not set")
    .load_value(F32Arr3Loader)
    .expect("type mismatch (expected vec3)");

I expect the code above to give you some meaningful values. However the files I've investigated does not have geometric TRS so I know almost nothing about them. And also I don't know how FbxNode::{eSourcePivot,eDestinationPivot} are handled in FBX files and FBX SDK. (In fact, I've never used FBX SDK to show FBX scene...)

const-volatile commented 2 years ago

Thank you so much, it helped pointing into the right direction. I got it working as following:

use fbxcel_dom::v7400::object::property::loaders::F64Arr3Loader;
let obj_props = object.properties_by_native_typename("KFbxNode");
let translation : [f64; 3] = match obj_props.get_property("Lcl Translation") {
  Some(property) => {
    property.load_value(F64Arr3Loader).unwrap_or([0.0, 0.0, 0.0])
  },
  None => { [0.0, 0.0, 0.0] }
};
let rotation : [f64; 3] = match obj_props.get_property("Lcl Rotation") {
  Some(property) => { property.load_value(F64Arr3Loader).unwrap_or([0.0, 0.0, 0.0]) },
  None => { [0.0, 0.0, 0.0] }
};
let scale : [f64; 3] = match obj_props.get_property("Lcl Scaling") {
  Some(property) => { property.load_value(F64Arr3Loader).unwrap_or([0.0, 0.0, 0.0]) },
  None => { [0.0, 0.0, 0.0] }
};
lo48576 commented 2 years ago
let scale : [f64; 3] = match obj_props.get_property("Lcl Scaling") {
  Some(property) => { property.load_value(F64Arr3Loader).unwrap_or([0.0, 0.0, 0.0]) },
  None => { [0.0, 0.0, 0.0] }
};

Maybe [1.0, 1.0, 1.0] for scaling?