C++ custom tool SDK programming tip

Discussions concerning programming of SOFTIMAGE©
Ahmidou
Posts: 106
Joined: 04 Jan 2010, 14:00

Re: C++ custom tool SDK programming tip

Post by Ahmidou » 28 Jul 2012, 02:33

Hi Steven.
It might not be the better way to do it, but for my LivePaint Tool, I'm caching the geometry in the Activate callback:
oSel = selected[0];
oGeo= oSel.GetActivePrimitive().GetGeometry();
oGeo.SetupPointLocatorQueries(siClosestSurfaceRaycastIntersection, & oSel.GetKinematics().GetGlobal().GetTransform(),-1,NULL,1);

then on move:
PointLocatorData brushCenterLocator = oGeo.GetRaycastIntersections( 1, (double*)&l_cursorRay.GetOrigin(), (double*)&oDir, siSegmentIntersection );;
oGeo.EvaluatePositions(brushCenterLocator, -1, 0, pos);
oGeo.EvaluateNormals(brushCenterLocator, siInterpolatedVertexAngleBasedGeometricNormals, -1, 0, lNorm);
norm.Set(lNorm[0],lNorm[1],lNorm[2]);
brushCenter.Set(pos[0],pos[1],pos[2]);

Cheers

User avatar
origin
Posts: 619
Joined: 09 Jun 2009, 11:59
Location: warsaw

Re: C++ custom tool SDK programming tip

Post by origin » 28 Jul 2012, 02:43

This way, with Pick method (in_objects should be narrowed down to selection/or object under cursor for faster picking)

Code: Select all

X3DObject GetPolyComponent(ToolContext& in_ctxt,CRef &target, PolygonFace &out_polyface)
{			
		X3DObject l_meshObject;
		CComAPIHandler cCollItem(target);
		CComAPIHandler cSubComp(cCollItem.GetProperty(L"SubComponent"));
		CComAPIHandler cCompColl(cSubComp.GetProperty(L"ComponentCollection"));
		CValueArray indices = cSubComp.GetProperty( L"ElementArray" );
		l_meshObject = cSubComp.GetProperty( L"Parent3DObject" ); 
		
		PolygonMesh pmesh( l_meshObject.GetActivePrimitive().GetGeometry() );
		CString l_subcomp = cSubComp.GetProperty(L"Type");
		if(LONG(indices.GetCount() ) == 1L)
			if ( l_subcomp == L"polySubComponent" )	{
				out_polyface = pmesh.GetPolygons().GetItem((LONG)indices[0]);
				m_pickedSubcompType = kPoly;
			}
		return l_meshObject;
}

CStatus GetGeometrySubcomponentData(ToolContext& in_ctxt, LONG x, LONG y, CRefArray& in_objects, X3DObject& out_pickedObject, PolygonFace& out_pickedPolyFace, CVector3& out_pickedNormal)
{
	CLongArray l_points;
	l_points.Add(x);
	l_points.Add(y);
	CRefArray components;
	X3DObject l_picked = in_objects[0];

	//only polys

	in_ctxt.Pick( l_points, siPickSingleSubComponent, siPickRaycast, siPolygonFilter, in_objects, components );

	if( components.GetCount() != 0 )
	{
		out_pickedObject = GetPolyComponent(in_ctxt,components[0], out_pickedPolyFace);
		out_pickedNormal = getPolyNormal(in_ctxt,out_pickedPolyFace, false);				
	}	
	else
		return CStatus::False;
	return CStatus::OK;
}
or

Code: Select all

CRefArray l_objects;
PickBuffer l_pickbuff = in_ctxt.GetPickBuffer(x,y,4,4, siObjectFilter, l_objects);
CRef l_picked = l_pickbuff.GetObjectAtPosition(x, y );
if ( !l_picked.IsValid() )
	return CStatus::False;

PolygonMesh mmesh = l_picked.GetActivePrimitive().GetGeometry();
CRefArray l_cobjects; 
l_cobjects.Add(l_picked);

