wavefront

OBJ Parser with Boost Spirit - Ignoring comments

╄→гoц情女王★ 提交于 2019-12-06 15:24:25
I'm trying to write a basic OBJ file loader using the Boost Spirit library. Although I got it working using the standard std::ifstreams, I'm wondering if it's possible to do a phrase_parse on the entire file using a memory mapped file, since it seems to provide the best performance as posted here . I have the following code, which seems to work well, but it breaks when there is a comment in the file. So, my question is how do you ignore a comment that starts with a '#' in the OBJ file using Spririt? struct vertex { double x, y, z; }; BOOST_FUSION_ADAPT_STRUCT( vertex, (double, x) (double, y)

Mapping Wavefront .obj texture vertex on OpenGL

瘦欲@ 提交于 2019-12-05 10:55:48
An artist gave me all 3D models for me exporting to .obj and .mtl in order that I can render it using OpenGL. But I can't figure out why the texture vertex are greater than 1 and sometimes negative. Take a look at this example: (...) vn -0.000717425 0.00106739 -0.00991695 vn 3.49779e-09 -5.22866e-09 -0.01 vn -0.00142294 0.00211706 -0.00966919 vn -0.00831486 -0.00555545 0 vt 5.82424 -20.091 vt 6.97527 -20.1873 vt 5.81848 -20.1618 vt -7.48189 8.29159 (...) He sent me all textures on TGA format, which I am loading it correctly, but I am not being able to map these vt s to a correct OpenGL texture

Loading an OBJ file, how to use normals (#vertices < #normals)

我怕爱的太早我们不能终老 提交于 2019-12-04 16:42:59
I have an obj file and have succesfully loaded the object to opengl without using the normals given. This is how it looks: The format of the file is: v x y z vn x y z f x//x' y//y' z//z' The displaying function of the mesh is like that: glBegin(GL_TRIANGLES); for all faces { glVertex3f(.., .., ..); glVertex3f(.., .., ..); glVertex3f(.., .., ..); } glEnd(); And the result is this: I've read that the object might look flat due to the default normal vector that OpenGL uses for lighting equations. This could be solved with normals. The normals given are 780 and the vertices 155. I've tried using

Understanding normals indices with Wavefront Obj

徘徊边缘 提交于 2019-12-04 13:03:51
I've written a C++ Obj file loader that I can't get to work correctly. The problem is that while parsing a simple obj file like the following: # Blender v2.62 (sub 0) OBJ File: '' # www.blender.org mtllib cube.mtl o Cube v 1.000000 -1.000000 -1.000000 v 1.000000 -1.000000 1.000000 v -1.000000 -1.000000 1.000000 v -1.000000 -1.000000 -1.000000 v 1.000000 1.000000 -0.999999 v 0.999999 1.000000 1.000001 v -1.000000 1.000000 1.000000 v -1.000000 1.000000 -1.000000 vn 0.000000 0.000000 -1.000000 vn -1.000000 -0.000000 -0.000000 vn -0.000000 -0.000000 1.000000 vn 1.000000 -0.000000 0.000000 vn 1

auto concatenation of parse results into vectors

与世无争的帅哥 提交于 2019-12-01 10:12:23
I've written some rules to parse floats into two std::vector's of floats, which in turn are stored in a struct: Data input: # # object name01 # v -1.5701 33.8087 0.3592 v -24.0119 0.0050 21.7439 # a comment vn 0.0000 0.5346 0.8451 vn 0.8331 0.5531 -0.0000 # another comment Struct: struct ObjParseData { ObjParseData() : verts(), norms() {} std::vector<float> verts; std::vector<float> norms; }; And the relevant parsing code: struct objGram : qi::grammar<std::string::const_iterator, ObjParseData(), iso8859::space_type> { objGram() : objGram::base_type(start) { vertex = 'v' >> qi::double_ >> qi:

in a wavefront object file (.obj) how am i supposed to render faces with more than 4 vertices in opengl?

空扰寡人 提交于 2019-11-30 04:22:25
问题 So using a Wavefront object file how am i supposed to render faces that have more than 4 vertices in OpenGL? I understand that if it has 3 vertices I use GL_TRIANGLES , if it has 4 I use GL_QUADS , but if it has 5 or more, what am I supposed to use? Is there a standard? 回答1: OBJ exporters will export the vertices in a sane order for each face (anti-/clockwise), and long as your faces are coplanar and convex (which they bloody should be!) - you can use GL_TRIANGLE_FAN. I disagree with Nicol

How do you convert Wavefront OBJ file to an SCNNode with Model I/O

痞子三分冷 提交于 2019-11-29 02:31:50
I've imported a Wavefront OBJ file from a URL and now I'd like to insert it into my scene (SceneKit) on my iOS 9 app (in Swift). What I've done so far is: let asset = MDLAsset(URL: localFileUrl) print("count = \(asset.count)") // 1 Any help converting this to a SCNNode would be appreciated. According to to Apple's docs: Model I/O can share data buffers with the MetalKit, GLKit, and SceneKit frameworks to help you load, process, and render 3D assets efficiently. But I'm not sure how to get buffer from an MDLAsset into a SCNNode. Turns out this quite easy as many of the ModelIO classes already

Converting quadriladerals in an OBJ file into triangles?

匆匆过客 提交于 2019-11-27 19:54:47
At first, it seemed obvious... Make 2 triangles per face wherever 4 indices were found, right? Meaning, the following: v 1.000000 1.000000 0.000000 v -1.000000 1.000000 -0.000000 v 1.000000 -1.000000 0.000000 v -1.000000 -1.000000 -0.000000 f -4 -3 -2 -1 ... would, in turn, need to be converted into something like: v 1.000000 1.000000 0.000000 v -1.000000 1.000000 -0.000000 v 1.000000 -1.000000 0.000000 v -1.000000 -1.000000 -0.000000 f -4 -3 -2 f -2 -3 -1 This particular example, of course, would render correctly. However, not all cases are as simple as splitting the face into two faces

How do you convert Wavefront OBJ file to an SCNNode with Model I/O

主宰稳场 提交于 2019-11-27 16:49:00
问题 I've imported a Wavefront OBJ file from a URL and now I'd like to insert it into my scene (SceneKit) on my iOS 9 app (in Swift). What I've done so far is: let asset = MDLAsset(URL: localFileUrl) print("count = \(asset.count)") // 1 Any help converting this to a SCNNode would be appreciated. According to to Apple's docs: Model I/O can share data buffers with the MetalKit, GLKit, and SceneKit frameworks to help you load, process, and render 3D assets efficiently. But I'm not sure how to get

How do I sort the texture positions based on the texture indices given in a Wavefront (.obj) file?

元气小坏坏 提交于 2019-11-27 09:33:08
I'm currently trying to make a Wavefront (.obj) file loader for an OpenGL project. The method I'm currently using goes line-by-line and separates the vertex positions, texture positions and normal positions in vectors (std::vectors) and I'm storing their indices (vertex, texture and normal indices) in three separate vectors (from the 'f' lines of the file, for each face). I'm having trouble sorting the vector full of texture coordinates based on the texture indices. I'm able to render the vertices in the correct positions because my 'loader' class calls for the indices, but I can't figure out