netherknight Posted January 10, 2019 Share Posted January 10, 2019 (edited) So I'm working on creating a grid with specific attributes or perhaps groups. So say "1" generates a Cube "2" generates a Sphere and "3" generates a Torus, going up to 9. So my idea is that I can type out a grid like so: 1;1;1;3;3;3;2;2;2 2;2;2;3;3;3;1;1;1 3;2;1;3;2;1;3;2;1 1;2;3;1;2;3;1;2;3 3;2;1;2;3;2;1;2;3 This would then divide the 5x9 grid into groups based on the numbers. Is there an elegant way of achieving this in VEX/Python? This could also work as a point cloud but it would need to have constant spacing between the numbers and control over the size in units of the grid. As a follow up this would be great if I could use this as a weaving pattern with splines. So in this case "1" would mean: on top, "2" would mean under: and "3" would mean: extra high. Though this should work if we get the rest to work as is. Any help with this would be appreciated. Edited January 10, 2019 by netherknight Quote Link to comment Share on other sites More sharing options...
netherknight Posted January 10, 2019 Author Share Posted January 10, 2019 I would also like to add that adding them all manually would be impossible due to the various weave patterns being grids of around 200x200 points. So having a way of copy pasting the pattern and having it make the group would be ideal. Quote Link to comment Share on other sites More sharing options...
Andrea Posted January 10, 2019 Share Posted January 10, 2019 Probably there are better ways to convert the text to geo, but could this be an idea? Grid_based_on_text_example_00.hip Quote Link to comment Share on other sites More sharing options...
netherknight Posted January 10, 2019 Author Share Posted January 10, 2019 Great! That's basically exactly what I need though that method seems to destroy my memory (128gb) when I try to apply the array to a large weave pattern which is to be expected. It seems to do fine around 200x200 but double that causes my memory to run out. So I'm thinking I could split it up and merge after which would alleviate that issue. Though if there's a better way of going about it that would be great. Quote Link to comment Share on other sites More sharing options...
Andrea Posted January 10, 2019 Share Posted January 10, 2019 Here if I take my scene and I just increase the grid to be 500x500 it works really fast. Is taking just a few seconds and 100 Mb of memory. There is something different in your scene with the weave pattern from mine? Quote Link to comment Share on other sites More sharing options...
netherknight Posted January 10, 2019 Author Share Posted January 10, 2019 That would be 500 rows and 500 columns and then applying a patern of 500x500 numbers. with the size of the grid being 15 x 15 Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted January 10, 2019 Share Posted January 10, 2019 (edited) Hi Thomas, here is some Python code to create a grid based on a multi-line string: node = hou.pwd() geo = node.geometry() text = node.evalParm('text') lines = text.splitlines() numbers = [map(int, line.split(';') ) for line in lines] geo.addAttrib(hou.attribType.Point, 'instance', -1) for row, n in enumerate(numbers): for col, value in enumerate(n): pos = (col, 0.0, row) pt_add = geo.createPoint() pt_add.setAttribValue('instance', value) pt_add.setPosition(pos) copy_to_grid.hipnc Edited January 11, 2019 by konstantin magnus 2 Quote Link to comment Share on other sites More sharing options...
netherknight Posted January 11, 2019 Author Share Posted January 11, 2019 (edited) Thanks Konstantin, I'm new to python so I'm not entirely sure how I would go about implementing this. I'm assuming you'd add a multi-line string as a parameter on the python node, but I'm not sure how to get the geometry attached? Edited January 11, 2019 by netherknight Quote Link to comment Share on other sites More sharing options...
Andrea Posted January 11, 2019 Share Posted January 11, 2019 That's funny. It was super fast in my grid 500x500 because I still had an array of 16 numbers. The remaining points after the first 16 were getting a default value. At first I thought the problem was in copy stamping the geo for all this points but then I've noticed that it was because of this simple VEX line: i@val = i[]@myarray[@ptnum]; If I create an array for a 200x200 grid and then I use a wrangle with this line, is taking a lot of time (~20 seconds) while is just an instant using an array of 16 elements for the same amount of points. Using a wrangle running over detail and with a loop seems to work a lot faster. I wasn't expecting a so huge difference between the two Grid_based_on_text_example_01.hip Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted January 11, 2019 Share Posted January 11, 2019 2 hours ago, netherknight said: I'm not entirely sure how I would go about implementing this. I'm assuming you'd add a multi-line string as a parameter on the python node, but I'm not sure how to get the geometry attached? You could blast unnecessary points from your grid based on their instance number attribute and assign the models with copy to points. I added the HIP file to the post above. 1 Quote Link to comment Share on other sites More sharing options...
netherknight Posted January 11, 2019 Author Share Posted January 11, 2019 @Andrea, I like where you're going with this but I'm having trouble applying a hand input array for the "set_Geo_by_array2" node. Seeing as that method has you creating the array based on randomly input values. Wouldn't you then still need to use "i@val = i[]@myarray[@ptnum];" seeing as you need to set the array values? Quote Link to comment Share on other sites More sharing options...
Andrea Posted January 11, 2019 Share Posted January 11, 2019 I created the array using random values because I don't have a list of 40'000 values to set as input and no way I am going to type them by hand The wrangle "create array" where there are the 16 values typed by hand is still valid if you set it to run over detail and you put it between the grid and "set_geo_by_array2". Of course using the Python script Magnus posted is the way to go. At least Python is easily customizable. I was just curious why it was so slow with the first wrangle. Quote Link to comment Share on other sites More sharing options...
netherknight Posted January 11, 2019 Author Share Posted January 11, 2019 @Konstantin That's perfect! Thanks for the help! @Andrea Great! I didn't put it to run over detail. It doesn't seem to take very well to a pattern though for some reason <-This being your version Andrea <-And this being the same pattern plugged into Konstantin's python. I'll be trying to figure out why it's not working but for now the python code seems to work better and faster. Quote Link to comment Share on other sites More sharing options...
netherknight Posted January 11, 2019 Author Share Posted January 11, 2019 (edited) Also @konstantin magnus Would there be a way in python of reading the created array and say for example above the "1" there is an "11" then delete the "1"? The same for "2" and "12" ect. And then if the "11" is under another "11" than it too shall be deleted? I'm thinking two passes, the first one deleting all "1"s under "11"s and then the second pass deleting all "11"s under "11"s if that makes sense. So a grid of: 1;1;11;2 1;11;11;12 1;1;1;2 Would result in a grid of: ("x" being deleted resulting in an empty spot. So this wouldn't cause the whole grid to move up. ) 1;1;11;2 1;11;x;12 1;x;x;x; Edited January 11, 2019 by netherknight Clarified x 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.