Edit: I figured it out, ignore the asking for help (if you saw it).
So I'm not much of a Thymer, but I have some programming knowledge. I think this is really cool but a) it has a couple problems with the physical results (I'll get to that in a moment) and b) it's doing the same thing four times, which immediately made me think "for loop." So I made a version that fixes all that.
- Code: Select all
(e)=>{
e.other.pos = [0, 0];
e.other.size = [0, 0];
app.step;
app.undo;
scene.my.my1 = scene.my.my1 + 1;
scene.my.size = e.other.size;
for(4,(i)=>{
offset := {
(i == 0) ? {[0.25,0.25]} : {
(i == 1) ? {[0.25,-0.25]} : {
(i == 2) ? {[-0.25,-0.25]} : {[-0.25,0.25]}
}
}
};
Scene.addBox({
color := [0.1,0.05,0.25,1.0];
entityID := 154 + i;
zDepth := 5.0 + i;
geomID := scene.my.my1 + 855 + i;
pos := e.other.pos + e.other.size * offset;
angle := 0.0;
size := e.other.size * [0.5, 0.5]
});
});
for(4,(j)=>{
offset := {
(j == 0) ? {[0,-0.25]} : {
(j == 1) ? {[-0.25,0]} : {
(j == 2) ? {[0,0.25]} : {[0.25,0]}
}
}
};
Scene.addHinge({
geom0 := scene.my.my1 + 855 + (j % 4);
geom0pos := e.other.size * offset;
geom1 := scene.my.my1 + 855 + ((j + 1) % 4);
geom1pos := e.other.size * offset * (-1);
color := [1,1,1,1.0];
entityID := 158 + j;
zDepth := 9.0 + j;
size := (e.other.size(0)^2 + e.other.size(1)^2)^0.5 * 0.1;
});
});
e.other.density = 0
}
The problems I fixed are:
The old version spawned the quadrant boxes at the corners of the original box, so they then "settled" into place with a jerk from the hinges. Worse, when further subdividing an already-subdivided box, the new quadrants still spawn 1m apart—not even the size of the smaller "parent." So I made it so they spawn exactly where they're supposed to end up.
The old version also spawned the hinges at a fixed size, so multiple subdivisions meant the boxes were obscured by the hinges. The hinges now spawn as 1/10 the size of the object.
I also took out "e.this.density = 0" for troubleshooting (that way I don't lose my test objects) but it can obviously be added back.