How to load obj with texture

classic Classic list List threaded Threaded
28 messages Options
12
Reply | Threaded
Open this post in threaded view
|

How to load obj with texture

junsmog

Hi, guys

 

I tried to read .obj file(with .mtl and texture files) and display using PCLVisualizer.

 

But I couldn’t load texture file when using loadPolygonFileOBJ function.

 

Please take a look of the following example code.

 

//////////////////////////////////////////////////////////////////////////////

 pcl::TextureMesh mesh7;

 pcl::io::loadPolygonFileOBJ("inputscan.obj", mesh7);

 pcl::visualization::PCLVisualizer viewer_pre7("PCL Viewer_pre7");

 viewer_pre7.addTextureMesh(mesh7, "texture", 0);

while(!viewer_pre7.wasStopped()){

  viewer_pre7.spinOnce();

 }

///////////////////////////////////////////////////////////////////////////////

 

After running the addTextureMesh function, I had the following messages.

 

[PCLVisualizer::textureFromTexMaterial] No texture file given for material !

[PCLVisualizer::addTextureMesh] Fail to create vtkTexture from !

 

Of course, .obj, .mtl and texture files exist properly and can be read in meshlab.

 

I tested several .obj files and got the same problem. And I also tested in PCL version 1.7.2 and 1.8.0.

 

Would anyone suggest me how to load obj file with texture in pcl?

 

Thank you in advance.


_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: How to load obj with texture

Sérgio Agostinho
Hey, 

Do you mind sharing your file bundle so that I can test it?

Cheers,
Sérgio

2016-04-08 12:58 GMT+01:00 Jun-Su Jang <[hidden email]>:

Hi, guys

 

I tried to read .obj file(with .mtl and texture files) and display using PCLVisualizer.

 

But I couldn’t load texture file when using loadPolygonFileOBJ function.

 

Please take a look of the following example code.

 

//////////////////////////////////////////////////////////////////////////////

 pcl::TextureMesh mesh7;

 pcl::io::loadPolygonFileOBJ("inputscan.obj", mesh7);

 pcl::visualization::PCLVisualizer viewer_pre7("PCL Viewer_pre7");

 viewer_pre7.addTextureMesh(mesh7, "texture", 0);

while(!viewer_pre7.wasStopped()){

  viewer_pre7.spinOnce();

 }

///////////////////////////////////////////////////////////////////////////////

 

After running the addTextureMesh function, I had the following messages.

 

[PCLVisualizer::textureFromTexMaterial] No texture file given for material !

[PCLVisualizer::addTextureMesh] Fail to create vtkTexture from !

 

Of course, .obj, .mtl and texture files exist properly and can be read in meshlab.

 

I tested several .obj files and got the same problem. And I also tested in PCL version 1.7.2 and 1.8.0.

 

Would anyone suggest me how to load obj file with texture in pcl?

 

Thank you in advance.


_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users



_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

RE: Re: How to load obj with texture

junsmog

Two obj samples are attached.

3DScan_test3.obj ( generated from Intel RealSense SDK )

3DScan_test3a.obj ( converted from Meshlab)

 

By the way, the documentation of loadPolygonFileOBJ() says that it does not load texture information.

So, I found loadOBJFile() and tested, but still not working.

 

Test code:

#include <pcl/common/common.h>
#include <pcl/io/obj_io.h>
#include <pcl/io/vtk_lib_io.h>
#include <pcl/visualization/pcl_visualizer.h>

int main()
{
pcl::TextureMesh mesh7;
//pcl::io::loadPolygonFileOBJ("3DScan_test3a.obj", mesh7);
pcl::io::loadOBJFile("3DScan_test3a.obj", mesh7);

pcl::visualization::PCLVisualizer viewer_pre7("PCL Viewer_pre7");
viewer_pre7.addTextureMesh(mesh7, "texture", 0);
viewer_pre7.spin();

return 0;
}

 

Results:

3DScan_test3.obj
After loadOBJFile function, I got error message, "Debug Assertion Failed! Expression:vector subscript out of range"


3DScan_test3a.obj
addTextureMesh() said "No textures coordinates found!"

 

Help me!

 


=?UTF-8?B?M0RTY2FuX3Rlc3QzLnppcA==?= (2M) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to load obj with texture

junsmog
In reply to this post by Sérgio Agostinho
Reply | Threaded
Open this post in threaded view
|

Re: How to load obj with texture

junsmog
Would anyone please test the loadOBJFile function?
If you have the same results, I think it should be reported as a bug.
Reply | Threaded
Open this post in threaded view
|

Re: How to load obj with texture

felixm
Moin Arne,

klar, kann ich machen.

