[osg-users] runtime bug when loading obj model in OpenSceneGraph 2.8.2

199 views
Skip to first unread message

tien dat

unread,
Oct 22, 2009, 3:40:44 PM10/22/09
to OpenSceneGraph Users
Dear all,
I have a model in obj format and want to load the model into
OpenSceneGraph. When there is no texture, OpenSceneGraph can load the
model fine. But when I use the model with texture, OpenSceneGraph
allocates a huge amount of memory and crashes. I think it's a runtime
bug and would like to know how to fix it. Please find some pictures
about the error in the following webpage:
http://cs.uiowa.edu/~tinguyen/osgbug.html
You can find the model in the above page as well, if you want to
reproduce the error.
Thanks,
Dat
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Ulrich Hertlein

unread,
Oct 23, 2009, 4:58:16 AM10/23/09
to OpenSceneGraph Users
Hi,

On 22/10/09 9:40 PM, tien dat wrote:
> I have a model in obj format and want to load the model into
> OpenSceneGraph. When there is no texture, OpenSceneGraph can load the
> model fine. But when I use the model with texture, OpenSceneGraph
> allocates a huge amount of memory and crashes. I think it's a runtime
> bug and would like to know how to fix it. Please find some pictures

Not really a bug, I'd say you're running out of memory.

- try to reduce the image sizes.
- a lot of materials reference the same image. I don't think the obj loader caches this
which means you're loading that image over and over again. Use osgDB::Options to specify
caching of images.

Hope this helps,
Cheers,
/ulrich

Ulrich Hertlein

unread,
Oct 23, 2009, 6:02:50 AM10/23/09
to OpenSceneGraph Users
On 23/10/09 10:58 AM, Ulrich Hertlein wrote:
> On 22/10/09 9:40 PM, tien dat wrote:
>> I have a model in obj format and want to load the model into
>> OpenSceneGraph. When there is no texture, OpenSceneGraph can load the
>> model fine. But when I use the model with texture, OpenSceneGraph
>> allocates a huge amount of memory and crashes. I think it's a runtime
>> bug and would like to know how to fix it. Please find some pictures
>
> Not really a bug, I'd say you're running out of memory.
>
> - try to reduce the image sizes.
> - a lot of materials reference the same image. I don't think the obj
> loader caches this which means you're loading that image over and over
> again. Use osgDB::Options to specify caching of images.

Oh, and you seem to have pretty much one material per drawable. This will absolutely kill
your performance. Have a look at the .mtl file, you'll notice that there are heaps of
materials that have identical properties.

tien dat

unread,
Oct 23, 2009, 11:26:19 AM10/23/09
to OpenSceneGraph Users
Dear Ulrich,
Could you tell me more about how to specify that option? Can I specify
it while using osgviewer.exe or I have to rebuild osgviewer.exe with
the option?
Thanks,
Dat

Ulrich Hertlein

unread,
Oct 26, 2009, 8:33:42 AM10/26/09
to OpenSceneGraph Users
Hi Dat,

On 23/10/09 5:26 PM, tien dat wrote:
> Dear Ulrich,
> Could you tell me more about how to specify that option? Can I specify
> it while using osgviewer.exe or I have to rebuild osgviewer.exe with
> the option?

Unfortunately you can't (at the moment) set this option externally or internally, because
the .obj loader doesn't pass the options object along.

Even if you could it would only avoid loading the same image over and over again. It will
not solve the massively duplicated state/material that the model has.

Either the modelling is done very inefficiently in the 3D application or whatever exporter
is used messes things up.

If you absolutely have to use osgviewer (rather than your own app) I'd actually write a
script to optimise the .obj and .mtl files by removing duplicate materials.

What you might also want to do is to remove the 'map_Ka' (ambient texture map) statements
since they are not used with the standard OpenGL paths (but are still loaded).

Cheers,
/ulrich

> On Fri, Oct 23, 2009 at 5:02 AM, Ulrich Hertlein<u.her...@sandbox.de> wrote:
>> On 23/10/09 10:58 AM, Ulrich Hertlein wrote:
>>>
>>> On 22/10/09 9:40 PM, tien dat wrote:
>>>>
>>>> I have a model in obj format and want to load the model into
>>>> OpenSceneGraph. When there is no texture, OpenSceneGraph can load the
>>>> model fine. But when I use the model with texture, OpenSceneGraph
>>>> allocates a huge amount of memory and crashes. I think it's a runtime
>>>> bug and would like to know how to fix it. Please find some pictures
>>>
>>> Not really a bug, I'd say you're running out of memory.
>>>
>>> - try to reduce the image sizes.
>>> - a lot of materials reference the same image. I don't think the obj
>>> loader caches this which means you're loading that image over and over
>>> again. Use osgDB::Options to specify caching of images.
>>
>> Oh, and you seem to have pretty much one material per drawable. This will
>> absolutely kill your performance. Have a look at the .mtl file, you'll
>> notice that there are heaps of materials that have identical properties.

Nguyen Tien Dat

