Search Unity

Stop Motion App

Discussion in 'iOS and tvOS' started by nm8shun, Aug 11, 2017.

  1. nm8shun

    nm8shun

    Joined:
    Jul 14, 2007
    Posts:
    476
    Hi. I'm looking for a bit of strategy help on a project for iOS iPad.

    I need to create a Stop Motion Studio app. It's fairly simple:
    1) Take snapshots
    2) Play the snapshots back a 10-15 fps.

    I've successfully use WebCameraTexture to get what the camera sees onto a plane.

    From here, I anticipated creating an array where I could store images that were taken via screen capture or otherwise, and simply play them back on another plane by rotating through the images.

    The problem I'm having is in trying to take Screenshots that store in a place temporarily that I can grab while the animation is playing, and then delete them all when a new animation is chosen. Anyone have any guidance on how to approach this?
     
  2. nm8shun

    nm8shun

    Joined:
    Jul 14, 2007
    Posts:
    476
    Alrighty. Well, here's where I'm at:

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.UI;
    6. using System.IO;
    7.  
    8. public class StopMotionCameraController : MonoBehaviour {
    9.     public RawImage cameraPanel;
    10.     WebCamTexture webcamTexture;
    11.     public Texture[] savedImages;
    12.     int imageCount = 1;
    13.  
    14.     public RawImage playbackPanel;
    15.     public bool loopPlaybackPanel;
    16.  
    17.  
    18.     void Start ()
    19.     {
    20.         webcamTexture = new WebCamTexture(null, 1024, 768);
    21.         cameraPanel.texture = webcamTexture;
    22.         webcamTexture.Play();
    23.     }
    24.  
    25.     public void TakeAFrame()
    26.     {
    27.         StopCoroutine(PlaybackCoroutine());
    28.  
    29.         Texture2D texture = new Texture2D(cameraPanel.texture.width, cameraPanel.texture.height, TextureFormat.ARGB32, false);
    30.  
    31.         texture.SetPixels(webcamTexture.GetPixels());
    32.         texture.Apply();
    33.  
    34.         System.Array.Resize(ref savedImages, imageCount+1);
    35.         savedImages[imageCount] = texture;
    36.         imageCount ++;
    37.  
    38.         StartCoroutine(PlaybackCoroutine());
    39.     }
    40.  
    41.     IEnumerator PlaybackCoroutine()
    42.     {
    43.         while (loopPlaybackPanel)
    44.         {
    45.             for (int i = 0; i < savedImages.Length; i++)
    46.             {
    47.                 yield return new WaitForSeconds (1f);
    48.                 playbackPanel.texture = savedImages[i];
    49.             }
    50.         }
    51.     }
    52. }
    53.  
    Some parts of this are working real well in the editor (I haven't tried it on an iOS device).

    The problem is in the IEnumerator PlaybackCoroutine. The more images I take, the faster it plays. I seems to ignore the WaitForSeconds. Any ideas?