Storm Keeper Posted June 17, 2014 Share Posted June 17, 2014 Hello everyone! I am developing a custom tool that should be able for fast primitive selection by clicking at the given pixel and finding all the primitives in the given radius around it. Something very similar to inspect tool, but searching not just by one pixel. I found that Python's hou.GeometryViewport class has a functions queryNodeAtPixel(x, y) and queryPrimAtPixel(node, x, y). So, if I knew the x and y, I would get what I need. But I didn't find any function that returns these values in Python. My question is: is there such a function in Python and how fast it will be to iterate over, for example, 10000 pixels and using queryInspectedPrim? Or shall I dive into HDK to solve this problem? Quote Link to comment Share on other sites More sharing options...
yesyes Posted June 17, 2014 Share Posted June 17, 2014 chops???? Quote Link to comment Share on other sites More sharing options...
Storm Keeper Posted June 17, 2014 Author Share Posted June 17, 2014 (edited) No, it's SOP context. In CHOP there's no problem Edited June 17, 2014 by DmitryShurov Quote Link to comment Share on other sites More sharing options...
Storm Keeper Posted June 17, 2014 Author Share Posted June 17, 2014 Thanks to this, http://odforce.net/wiki/doku.php?id=viewers I found that there is a method selectPositions in hou.SceneViewer class, which prompts a selection and returns a position in a given space (Screen, viewport XY and UV). So, the code might be: import toolutils pos = toolutils.sceneViewer().selectPositions(position_type=hou.positionType.ViewportXY) x = pos[0] y = pos[1] Unfortunately, it is not very suitable to use as a brush since it requires a click and cannot be used in an event loop with hou.ui.addEventLoopCallback() function. Still searching for a better solution. Will try to search into HDK. Quote Link to comment Share on other sites More sharing options...
Alexey Vanzhula Posted June 17, 2014 Share Posted June 17, 2014 When your tool is active, you can temporary create CHOP subnet with MouseCHOP inside and work with mapFromMouseChop. Also you can hide subnet node when tool is active. Quote Link to comment Share on other sites More sharing options...
Storm Keeper Posted June 17, 2014 Author Share Posted June 17, 2014 Alexey, thanks for your reply! That's exactly what I needed, but as I expected, it works too slow, so I can't interactively query primitives when the brush radius is larger than approximately 5 pixels. Here is my code (I use a square brush for simplicity): def getPrimsUnderBrush(xy, rad): view = toolutils.sceneViewer().curViewport() xc = xy[0] yc = xy[1] for x in range(xc - rad, xc + rad): for y in range(yc - rad, yc + rad): node = view.queryNodeAtPixel(x, y) prim = view.queryPrimAtPixel(node, x, y) Quote Link to comment Share on other sites More sharing options...
Alexey Vanzhula Posted June 17, 2014 Share Posted June 17, 2014 Dmitry Shurov look at this simple example:http://youtu.be/L7i0AaezN-4 Quote Link to comment Share on other sites More sharing options...
Storm Keeper Posted June 17, 2014 Author Share Posted June 17, 2014 Alexey, thank you! I've posted a little comment on your channel) Quote Link to comment Share on other sites More sharing options...
edward Posted June 18, 2014 Share Posted June 18, 2014 Why not just get the artist to change to brush selection mode? Quote Link to comment Share on other sites More sharing options...
Alexey Vanzhula Posted June 18, 2014 Share Posted June 18, 2014 Yes. Why? Maybe because it doesn`t selecting when you clicking - it is only for dragging Quote Link to comment Share on other sites More sharing options...
edward Posted June 19, 2014 Share Posted June 19, 2014 What about doing it procedurally using an HDA around the Stroke SOP? Quote Link to comment Share on other sites More sharing options...
Alexey Vanzhula Posted June 19, 2014 Share Posted June 19, 2014 Good offer Quote Link to comment Share on other sites More sharing options...
Storm Keeper Posted June 19, 2014 Author Share Posted June 19, 2014 (edited) Why not just get the artist to change to brush selection mode? Yes, the brush selection mode would be a good choice where selection has to be dene before the actual brush editing. But in my case I have to select only the area that is currently under the brush. What about doing it procedurally using an HDA around the Stroke SOP? Yes, Edward, that's exactly what I've done. I takе the Stroke SOP, collect stroke_dir and stroke_origin attributes, and find the distances from the stroke ray to the points of my geometry, then filter these points by this distance. Then, the brush influence is calculated as a distance function from any given point to the stroke ray. The problem was that I implemented this algorithm in Python and it was too slow, so I tried to find an other solution. Now I've ported it to HDK and it works really fast. Edited June 19, 2014 by Dmitry Shurov Quote Link to comment Share on other sites More sharing options...
edward Posted June 20, 2014 Share Posted June 20, 2014 Cool, would love to see your tool in action! 1 Quote Link to comment Share on other sites More sharing options...
freaq Posted June 23, 2014 Share Posted June 23, 2014 i'd be interested to see how you achieved this as well! Quote Link to comment Share on other sites More sharing options...
Storm Keeper Posted June 24, 2014 Author Share Posted June 24, 2014 Thanks for your interest, but my tool is a property of the studio that I work in, so I can't show much. But I'd like to share some ideas and concepts during the WIP. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.