OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Visualizing triangle data


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
sam
Guest





PostPosted: Wed Jun 13, 2018 9:52 pm    Post subject:
Visualizing triangle data
Reply with quote

Hi All,


I am working on reverse engineering a mesh format. I've managed to successfully get the mesh to draw and texture. I'm now working on visualizing the walkable data that is against the mesh. I think I've dissected the section of the format that stores that information and it looks like such:





The actual mesh itself is made out of vertex and indexs. However, this section for each walkable triangle seems to not share any vertices.


My question is, what is the best way to visualize this data in OSG? I'd like to be able to toggle them on and off when the entire map is rendered to view the flags. Solid colored triangles would be preferable.


Thanks, Sam

------------------
Post generated by Mail2Forum
Back to top
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12094

PostPosted: Thu Jun 14, 2018 7:18 am    Post subject:
Visualizing triangle data
Reply with quote

HI Sam,


Have a look at the osggeometry example as this illustrates how to set up geometry data, which includes triangles.  For the traingle mesh what you'll likely want to do is use an osg::DrawElementUShort(GL_TRIANGLES) and then add you triangle indices to this.


Robert.


On Wed, 13 Jun 2018 at 22:51, sam < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:

Quote:
Hi All,


I am working on reverse engineering a mesh format. I've managed to successfully get the mesh to draw and texture. I'm now working on visualizing the walkable data that is against the mesh. I think I've dissected the section of the format that stores that information and it looks like such:





The actual mesh itself is made out of vertex and indexs. However, this section for each walkable triangle seems to not share any vertices.


My question is, what is the best way to visualize this data in OSG? I'd like to be able to toggle them on and off when the entire map is rendered to view the flags. Solid colored triangles would be preferable.


Thanks, Sam




_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
sbrkopac
Newbie


Joined: 14 Jun 2018
Posts: 8

PostPosted: Thu Jun 14, 2018 7:39 am    Post subject:
Reply with quote

Hi Robert,

I have the mesh setup correctly using the DrawElementsUShort. My question was regarding drawing the walkable triangles that are attached to the mesh. These don't have indices and just consist of the vertex information. Here was my approach to draw them.

Code:

for (size_t index = 0; index < sno.mystery_section_count(); index++)
{
    const auto * mystery_section = sno.mystery()->at(index);

    const auto triangleSectionCount = mystery_section->triangle_section_count();

    osg::ref_ptr<osg::Geode> flags = new osg::Geode;
    grouping->addChild(flags);

    const osg::Vec4 non(1.0f, 0.0f, 0.0f, 0.5f); // red for non-walkable
    const osg::Vec4 floor(0.0f, 1.0f, 0.0f, 0.5f); // green for walkable
    const osg::Vec4 water(0.0f, 0.0f, 1.0f, 0.5f); // blue for water

    osg::ref_ptr<osg::Vec4Array> color(new osg::Vec4Array(1));

    switch (mystery_section->floor())
    {
    case sno_t::floor_t::FLOOR_IGNORED:
        (*color)[0] = non;
        break;
    case sno_t::floor_t::FLOOR_FLOOR:
        (*color)[0] = floor;
        break;
    case sno_t::floor_t::FLOOR_WATER:
        (*color)[0] = water;
        break;
    }

    for (size_t j = 0; j < triangleSectionCount; j++)
    {
        const auto * triangle_section = mystery_section->triangle_section()->at(j);

        const auto * triangleA = triangle_section->triangle()->a();
        const auto * triangleB = triangle_section->triangle()->b();
        const auto * triangleC = triangle_section->triangle()->c();

        // setup the vertices based on the triangles
        osg::ref_ptr<osg::Vec3Array> vertices(new osg::Vec3Array(3));
        (*vertices)[0] = osg::Vec3(triangleA->x(), triangleA->y(), triangleA->z());
        (*vertices)[1] = osg::Vec3(triangleB->x(), triangleB->y(), triangleB->z());
        (*vertices)[2] = osg::Vec3(triangleC->x(), triangleC->y(), triangleC->z());

        // setup our geometry
        osg::ref_ptr<osg::Geometry> geometry(new osg::Geometry);
        geometry->setVertexArray(vertices);
        geometry->setColorArray(color);
        geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
        geometry->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLES, 0, 3));

        osg::ref_ptr<osg::Geode> geode(new osg::Geode);
        geode->addDrawable(geometry);
        geode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
        geode->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
        geode->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);

        // prevent z-fighting.
        osg::ref_ptr<osg::PolygonOffset> polyOffset = new osg::PolygonOffset;
        polyOffset->setFactor(-1.0f);
        polyOffset->setUnits(-1.0f);

        osg::ref_ptr<osg::PolygonMode> polyMode = new osg::PolygonMode;
        polyMode->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::FILL);
        geode->getOrCreateStateSet()->setAttributeAndModes(polyOffset, osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
        geode->getOrCreateStateSet()->setAttributeAndModes(polyMode, osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);

        flags->addChild(geode);
    }
}


