I want to maintain state, have loops, how are these done in MCG?
I'e been coding for 20 years, but MCG has me stumped, and I'm finding the documentation doesn't appear to cater to C++/C#/Java types and many nodes don't have examples or are named very strangely, making it hard to find a node that does what I want.
Here is how my brain works, in a C like language:
Declare some stuff to hold onto: "variables" / state.
Loop some number of times while applying function arguments/parameters to current state to generate new data.
"loop doing work" in MCG seems to be tied up in making arrays, but I have so many other things I want to input besides one or two types. For example.
I want a point 'P' to be initialized with the location of a node.
I want 'V' a vector3 to be initialized to some parameter.
A is a constant parameter.
Loop 15 times doing the following: P = P + V AND V = V + A
Each time in the loop, I append P to an array.
So, for this case, I suppose I can make an array of V first, then shove that into something that takes that array, and does the addition to P, and it generates a array of P's.
However, this next bit is where I get stuck.
I want P+V to be a ray, and that does a hit check against a mesh. If it collides, it 'bounces'. So now there is a conditional( which can change both P and V), and the two values are interconnected and can no longer be separate arrays. I need to maintain P and V as 'state', but this node stuff doesn't make that easy to do.
The whole idea is to have a simple particle system that 'traces' the particles as they go. I just set a starting point, iterations, and direction and this geometry tool would spit out a path (a ribbon made of quads).
Eventually I want to be able to do that some 'n' number of times and get particle traces for a set of particles, who's start is along a spline defined by the user.
I can use python or write a C++/C# plugin for this of course, and it would be super simple, but I'd like to be able to learn how MCG would handle this.
in C++/C# psuedo code:
List<Vector3> PathOfParticle(Vector3 startPosition, Vector3 initialVelocity, Vector3 acceleration, TriMesh mesh, unsigned int iterations)
{
Vector3 position = startPosition;
Vector3 velocity = initialVelocity;
List<Vector3> pointStorage;
unsigned int i;
for(i=0;i<iterations;i++)
{
v = v+ acceleration; // apply 'gravity', etc
Ray r(p,v);
Vector3 hitPoint;
Vector3 hitNormal;
bool hit =mesh.RayIntersect(r, hitPoint, hitNormal);
if (hit)
{
p = hitPoint; // move to intersect point.
v = Reflect(v, hitNormal); // bounce perfectly from normal
v *= 0.9; // lose some energy
}
p = p + v; // update position from velocity.
pointStorage.append(p); // store position this 'tick'.
}
return pointStorage;
}
This is also compromising on iterations, as what I really want is to keep the particle moving until it moves out of the bounding box for example, or hits a triangle of a certain color, or any other reason.
in MCG however, If, While, Repeat, don't operate like C#/C++.
What would be helpful is if I can learn to 'write' MCG as perhaps a C#/C++ program so I can map the concepts in my old befuddled brain. It appears there are no variables, no state, only function arguments (which are immutable)?
so in kinda C++ I'm guessing:
<template T>
typedef (void)(*)RepeatFuncPtr(int, T); // not even sure if this is correct!
T Repeat(T init, int n, RepeatFuncPtr* ptr)
{
int i;
T val = init;
for(i=0;i<n;i++)
{
val = RepeatFuncPtr(n, val);
}
return val;
}
Of course any function I then make has to be made up of only other functions, returns only one 'item', and has read only arguments.
Is this anywhere close? Any resources to help make this transition?