iOS .


PBG4 Dude

macrumors 68030
Jul 6, 2007
2,666
1,836
I did an internet search and found this neat tutorial that uses core animation and 3d transforms to make a cube out of a flat cross-shape. Maybe you can adapt it to your needs?

I'm going to play with it when I get back to my computer. :)

https://www.cocoanetics.com/2012/08/cubed-coreanimation-conundrum/
 

Duncan C

macrumors 6502a
Jan 21, 2008
853
0
Northern Virginia
I've done some research on CATransformLayers, but everything I've seen only shows folding/flipping along a straight line axis. I've been struggling to try to figure out what I need to do to accomplish what I want: creating a basic paper airplane fold animation on a UIImageView with all of it's subviews, etc in the hierarchy. The below pictures show what I want to accomplish if it's technically doable. The numbers on the blue paper indicate the folding steps the animation should do in that order.

If anyone can point me in the right direction or care to post your thoughts I'd greatly appreciate it :)

Core Animation is commonly referred to as "2.5D" It lets you create animations of flat objects (layers) in 3D. It does NOT let you manipulate 3D objects.

Your paper airplane is a 2D object until you begin folding it.

You could break up your paper into a bunch of views/layers, with a seam at each fold. You'd have to take the image of the piece of paper and slice it into pieces, and feed those pieces in as the content of each of your layers.

then you would have to work out the math to transform your views in 3D. Things would get very ugly when you fold the already-folded paper with more seams. I don't know how you would do that.

It would be better to use OpenGL, or one of it's wrappers. You would map the image of your paper into a texture, and then map that texture onto a 3D shape of a flat piece of paper. You would need to slice up the 3D paper shape into enough triangles to make all the different folds that you need. Then you would need to write code that animated moving the vertexes of your paper shape to create the folds.

Apple's new SceneKit API would probably make this a lot easier, although I haven't used it. I suggest researching SceneKit first.
 

Duncan C

macrumors 6502a
Jan 21, 2008
853
0
Northern Virginia
Duncan, thank you for your kind and much appreciated input.

I'd like to throw some ideas at you: What if I create CAShapeLayers using UIBezierPaths to create non rectangular shapes (for the triangle/parallelogram
small paper folds), and then render my UIImageView with it's subviews into these respective CAShapeLayers. No idea about how to fold these layers currently, just wanted to see what your thoughts were on my CAShapeLayer idea to at least get me started.

Thank you again!
Core animation deals with flat, rectangular 2D objects in 3D space. You can have different 2D objects at different angles to each other, but that's it. No folds of any kind. The only way you'd be able to do that is to break each part where there is a fold into 2 parts, and set them up so they intersect so it LOOKS like a fold. It would be awful.

Much better to use a real 3D modeling environment like OpenGL or SceneKit.
 

dantastic

macrumors 6502a
Jan 21, 2011
567
645
Why do you need to email him? He is linking plenty of sample code you should be able to modify to meet your needs.