Color OBJ model with GL3

42 views
Skip to first unread message

marco....@elmansrl.eu

unread,
Sep 27, 2022, 10:23:50 AM9/27/22
to OpenSceneGraph Users
Hi,

if I can't use material to color the model loaded from obj file, now how can I color that model avoiding to use shaders?



Thanks

alexandre.vai...@gmail.com

unread,
Sep 27, 2022, 1:42:39 PM9/27/22
to OpenSceneGraph Users
Hello Marco(?)

Although wavefront .obj don't support vertex colours out of the box, it appears the OSG obj plugin code can read vertex colours the way MeshLab outputs it. I'm not sure how it's done, but I would give it a try.

Trajce Nikolov NICK

unread,
Sep 27, 2022, 2:14:51 PM9/27/22
to osg-...@googlegroups.com
Hi,

obj does support colouring by using mtl (material) associated text file where materials are defined with all the color and texture info in it. if the obj is text (not binary) you can set your material to be used per face for example in text editor - for binary you are left to your modelling software. And the osg obj loader uses the mtl file if present - from real cases with obj from Blender you might need to adjust some color properties in text editor

--
You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osg-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osg-users/c4473ca3-286e-4c9d-8a9f-4870af61f197n%40googlegroups.com.


--
trajce nikolov nick

alexandre.vai...@gmail.com

unread,
Sep 27, 2022, 2:43:47 PM9/27/22
to OpenSceneGraph Users
Trajce,

The way I read it, they can't use materials to colour their object.

OSG's .OBJ reader supports vertex colours when written like this:

v -7.941349983215332 -11.136899948120117 -3.4483699798583984       1.0 0.0 0.0

with the last three values here being the red, the green and the blue.

This works at least with the text version of .OBJ files. If the user has actually access to the .mtl file, your approach is fine. This vertex colour approach here is an alternative, although, as I understand, it's not totally supported by 3d graphics editors.

- Vaillancourt

Trajce Nikolov NICK

unread,
Sep 28, 2022, 1:13:35 AM9/28/22
to osg-...@googlegroups.com
Yes, you are right!

I knew also vertex colors are supported but wasn't sure if that was in the 'v' or separate parameter. It's been a while since I worked with it, and I think most of the Editors supports it when dealing with point clouds, not sure for 3D models



--
trajce nikolov nick

marco....@elmansrl.eu

unread,
Sep 28, 2022, 3:46:02 AM9/28/22
to OpenSceneGraph Users

Thanks for the various answers .... 

 First I downloaded MeshLab and tried to create a cube and color it ... actually OSG colors it well and I'm happy with that. 

 However, the problem arises when I attach a texture to a face. In fact, the .mtl file is created and this is managed as a material and then everything returns as before and OSG fails not knowing how to manage it .... 

 My need is to import complex .obj models (boats) containing a lot of textures ....

Trajce Nikolov NICK

unread,
Sep 28, 2022, 8:43:32 AM9/28/22
to osg-...@googlegroups.com
Hi !,

You can open the .mtl in a text editor and check the texture paths - absolute vs. relative paths, based on your 3D editor. You might also tune the ambient, diffuse component for the material -  the reason for this is just empirical from experience so far, some 3D editors might export the textured faces too dark or black, I mean that it how they will appear , but in fact is just dark or black component



--
trajce nikolov nick
Reply all
Reply to author
Forward
0 new messages