It is currently 27 Apr 2017, 01:37

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 34 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
 Post subject: C++ custom tool SDK programming tip
PostPosted: 26 Jul 2011, 12:14 
Offline
Moderator
User avatar

Joined: 26 Sep 2009, 15:51
Posts: 1270
Location: Bonn, Germany
Here's a tip how to get the actual component object (edge, point, polygon) from a custom tool snap/pick operation.

This is useful for example in case you want to highlight an edge.

The component arrives as the first and only element of the Component Collection of the SubComponent property of a CollectionItem. Phew ,).... The C++ API doesn't provide access to either of those elements, so you'll have to go through the CComAPIHander again (similar to handling component selections)

So basically to get the component, you will have to do:

Code:
CRef ref = in_ctxt.GetSnapComponent();
if(!ref.IsValid())
   break;
                              
CComAPIHandler cCollItem(ref);
CComAPIHandler cSubComp(cCollItem.GetProperty(L"SubComponent"));
CComAPIHandler cCompColl(cSubComp.GetProperty(L"ComponentCollection"));
if(LONG(cCompColl.GetProperty(L"Count")) != 1L)
   break;

CValue rVal;
CValueArray rrParams;
rrParams.Add(0L);
CStatus bOk = cCompColl.Invoke(L"Item", CComAPIHandler::PropertyGet, rVal, rrParams);
CRef edgeRef(rVal);
Edge theEdge(edgeRef);


Code:
Edge theEdge(in_ctxt.GetSnapComponent());

would have been easier.... but it works ;)

Note that snap works on the unsubdivided mesh of a subd surface, and pick works on the subdivided mesh (uses a hidden pick bitmap)

Hope this helps somebody get started with custom tool programming.

_________________
Image rray.de, a resource site for softimage, updated Oct 15th 2016


Last edited by rray on 26 Jul 2011, 18:59, edited 1 time in total.
some added info....


Top
 Profile  
 
 Post subject: Re: C++ custom tool programming tip
PostPosted: 26 Jul 2011, 13:45 
Offline
User avatar

Joined: 09 Aug 2010, 01:37
Posts: 339
Location: Tits
Thank you rray.
The old "XSI user normals" SDK example/tool has hover highlight and select functionality.
I wonder if it's possible to "chop ++" the actual normal display and rotation tweaking code, and leave it as multi-component selection tool with highlighting?
Maybe even put loop and range select on middle and right click? Is this possible?

Thanks.


Top
 Profile  
 
 Post subject: Re: C++ custom tool programming tip
PostPosted: 26 Jul 2011, 14:15 
Offline
Moderator
User avatar

Joined: 26 Sep 2009, 15:51
Posts: 1270
Location: Bonn, Germany
Tweak tool "sort of" does that, presumed you don't move anything
Never looked into the old "UserNormals" code. But I guess it would be possible to modify the code. Although since the tool SDK wasn't finished back then I assume it involved a bit of hacking. So probably it would be easier to build on one of the new tool SDK examples.

_________________
Image rray.de, a resource site for softimage, updated Oct 15th 2016


Top
 Profile  
 
 Post subject: Re: C++ custom tool SDK programming tip
PostPosted: 26 Jul 2011, 19:12 
Offline
Moderator
User avatar

Joined: 26 Sep 2009, 15:51
Posts: 1270
Location: Bonn, Germany
Btw, how would I get the subdivided version of an edge in case I want to highlight that?

Currently looking into the GeometryAccessor, but no idea if this will work.

_________________
Image rray.de, a resource site for softimage, updated Oct 15th 2016


Top
 Profile  
 
 Post subject: Re: C++ custom tool SDK programming tip
PostPosted: 15 Aug 2011, 15:07 
Offline
User avatar

Joined: 09 Jun 2009, 11:59
Posts: 619
Location: warsaw
Thanks ray, now I got highlighting of all components, funny thing it's reacting faster than tweak tool
Of course subdees are not working...

on a sidenote, would be cool to have a source code of new edge split tool which will be available in SAP for 2012...since it's build on custom tool sdk, It would be very helpful to look into its code

_________________
http://vimeo.com/origin/videos


Top
 Profile  
 
 Post subject: Re: C++ custom tool SDK programming tip
PostPosted: 24 Aug 2011, 01:54 
Offline
User avatar

Joined: 09 Jun 2009, 11:59
Posts: 619
Location: warsaw
rray wrote:
Btw, how would I get the subdivided version of an edge in case I want to highlight that?

Currently looking into the GeometryAccessor, but no idea if this will work.


yep, GeometryAccessor works flawless.
here's code for polygons (objSelected is X3dObject from picking and theFace is face from picking, out_vertPos is vertices position for OGL triangles drawing)

it's quite slow for higher poly meshes, not sure if I can optimize that

