[H20.5] Structs and Outer Code

   743   3   0
User Avatar
Member
277 posts
Joined: Jan. 2013
Offline
Hi,
Maybe someone missed this cool update and didn't point it out in the release notes, but in H20.5 it's now possible to define your types directly in the AttribWrangle snippet.

#include <math.h>

#outer // {
// This code will be placed outside of the generated function
struct Point{
    float x, y;
    
    float dist(const Point other){
        return sqrt(pow(other.x - x, 2) + pow(other.y - y, 2)); 
    }
};

struct Rectangle{
    Point p1, p2;
    
    float area(){
        return abs((p1.x - p2.x) * (p1.y - p2.y));
    }
    
    float perimeter(){
        return 2 * (abs(p1.x - p2.x) + abs(p1.y - p2.y));
    }
}
#endouter // }
// This code will be in the function.

Point pt1 = Point(0,0);
Point pt2 = Point(1,2);

@dist = pt1->dist(pt2);

Rectangle rect = Rectangle(pt1, pt2);

@area = rect->area();
@perimeter = rect->perimeter();

https://www.sidefx.com/docs/houdini/vex/snippets.html#structs-and-outer-code [www.sidefx.com]
Edited by alexwheezy - July 19, 2024 01:10:43
User Avatar
Member
197 posts
Joined: May 2017
Offline
This is a great improvement, opens up a lot - thanks for sharing.
User Avatar
Member
87 posts
Joined: Jan. 2018
Offline
Can you explain it in more detail please?

Coding is black magic for me, but iam curious about it and specially interested in new possibilities compared with previous version. I love Houdinis endless power
User Avatar
Member
373 posts
Joined: June 2023
Offline
oldteapot7
Can you explain it in more detail please?

Coding is black magic for me, but iam curious about it and specially interested in new possibilities compared with previous version. I love Houdinis endless power

In Vex you can define struct, which is like several variables grouped together. However, there was a caveat: you couldn't define a new struct in Attribute Wrangle. You had to define it in an external file. Since Attribute Wrangle is where most people use VEX, it was rather inconvenient to define struct.

Now you can do it. It technically doesn't open new possibilities, just more convenient than before.
  • Quick Links