PickBuffer l_pickbuffComp = in_ctxt.GetPickBuffer(x,y,4,4, siPolygonFilter, l_cobjects);
LONG pti = l_pickbuffComp.GetComponentIndexAtPosition(x, y);
if (pti == -1)	{
	#ifdef _DEBUG
		logmsg(" l_pickbuffComp.GetComponentIndexAtPosition(x, y); FAIL");
	#endif
	return CStatus::False;
}

PolygonFace pface = mmesh.GetPolygons().GetItem(pti);

I think it's all necessary code...afaik pickbuffer is faster, and you can cache it (like whole screen, but it takes time so there is a microlag with many objects in view)

User avatar
origin
Posts: 619
Joined: 09 Jun 2009, 11:59
Location: warsaw

Re: C++ custom tool SDK programming tip

Post by origin » 28 Jul 2012, 02:49

Hey Ahmidou, I think SetupPointLocatorQueries is very slow when you pass -1 (all polys) argument, so its better to restrict search for particular polygons

scaron
Posts: 119
Joined: 08 Jul 2009, 05:16

Re: C++ custom tool SDK programming tip

Post by scaron » 28 Jul 2012, 03:16

@piotrek, yes caching normals in the view frustrum seems to be what softimage weight paint brush does. if you give it a try with >500k triangles you will see initial lag and various lags happen after camera manipulation.

i am going to stick with the PickBuffer and use what i have learned from this thread to do some performance tests. use a PickBuffer the size of the view and cache it, then use either Pick or PickBuffer to get components during MouseMove and orient the brush. the PickBuffer will allow me to query many components if i want to do averaging of normals based brush radius. not sure if this is desired...

btw, i am trying to build my brush to be as generic and basic as possible, i will open source it and provide others with a starting point. once i have something decent to share we can start implementing different techniques for the best performance. hopefully you fine fellows can find some time to contribute back to the project.

thanks guys!
steven

Ahmidou
Posts: 106
Joined: 04 Jan 2010, 14:00

Re: C++ custom tool SDK programming tip

Post by Ahmidou » 28 Jul 2012, 11:31

Nice Steven! too bad I didn't found the time to finish mine... Anyway as piotrek pointed it was slow with dense meshes and your's should be more effective :)

User avatar
origin
Posts: 619
Joined: 09 Jun 2009, 11:59
Location: warsaw

Re: C++ custom tool SDK programming tip

Post by origin » 28 Jul 2012, 17:17

Steven what about cmake tutorial you mentioned some time ago on mailinglist ;) :ympray:

scaron
Posts: 119
Joined: 08 Jul 2009, 05:16

Re: C++ custom tool SDK programming tip

Post by scaron » 29 Jul 2012, 10:10

i made the first part a while ago, just not the second part which is needed for new projects using cmake. feel free to ask my any questions though... maybe i can turn this new project into a tutorial on cmake also :)

Last edited by scaron on 01 Aug 2012, 01:08, edited 1 time in total.

luceric
Posts: 1251
Joined: 22 Jun 2009, 00:08

Re: C++ custom tool SDK programming tip

Post by luceric » 30 Jul 2012, 02:47

just wanted to note that you can talk to the developer of the tool SDK (and the tweak and manipulators), Brent, by posting on the XSI mailing list.

scaron
Posts: 119
Joined: 08 Jul 2009, 05:16

Re: C++ custom tool SDK programming tip

Post by scaron » 30 Jul 2012, 03:06

i figured brent is too busy working on maya ;) thanks for the reminder...

s

scaron
Posts: 119
Joined: 08 Jul 2009, 05:16

Re: C++ custom tool SDK programming tip

Post by scaron » 30 Jul 2012, 09:29

here is the code...

https://github.com/caron/SimpleBrush

this basic brush looks like the built in weight paint brush, adjusting the radius with the r key works, normal alignment is still wrong. i am trying to mimic the built in weight paint brush, i havent figured out how they're doing the smooth interpolation or averaging yet. you can see it on the default sphere when you move the brush across the surface.

i am sharing for others who haven't made a brush tool yet but want to, this should could be a nice start. piotrek wont find anything new in here ;)

steven

User avatar
origin
Posts: 619
Joined: 09 Jun 2009, 11:59
Location: warsaw

Re: C++ custom tool SDK programming tip