Code:
                        PolygonMesh mesh(this->objSelected.GetActivePrimitive().GetGeometry() );
                        PolygonFace theFace(compRef);
                        Property oGApprox;
                        this->objSelected.GetPropertyFromName("geomapprox", oGApprox);
                        siSubdivisionRuleType subdrule;
                        switch ( (int)oGApprox.GetParameter("gapproxmosr").GetValue() ) {
                           case 0: subdrule = siCatmullClark;break;
                           case 1: subdrule = siXSIDooSabin ;break;
                           case 2: subdrule = siLinearSubdivision ;break;
                           default: subdrule = siCatmullClark;break;
                        };

                        CGeometryAccessor geoAc(mesh.GetGeometryAccessor(siConstructionModeDefault,
                                          subdrule,
                                          oGApprox.GetParameter("gapproxmosl").GetValue(),
                                          oGApprox.GetParameter("gapproxmoad").GetValue(),
                                          oGApprox.GetParameter("gapproxmoan").GetValue()
                           )
                           );
                        
                        LONG faceindex = theFace.GetIndex();

                        CLongArray vertInd, trianglesInd,triangleVertInd;
                        CDoubleArray vertPos,out_vertPos;
                        LONG triangleInd;
                        geoAc.GetVertexIndices(vertInd);
                        geoAc.GetVertexPositions(vertPos);
                        geoAc.GetTriangleVertexIndices(triangleVertInd);
                        geoAc.GetPolygonTriangleIndices(trianglesInd);
                        
                        CLongArray SelfaceInd;

                        for (LONG i=0;i<geoAc.GetTriangleCount();i++)
                        {
                           geoAc.GetPolygonTriangleIndex(i, triangleInd);
                           if (triangleInd == faceindex)
                           {
                              SelfaceInd.Add(i);
                           }
                        }

                        for(LONG i=0;i<SelfaceInd.GetCount();i++)//for every triangle index
                        {
                           LONG tidx = SelfaceInd[i]*3;
                           
                           
                           for(int k=0;k<3;k++)
                           {
                              LONG tvidx = triangleVertInd[tidx+k];
                              LONG vidx = tvidx*3;
                              out_vertPos.Add( vertPos[ vidx ]);
                              out_vertPos.Add( vertPos[ vidx + 1]) ;
                              out_vertPos.Add( vertPos[ vidx + 2]);
                              
                           }
                        }

_________________
http://vimeo.com/origin/videos


Top
 Profile  
 
 Post subject: Re: C++ custom tool SDK programming tip
PostPosted: 24 Aug 2011, 03:11 
Offline

Joined: 08 Jul 2009, 05:16
Posts: 114
rray wrote:
Here's a tip how to get the actual component object (edge, point, polygon) from a custom tool snap/pick operation.

This is useful for example in case you want to highlight an edge.

alternatively you could...

Code:
CRef ref = in_ctxt.GetSnapComponent();
if(!ref.IsValid())
   break;                         
CComAPIHandler cCollItem(ref);
CComAPIHandler cSubComp(cCollItem.GetProperty(L"SubComponent"));
CValueArray indices = cSubComp.GetProperty( L"ElementArray" );
m_meshObject = cSubComp.GetProperty( L"Parent3DObject" );
PolygonMesh mesh( m_meshObject.GetActivePrimitive().GetGeometry() );
Edge edge = mesh.GetEdges().GetItem(indices[0]);

essentially get the element index, parent 3d object, and ask for that index again from the geo. i only suggest that because it took me 5 mins to figure out what the hell that last part was doing in your example code ;)

i wonder why this had to go through com api? i feel like the need for it was removed a long time ago.


Top
 Profile  
 
 Post subject: Re: C++ custom tool SDK programming tip
PostPosted: 24 Aug 2011, 11:33 
Offline
Moderator
User avatar

Joined: 26 Sep 2009, 15:51
Posts: 1270
Location: Bonn, Germany
Quote:
yep, GeometryAccessor works flawless.
here's code for polygons (objSelected is X3dObject from picking and theFace is face from picking, out_vertPos is vertices position for OGL triangles drawing)

it's quite slow for higher poly meshes, not sure if I can optimize that


Hey thanks for the code, completely missed that function of the GeometryAccessor, was only looking at GetGeometryElementFlags of the Cluster class which let to nothing. Very useful for that!
Btw, I noticed that you use the GetPolygonTriangleIndex function instead of accessing the trianglesInd array, wouldn't that be faster?

Quote:
essentially get the element index, parent 3d object, and ask for that index again from the geo. i only suggest that because it took me 5 mins to figure out what the hell that last part was doing in your example code ;)

i wonder why this had to go through com api? i feel like the need for it was removed a long time ago.


Thanks Steven - That "Item" call is nasty ;D Your code is better to read, and probably a bit faster too.
I too hope COM will go away from the C++ API, but it's good to have the CComAPIWrapper already instead of doing pure COM programming using IDispatch etc.

_________________
Image rray.de, a resource site for softimage, updated Oct 15th 2016


Top
 Profile  
 
 Post subject: Re: C++ custom tool SDK programming tip
PostPosted: 24 Aug 2011, 13:30 
Offline
User avatar

Joined: 09 Jun 2009, 11:59
Posts: 619
Location: warsaw
I tried GetPolygonTriangleIndices but it's returning indicies of new polygons, not old ones.
I made it abit faster by starting iterating from index faceindex*(pow(4.0,oglapproxlevel)) and ending loop just after I have all indexes but it's still dead slow on hi poly meshes.

_________________
http://vimeo.com/origin/videos


Top
 Profile  
 
 Post subject: Re: C++ custom tool SDK programming tip
PostPosted: 24 Aug 2011, 14:10 
Offline
Moderator
User avatar

Joined: 26 Sep 2009, 15:51
Posts: 1270
Location: Bonn, Germany
Ok I see. Hm this is weird, the docs mention that GetPolygonTriangleIndexArray should be used if GetPolygonTriangleIndex is used for each triangle on the object, but I can't find that function in CGeometryAccessor.

_________________
Image rray.de, a resource site for softimage, updated Oct 15th 2016


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 34 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group