unread,
Oct 26, 2009, 11:10:54 AM10/26/09
to OpenSceneGraph Users
Dear Ulrich,
Sorry for my stupidity, but I don't know anything about modifying
models. The model is actually created in VRML, and I use 3DS Max to
export it to obj format. So if you can, please tell me a bit more
about how to optimize the model:
- How can you remove duplicate materials (if you can tell me how to do
it by hand, that helps too)
- What else can I do to load the model in an efficient way?
Thank you very much,
Dat

Nguyen Tien Dat

unread,
Oct 26, 2009, 9:05:33 PM10/26/09
to OpenSceneGraph Users
Hi,
So I have read about .mtl and .obj files and understood what you
meant. I created a program to optimize the model
(http://cs.uiowa.edu/~tinguyen/OptimizeMtlFiles.rar)
But the new one that I created doesn't look the same as the old one
when I don't use texture. Please click this link to download both
versions, and use osgviewer.exe to view them.
http://cs.uiowa.edu/~tinguyen/supermarket_3ds.rar
The old one has some color (again, without texture), but the new one
doesn't. So I'm wondering what's wrong.
Could any of you give me a hand?
Thanks,
Dat

--
Dat Tien Nguyen
PhD student, Computer Science Department
The University of Iowa, IA 52242
http://cs.uiowa.edu/~tinguyen

Ulrich Hertlein

unread,
Oct 27, 2009, 6:53:10 AM10/27/09
to OpenSceneGraph Users
Hello Dat,

On 27/10/09 2:05 AM, Nguyen Tien Dat wrote:
> So I have read about .mtl and .obj files and understood what you
> meant. I created a program to optimize the model
> (http://cs.uiowa.edu/~tinguyen/OptimizeMtlFiles.rar)
> But the new one that I created doesn't look the same as the old one
> when I don't use texture. Please click this link to download both
> versions, and use osgviewer.exe to view them.
> http://cs.uiowa.edu/~tinguyen/supermarket_3ds.rar
> The old one has some color (again, without texture), but the new one
> doesn't. So I'm wondering what's wrong.

Quite simple: if you look at the beginning of the 'supermarket_new.obj' file you'll see
the reference to the material file: 'mtllib supermarket_new.mlt'

Note the file extension, it's 'mlt' but it should be 'mtl'.
The obj reader should complain rather loudly that it can't find this file but apparently
it isn't.

Cheers,
/ulrich

Erik den Dekker

unread,
Oct 27, 2009, 7:27:57 AM10/27/09
to OpenSceneGraph Users

Hi Dat,

Maybe I am not seeing something obvious here, but why don't you use
the OpenSceneGraph VRML loader instead of taking a detour via 3DS Max
and convert to .obj format?

Erik den Dekker

Nguyen Tien Dat

unread,
Oct 27, 2009, 12:36:07 PM10/27/09
to OpenSceneGraph Users
Dear Ulrich and Erik,
Yeah, I can load the model with texture now. Thanks Ulrich for your
help. I really appreciate that.
For Erik's question, I must say that I did try the VRML loader, but it
didn't compile. I had another thread to ask for the issue (you can
search in osg mails for "VRML plug in"), and there were some answers.
Some said I may use Linux instead, and some said I should be able to
compile in in Windows. Anyway, I wasn't able to compile the plug-in,
so converting to obj model is the next thing I try. It works for me
now, so I think I'm good.
Thanks,
Dat

--

Dat Tien Nguyen
PhD student, Computer Science Department
The University of Iowa, IA 52242
http://cs.uiowa.edu/~tinguyen

Ulrich Hertlein

unread,
Oct 28, 2009, 3:14:13 AM10/28/09
to OpenSceneGraph Users
Hi Dat,

On 27/10/09 11:53 AM, Ulrich Hertlein wrote:
> On 27/10/09 2:05 AM, Nguyen Tien Dat wrote:
>> So I have read about .mtl and .obj files and understood what you
>> meant. I created a program to optimize the model
>> (http://cs.uiowa.edu/~tinguyen/OptimizeMtlFiles.rar)

Oh and one more thing: you have a lot of identical materials without texture. Does your
optimizer only check for identical textures?

Nguyen Tien Dat

unread,
Oct 28, 2009, 7:27:42 PM10/28/09
to OpenSceneGraph Users
My optimizer is only check for identical textures - i.e. materials
that load the same image. I didn't check for materials without
texture. Do you need to compare all properties of each material in
order to find duplicate?
Thanks,
Dat

--

Dat Tien Nguyen
PhD student, Computer Science Department
The University of Iowa, IA 52242
http://cs.uiowa.edu/~tinguyen

Ulrich Hertlein

unread,
Oct 29, 2009, 3:58:46 AM10/29/09
to OpenSceneGraph Users
On 29/10/09 12:27 AM, Nguyen Tien Dat wrote:
> texture. Do you need to compare all properties of each material in
> order to find duplicate?

Everything except the name ;-D

Nguyen Tien Dat

unread,
Oct 29, 2009, 3:46:20 PM10/29/09
to OpenSceneGraph Users
Thanks. I'll do that.
Dat
Reply all
Reply to author
Forward
0 new messages