Bis später
Felix

On Donnerstag, 14. April 2016 19:08:36 CEST junsmog wrote:

> Would anyone please test the loadOBJFile function?
> If you have the same results, I think it should be reported as a bug.
>
>
>
> --
> View this message in context:
> http://www.pcl-users.org/How-to-load-obj-with-texture-tp4041450p4041507.htm
> l Sent from the Point Cloud Library (PCL) Users mailing list mailing list
> archive at Nabble.com. _______________________________________________
> [hidden email] / http://pointclouds.org
> http://pointclouds.org/mailman/listinfo/pcl-users
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: How to load obj with texture

py_lwq
This post has NOT been accepted by the mailing list yet.
In reply to this post by junsmog
hello,I have two questions when i test it, one is that i haven't the function of addTextureMesh .so i can not finish the test. The other is can i get the idea about how to get the .obj and .mlt files, how i should design the parameters.
thank you for your reply.
junsmog wrote
Hi, guys
 
I tried to read .obj file(with .mtl and texture files) and display using PCLVisualizer.
 
But I couldn’t load texture file when using loadPolygonFileOBJ function.
 
Please take a look of the following example code.
 
//////////////////////////////////////////////////////////////////////////////
 pcl::TextureMesh mesh7;
 pcl::io::loadPolygonFileOBJ("inputscan.obj", mesh7);
 pcl::visualization::PCLVisualizer viewer_pre7("PCL Viewer_pre7");
 viewer_pre7.addTextureMesh(mesh7, "texture", 0);
while(!viewer_pre7.wasStopped()){
  viewer_pre7.spinOnce();
 }
///////////////////////////////////////////////////////////////////////////////
 
After running the addTextureMesh function, I had the following messages.
 
[PCLVisualizer::textureFromTexMaterial] No texture file given for material !
[PCLVisualizer::addTextureMesh] Fail to create vtkTexture from !
 
Of course, .obj, .mtl and texture files exist properly and can be read in meshlab.

I tested several .obj files and got the same problem. And I also tested in PCL version 1.7.2 and 1.8.0.
 
Would anyone suggest me how to load obj file with texture in pcl?
 
Thank you in advance.
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: How to load obj with texture

junsmog
This post was updated on .
What PCL version do you have?
You should have addTextureMesh in pcl::visualization::PCLVisualizer Class. I tested it in PCL 1.7.2 and 1.8.0
http://docs.pointclouds.org/trunk/classpcl_1_1visualization_1_1_p_c_l_visualizer.html#a1aa779bbc5e6a2aebf4b72e66676f04f

Please find obj, mtl samples in attached file.

3DScan_test3.zip

Test code:

#include <pcl/common/common.h>
#include <pcl/io/obj_io.h>
#include <pcl/io/vtk_lib_io.h>
#include <pcl/visualization/pcl_visualizer.h>

int main()
{
pcl::TextureMesh mesh7;
//pcl::io::loadPolygonFileOBJ("3DScan_test3a.obj", mesh7);
pcl::io::loadOBJFile("3DScan_test3a.obj", mesh7);

pcl::visualization::PCLVisualizer viewer_pre7("PCL Viewer_pre7");
viewer_pre7.addTextureMesh(mesh7, "texture", 0);
viewer_pre7.spin();

return 0;
}


If you want to know obj file details, use google.
http://3dcoat.com/forum/index.php?showtopic=15984

py_lwq wrote
hello,I have two questions when i test it, one is that i haven't the function of addTextureMesh .so i can not finish the test. The other is can i get the idea about how to get the .obj and .mlt files, how i should design the parameters.
thank you for your reply.
junsmog wrote
Hi, guys
 
I tried to read .obj file(with .mtl and texture files) and display using PCLVisualizer.
 
But I couldn’t load texture file when using loadPolygonFileOBJ function.
 
Please take a look of the following example code.
 
//////////////////////////////////////////////////////////////////////////////
 pcl::TextureMesh mesh7;
 pcl::io::loadPolygonFileOBJ("inputscan.obj", mesh7);
 pcl::visualization::PCLVisualizer viewer_pre7("PCL Viewer_pre7");
 viewer_pre7.addTextureMesh(mesh7, "texture", 0);
while(!viewer_pre7.wasStopped()){
  viewer_pre7.spinOnce();
 }
///////////////////////////////////////////////////////////////////////////////
 
After running the addTextureMesh function, I had the following messages.
 
[PCLVisualizer::textureFromTexMaterial] No texture file given for material !
[PCLVisualizer::addTextureMesh] Fail to create vtkTexture from !
 
Of course, .obj, .mtl and texture files exist properly and can be read in meshlab.