Post by origin » 30 Jul 2012, 18:10

I have noone to learn from in my work so I welcome any piece of code with joy :)
I have a question, do you write those cmakelist.txt files by hand from scratch or you have some templates that you fill only with links to libs and cpps? Do these files work without any modifications on linux too? (i started to learn fedora...)

scaron
Posts: 119
Joined: 08 Jul 2009, 05:16

Re: C++ custom tool SDK programming tip

Post by scaron » 30 Jul 2012, 19:13

origin wrote:I have a question, do you write those cmakelist.txt files by hand from scratch or you have some templates that you fill only with links to libs and cpps? Do these files work without any modifications on linux too? (i started to learn fedora...)
i usually copy from my last one, or copy from other available projects using cmake (alembic is big ol'nasty one) but otherwise they are written by hand. this file can be source controlled easily and is included in the visual studio project so you can make edits easily. visual studio actually knows when you changed the cmakelist.txt and will auto regenerate the project with new settings.

i only have to fill out 'extra' links, at this time the FindSoftimage.cmake module (this is actually all the hard work done by alan jones) doesn't understand CustomTool plugin types but that is an easy addition and i will do so eventually so all you need to do is call 'add_softimage_tool_plugin()' and the adding of the ogl and glu libs will be taken care of automatically. also you can use globbing to collect all your source files instead of listing them by hand. http://www.cmake.org/Wiki/CMake:How_To_ ... nput_Files

these cmake files might need modification for linux, but since alan jones made them i doubt it will be much to change. this does NOT mean you can neglect to make your code cross platform. the FindSoftimage.cmake module needs to be updated as new versions of softimage come out, updating the various paths to the new version.

good luck!
s

User avatar
origin
Posts: 619
Joined: 09 Jun 2009, 11:59
Location: warsaw

Re: C++ custom tool SDK programming tip

Post by origin » 03 Aug 2012, 21:35

Thanks I migrated all my projects to cmake, simply by editing your cmakelist.txt and hand typing all the *.c* and *.h files. So no more setting up VS projects, great!
Now the only annoying thing is that I have to copy my .dll from cmake's build dir to plugin's Application/bin/... folder everytime I build project in VS. Should I manually change output directory in VS?

User avatar
origin
Posts: 619
Joined: 09 Jun 2009, 11:59
Location: warsaw

Re: C++ custom tool SDK programming tip

Post by origin » 07 Aug 2012, 08:26

OK It was just a matter of setting CMAKE_INSTALL_PATH pointing to plugin base dir. and turning on INSTALL project in Configuration Manager

Ahmidou
Posts: 106
Joined: 04 Jan 2010, 14:00

Re: C++ custom tool SDK programming tip

Post by Ahmidou » 10 May 2013, 10:40

origin wrote:Hey Ahmidou, I think SetupPointLocatorQueries is very slow when you pass -1 (all polys) argument, so its better to restrict search for particular polygons
Hi Piotrek,
I took some time to run some tests and found out that it's equivalent.
The only difference is when moving the camera, when I pass a polygon, it's slower on the first and second iteration,
then it's coming back at the same speed.

Good to know!

Cheers
A

User avatar
origin
Posts: 619
Joined: 09 Jun 2009, 11:59
Location: warsaw

Re: C++ custom tool SDK programming tip

Post by origin » 10 May 2013, 11:37

I think it's dependand whenever raycasting cache (generated with GetRaycastIntersection...) is cleared or not.
It's cleared when you lose scope of your PolygonMesh variable.
So best bet is to run SetupPoint.. in customtool's Setup function (and maybe in SelectionChange event) with PolygonMesh being global variable.
This way cache is generated only once and futher raycasts are instant.
Eg for 31 million poly raycasting with cache its realtime (no drop in fps)
The only problem is to keep this cache so It won't be cleared when you exit the tool, not sure how you would do that (it take ~10seconds to cache 31 million tri object)
I think, watching ram usage, in your LivePaint tool you're recaching also on changeview which leads to huge performance drop.
Another case in your tool is that your pointposition change, so the cache needs to regenerated every mouse drag...

Post Reply

Who is online

Users browsing this forum: No registered users and 23 guests