loading textured obj with PCL c++ - c++

I am trying to load a textured .obj file using the predefined PCL (Point Cloud Library) functions like so:
pcl::TextureMesh texture_mesh;
int loaded = pcl::io::loadOBJFile(<path to obj>,texture_mesh);
boost::shared_ptr<pcl::visualization::PCLVisualizer> result_view(new pcl::visualization::PCLVisualizer("Viewer"));
result_view->addTextureMesh(texture_mesh, "texture mesh", 0);
while (!result_view->wasStopped())
{
//---{ update the viewer }
result_view->spinOnce(100);
boost::this_thread::sleep(boost::posix_time::microseconds(100000));
}
However, the texture is not loaded correctly and the model remains colourless. I have tried to save the "texture_mesh" to a new .obj to see the result but it appears the texture coords are being jumbled up.
My questions are:
1) Are the files in the correct format?
2) Is the obj loading and veiwing correct?
3) Has anyone had success loading textured .obj files with PCL?
To demonstrate the issue, I have initialized a test repo here loadOBJ
paths supplied in src are relative so set cmake source=loadOBJ, build=loadOBJ/build.
Due to the relative path I had to edit the output of saving the obj with pcl, this is noted in the READMEs.
Due to issue with not knowing enough about git, I had to manually upload the .obj files haha
This is only an issue on windows machines, it has been tested on unix and runs fine.

Related

How to export actors (point clouds, lines, splines) from VTK viewer?

I am working with PCL and vtk viewer and I have created a scene which consists of a pointcloud, some lines and some splines. How can I export these actors in one file that would be readable by Blender or Cinema4D? I have already tried vtkOBJExporter:
vtkOBJExporter* vtkExporter = vtkOBJExporter::New();
vtkExporter->SetRenderWindow(this->viewer->getRenderWindow());
vtkExporter->SetFilePrefix("/tmp/scene");
vtkExporter->Write();
This does not seem to save my actors. When I try to open the file with Blender or with view3dscene it seems empty.

Ogre 3D load models created with Easy Ogre Exporter

I'm currently trying to export a .max file to .mesh and it success.
The problem is that I don't have any color on my form (it's a basic cylinder actually).
Easy Ogre Exporter gave me several more files like .scene .material .cg .program. I tried to set this .material to .mesh entity but it's still white.
Please help me, I really searched on the web but found nothing working.
Best regards,
Coucka
If Ogre encounters an issue with your materials / shaders / textures, it usually falls back to a material called "BaseWhite", which might be what you are experiencing.
First step: Check the Ogre.log file to see if the *.material file was loaded at all and if there were any error while parsing it. You should find an entry similar to this one:
23:45:10: Parsing script Test.material
If your material is also using the shader that was written into the *.cg shader file, check that it is loaded as well without any errors, plus check that a valid shader profile was used, that your hardware supports (otherwise you will find a note in the log, telling you that no supported profile was found). The supported shader profiles will also the output into the log file, like so:
23:45:10: * Supported Shader Profiles: hlsl ps_1_1 ps_1_2 ps_1_3 ps_1_4 ps_2_0 ps_2_a ps_2_b ps_2_x ps_3_0 vs_1_1 vs_2_0 vs_2_a vs_2_x vs_3_0
If you are using textures on your model, make sure that the needed texture files can be found by Ogre. To do so verify that all paths from where Ogre should load resources are listed in the configuration file resources.cfg. Also for textures to work, your model of course needs to have exported UV coordinates. If the texture was successfully loaded, the following entry should appear in the log (the types and formats of course could be different):
23:45:10: Texture: Texture.jpg: Loading 1 faces(PF_R8G8B8,256x256x1) Internal format is PF_X8R8G8B8,256x256x1.

Load An Image From A Relative Path in SFML

Im playing around with SFML and C++ and have one question, when loading a texture, you must specify its directory like so:
sf::Texture myTexture;
if(!(myTexture.loadFromFile("C:\\Folder\\image.png")));
But when distributing my game how will i be sure that the user will download the game onto the same drive, and image.png may be on the E: drive instead of the C: drive. I want to know a way to locate an image file in C++ without having to specif its directory. Here is theoretical code
if(!(myTexture.loadFromFile(#"image.png")));
so now no matter where this image is located my game can find the image. My only concern is that someone might already have a file called image.png on there computer so for this i would give the image files very abstract and unique names, to prevent duplication.
Loading images (and sounds, fonts etc) from a relative path works as well.
If you are concerned about potential filename collisions, distribute your game with a folder containing all your assets. For example yourGame_resources, placed at the same level as your executable. Load by
myTexture.loadFromFile("yourGame_resources/image.png")

Can't open any files in Code::Blocks application during runtime

I am using Code::Blocks to make an OpenGL program in C++. The program compiles and runs, but the texture is never displayed. I just get an empty grey rectangle against a white background, when there should have been a picture in the grey rectangle.
I first noticed problems when trying to load the images for textures using the Simple OpenGL Image Library (SOIL). I did some digging around in the code of SOIL and found that the program was not opening any files at all. I tried changing image format, creating some random text files to test, and more, but it would not open any files of any type.
I think I may have the files in the wrong directory, but if so, where are they supposed to go? Right now, I have them saved in the same directory as the code.
Somewhere, you are giving paths to the files. These should be relative to the location of the executable. So examples could be this:
someFunction("file.jpg");
Here, the file.jpg should be somewhere like: <project_dir>/bin/Debug/
someFunction("../../file.jpg");
Now the correct location will be: <project_dir>/

Loading meshes from .obj (or any other) File into DirectX9/C++ project

Currently I have a 3D Cube that I drew by writing coordinates, that can rotate and move on a black screen.
Now I have a Model that I created in "3Ds Max"(It's a little backyard with high stonewalls, so I'm trying to use it as my world object.) and I want to load this model into my DirectX9/C++ project.
As far as I see in DirectX SDK examples this code is for loading .X model (which needs a plugin for "3Ds Max" to export that kind of extension. I'm not sure of this.)
Code for loading .X files into DX9/C++:
D3DXLoadMeshFromX( "Tiger.x", D3DXMESH_SYSTEMMEM,
g_pd3dDevice, NULL, &pD3DXMtrlBuffer, NULL,
&g_dwNumMaterials, &g_pMesh )
Is there a function like "D3DXLoadMeshFromOBJ(.....)" to load an Object? How do I load and render .OBJ files? 8(
Another question of mine is what is the difference between an .X file and an .OBJ file and which of them should I use?
AFAIK, DirectX does not support wavefront object files out of the box. You will need an external mesh loader for that purpose.
I can remember, that in the DX 10 SDK is a sample of how to load an .obj file, I think the sample is called MeshFromOBJ10. I don't know if it is of any use in DirectX 9.
As far as I know, the standard .x just supports basic meshes with no enhancements such as animation. If you want to try out graphical programming it is not bad, but if you are aiming for higher concepts you can later switch. I guess you can look up the advantages of the .obj files here.
It is always a good idea to create an abstraction for the input data you are using. For example, you could create a class AbstractMesh and an implementation XMesh deriving from it. Later on, you can than add other implementations like OBJMesh or anything similar.
I hope I could help you a bit :) Happy Coding!
Animation is full supported in x file format, and furthermore, it support fx files when you want to use shaders. A exporter plugin and samples you can download from this page:
http://www.cgdev.net/download.php