I tested several .obj files and got the same problem. And I also tested in PCL version 1.7.2 and 1.8.0.
 
Would anyone suggest me how to load obj file with texture in pcl?
 
Thank you in advance.
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: How to load obj with texture

junsmog
In reply to this post by felixm
Felix,

Would you report the result of testing loadOBJFile please?


felixm wrote
Moin Arne,

klar, kann ich machen.

Bis später
Felix

On Donnerstag, 14. April 2016 19:08:36 CEST junsmog wrote:
> Would anyone please test the loadOBJFile function?
> If you have the same results, I think it should be reported as a bug.
>
>
>
> --
> View this message in context:
> http://www.pcl-users.org/How-to-load-obj-with-texture-tp4041450p4041507.htm
> l Sent from the Point Cloud Library (PCL) Users mailing list mailing list
> archive at Nabble.com. _______________________________________________
> [hidden email] / http://pointclouds.org
> http://pointclouds.org/mailman/listinfo/pcl-users
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: How to load obj with texture

py_lwq
This post has NOT been accepted by the mailing list yet.
In reply to this post by junsmog
 I tested it in PCL 1.6.0 , maybe it's too old.
Reply | Threaded
Open this post in threaded view
|

Re: How to load obj with texture

py_lwq
This post has NOT been accepted by the mailing list yet.
In reply to this post by junsmog
today,I test it in PCL1.8.0,and i also can't see the result. but the message is [PCLVisualizer::textureFromTexMaterial] No textures coordinates found !
 and I will continue testing it.
Reply | Threaded
Open this post in threaded view
|

Re: How to load obj with texture

Sérgio Agostinho
In reply to this post by junsmog
Hey, 

So I opened your file (3DScan_test3a.obj) and got the same issue. The reason behind it is because there are texture coordinates being defined after the invocation of "usemtl". I tried to search for the OBJ spec, but the best I found were these

Although nothing states that you should specify your texture coordinates before declaring the material used, loadOBJFile was implemented with that in mind. A searched a little bit through some examples and a bunch of files I had and your  3DScan_test3a.obj is the first one I see defining texture coordinates apearing after "usemtl" and intercalated with face objects. 

Nevertheless, you got me looking at the code and I found a bug in the way the function was loading the reflectivity parameters. :)

Cheers


2016-04-25 2:35 GMT+01:00 junsmog <[hidden email]>:
Felix,

Would you report the result of testing loadOBJFile please?



felixm wrote
> Moin Arne,
>
> klar, kann ich machen.
>
> Bis später
> Felix
>
> On Donnerstag, 14. April 2016 19:08:36 CEST junsmog wrote:
>> Would anyone please test the loadOBJFile function?
>> If you have the same results, I think it should be reported as a bug.
>>
>>
>>
>> --
>> View this message in context:
>> http://www.pcl-users.org/How-to-load-obj-with-texture-tp4041450p4041507.htm
>> l Sent from the Point Cloud Library (PCL) Users mailing list mailing list
>> archive at Nabble.com. _______________________________________________
>>

> PCL-users@

>  / http://pointclouds.org
>> http://pointclouds.org/mailman/listinfo/pcl-users
> _______________________________________________

> PCL-users@

>  / http://pointclouds.org
> http://pointclouds.org/mailman/listinfo/pcl-users





--
View this message in context: http://www.pcl-users.org/How-to-load-obj-with-texture-tp4041450p4041569.html
Sent from the Point Cloud Library (PCL) Users mailing list mailing list archive at Nabble.com.
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users


_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: How to load obj with texture

junsmog
Would you give me an example set of obj, mtl, and png which loadOBJFile can load successfully including texture?
When I moved "usemtl" part to the end of file, loadOBJFile did not work having error message "Debug Assertion Failed! Expression:vector subscript out of range"
I just want to know whether there exists a certain format of obj, mtl files which loadOBJFile properly work at.

Sérgio Agostinho wrote
Hey,

So I opened your file (3DScan_test3a.obj) and got the same issue. The
reason behind it is because there are texture coordinates being defined
after the invocation of "usemtl". I tried to search for the OBJ spec, but
the best I found were these
http://www.martinreddy.net/gfx/3d/OBJ.spec
http://www.fileformat.info/format/wavefrontobj/egff.htm

Although nothing states that you should specify your texture coordinates
before declaring the material used, loadOBJFile was implemented with that
in mind. A searched a little bit through some examples and a bunch of files
I had and your  3DScan_test3a.obj is the first one I see defining texture
coordinates apearing after "usemtl" and intercalated with face objects.

Nevertheless, you got me looking at the code and I found a bug in the way
the function was loading the reflectivity parameters. :)

Cheers


