Skip to main content
Up and Coming
September 15, 2014

mesh sequence playback in Unity -(simple DK2 demo inside)

Hi guys,

I have some interesting idea to create liquid simulation (flooding street, waterfalls, water explosions etc.) and play it back in Unity. As fx guy with DK2 at home this is something I would love to try experiencing inside Rift. I am really new in Unity, so I would really appreciate if anybody can help me with loading these mesh sequences to Unity. I understand its very performance intensive, but maybe I can try to optimize resolutions a lot.

Thank you, Tomas.
    This topic has been closed for replies.

    17 replies

    Inspiring
    September 18, 2014
    Cool stuff man! if i have some time i'll see what i can do to improve it so its easier to load in the frames.
    I also want to run a few tests myself to see if we can get that filesize down somehow
    Up and Coming
    September 18, 2014
    Thanks Mike, :)

    compiled demo size and loading into frames are now biggest obstacles. And of course loading OBJ files into Unity :)

    If you solve this, I could create something more interesting. For example atomic explosion. or building collapse.

    Tom.
    New Participant
    January 4, 2018
    Hi,

    I'm sorry to restart a 4 years old discussion, but I'm out of luck in making the script work and I thought maybe somebody could help. I mean, the script seems to work- there is some mesh changing in the Project window- but I can't see anything in the Game window. Moreover, as soon as the meshes are dragged into the array, they dissapear from the game camera.
    I would appreciate any help, thanks!
    Inspiring
    January 4, 2018
    It looks like some stuff has been messed up in the formatting since i posted this in the old forums, and its in js which i dont think is supported in unity anymore

    here's a cleaner simplified version in C#
    just attach to the parent object of your frame sequence and hit play.
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    /// <summary>
    /// Mesh sequence playback, 1/04/2018 MikeF
    /// Attach to gameobject containing a series of child gameobjects/meshes to cycle through
    /// Modify public vars below in the inspector an hit play
    /// </summary>
    public class MeshSequence : MonoBehaviour {

    public bool PingPong = false; //ping pong sequence
    public float PlaybackSpeed = 1.0f; //framerate of sequence playback
    public int StartFrame =0; //starting frame of sequence playback

    private GameObject m_lastFrame;
    private GameObject m_currentFrame;
    private bool m_reverse = false;
    private float CycleTimer = 0.0f;
    private int m_NextFrame = 0;
    private List<GameObject> m_frames = new List<GameObject>();

    void Start () {
    SetupFrames ();
    }

    private void SetupFrames(){
    foreach (Transform child in transform) {
    m_frames.Add (child.gameObject);
    child.gameObject.SetActive (false);
    }

    if (StartFrame >= m_frames.Count) {
    Debug.Log ("Start frame is higher than total number of frames, starting from frame 0");
    StartFrame = 0;
    }

    m_currentFrame = m_frames [StartFrame];
    m_currentFrame.gameObject.SetActive (true);
    }


    void Update () {
    CycleTimer += Time.deltaTime*PlaybackSpeed;

    if (CycleTimer >= 1) {
    CycleTimer = 0;
    m_lastFrame = m_currentFrame;
    m_lastFrame.gameObject.SetActive (false);
    m_currentFrame = m_frames [m_NextFrame];
    m_currentFrame.gameObject.SetActive (true);

    if (m_NextFrame == m_frames.Count-1 && !m_reverse) {

    if (PingPong) {
    m_reverse = true;
    m_NextFrame--;
    }

    else if (!PingPong) {
    m_NextFrame = 0;
    }

    }

    if (m_reverse) {
    m_NextFrame--;
    if (m_NextFrame == 0) {
    m_reverse = false;
    m_NextFrame = 0;
    }
    }

    else m_NextFrame++;
    }
    }
    }


    New Participant
    January 8, 2018
    Hey,
    sorry for the delayed answer, the system didn't notify me :(
    Anyways, you're DA MAN! Thank you so much for your reply!
    I will try asap and come back with flowers :D!
    As for 2017 Unity doesn't support js anymore, indeed (dev) but I took my chances since the script was 4 years old. Please tell me if I can offer you some 3d stuff in exchange!


    New Participant
    January 8, 2018
    Yep. It works like a charm!I can't thank you enough! My offer stands and I still need to send you flowers :D
    Inspiring
    January 9, 2018
    No problem, glad it worked for you!