Andrew Kant Posted September 4, 2017 Share Posted September 4, 2017 I'm still a novice in Houdini. Help me understand how to swap the rows and columns of primitive indices. It is necessary that I can rotate the indexes, as shown in blue. Quote Link to comment Share on other sites More sharing options...
Atom Posted September 4, 2017 Share Posted September 4, 2017 (edited) Try dropping down a Sort node and place it in Shift mode. Then you can offset primitives with the slider. Edited September 4, 2017 by Atom Quote Link to comment Share on other sites More sharing options...
Andrew Kant Posted September 4, 2017 Author Share Posted September 4, 2017 (edited) 1 hour ago, Atom said: Try dropping down a Sort node and place it in Shift mode. Then you can offset primitives with the slider. Sort Node gives the wrong result. I do not need to shift the indexes, but rotate them 90 degrees. Node Sort works well with Grid, you can specify which axis to build columns, but for the torus it does not fit. I think that this can be implemented in the VOP. But I do not know. Edited September 4, 2017 by Andrew Kant Quote Link to comment Share on other sites More sharing options...
f1480187 Posted September 4, 2017 Share Posted September 4, 2017 (edited) Compute index attribute: // Primitive wrangle. int rows = chi("../torus1/rows"); int cols = chi("../torus1/cols"); i@index = @primnum % cols * rows + @primnum / cols; Then Sort by attribute: swap_rows_cols.hipnc By the way, this is reshape and transposition. Not 90 degree rotation: | 0 1 2 3 4 5| | 6 7 8 9 10 11| |12 13 14 15 16 17| | 0 3 6 9 12 15| | 1 4 7 10 13 16| | 2 5 8 11 14 17| Edited September 4, 2017 by f1480187 1 1 Quote Link to comment Share on other sites More sharing options...
Andrew Kant Posted September 4, 2017 Author Share Posted September 4, 2017 1 hour ago, f1480187 said: Compute index attribute: // Primitive wrangle. int rows = chi("../torus1/rows"); int cols = chi("../torus1/cols"); i@index = @primnum % cols * rows + @primnum / cols; Then Sort by attribute: swap_rows_cols.hipnc By the way, this is reshape and transposition. Not 90 degree rotation: | 0 1 2 3 4 5| | 6 7 8 9 10 11| |12 13 14 15 16 17| | 0 3 6 9 12 15| | 1 4 7 10 13 16| | 2 5 8 11 14 17| Many thanks! That's exactly what I wanted. I was also advised to use the Transpose node. Can you know how you can apply it for this task? Quote Link to comment Share on other sites More sharing options...
f1480187 Posted September 4, 2017 Share Posted September 4, 2017 It's limited to Houdini's native 2×2, 3×3 and 4×4 matrices, and it probably used for shading and 3D transformation tasks. We can't really use it to transpose r×c matrix. Simple numerical algorithm in VEX did the job too. For the sake of completeness, to work with arbitrary-sized matrices in Houdini use numpy: import numpy as np rows = hou.evalParm('../torus1/rows') cols = hou.evalParm('../torus1/cols') # Make initial matrix representation. old_sort = np.arange(rows * cols).reshape(rows, cols) # Reshape and transpose. new_sort = old_sort.reshape(cols, rows).T # Make index attribute. node = hou.pwd() geo = node.geometry() geo.addAttrib(hou.attribType.Prim, 'index', -1) geo.setPrimIntAttribValues('index', new_sort.ravel()) swap_rows_cols_python.hipnc 2 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.