Hi Jon,

On Sat, 2003-12-20 at 01:38, Jon Guerin wrote:
> Hey guys, I'm in need of a little assistance.
>  
> I've created a model in 3DS and exported it as a Wavefront .OBJ file.
> I've loaded it up using OSG's file reader. I now need to change the
> colors of the vertices of the model. The Geometry nodes of the tree
> don't appear to have Color information, geo->getColors() returns
> NullFC. I attempt to create them.

OK, sounds good so far. ;)
 
> I have a function that traverses through the tree returned by the file
> reader. I've created a GeoColors object and for each vertex in the
> Geometry, accessed through the GeoPositions object returned by the
> node's Geometry, I added a color to the GeoColors via
> col->addValue(c). Finally, I tell the Geometry node to use the new
> color object, geo->setColors(col). 
>  
> This approach worked for a few of my earlier models, but not the later
> ones. I have no idea why. The first few models I used didn't have
> normals in the .OBJ file, and while they looked horrendous they still
> showed colors when rendered. 

That sounds like the culprit, see below.
 
> In the newer models, I have normal information in the .OBJ file. Now,
> it seems no matter what I do, creating color information for geometry
> does not do anything. The model always renders grey. I've tried
> several things; creating SimpleMaterial objects and
> setting glColorMaterial() to different values. Changing/adding
> material information to the geometry node results in a visible changes
> to the model, but the information from the Colors object I created and
> added seems to be ignored. Turning lighting on and off, changing
> glShadeModel(), do nothing. I've used begin/endEditCP() functions like
> in the tutorials, but that still doesn't make it work.
>  
> If anybody can help me out with my problem I'd appreciate it. I need
> to add color information to vertices in geometry nodes that have been
> obtained from importing .OBJ files and have it visible when rendering.
> I have a feeling that there's some gl___() command that I'm not aware
> of or something tricky having to do with materials or lighting, or
> perhaps I'm not adding the colors to the geometry correctly. Help?

Yup. The problem is that OBJ files have different indices for
position/normals/texcoords, which in OpenSG means the Geometry is
multi-indexed. Now if you add Colors to the Geometry, they are ignored
unless you tell it which index to use for the colors.

At the spot where you set the colors, try to add a 

UInt16 pind = geo->calcMappingIndex(Geometry::MapPosition);
geo->getIndexMapping()[pind] |= Geometry::MapColor;

to tell the Geometry to use the same index for positions and colors.

The interleaved multi-indexing, while simple and compact, is not easy to
uinderstand, and not easy to manipulate, and thus will go away in the
future to be replaced by separate indices. But for now be aware of this
side requirement.

Hope it helps

        Dirk




-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to