Coder Social home page Coder Social logo

meshio's Introduction

MeshIO Build License nuget

C# modular library to read/write and modify different 3D formats.

Here you can find a sample project that shows how to use MeshIO.

MeshIO modules

Each module integrates a different 3D format, all of them use MeshIO as a core library so it makes easier to modify and convert the different 3D formats.

MeshIO.FBX

  • Read FBX binary files
  • Read/Write FBX ASCII files
  • Process and add custom FbxProperties

For more information.

MeshIO.STL

  • Read/Write STL binary files
  • Read/Write STL ASCII files

For more information.

MeshIO.GLTF

  • Read GLB files

For more information.

MeshIO.OBJ

  • Read Wavefront OBJ files

For more information.

Contributing

Please feel free to fork this repo and send a pull request if you want to contribute to this project.

meshio's People

Contributors

domcr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

meshio's Issues

Can't export to FBX

Hello.
I was trying to export my mesh to fbx with this code:
(Mesh was constructed from Unity model and I was able to successfully export it to STL earlier)

        MeshIO.Scene scene = new();
        scene.RootNode.Nodes.Add(convertedMesh);
        string pathfBX = System.IO.Path.Combine("D:/test", "fbx_bin.fbx");
        using(MeshIO.FBX.FbxWriter writer = new MeshIO.FBX.FbxWriter(pathfBX, scene)) {
            writer.Write(MeshIO.FBX.FbxFileFormat.Binary);
        }

This generates exception:

InvalidOperationException: Nullable object must have a value.
System.Nullable`1[T].get_Value () (at <88e4733ac7bc4ae1b496735e6b83bbd3>:0)
MeshIO.FBX.Converters.SceneConverterBase.buildObjectsNode () (at MeshIO.FBX/Converters/SceneConverterBase.cs:171)
MeshIO.FBX.Converters.SceneConverterBase.ToRootNode () (at MeshIO.FBX/Converters/SceneConverterBase.cs:82)
MeshIO.FBX.FbxRootNode.CreateFromScene (MeshIO.Scene scene, MeshIO.FBX.FbxVersion version) (at MeshIO.FBX/FbxRootNode.cs:28)
MeshIO.FBX.FbxWriter.Write (MeshIO.FBX.FbxFileFormat fileFormat) (at MeshIO.FBX/FbxWriter.cs:104)

изображение
If I try to add some ID like this:

        convertedMesh.Id = 0;

then exception changes to this:

FbxException: Invalid property type System.UInt64, at Geometry/Objects[0]
MeshIO.FBX.FbxBinaryWriter.WriteProperty (System.Object obj, System.Int32 id) (at MeshIO.FBX/Writers/FbxBinaryWriter.cs:195)
MeshIO.FBX.FbxBinaryWriter.WriteNode (MeshIO.FBX.FbxRootNode document, MeshIO.FBX.FbxNode node) (at MeshIO.FBX/Writers/FbxBinaryWriter.cs:254)
MeshIO.FBX.FbxBinaryWriter.WriteNode (MeshIO.FBX.FbxRootNode document, MeshIO.FBX.FbxNode node) (at MeshIO.FBX/Writers/FbxBinaryWriter.cs:271)
MeshIO.FBX.FbxBinaryWriter.Write () (at MeshIO.FBX/Writers/FbxBinaryWriter.cs:60)
MeshIO.FBX.FbxWriter.Write (MeshIO.FBX.FbxFileFormat fileFormat) (at MeshIO.FBX/FbxWriter.cs:109)

изображение

If I change to ACSII, then I get some file, which apps can not open:
fbx_ascii.zip

Unfortunately I was not able to find examples of saving FBX with this library. Even MeshIO.STL.Tests just creates empty scene without trying to save actual model. So I'm not sure if I did something wrong, or support for fbx format is incomplete.

Nuget Package

Hi! This is awesome what you're doing here. I was thinking about maybe using your MeshIO.FBX in my AssetRipper project. Would you be willing to publish a nuget package for it?

Materials

Implementation for shading materials

Force dot instead of comma for decimal number separator in ASCII formats.

When I was trying to use this library from Unity I noticed that exported ASCII STL files looked incorrectly.
For example vertex looks like that:
vertex 3,488124 8,464913 11
So the result was corrupted:
изображение
To fix this problem I changed StlWriter as described here https://groups.google.com/g/dotnetdevelopment/c/weQuHv-C-XE

		public void WriteAscii(Mesh mesh)
		{
			this.validate(mesh);
			
			using (TextWriter tw = new StreamWriter(this._stream.Stream, new UTF8Encoding(false)))
			{
				System.Globalization.NumberFormatInfo nfi = new();
				nfi.NumberDecimalSeparator = ".";

				tw.WriteLine($"solid {mesh.Name}");

				LayerElementNormal normals = mesh.Layers.GetLayer<LayerElementNormal>();
				for (int i = 0; i < mesh.Polygons.Count; i++)
				{
					XYZ normal = normals.Normals[i];

					tw.WriteLine($"  facet normal {normal.X.ToString(nfi)} {normal.Y.ToString(nfi)} {normal.Z.ToString(nfi)}");

					tw.WriteLine($"    outer loop");

					foreach (int item in (Triangle)mesh.Polygons[i])
					{
						var v = mesh.Vertices[item];

						tw.WriteLine($"      vertex {v.X.ToString(nfi)} {v.Y.ToString(nfi)} {v.Z.ToString(nfi)}");
					}

					tw.WriteLine($"    endloop");
					tw.WriteLine($"  endfacet");
				}

				tw.WriteLine($"endsolid {mesh.Name}");
			}
		}

With this changes result looks as intended
изображение
I'm not sure that this is the best solution, so I decided to create an issue here.

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

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

Open to pull requests?

I want to help development here. Are you open to pull requests? If not, I can just fork and continue on my own development path.

How to write a FLAC3D file?

Hello~It is amazing to find this tool, but I can not figure out how to write a FEM file out to specific file, say FLAC3D?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.