domcr / meshio Goto Github PK
View Code? Open in Web Editor NEW3D library in pure C# that allows reading and writing in multiple formats.
License: MIT License
3D library in pure C# that allows reading and writing in multiple formats.
License: MIT License
Implementation for shading materials
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.
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.
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
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.
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?
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.