2016-04-25 2:35 GMT+01:00 junsmog <[hidden email]>:

> Felix,
>
> Would you report the result of testing loadOBJFile please?
>
>
>
> felixm wrote
> > Moin Arne,
> >
> > klar, kann ich machen.
> >
> > Bis später
> > Felix
> >
> > On Donnerstag, 14. April 2016 19:08:36 CEST junsmog wrote:
> >> Would anyone please test the loadOBJFile function?
> >> If you have the same results, I think it should be reported as a bug.
> >>
> >>
> >>
> >> --
> >> View this message in context:
> >>
> http://www.pcl-users.org/How-to-load-obj-with-texture-tp4041450p4041507.htm
> >> l Sent from the Point Cloud Library (PCL) Users mailing list mailing
> list
> >> archive at Nabble.com. _______________________________________________
> >>
>
> > PCL-users@
>
> >  / http://pointclouds.org
> >> http://pointclouds.org/mailman/listinfo/pcl-users
> > _______________________________________________
>
> > PCL-users@
>
> >  / http://pointclouds.org
> > http://pointclouds.org/mailman/listinfo/pcl-users
>
>
>
>
>
> --
> View this message in context:
> http://www.pcl-users.org/How-to-load-obj-with-texture-tp4041450p4041569.html
> Sent from the Point Cloud Library (PCL) Users mailing list mailing list
> archive at Nabble.com.
> _______________________________________________
> [hidden email] / http://pointclouds.org
> http://pointclouds.org/mailman/listinfo/pcl-users
>

_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: How to load obj with texture

Sérgio Agostinho
It failed because you need the faces to be defined after "usemtl". ​Like I said, your 3DScan_test3a.obj file is very "peculiar". 

Here's one that should work

Cheers

_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: How to load obj with texture

py_lwq
This post has NOT been accepted by the mailing list yet.
Hello,I have a question, Why can I just saw a white cube when using addtexturemesh in PCL 1.8.0, but i can see a colorful cube in Meshlab. How can i do to see a colorful cube in PCL.
Thank you very much !
Reply | Threaded
Open this post in threaded view
|

Re: How to load obj with texture

py_lwq
This post has NOT been accepted by the mailing list yet.
In reply to this post by junsmog
Can I see the texture with the function of addTextureMesh? Why can't I see the picture?
Thank you for replying!
Reply | Threaded
Open this post in threaded view
|

Re: How to load obj with texture

junsmog
In reply to this post by Sérgio Agostinho
Hi, Sérgio Agostinho

I tested the cube.obj and had no error, but the texture is not displayed.
All of cloud location, texture coordinate, mtl information and texture file name was successfully loaded, but I don't know where and when the actual texture image is loaded from the texture file.

Can you display texture when trying 3DScan_test3.obj which has right order of .obj format you suggested?
I have no idea why 3DScan_test3a.obj has weird format. It was exported in Meshlab.

3DScan_test3.obj ( generated from Intel RealSense SDK )
3DScan_test3a.obj ( converted from Meshlab)

I have the same error of "Debug Assertion Failed! Expression:vector subscript out of range" in both of the files.

Thank you.  

Sérgio Agostinho wrote
It failed because you need the faces to be defined after "usemtl". ​Like I
said, your 3DScan_test3a.obj file is very "peculiar".

Here's one that should work
https://mega.nz/#!UQNGRKoC!4H-sqfxnTDUOLsEOToVqDXOdHSe7spj6KzMGObAmS0k

Cheers

_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: How to load obj with texture

junsmog
In reply to this post by py_lwq
I have the same problem. What PCL version do you use?
I installed PCL 1.8.0rc2 All-in-one Installer MSVC2015 Win32
( http://unanancyowen.com/?p=1794&lang=en )

py_lwq wrote
Can I see the texture with the function of addTextureMesh? Why can't I see the picture?
Thank you for replying!
Reply | Threaded
Open this post in threaded view
|

Re: How to load obj with texture

py_lwq
This post has NOT been accepted by the mailing list yet.
Hi,I installed PCL 1.8.0 All-in-one Installer MSVC2013 Win32.
Dose "addtexturemesh" have the function of displying texture? I just see "addtexturemesh" in .h file , but isn't in .hpp file. And there isn't a detailed introduction about "addtexturemesh".
Reply | Threaded
Open this post in threaded view
|

Re: How to load obj with texture

Sérgio Agostinho
In reply to this post by junsmog
With 3DScan_test3.obj I get this.

​The texture is there, but the texture mapping is messed up. 
I'm using PCL from git, compiled from source on a Mac platform. VTK is 6.3.0

Side note: creepy face ^^

Cheers


_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
12