tgjones / meshellator Goto Github PK
View Code? Open in Web Editor NEW3D asset import library for .NET 4.0. Supported formats are Autodesk 3DS and Lightwave OBJ.
License: Other
3D asset import library for .NET 4.0. Supported formats are Autodesk 3DS and Lightwave OBJ.
License: Other
Dear Sir
When I run this project in visual studio 2013 I get this error.
please see the picture:
Hi,
Is it possible to get a simple example how to make simple mesh from points and faces.
And then remesh it.
I do not want to import the model each time. I want just to pass mesh model to type that is readable to your library remesh it and return it back.
I see that it is not possible to make a simple mesh as there are no functions for them:
Meshellator.Mesh m = new Meshellator.Mesh();
Also when I try to get coordinates out of a simple solid I get empty list:
Kind Regards,
Petras
Hi
First of all, you did a great work.
I found a tiny bug in the obj importer (ObjImporter), when trying to import an obj file that has no textures the code will raise IndexOutOfRangeException in line 77. The solution is very simple, just add an if condition to check if the number of textures in the mtl file.
Old code:
// Copy normals.
foreach (int textureIndex in f.TextureIndices)
{
TextureCoordinate tc = wavefrontObject.Textures[textureIndex];
mesh.TextureCoordinates.Add(new Point3D(tc.U, tc.V, tc.W));
}
New code (my code):
// Copy normals.
foreach (int textureIndex in f.TextureIndices)
{
if (wavefrontObject.Textures.Count > 0)
{
TextureCoordinate tc = wavefrontObject.Textures[textureIndex];
mesh.TextureCoordinates.Add(new Point3D(tc.U, tc.V, tc.W));
}
}
Thanks a lot
Hi,
I should say I am a newbie to DirectX and Meshellator (obviously).
I am reading the SkinnedSample from MSDN:
http://msdn.microsoft.com/en-us/library/ee418800(VS.85).aspx
Which talk about hierarchy of meshes.
Yet, when I look at the Scene.cs and Mesh.cs class, it seems to be flat to me, i.e. no hierarchy!
Did I miss something?
Thanks!
Lloyd
'face' element (f) in OBJ file can have one of the following formats:
(1) f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3
(2) f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3 v4/vt4/vn4
(3) f v1//vn1 v2//vn2 v3//vn3
(4) f v1//vn1 v2//vn2 v3//vn3 v4//vn4
(5) f v1/vn1 v2/vn2 v3/vn3
(6) f v1/vn1 v2/vn2 v3/vn3 v4/vn4
or simply
(7) f v1 v2 v3 ...
FaceParser.ParsLine() method is throwing an IndexOutOfRange exception when formats 3-7 are used.
The following modification of FaceParser.ParsLine() method will fix the issue:
private void ParseLine( int vertexCount ) {
// Fix: explicitly set the array length
string[] rawFaces = new string[3];
vindices = new int[vertexCount];
nindices = new int[vertexCount];
tindices = new int[vertexCount];
vertices = new Vertex[vertexCount];
normals = new Vertex[vertexCount];
textures = new TextureCoordinate[vertexCount];
for ( int i = 1; i <= vertexCount; i++ ) {
// Fix: Use additional array for parsed words
var wordParts = Words[i].Split('/');
// Fix: setup rawFaces array
rawFaces[0] = wordParts[0];
rawFaces[1] = wordParts.Length == 3 ? wordParts[1] : null;
rawFaces[2] = wordParts.Length == 3
? wordParts[2]
: wordParts.Length == 2
? wordParts[1]
: null
;
// v
int currentValue = int.Parse(rawFaces[0]);
vindices[i - 1] = currentValue - 1;
// save vertex
vertices[i - 1] = _object.Vertices[currentValue - 1]; // -1 because references starts at 1
if ( wordParts.Length == 1 ) {
continue;
}
// save texcoords.
if ( !string.IsNullOrEmpty(rawFaces[1]) ) {
currentValue = int.Parse(rawFaces[1]);
// This is to compensate the fact that if no texture is in the obj file,
// sometimes '1' is put instead of 'blank' (we find coord1/1/coord3 instead of
// coord1//coord3 or coord1/coord3)
if (currentValue <= _object.Textures.Count) {
tindices[i - 1] = currentValue - 1;
textures[i - 1] = _object.Textures[currentValue - 1]; // -1 because references starts at 1
}
}
// save normal
currentValue = int.Parse(rawFaces[2]);
nindices[i - 1] = currentValue - 1;
normals[i - 1] = _object.Normals[currentValue - 1]; // -1 because references starts at 1
}
}
I have an OBJ mesh (I'd like to attach it to this issue, but I don't know how) that crashes Meshellator when I attempt to load it. First I got an "dictionary key not found" error in the MTL loader; I figured out that was because I had spaces in some of my material names, so I removed the spaces from both the MTL file and the references to the materials in the OBJ file. However even after doing so I get an error that I can't figure out. It's just an "index out of range" error, and it's in the OBJ loader itself, so I'm not sure what's wrong.
edit: Since I can't seem to attach files, I'll link to my mesh here: http://edkolis.exofire.net/hull-segment-1.7z
According to OBJ spec,
usemtl material-ref
operator could be found before any group is created. The following test is failing:
# start test file
mtllib ./mylib.mtl
usemtl red
# end test file
To fix this issue I would propose the following change in MaterialParser.IncorporateResults():
public override void IncorporateResults(WavefrontObject wavefrontObject) {
if (!wavefrontObject.Materials.ContainsKey(_materialName))
return;
Material newMaterial = wavefrontObject.Materials[_materialName];
// Fix: CurrentGroup could be null...
if ( wavefrontObject.CurrentGroup == null ) {
wavefrontObject.CurrentGroup = new Group("default");
}
wavefrontObject.CurrentGroup.Material = newMaterial;
}
Note that OBJ spec is using "default" as a group name in these cases (not "Default created by loader")
This will allow quad primitives to be imported from meshes that support that kind of primitive, and then Meshellator will convert the quads to triangles as a post-process.
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.