Jump to content

MSS_SingleOpState render shaded 'guides'

Recommended Posts

Hello again,

I've been digging around trying to find a way of rendering some shaded geometry within the doRender() method of a viewport state. The only example I could find was in MSS_CustomBrushState via DM_Detail which only has as renderWire() method.

Looked into the idea of rendering a set of GT_PrimSphere objects, but wanted to check to see if anyone had tried something similar and if this was the right way to go, or if there was a more straightforward way of handling this.

Any help very much appreciated!



Share this post

Link to post
Share on other sites

What are you intending to accomplish?

If you use a valid shader for the purpose, you should be able to render anything you like.

Though you may need to push the Viewer and Perspective matrices first something like this pseudocode.

	r->assignUniformMatrix(RE_UNIFORM_PROJECT_MATRIX, getViewportProjectionTransform());
	r->assignUniformMatrix(RE_UNIFORM_VIEW_MATRIX, getViewportTransform());

I haven't tested any of that though.


What I would do is create a DM_SceneRenderHook instead if you just want to render some spheres, though without knowing your intention it's hard to comment on best practice.

Share this post

Link to post
Share on other sites

Hi again! :)

Thanks very much for the reply.

Here's a look at what I was driving at (built against 16.5.536). It's still very raw and unfortunately change of target version has introduced a crash in the node which I haven't had a chance to chase down, hence the very paired down example file. If you did feel like taking a look, hopefully it will give you a better idea though! (NB. Turning primitive snapping on helps replicate the feel I was aiming for)

In the attached scene I've created persistent handles for each of the 'positions' on the two fa_edgeloop nodes. The idea is to be able to interact with the positions to create seams along the shortest edge loop extending from the nearest point to each position. What I'd like the state to render is just a sphere per position that can be dragged over the surface, would also be nice to provide colour feedback on the state of each position (i.e. did it succeed in finding a valid loop, is it set to only return closed loops?... etc).

Having used SOP_NodeVerb and all the nice goodies that come with that, I was hesitant to add a cookMyGuide to the node for this purpose, and it seemed like the rendering of these guides really did belong with the accompanying state. Hopefully that makes some kind of sense. This is my first foray in rendering anything in the viewport directly!



Share this post

Link to post
Share on other sites

What I would do is create an array of the positions in the state and use that to render points

class PointsHandles 
	void draw(RE_Render* r);

	UT_Int32Array mySelection;
	UT_Vector3FArray myPoints;
	RE_Geometry* myReGeo = nullptr;

void PointsHandles::draw(RE_Render* r)
	if (myReGeo)
		myReGeo = new RE_Geometry(myPoints.size());

	myReGeo->createAttribute(r, "P", RE_GPU_FLOAT32, 3, myPoints.data());
	myReGeo->createAttribute(r, "Sel", RE_GPU_INT32, 1, mySelection.data());
	myReGeo->connectAllPrims(r, 0, RE_PRIM_POINTS);

	myReGeo->draw(r, 0);

that should basically work, you'll need a shader that uses the "Sel" attribute and creates some visual feedback for the user.(let me know if you need help with the shader)

I would do something like sort points by collinearity with the results of the vector from mapToWorld() for the selection, that's a personal preference though (it's easy to implement and I find it very intuitive as a user as well).

Then use a GU_RayIntersect to intersect with the geometry your creating loops on, and just write the positions to the parameters. 

Share this post

Link to post
Share on other sites


Sorry for the super late reply, and thanks for pointing me in the RE_Geometry direction. Unfortunately I haven't had much time to finish this one off, but hopefully I'll be able to put the advice into practice soon!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now