Start a new topic

Metadata

Original Post by: jrhea Tue Aug 9 20:38:52 2011


Hello,


I see that it is pretty easy to add comments to a node, but is there anyway to have these comments render when the model is viewed?


Thanks in advance


Original Post by: ChrisRogers Tue Aug 9 21:19:07 2011


This depends on where the model is viewed. One could write special code in their runtime to find important comments and render the found nodes different. Or if you are intending this to be a model-time enhancement, then you could write a special tool that searches the database and modifies nodes that have particular comments. However nothing very flexible is done automatically that I am aware of. What did you have in mind?

Original Post by: jrhea Tue Aug 9 21:29:46 2011


Thanks for the fast reply. Basically, I want to write an app that adds metadata to a particular object in the scene graph based on some data in a database. I would like this metadata to appear in a viewer like Deep View or any program that renders flt files. I tried adding an fltText node to the scene graph, but I couldn't get it to work. My code is below:


void AddText(mgrec *node)

{

mgrec* g1 = mgGetChild(node);

mgrec* wt1frame = mgGetNext(g1);

mgDetach(g1);

mgDetach(wt1frame);

mgrec* newNode = mgNewRec(fltGroup);

mgAttach(node,newNode);

mgAttach(newNode,g1);

mgAppend(newNode,wt1frame);


//Create text Node

mgrec* txtNode = mgNewRec(fltText);

mgSetTextString(txtNode,"Foo");

mgAppend(g1,txtNode);

}


int main(int argc, char* argv[])

{

mgrec* db;

char idname[80];

char *id = idname;


mgInit(&argc;, argv);

if (!(db = mgOpenDb(argv[1])))

{

printf("\nError in mgOpenDb(%s)\n", argv[1]);

exit(1);

}

AddText(db);

mgSaveAsDb(db,"foo.flt");

mgCloseDb (db);

return 0;

}

Original Post by: ChrisRogers Wed Aug 10 14:36:06 2011


I'm not sure how widespread the support for text nodes is, but it sounds like it might do what you want. In order to get it to work, you need to add a little bit to your code. Specifically you need to set up the ftFontname, fltTextDrawType and fltTextType. Also, it seems that there is a quirk with this node type in that you must set the fltTextType after you set the text string. Failure to do this in the correct order seems to result in the text string getting rejected.


here is a python snippet that shows how to create a fltText node:


db = mgGetCurrentDb()

g1 = mgGetChild(db)

txt = mgNewRec (fltText)

mgAttach (g1, txt)

mgSetAttList (txt, fltTextFontname, "paradigmfont.dat")

mgSetAttList (txt, fltTextDrawType, 1)

mgSetTextString (txt, "My String")

mgSetAttList (txt, fltTextType, 0)

Original Post by: jrhea Wed Aug 10 17:19:44 2011


Thanks for the reply. I am having issues even getting the fltText node to appear in the scene graph. When I run it there are no errors, but when I open it up in a viewer the fltText node does not appear. Do you see anything I am doing wrong? Thanks in advance.


//node is the dbNode

mgrec* g1 = mgGetChild(node);

mgrec* wt1frame = mgGetNext(g1);

mgDetach(g1);

mgDetach(wt1frame);\

//Create a group node and attach the two existing nodes to this group node

mgrec* newNode = mgNewRec(fltGroup);

mgAttach(node,newNode);

mgAttach(newNode,g1);

mgAppend(newNode,wt1frame);


//Create text Node and attach it to the group node

mgrec* txtNode = mgNewRec(fltText);

mgAttach(newNode,txtNode);

mgSetAttList (txtNode, fltTextFontname, "paradigmfont.dat",MG_NULL);

mgSetAttList (txtNode, fltTextDrawType, 1,MG_NULL);

mgSetTextString(txtNode,"Foo");

mgSetAttList (txtNode, fltTextType, 0,MG_NULL);


Original Post by: ChrisRogers Wed Aug 10 17:37:58 2011


I don't see much wrong. There is an unneeded \ after your a mgDetach, and if you run this on a new database it won't find wt1frame because there is usually no siblng to g1. I assume that the extra \ character was a typo, and that your databae does have a sibling to g1, so other than that there seems to be no problems. You could add some code to check the return value of the functions. Make sure the txtNode is not null after mgNeRec, make sure teh mgSetAttList functions work etc...


