# Fold paper by mid-axis several times

**URL:** <https://forum.babylonjs.com/t/fold-paper-by-mid-axis-several-times/7197>\
**Category:** Questions\
**Created:** [November 25, 2019, 8:43am UTC](https://forum.babylonjs.com/t/fold-paper-by-mid-axis-several-times/7197 "2019-11-25T08:43:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dom](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@dom](https://forum.babylonjs.com/u/dom)\
**Post date:** [November 25, 2019, 8:43am UTC](https://forum.babylonjs.com/t/fold-paper-by-mid-axis-several-times/7197/1 "2019-11-25T08:43:44Z")

</div>

Hi forum,  
I got some questions about a project I´m working on, the project is about folding a paper in DIN steps. I generate a plane out of several subplanes that represent a page of DIN A4 paper (means 210x297 mm). The first fold is on the mid-axis of the long side - thats what I got to work as you can see here:

[https://playground.babylonjs.com/#Y5SWJ2](https://playground.babylonjs.com/#Y5SWJ2)

I achieved this by doing a 2-way for-loop with horizontal and vertical amount of pages, within those loops I grouped pages on their sheet half and made a simple rotation of the sheet half until 180 degrees. So far so good, now my questions:

1. Is there a possibility to have planes in several groups (parent transform nodes), because for the next fold I need to move the bottom side up - this includes pages from both sheet halfs.
2. Useful would also be if I could address to every specific plane by a key, putting: “page\_” + i + j seems to be a way, but how do I use those information

Thanks for every help or hint  
Regards, Dom

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [November 25, 2019, 4:37pm UTC](https://forum.babylonjs.com/t/fold-paper-by-mid-axis-several-times/7197/2 "2019-11-25T16:37:01Z")

</div>

Hello and welcome!

I could image having 4 planes to make a page so you can decide how to animate the fold. Does it make sense?

---

<div class="post-metadata">

**Author:** ![Wingnut](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wingnut/32/53_2.png) [@Wingnut](https://forum.babylonjs.com/u/Wingnut)\
**Post date:** [November 25, 2019, 5:09pm UTC](https://forum.babylonjs.com/t/fold-paper-by-mid-axis-several-times/7197/3 "2019-11-25T17:09:36Z")

</div>

Hi guys. Welcome dom!

Somebody did SOMETHING… here: [https://www.babylonjs-playground.com/#192VEQ#10](https://www.babylonjs-playground.com/#192VEQ#10)

And there’s another box-folder playground/project available, too, but I couldn’t find it. I think it might be from [old forum](http://www.html5gamedevs.com/index.php?app=core&module=search&controller=search&type=forums_topic&nodes=16,28,29,30,31,38) days. I’ll keep looking. Pinging @flomotion just in case he/she was involved… possibly.

I have an idea (yikes!). Using onAnimationEnd callback, or similar folding-finished observer… FAKE IT. 🙂 There is ALWAYS ONLY two planes. After first folding visually becomes overlapped planes (looks like a single plane)… instead it becomes TWO planes again (un-noticed by users).

Before first fold… planes are side-by-side, as shown in dom’s playground. OnAnimationEnd… quickly place two (down-scaled) planes… above/below each other, and texture them so that you see no visual change during the onAnimationEndSoItsTimeToScaleAndRepositionAndTextureTwoPlanes() function. hehe.

Next foldFinished(), place two new down-scaled planes… side-by-side again… ready for next fold.

Next foldFinished(), place two new down-scaled planes… above-by-below again… ready for next fold.

etc.

In brief, user sees no visual change when any fold/unfold ends, even though you secretly re-adjusted for further folding/unfolding of two fresh planes. (the “fake”).

During unfolds, same thing… except onUnfoldFinished(), replace unfolded dual-planes… with 100% up-scaled single plane (or two up-scaled planes z-stacked, which looks like a single plane)… ready for further unfolding.

“Faking it” has some limitations, of course, but it makes “plane management”… more manageable. 🙂

OR… power-hack the vertices (positions-kind data) of a ground mesh grid. 😮[Plotting](https://www.babylonjs-playground.com/#1UHFAP#231). It’s not always easy to [animate vertex positions](https://www.babylonjs-playground.com/#1AVEYO#17)… in curved arcs… but can be done.

Wha-da-ya-figure, dom? 16 cells in the paper? What is that… 4 fold-in-halfs? (Wingy checks his math manual - powers of 2 section) 🙂

---

<div class="post-metadata">

**Author:** ![dom](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@dom](https://forum.babylonjs.com/u/dom)\
**Post date:** [November 28, 2019, 12:57pm UTC](https://forum.babylonjs.com/t/fold-paper-by-mid-axis-several-times/7197/4 "2019-11-28T12:57:51Z")

</div>

Hi Wingnut,

thanks for showing me a new strategy. I had a talk with some colleagues and we all agree to your solution. I´ll post my progress in some time.

Regards, Dom

---

<div class="post-metadata">

**Author:** ![dom](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@dom](https://forum.babylonjs.com/u/dom)\
**Post date:** [November 30, 2019, 1:35am UTC](https://forum.babylonjs.com/t/fold-paper-by-mid-axis-several-times/7197/5 "2019-11-30T01:35:53Z")

</div>

Hi there,

[https://www.babylonjs-playground.com/#J06MJ3](https://www.babylonjs-playground.com/#J06MJ3)

as you can see I´ve build two functions:

```
    // Folding horizontally from left to right or otherwise
    doHorizontalFold(sheetWidth, sheetHeight, step, side, direction, scene);
    // Folding vertically from bottom to top or otherwise
    doVerticalFold(sheetWidth, sheetHeight, step, side, direction, scene);

```

Those params mean:

sheetWidth/sheetHeight = dimensions of the paper (INT)  
step = the number of the fold (INT)  
side = top/bottom or left/right (STRING)  
direction = up or down (STRING)  
scene = the current babylon scene

You can try out by changing line 187: this.doHorizontalFold(sheetWidth, sheetHeight, 1, ‘left’, ‘up’, scene);

After the animation those 2 parts of the sheet become deleted by i.e. “sheetHalfTop.dispose();” as you said, but **I have no idea how to begin the following fold step at the last position of the sheet half with its dimensions**.

Maybe you could give me additional hints how to achieve that.

Regards, Dom

---

<div class="post-metadata">

**Author:** ![Mounika\_Reddy](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mounika_reddy/32/13654_2.png) [@Mounika\_Reddy](https://forum.babylonjs.com/u/Mounika_Reddy)\
**Post date:** [January 15, 2021, 9:23am UTC](https://forum.babylonjs.com/t/fold-paper-by-mid-axis-several-times/7197/6 "2021-01-15T09:23:52Z")

</div>

Hi folks,  
I have a similar requirement of folding paper multiple times both horizontal and vertical multiple times .the solution you mentioned above is really useful @dom.I would like to know if you had achiedved the solution for the next fold from last position ( **how to begin the following fold step at the last position of the sheet half with its dimensions**.)and also is it possible to fold the sheet horizontal and vertical 1/3rd or 1/4th instead of half .  
Any help is appreciated .

Thanks in advance,
