Transform in "for" loop strange behavior

christopher_dziuba
christopher_dziuba Member Posts: 124 ✭✭✭

I've made a featurescript that spaces parts with an exact gap away from each other along a plane No mater what their shape or orientation (yes I am fishing for brownie points).

image.png


HOWEVER! The last transform in the last loop seems to change it's vector despite the debug tool showing the vector is correct:

        var moveVector = spaceDist.sides[0].point - spaceDist.sides[1].point; //Distance result points to get a vector
        var clusterTransform = transform(moveVector / 2);
        var nonClusterTransform = transform(-moveVector / 2);
        
        opTransform(context, id + "2ndLoop" + m + "moveCluster", {
                    "bodies" : clusterBodies,
                    "transform" : clusterTransform
                });
        opTransform(context, id + "2ndLoop" + m + "moveNonCluster", {
                    "bodies" : nonClusterBodies,
                    "transform" : nonClusterTransform
                });

        var partBodies = qUnion([partMap.part, partMap.gapPath, partMap.spiralPath]);
        clusterBodies = qUnion(clusterBodies, partBodies);
        nonClusterBodies = qSubtraction(nonClusterBodies, partBodies);
image.png

This is supposed to be equally spaced and the vectors confirm that:

image.png

This is debug of the "moveVector" and I have drawn the equivalent transforms.
My script essentially loops through the selected parts one by one and once the part is "spaced" its added to a query called "clusterBodies" and removed from "nonClusterBodies" so that the cluster is spaced from non cluster part by part until all have been spaced. So in theory those 3 square parts should be equally spaced but the top one aligns with one side for some dumb reason. I have already confirmed that the parts are being looped through in the correct order. Please help:
The part studio I'm testing in
The Feature Studio

Tagged:

Best Answer

  • christopher_dziuba
    christopher_dziuba Member Posts: 124 ✭✭✭
    Answer ✓

    Never mind I figured it out. Such an idiot hahaha, I was transforming all remaining parts rather then just the next part in question

Answers

  • christopher_dziuba
    christopher_dziuba Member Posts: 124 ✭✭✭

    If you want some explanation on how the spacing itself is calculated it's pretty strange and complicated so I'm happy to elaborate here. Just ask

  • christopher_dziuba
    christopher_dziuba Member Posts: 124 ✭✭✭

    Just tried rewriting everything to simplify it and reduce the number of variables to no avail

  • christopher_dziuba
    christopher_dziuba Member Posts: 124 ✭✭✭
    Answer ✓

    Never mind I figured it out. Such an idiot hahaha, I was transforming all remaining parts rather then just the next part in question