What viewer are you using?

Original Post by: jrhea Wed Aug 10 18:00:36 2011


I think it was a typo. BTW, I pasted the wrong code in...this line:


mgAttach(g1,txtNode);


should have read:


mgAttach(newNode,txtNode);


It still didn't make a difference. I am using Deep View to look at the scene graph


I attached what the scene graph looks like before and after the code runs.


They are displayed in this order: scene graph_after.jpg, scene_graph_before.jpg


I will check the return values like you suggested.


Thanks for your help

Original Post by: jrhea Wed Aug 10 18:11:56 2011


OK so I changed the code to display the return values like so:


mgrec* g1 = mgGetChild(node);

mgrec* wt1frame = mgGetNext(g1);

mgDetach(g1);

mgDetach(wt1frame);

mgrec* newNode = mgNewRec(fltGroup);

mgAttach(node,newNode);

mgAttach(newNode,g1);

mgAppend(newNode,wt1frame);


//Create text Node

mgrec* txtNode = mgNewRec(fltText);

mgbool bReturn = mgAttach(newNode,txtNode);

cout << "Attach return value: " << bReturn << endl;

cout << "Node name: " << mgGetName(txtNode) << endl;

int iReturn = mgSetAttList (txtNode, fltTextFontname, "paradigmfont.dat",MG_NULL);

cout << "Return value: " << iReturn << endl;

iReturn = mgSetAttList (txtNode, fltTextDrawType, 1,MG_NULL);

cout << "Return value: " << iReturn << endl;

iReturn = mgSetTextString(txtNode,"Foo");

cout << "Return value: " << iReturn << endl;

iReturn = mgSetAttList (txtNode, fltTextType, 0,MG_NULL);

cout << "Return value: " << iReturn << endl;


This is the output:


D:\My Documents\Visual Studio 2008\Projects\RadarConversionTest\x64\Debug>RadarConversionTest.exe WOD_Visuals.flt

I: OpenFlight API version 4.2.0.

I: Site <FLTDATA> registered for plugin <OpenFlight Data Dictionary>.

I: Plugin <fltdata.dll> loaded.

Attach return value: 1

Node name: t1

Return value: 1

Return value: 1

Return value: 1

Return value: 1

I: File written <foo.flt>.


Everything looks like it is working fine, but the "t1" node does not appear in the scene graph. Do you think it could be the viewer?

Original Post by: jrhea Wed Aug 10 19:57:47 2011


Out of curiosity, I went ahead and walked the scene graph printing out each node. It looks like the fltText node was added, but it isn't showing up in the scene tree in the viewer. Any suggestions would be appreciated. Thanks

Original Post by: ChrisRogers Thu Aug 11 16:13:20 2011


It looks like the viewer does not support the node type. If you want any viewer to be able to see the text, then the most reliable solution would be to make your own text using polygons. This is not as hard as it sounds. Here is how I would approach the problem.


First model each letter/number that you want to be able to use. I would use the 3d text tool to do this, and I would make sure each character is centered at the origin with a width and height of one meter. I would save each character under a group node and name that node the same name as the character.


Second I would include that file in my plugin distribution so it could be used later.


Third I would make my plugin function that needs to make text, open that file, find each character of the text it wants to make by using mgGetRecByName, and then duplicate each object to the db that needs to contain the text.


Last I would apply a transform of 1 meter to each character for each character that came before it in the string.


Below is a quick python script to show what the code would look like. This has the benefit of making real geometry and any viewer would be able to view it. You could then make your alphabet characters as fancy as you want. They could be filled polygons, wireframe outlines of letters, or anything you want.


db = mgGetCurrentDb()


def writeString (txt, node):

length = len(txt)

for i in range(0,length):

char = txt

characters = mgOpenDb ("c:/alpha/alphanumeric.flt")

grp = mgGetRecByName (characters, char)

dup = mgDuplicateToDb (grp, db)

mgCloseDb(characters)

xform = mgNewRec(fltXmTranslate)

mgSetCoord3d (xform, fltXmTranslateDelta, i,0,0)

print mgAttach (dup, xform)

print mgAppend (node, dup)

g1 = mgGetChild (db)

writeString ("abc", g1)

Original Post by: jrhea Thu Aug 11 17:36:29 2011


That is a great idea. Thank you for your help.

Login to post a comment