Jump to content
netherknight

Generating a grid of points based on text.

Recommended Posts

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 by netherknight

Share this post


Link to post
Share on other sites

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. 

Share this post


Link to post
Share on other sites

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. 

 

Share this post


Link to post
Share on other sites

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? 

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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)

 

grid_copies.jpg.3b517023b6f8e15b055b3d177b5b20e7.jpg

copy_to_grid.hipnc

Edited by konstantin magnus
  • Like 2

Share this post


Link to post
Share on other sites

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 by netherknight

Share this post


Link to post
Share on other sites

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

 

 

Share this post


Link to post
Share on other sites

 

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.

  • Like 1

Share this post


Link to post
Share on other sites

@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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

@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
image.png.76d280ef40bbd1ce8eb5fe48507f7383.png<-This being your version Andrea image.png.1d3127a37a1747f5dfebeb29aeb9aa07.png <-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. 

Share this post


Link to post
Share on other sites

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 by netherknight
Clarified x

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

×