If you have any feedback on the methodology, I'd love to hear it.

Thanks,
Sam[/code]
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12094

PostPosted: Thu Jun 14, 2018 10:05 am    Post subject:
Visualizing triangle data
Reply with quote

Hi Sam,

On a quick read of your code I can't see a problem. Does this work OK?

It's perfectly find to just use DrawArrays without indices like you
have done. You can mix both DrawArrays and DrawElementsUShort in a
single osg::Geometry as well.

I'm not clear on what issue you are having.

Cheers,
Robert.
On Thu, 14 Jun 2018 at 09:24, Sam Brkopac <> wrote:
Quote:

Hi Robert,

I have the mesh setup correctly using the DrawElementsUShort. My question was regarding drawing the walkable triangles that are attached to the mesh. These don't have indices and just consist of the vertex information. Here was my approach to draw them.


Code:

for (size_t index = 0; index < sno.mystery_section_count(); index++)
{
const auto * mystery_section = sno.mystery()->at(index);

const auto triangleSectionCount = mystery_section->triangle_section_count();

osg::ref_ptr<osg::Geode> flags = new osg::Geode;
grouping->addChild(flags);

const osg::Vec4 non(1.0f, 0.0f, 0.0f, 0.5f); // red for non-walkable
const osg::Vec4 floor(0.0f, 1.0f, 0.0f, 0.5f); // green for walkable
const osg::Vec4 water(0.0f, 0.0f, 1.0f, 0.5f); // blue for water

osg::ref_ptr<osg::Vec4Array> color(new osg::Vec4Array(1));

switch (mystery_section->floor())
{
case sno_t::floor_t::FLOOR_IGNORED:
(*color)[0] = non;
break;
case sno_t::floor_t::FLOOR_FLOOR:
(*color)[0] = floor;
break;
case sno_t::floor_t::FLOOR_WATER:
(*color)[0] = water;
break;
}

for (size_t j = 0; j < triangleSectionCount; j++)
{
const auto * triangle_section = mystery_section->triangle_section()->at(j);

const auto * triangleA = triangle_section->triangle()->a();
const auto * triangleB = triangle_section->triangle()->b();
const auto * triangleC = triangle_section->triangle()->c();

// setup the vertices based on the triangles
osg::ref_ptr<osg::Vec3Array> vertices(new osg::Vec3Array(3));
(*vertices)[0] = osg::Vec3(triangleA->x(), triangleA->y(), triangleA->z());
(*vertices)[1] = osg::Vec3(triangleB->x(), triangleB->y(), triangleB->z());
(*vertices)[2] = osg::Vec3(triangleC->x(), triangleC->y(), triangleC->z());

// setup our geometry
osg::ref_ptr<osg::Geometry> geometry(new osg::Geometry);
geometry->setVertexArray(vertices);
geometry->setColorArray(color);
geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
geometry->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLES, 0, 3));

osg::ref_ptr<osg::Geode> geode(new osg::Geode);
geode->addDrawable(geometry);
geode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
geode->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute:ShockedN);
geode->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);

// prevent z-fighting.
osg::ref_ptr<osg::PolygonOffset> polyOffset = new osg::PolygonOffset;
polyOffset->setFactor(-1.0f);
polyOffset->setUnits(-1.0f);

osg::ref_ptr<osg::PolygonMode> polyMode = new osg::PolygonMode;
polyMode->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::FILL);
geode->getOrCreateStateSet()->setAttributeAndModes(polyOffset, osg::StateAttribute::OVERRIDE | osg::StateAttribute:ShockedN);
geode->getOrCreateStateSet()->setAttributeAndModes(polyMode, osg::StateAttribute::OVERRIDE | osg::StateAttribute:ShockedN);

flags->addChild(geode);
}
}




If you have any feedback on the methodology, I'd love to hear it.

Thanks,
Sam[/code]

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74070#74070








------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
sbrkopac
Newbie


Joined: 14 Jun 2018
Posts: 8

PostPosted: Thu Jun 14, 2018 4:16 pm    Post subject:
Reply with quote

Hi Robert,

It seems to work okay. I wasn't sure how to do it in my original post and that is what I came up with. I haven't tried this on a large scale map consisting of around ~1700 of the nodes. I'll post back if there are any performance issues.

Thanks, Sam
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Converting PrimitiveSet to use triang... Waaayoff General 7 Fri Jul 27, 2018 12:06 pm View latest post
No new posts How to get the normal of every triangle? Wangbingqian General [forum] 2 Mon Mar 19, 2018 1:53 am View latest post
No new posts How to get the triangle normal vector? Wangbingqian General 0 Fri Mar 16, 2018 1:07 pm View latest post
No new posts Specifying indices of triangle vertic... antiro42 General 1 Thu Dec 21, 2017 12:44 pm View latest post
No new posts How to Save and Load the current scen... blackball General 1 Mon Dec 11, 2017 5:52 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP