Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract vertices data (X,Y,Z) from a *.fbx #13

Closed
pmorshed opened this issue Dec 16, 2022 · 4 comments
Closed

Extract vertices data (X,Y,Z) from a *.fbx #13

pmorshed opened this issue Dec 16, 2022 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@pmorshed
Copy link

Hi. How can I extract vertices data (X,Y,Z list) from a *.fbx 3D model via MeshIO?
For example, suppose I have a box in the fbx file (attached) and I want to extract the coordinates of its vertices in CSV format. What should I do?
box1.zip

@DomCR DomCR added the help wanted Extra attention is needed label Dec 16, 2022
@DomCR
Copy link
Owner

DomCR commented Dec 16, 2022

Hi @pmorshed,

to extract the vertices you just need to access to the Scene.Nodes and look for the Element that you are looking for, here is an example:

Scene scene = FbxReader.Read(test, ErrorLevel.Checked);

//Iterate throgh all the nodes in the scene
foreach (Node item in scene.Nodes)
{
      //Here you can apply filter if you know the name of the node
      //Each node can contain geometric elements so you have to look in the elements contained in the main node
      foreach (Element c in item.Children)
      {
	      //Check if the element is a geometric type
	      if (!(c is Geometry geometry))
		      continue;
      
	      //Get the vertices of the element
	      List<CSMath.XYZ> vertices = geometry.Vertices;
      }
}

@pmorshed
Copy link
Author

Hi @pmorshed,

to extract the vertices you just need to access to the Scene.Nodes and look for the Element that you are looking for, here is an example:

Scene scene = FbxReader.Read(test, ErrorLevel.Checked);

//Iterate throgh all the nodes in the scene
foreach (Node item in scene.Nodes)
{
      //Here you can apply filter if you know the name of the node
      //Each node can contain geometric elements so you have to look in the elements contained in the main node
      foreach (Element c in item.Children)
      {
	      //Check if the element is a geometric type
	      if (!(c is Geometry geometry))
		      continue;
      
	      //Get the vertices of the element
	      List<CSMath.XYZ> vertices = geometry.Vertices;
      }
}

Hi. Thanks for the quick reply. I tried it but it didn't give any output. Have you tried it yourself?

@DomCR
Copy link
Owner

DomCR commented Dec 16, 2022

You are right, the problem is that the mesh is inside another node, so 2 levels Node.Node.Geometry with recursion is easy to pick all geometries, try this:

public static IEnumerable<Geometry> GetAllGeometryInTheScene(string path)
{
	Scene scene = FbxReader.Read(path, ErrorLevel.Checked);
	List<Geometry> geometries = new List<Geometry>();

	//Iterate throgh all the nodes in the scene
	foreach (Node item in scene.Nodes)
	{
		//Here you can apply filter if you know the name of the node

		geometries.AddRange(GetAllGeometryInTheNode(item));
	}

	return geometries;
}

public static List<Geometry> GetAllGeometryInTheNode(Node node)
{
	List<Geometry> list = new List<Geometry>();
	//Each node can contain geometric elements so you have to look in the elements contained in the main node
	foreach (Element c in node.Children)
	{
		//Check if the element is a geometric type
		if (c is Geometry geometry)
		{
			list.Add(geometry);
			continue;
		}
		else if (c is Node n)
		{
			list.AddRange(GetAllGeometryInTheNode(n));
		}
	}

	return list;
}

I've tried with your document and it worked find.

@pmorshed
Copy link
Author

Yes, works like a charm. Thanks so much

@DomCR DomCR closed this as completed Mar 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants