Beispiel #1
0
    void Update()
    {
        if (mod == null)
        {
            mod = (MegaPointCache)GetComponent <MegaPointCache>();
        }

        if (LinkedUpdate)
        {
            DoLinkedUpdate();
        }
        else
        {
            if (mod && clips.Count > 0 && current < clips.Count)
            {
                if (t >= 0.0f)
                {
                    t += Time.deltaTime;
                    float dt = clips[current].end - clips[current].start;

                    switch (clips[current].loop)
                    {
                    case MegaRepeatMode.Loop: at = Mathf.Repeat(t, dt); break;

                    case MegaRepeatMode.PingPong: at = Mathf.PingPong(t, dt); break;

                    case MegaRepeatMode.Clamp: at = Mathf.Clamp(t, 0.0f, dt); break;
                    }

                    at += clips[current].start;
                    mod.SetAnim(at);
                }
            }
        }
    }
Beispiel #2
0
    public override void OnInspectorGUI()
    {
        MegaPointCache am = (MegaPointCache)target;

        DoAdjustFirst = EditorGUILayout.Toggle("Mapping Adjust", DoAdjustFirst);
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Import PC2"))
        {
            LoadPC2();
            EditorUtility.SetDirty(target);
        }

        if (GUILayout.Button("Import MDD"))
        {
            LoadMDD();
            EditorUtility.SetDirty(target);
        }

        if (GUILayout.Button("Import MC"))
        {
            LoadMCC();
            EditorUtility.SetDirty(target);
        }

        EditorGUILayout.EndHorizontal();

        // Basic mod stuff
        showmodparams = EditorGUILayout.Foldout(showmodparams, "Modifier Common Params");

        if (showmodparams)
        {
            CommonModParamsBasic(am);
        }

        am.time         = EditorGUILayout.FloatField("Time", am.time);
        am.maxtime      = EditorGUILayout.FloatField("Loop Time", am.maxtime);
        am.animated     = EditorGUILayout.Toggle("Animated", am.animated);
        am.speed        = EditorGUILayout.FloatField("Speed", am.speed);
        am.LoopMode     = (MegaRepeatMode)EditorGUILayout.EnumPopup("Loop Mode", am.LoopMode);
        am.interpMethod = (MegaInterpMethod)EditorGUILayout.EnumPopup("Interp Method", am.interpMethod);

        am.blendMode = (MegaBlendAnimMode)EditorGUILayout.EnumPopup("Blend Mode", am.blendMode);
        if (am.blendMode == MegaBlendAnimMode.Additive)
        {
            am.weight = EditorGUILayout.FloatField("Weight", am.weight);
        }

        if (am.Verts != null && am.Verts.Length > 0)
        {
            int mem = am.Verts.Length * am.Verts[0].points.Length * 12;
            EditorGUILayout.LabelField("Memory: ", (mem / 1024) + "KB");
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }
Beispiel #3
0
    void BuildData(MegaModifiers mods, MegaPointCache am, string filename)
    {
        // Build vector3[] of base verts
        Vector3[] baseverts = new Vector3[am.Verts.Length];

        for (int i = 0; i < am.Verts.Length; i++)
        {
            baseverts[i] = am.Verts[i].points[0];
        }

        if (!TryMapping1(baseverts, mods.verts))
        {
            EditorUtility.DisplayDialog("Mapping Failed!", "Mapping of " + Path.GetFileNameWithoutExtension(filename) + " failed!", "OK");
            EditorUtility.ClearProgressBar();
            return;
        }

        // Remap vertices
        for (int i = 0; i < am.Verts.Length; i++)
        {
            for (int v = 0; v < am.Verts[i].points.Length; v++)
            {
                if (negx)
                {
                    am.Verts[i].points[v].x = -am.Verts[i].points[v].x;
                }

                if (flipyz)
                {
                    float z = am.Verts[i].points[v].z;
                    am.Verts[i].points[v].z = am.Verts[i].points[v].y;
                    am.Verts[i].points[v].y = z;
                }

                if (negz)
                {
                    am.Verts[i].points[v].z = -am.Verts[i].points[v].z;
                }

                am.Verts[i].points[v] = am.Verts[i].points[v] * scl;
            }
        }

        for (int i = 0; i < am.Verts.Length; i++)
        {
            am.Verts[i].indices = FindVerts(am.Verts[i].points[0]);

            if (am.Verts[i].indices.Length == 0)
            {
                EditorUtility.DisplayDialog("Final Mapping Failed!", "Mapping of " + Path.GetFileNameWithoutExtension(filename) + " failed!", "OK");
                EditorUtility.ClearProgressBar();
                return;
            }
        }
    }
    //public void OnSceneGUI()
    public override void DrawSceneGUI()
    {
        MegaPointCache mod = (MegaPointCache)target;

        if (mod.showmapping)
        {
            if (mod.Verts != null && mod.Verts[0] != null)
            {
                float     vsize  = mod.mappingSize;
                float     vsize1 = vsize * 0.75f;
                Matrix4x4 tm     = mod.gameObject.transform.localToWorldMatrix;
                Handles.matrix = tm;                    //Matrix4x4.identity;
                Handles.color  = Color.green;

                if (mo == null)
                {
                    mo = mod.gameObject.GetComponent <MegaModifyObject>();
                }

                if (mo)
                {
                    for (int i = 0; i < mo.verts.Length; i++)
                    {
                        Vector3 p = mo.verts[i];
                        Handles.DotCap(i, p, Quaternion.identity, vsize);
                    }
                }

                if (mod.mapEnd >= mod.Verts.Length)
                {
                    mod.mapEnd = mod.Verts.Length - 1;
                }

                if (mod.mapStart > mod.mapEnd)
                {
                    mod.mapStart = mod.mapEnd;
                }

                Handles.color = Color.white;                    //red;

                int findex = 0;
                if (uselastframe)
                {
                    findex = mod.Verts[0].points.Length - 1;
                }
                for (int i = mod.mapStart; i < mod.mapEnd; i++)
                {
                    Vector3 p = mod.Verts[i].points[findex];
                    Handles.DotCap(i, p, Quaternion.identity, vsize1);
                }

                Handles.matrix = Matrix4x4.identity;
            }
        }
    }
Beispiel #5
0
    void LoadMDD()
    {
        MegaPointCache am = (MegaPointCache)target;

        mods = am.gameObject.GetComponent <MegaModifiers>();

        string filename = EditorUtility.OpenFilePanel("Motion Designer File", lastpath, "mdd");

        if (filename == null || filename.Length < 1)
        {
            return;
        }

        lastpath = filename;

        // Clear what we have
        Verts.Clear();

        FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, System.IO.FileShare.Read);

        BinaryReader br = new BinaryReader(fs);

        int numSamples = MegaParse.ReadMotInt(br);
        int numPoints  = MegaParse.ReadMotInt(br);

        float t = 0.0f;

        for (int i = 0; i < numSamples; i++)
        {
            t = MegaParse.ReadMotFloat(br);
        }

        am.maxtime = t;

        am.Verts = new MegaPCVert[numPoints];

        for (int i = 0; i < am.Verts.Length; i++)
        {
            am.Verts[i]        = new MegaPCVert();
            am.Verts[i].points = new Vector3[numSamples];
        }

        for (int i = 0; i < numSamples; i++)
        {
            for (int v = 0; v < numPoints; v++)
            {
                am.Verts[v].points[i].x = MegaParse.ReadMotFloat(br);
                am.Verts[v].points[i].y = MegaParse.ReadMotFloat(br);
                am.Verts[v].points[i].z = MegaParse.ReadMotFloat(br);
            }
        }

        BuildData(mods, am, filename);
        br.Close();
    }
    public void LoadMDD(string filename)
    {
        MegaPointCache am = (MegaPointCache)target;

        oldverts = am.Verts;
        mods     = am.gameObject.GetComponent <MegaModifiers>();

        if (mods == null)
        {
            Debug.LogWarning("You need to add a Mega Modify Object component first!");
            return;
        }
        lastpath = filename;

        // Clear what we have
        Verts.Clear();

        FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, System.IO.FileShare.Read);

        BinaryReader br = new BinaryReader(fs);

        int numSamples = MegaParse.ReadMotInt(br);
        int numPoints  = MegaParse.ReadMotInt(br);

        float t = 0.0f;

        for (int i = 0; i < numSamples; i++)
        {
            t = MegaParse.ReadMotFloat(br);
        }

        am.maxtime = t;

        am.Verts = new MegaPCVert[numPoints];

        for (int i = 0; i < am.Verts.Length; i++)
        {
            am.Verts[i]        = new MegaPCVert();
            am.Verts[i].points = new Vector3[numSamples];
        }

        for (int i = 0; i < numSamples; i++)
        {
            for (int v = 0; v < numPoints; v++)
            {
                am.Verts[v].points[i].x = MegaParse.ReadMotFloat(br);
                am.Verts[v].points[i].y = MegaParse.ReadMotFloat(br);
                am.Verts[v].points[i].z = MegaParse.ReadMotFloat(br);
            }
        }

        BuildData(mods, am, filename);
        br.Close();
    }
    void DoUpdate()
    {
        if (mod == null && modref == null)
        {
            mod    = (MegaPointCache)GetComponent <MegaPointCache>();
            modref = (MegaPointCacheRef)GetComponent <MegaPointCacheRef>();
        }

        if (mod != null || modref != null)
        {
            if (LinkedUpdate)
            {
                DoLinkedUpdate();
            }
            else
            {
                if (clips.Count > 0 && current < clips.Count)
                {
                    if (t >= 0.0f)
                    {
                        t += Time.deltaTime * clips[current].speed;
                        float dt = clips[current].end - clips[current].start;

                        switch (clips[current].loop)
                        {
                        //case MegaRepeatMode.Loop: at = Mathf.Repeat(t, dt); break;
                        case MegaRepeatMode.Loop:
                            at = Mathf.Repeat(t, Mathf.Abs(dt));
                            if (dt < 0.0f)
                            {
                                at = clips[current].start - at;
                            }
                            break;

                        case MegaRepeatMode.PingPong: at = Mathf.PingPong(t, dt); break;

                        case MegaRepeatMode.Clamp: at = Mathf.Clamp(t, 0.0f, dt); break;
                        }

                        at += clips[current].start;

                        if (mod)
                        {
                            mod.SetAnim(at);
                        }
                        else
                        {
                            modref.SetAnim(at);
                        }
                    }
                }
            }
        }
    }
    void AdjustVerts(MegaModifiers mods, MegaPointCache am)
    {
        if (am.Verts != null)
        {
            Vector3[] baseverts = new Vector3[am.Verts.Length];

            for (int i = 0; i < am.Verts.Length; i++)
            {
                baseverts[i] = am.Verts[i].points[0];
            }

            Vector3 min1, max1;
            Vector3 min2, max2;

            Vector3 ex1 = Extents(mods.verts, out min1, out max1);
            Vector3 ex2 = Extents(baseverts, out min2, out max2);

            //Debug.Log("mesh extents " + ex1.ToString("0.00000"));
            //Debug.Log("cache extents " + ex2.ToString("0.00000"));

            //Debug.Log("mesh min " + min1.ToString("0.00000"));
            //Debug.Log("cache min " + min2.ToString("0.00000"));

            //Debug.Log("mesh max " + max1.ToString("0.00000"));
            //Debug.Log("cache max " + max2.ToString("0.00000"));

            int largest1 = MegaUtils.LargestComponent(ex1);
            int largest2 = MegaUtils.LargestComponent(ex2);

            //Debug.Log(largest1 + " " + largest2);
            am.adjustscl = ex1[largest1] / ex2[largest2];
            //Debug.Log("scl " + scl1.ToString("0.0000"));

            //off = verts[0] - (tverts[0] * scl);
            am.adjustoff = (min2 * am.adjustscl) - min1;

            //Debug.Log("scl " + am.adjustscl);
            //Debug.Log("off " + am.adjustoff);

            for (int i = 0; i < am.Verts.Length; i++)
            {
                for (int j = 0; j < am.Verts[i].points.Length; j++)
                {
                    Vector3 p = am.Verts[i].points[j] * am.adjustscl;

                    am.Verts[i].points[j] = p - am.adjustoff;
                }
            }
        }
    }
	protected override void OnTrackingFound()
	{
		_usherFacialAnimation = GameObject.Find("usher_mesh").GetComponent<MegaPointCache>();
			
		doUsherFadeIn();
			
		base.OnTrackingFound();
			
		_audioSource.clip = clipToPlay;
		_audioSource.volume = 1.0f;
		_audioSource.Play();
		_usherFacialAnimation.time = 0;
		_usherFacialAnimation.animated = true;			
			
		_usherTextAnimation.Play();
		
	}
    public int updateRate = 0; // update rate of mesh, 0 is every frame 1 every other etc

    #endregion Fields

    #region Methods

    // Call this to set the source game object which has the working point cache modifier attached
    public void SetSource(GameObject srcobj)
    {
        if ( srcobj )
        {
            if ( mesh == null )
                mesh = MegaUtils.GetMesh(gameObject);

            Mesh srcmesh = MegaUtils.GetMesh(srcobj);

            if ( srcmesh.vertexCount == mesh.vertexCount )
            {
                obj		= srcobj;
                mod		= (MegaPointCache)srcobj.GetComponent<MegaPointCache>();
                modobj	= (MegaModifyObject)srcobj.GetComponent<MegaModifyObject>();
                mesh	= MegaUtils.GetMesh(gameObject);
            }
        }
    }
    public bool recalcBounds = true;                                    // recalc bounds

    // Call this to set the source game object which has the working point cache modifier attached
    public void SetSource(GameObject srcobj)
    {
        if (srcobj)
        {
            if (mesh == null)
            {
                mesh = MegaUtils.GetMesh(gameObject);
            }

            Mesh srcmesh = MegaUtils.GetMesh(srcobj);

            if (srcmesh.vertexCount == mesh.vertexCount)
            {
                obj    = srcobj;
                mod    = (MegaPointCache)srcobj.GetComponent <MegaPointCache>();
                modobj = (MegaModifyObject)srcobj.GetComponent <MegaModifyObject>();
                mesh   = MegaUtils.GetMesh(gameObject);
            }
        }
    }
    void AdjustVertsSimple(MegaModifiers mods, MegaPointCache am)
    {
        if (am.Verts != null)
        {
            Vector3[] baseverts = new Vector3[am.Verts.Length];

            for (int i = 0; i < am.Verts.Length; i++)
            {
                baseverts[i] = am.Verts[i].points[0];
            }

            for (int i = 0; i < am.Verts.Length; i++)
            {
                for (int j = 0; j < am.Verts[i].points.Length; j++)
                {
                    Vector3 p = am.Verts[i].points[j] * am.adjustscl;

                    am.Verts[i].points[j] = p - am.adjustoff;
                }
            }
        }
    }
Beispiel #13
0
	void BuildData(MegaModifiers mods, MegaPointCache am, string filename)
	{
		if ( DoAdjustFirst )
			AdjustVerts(mods, am);

		// Build vector3[] of base verts
		Vector3[] baseverts = new Vector3[am.Verts.Length];

		for ( int i = 0; i < am.Verts.Length; i++ )
			baseverts[i] = am.Verts[i].points[0];

#if false
		for ( int i = 0; i < 32; i++ )
		{
			Debug.Log("vert " + mods.verts[i].ToString("0.000"));
		}

		for ( int i = 0; i < 32; i++ )
		{
			Debug.Log("pc " + baseverts[i].ToString("0.000"));
		}
#endif

		if ( !TryMapping1(baseverts, mods.verts) )
		{
			EditorUtility.DisplayDialog("Mapping Failed!", "Mapping of " + System.IO.Path.GetFileNameWithoutExtension(filename) + " failed!", "OK");
			EditorUtility.ClearProgressBar();
			return;
		}

		// Remap vertices
		for ( int i = 0; i < am.Verts.Length; i++ )
		{
			for ( int v = 0; v < am.Verts[i].points.Length; v++ )
			{
				if ( negx )
					am.Verts[i].points[v].x = -am.Verts[i].points[v].x;

				if ( flipyz )
				{
					float z = am.Verts[i].points[v].z;
					am.Verts[i].points[v].z = am.Verts[i].points[v].y;
					am.Verts[i].points[v].y = z;
				}

				if ( negz )
					am.Verts[i].points[v].z = -am.Verts[i].points[v].z;

				am.Verts[i].points[v] = am.Verts[i].points[v] * scl;
			}
		}

		for ( int i = 0; i < am.Verts.Length; i++ )
		{
			am.Verts[i].indices = FindVerts(am.Verts[i].points[0]);

			if ( am.Verts[i].indices.Length == 0 )
			{
				EditorUtility.DisplayDialog("Final Mapping Failed!", "Mapping of " + System.IO.Path.GetFileNameWithoutExtension(filename) + " failed!", "OK");
				EditorUtility.ClearProgressBar();
				return;
			}
		}
	}
 //////////////////////////////////////////////////////////////////////////////////////////////////////////
 void Start()
 {
     megaPointCache = GetComponent<MegaPointCache>();
 }
    public override void OnInspectorGUI()
    {
        MegaPointCache am = (MegaPointCache)target;

        DoAdjustFirst = EditorGUILayout.Toggle("Mapping Adjust", DoAdjustFirst);
        uselastframe  = EditorGUILayout.Toggle("Use Last Frame", uselastframe);

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Import PC2"))
        {
            LoadPC2();
            EditorUtility.SetDirty(target);
        }

        if (GUILayout.Button("Import MDD"))
        {
            LoadMDD();
            EditorUtility.SetDirty(target);
        }

        if (GUILayout.Button("Import MC"))
        {
            LoadMCC();
            EditorUtility.SetDirty(target);
        }

        EditorGUILayout.EndHorizontal();

        // Basic mod stuff
        showmodparams = EditorGUILayout.Foldout(showmodparams, "Modifier Common Params");

        if (showmodparams)
        {
            CommonModParamsBasic(am);
        }

        // Advanced
        showadvanced = EditorGUILayout.Foldout(showadvanced, "Advanced Params");

        if (showadvanced)
        {
            tolerance = EditorGUILayout.FloatField("Map Tolerance", tolerance * 100.0f) / 100.0f;
            if (am.Verts != null && am.Verts.Length > 0)                //[0] != null )
            {
                am.showmapping = EditorGUILayout.BeginToggleGroup("Show Mapping", am.showmapping);
                am.mapStart    = EditorGUILayout.IntSlider("StartVert", am.mapStart, 0, am.Verts.Length);
                am.mapEnd      = EditorGUILayout.IntSlider("endVert", am.mapEnd, 0, am.Verts.Length);
                am.mappingSize = EditorGUILayout.Slider("Size", am.mappingSize, 0.0005f, 10.01f);
                EditorGUILayout.EndToggleGroup();
            }

            //morph.tolerance = EditorGUILayout.Slider("Tolerance", morph.tolerance, 0.0f, 0.01f);
        }

        am.time         = EditorGUILayout.FloatField("Time", am.time);
        am.maxtime      = EditorGUILayout.FloatField("Loop Time", am.maxtime);
        am.animated     = EditorGUILayout.Toggle("Animated", am.animated);
        am.framedelay   = EditorGUILayout.Toggle("Frame Delay", am.framedelay);
        am.speed        = EditorGUILayout.FloatField("Speed", am.speed);
        am.LoopMode     = (MegaRepeatMode)EditorGUILayout.EnumPopup("Loop Mode", am.LoopMode);
        am.interpMethod = (MegaInterpMethod)EditorGUILayout.EnumPopup("Interp Method", am.interpMethod);

        am.blendMode = (MegaBlendAnimMode)EditorGUILayout.EnumPopup("Blend Mode", am.blendMode);
        if (am.blendMode == MegaBlendAnimMode.Additive)
        {
            am.weight = EditorGUILayout.FloatField("Weight", am.weight);
        }

        if (am.Verts != null && am.Verts.Length > 0)
        {
            int mem = am.Verts.Length * am.Verts[0].points.Length * 12;
            EditorGUILayout.LabelField("Memory: ", (mem / 1024) + "KB");
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }
    public void LoadPC2(string filename)
    {
        MegaPointCache am = (MegaPointCache)target;

        oldverts = am.Verts;
        mods     = am.gameObject.GetComponent <MegaModifiers>();

        if (mods == null)
        {
            Debug.LogWarning("You need to add a Mega Modify Object component first!");
            return;
        }

        lastpath = filename;

        // Clear what we have
        Verts.Clear();

        FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, System.IO.FileShare.Read);

        long         len = fs.Length;
        BinaryReader br  = new BinaryReader(fs);

        string sig = MegaParse.ReadStr(br);

        if (sig != "POINTCACHE2")
        {
            EditorUtility.DisplayDialog("PC2 Importer", "The selected file does not appear to be a valid PC2 File", "Ok");
            br.Close();
            return;
        }

        int fileVersion = br.ReadInt32();

        if (fileVersion != 1)
        {
            br.Close();
            return;
        }

        int numPoints = br.ReadInt32();

        br.ReadSingle();
        br.ReadSingle();
        int  numSamples = br.ReadInt32();
        long csamples   = (len - 24) / (numPoints * 12);

        numSamples = (int)csamples;

        am.Verts = new MegaPCVert[numPoints];

        for (int i = 0; i < am.Verts.Length; i++)
        {
            am.Verts[i]        = new MegaPCVert();
            am.Verts[i].points = new Vector3[numSamples];
        }

        for (int i = 0; i < numSamples; i++)
        {
            for (int v = 0; v < numPoints; v++)
            {
                am.Verts[v].points[i] = MegaParse.ReadP3(br);
            }
        }
        BuildData(mods, am, filename);
        br.Close();
    }
    void BuildData(MegaModifiers mods, MegaPointCache am, string filename)
    {
        bool domapping = true;

        if (am.havemapping)
        {
            domapping = EditorUtility.DisplayDialog("Point Cache Mapping", "Replace Existing Mapping?", "Yes", "No");
        }

        if (!domapping)
        {
            if (DoAdjustFirst)
            {
                AdjustVertsSimple(mods, am);
            }
        }
        else
        {
            if (DoAdjustFirst)
            {
                AdjustVerts(mods, am);
            }
        }
        // Build vector3[] of base verts
        Vector3[] baseverts = new Vector3[am.Verts.Length];

        int findex = 0;

        if (uselastframe)
        {
            findex = am.Verts[0].points.Length - 1;
        }
        for (int i = 0; i < am.Verts.Length; i++)
        {
            baseverts[i] = am.Verts[i].points[findex];
        }

#if false
        for (int i = 0; i < 32; i++)
        {
            Debug.Log("vert " + mods.verts[i].ToString("0.000"));
        }

        for (int i = 0; i < 32; i++)
        {
            Debug.Log("pc " + baseverts[i].ToString("0.000"));
        }
#endif

        if (domapping)
        {
            if (!TryMapping1(baseverts, mods.verts))
            {
                EditorUtility.DisplayDialog("Mapping Failed!", "Mapping of " + System.IO.Path.GetFileNameWithoutExtension(filename) + " failed!", "OK");
                EditorUtility.ClearProgressBar();
                am.havemapping = false;
                return;
            }

            am.negx   = negx;
            am.negz   = negz;
            am.flipyz = flipyz;
            am.scl    = scl;
        }
        else
        {
            negx   = am.negx;
            negz   = am.negz;
            flipyz = am.flipyz;
            scl    = am.scl;
        }

        am.havemapping = true;

        // Remap vertices
        for (int i = 0; i < am.Verts.Length; i++)
        {
            for (int v = 0; v < am.Verts[i].points.Length; v++)
            {
                if (negx)
                {
                    am.Verts[i].points[v].x = -am.Verts[i].points[v].x;
                }

                if (flipyz)
                {
                    float z = am.Verts[i].points[v].z;
                    am.Verts[i].points[v].z = am.Verts[i].points[v].y;
                    am.Verts[i].points[v].y = z;
                }

                if (negz)
                {
                    am.Verts[i].points[v].z = -am.Verts[i].points[v].z;
                }

                am.Verts[i].points[v] = am.Verts[i].points[v] * scl;
            }
        }

        if (domapping)
        {
            for (int i = 0; i < am.Verts.Length; i++)
            {
                am.Verts[i].indices = FindVerts(am.Verts[i].points[findex]);

                if (am.Verts[i].indices.Length == 0)
                {
                    EditorUtility.DisplayDialog("Final Mapping Failed!", "Mapping of " + System.IO.Path.GetFileNameWithoutExtension(filename) + " failed!", "OK");
                    EditorUtility.ClearProgressBar();
                    return;
                }
            }
        }
        else
        {
            for (int i = 0; i < am.Verts.Length; i++)
            {
                am.Verts[i].indices = oldverts[i].indices;
            }
        }

        oldverts = null;
    }
Beispiel #18
0
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
 void Awake()
 {
     megaPointCache = GetComponent<MegaPointCache>();
 }
    void Update()
    {
        if ( mod == null )
            mod = (MegaPointCache)GetComponent<MegaPointCache>();

        if ( LinkedUpdate )
        {
            DoLinkedUpdate();
        }
        else
        {
            if ( mod && clips.Count > 0 && current < clips.Count )
            {
                if ( t >= 0.0f )
                {
                    t += Time.deltaTime;
                    float dt = clips[current].end - clips[current].start;

                    switch ( clips[current].loop )
                    {
                        case MegaRepeatMode.Loop: at = Mathf.Repeat(t, dt); break;
                        case MegaRepeatMode.PingPong: at = Mathf.PingPong(t, dt); break;
                        case MegaRepeatMode.Clamp: at = Mathf.Clamp(t, 0.0f, dt); break;
                    }

                    at += clips[current].start;
                    mod.SetAnim(at);
                }
            }
        }
    }
Beispiel #20
0
 // Use this for initialization
 void Awake()
 {
     pla = transform.parent.gameObject.GetComponentInChildren <MegaPointCache>();
 }
    void AdjustVertsSimple(MegaModifiers mods, MegaPointCache am)
    {
        if ( am.Verts != null )
        {
            Vector3[] baseverts = new Vector3[am.Verts.Length];

            for ( int i = 0; i < am.Verts.Length; i++ )
                baseverts[i] = am.Verts[i].points[0];

            for ( int i = 0; i < am.Verts.Length; i++ )
            {
                for ( int j = 0; j < am.Verts[i].points.Length; j++ )
                {
                    Vector3 p = am.Verts[i].points[j] * am.adjustscl;

                    am.Verts[i].points[j] = p - am.adjustoff;
                }
            }
        }
    }
Beispiel #22
0
    // Maya format
    void LoadMCC()
    {
        MegaPointCache am = (MegaPointCache)target;

        mods = am.gameObject.GetComponent <MegaModifiers>();

        string filename = EditorUtility.OpenFilePanel("Maya Cache File", lastpath, "mc");

        if (filename == null || filename.Length < 1)
        {
            return;
        }

        lastpath = filename;

        FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, System.IO.FileShare.Read);

        BinaryReader br = new BinaryReader(fs);

        string id = Read(br, 4);

        if (id != "FOR4")
        {
            Debug.Log("wrong file");
            return;
        }

        int offset = MegaParse.ReadMotInt(br);

        br.ReadBytes(offset);

        List <MCCFrame> frames = new List <MCCFrame>();

        while (true)
        {
            string btag = Read(br, 4);
            if (btag == "")
            {
                break;
            }

            if (btag != "FOR4")
            {
                Debug.Log("File format error");
                return;
            }

            int blocksize = MegaParse.ReadMotInt(br);

            int bytesread = 0;

            btag = Read(br, 4);
            if (btag != "MYCH")
            {
                Debug.Log("File format error");
                return;
            }
            bytesread += 4;

            btag = Read(br, 4);
            if (btag != "TIME")
            {
                Debug.Log("File format error");
                return;
            }
            bytesread += 4;

            br.ReadBytes(4);
            bytesread += 4;

            int time = MegaParse.ReadMotInt(br);
            bytesread += 4;

            am.maxtime = (float)time / 6000.0f;

            while (bytesread < blocksize)
            {
                btag = Read(br, 4);
                if (btag != "CHNM")
                {
                    Debug.Log("chm error");
                    return;
                }
                bytesread += 4;

                int chnmsize = MegaParse.ReadMotInt(br);
                bytesread += 4;

                int mask           = 3;
                int chnmsizetoread = (chnmsize + mask) & (~mask);
                //byte[] channelname = br.ReadBytes(chnmsize);
                br.ReadBytes(chnmsize);

                int paddingsize = chnmsizetoread - chnmsize;

                if (paddingsize > 0)
                {
                    br.ReadBytes(paddingsize);
                }

                bytesread += chnmsizetoread;

                btag = Read(br, 4);

                if (btag != "SIZE")
                {
                    Debug.Log("Size error");
                    return;
                }
                bytesread += 4;

                br.ReadBytes(4);
                bytesread += 4;

                int arraylength = MegaParse.ReadMotInt(br);
                bytesread += 4;

                MCCFrame frame = new MCCFrame();
                frame.points = new Vector3[arraylength];

                string dataformattag = Read(br, 4);
                int    bufferlength  = MegaParse.ReadMotInt(br);
                bytesread += 8;

                if (dataformattag == "FVCA")
                {
                    if (bufferlength != arraylength * 3 * 4)
                    {
                        Debug.Log("buffer len error");
                        return;
                    }

                    for (int i = 0; i < arraylength; i++)
                    {
                        frame.points[i].x = MegaParse.ReadMotFloat(br);
                        frame.points[i].y = MegaParse.ReadMotFloat(br);
                        frame.points[i].z = MegaParse.ReadMotFloat(br);
                    }

                    bytesread += arraylength * 3 * 4;
                }
                else
                {
                    if (dataformattag == "DVCA")
                    {
                        if (bufferlength != arraylength * 3 * 8)
                        {
                            Debug.Log("buffer len error");
                            return;
                        }

                        for (int i = 0; i < arraylength; i++)
                        {
                            frame.points[i].x = (float)MegaParse.ReadMotDouble(br);
                            frame.points[i].y = (float)MegaParse.ReadMotDouble(br);
                            frame.points[i].z = (float)MegaParse.ReadMotDouble(br);
                        }

                        bytesread += arraylength * 3 * 8;
                    }
                    else
                    {
                        Debug.Log("Format Error");
                        return;
                    }
                }

                frames.Add(frame);
            }
        }

        // Build table
        am.Verts = new MegaPCVert[frames[0].points.Length];

        for (int i = 0; i < am.Verts.Length; i++)
        {
            am.Verts[i]        = new MegaPCVert();
            am.Verts[i].points = new Vector3[frames.Count];

            for (int p = 0; p < am.Verts[i].points.Length; p++)
            {
                am.Verts[i].points[p] = frames[p].points[i];
            }
        }

        BuildData(mods, am, filename);
        br.Close();
    }
    void BuildData(MegaModifiers mods, MegaPointCache am, string filename)
    {
        bool domapping = true;
        if ( am.havemapping )
            domapping = EditorUtility.DisplayDialog("Point Cache Mapping", "Replace Existing Mapping?", "Yes", "No");

        if ( !domapping )
        {
            if ( DoAdjustFirst )
                AdjustVertsSimple(mods, am);
        }
        else
        {
            if ( DoAdjustFirst )
                AdjustVerts(mods, am);
        }
        // Build vector3[] of base verts
        Vector3[] baseverts = new Vector3[am.Verts.Length];

        int findex = 0;
        if ( uselastframe )
        {
            findex = am.Verts[0].points.Length - 1;
        }
        for ( int i = 0; i < am.Verts.Length; i++ )
            baseverts[i] = am.Verts[i].points[findex];

        #if false
        for ( int i = 0; i < 32; i++ )
        {
            Debug.Log("vert " + mods.verts[i].ToString("0.000"));
        }

        for ( int i = 0; i < 32; i++ )
        {
            Debug.Log("pc " + baseverts[i].ToString("0.000"));
        }
        #endif

        if ( domapping )
        {
            if ( !TryMapping1(baseverts, mods.verts) )
            {
                EditorUtility.DisplayDialog("Mapping Failed!", "Mapping of " + System.IO.Path.GetFileNameWithoutExtension(filename) + " failed!", "OK");
                EditorUtility.ClearProgressBar();
                am.havemapping = false;
                return;
            }

            am.negx = negx;
            am.negz = negz;
            am.flipyz = flipyz;
            am.scl = scl;
        }
        else
        {
            negx = am.negx;
            negz = am.negz;
            flipyz = am.flipyz;
            scl = am.scl;
        }

        am.havemapping = true;

        // Remap vertices
        for ( int i = 0; i < am.Verts.Length; i++ )
        {
            for ( int v = 0; v < am.Verts[i].points.Length; v++ )
            {
                if ( negx )
                    am.Verts[i].points[v].x = -am.Verts[i].points[v].x;

                if ( flipyz )
                {
                    float z = am.Verts[i].points[v].z;
                    am.Verts[i].points[v].z = am.Verts[i].points[v].y;
                    am.Verts[i].points[v].y = z;
                }

                if ( negz )
                    am.Verts[i].points[v].z = -am.Verts[i].points[v].z;

                am.Verts[i].points[v] = am.Verts[i].points[v] * scl;
            }
        }

        if ( domapping )
        {
            for ( int i = 0; i < am.Verts.Length; i++ )
            {
                am.Verts[i].indices = FindVerts(am.Verts[i].points[findex]);

                if ( am.Verts[i].indices.Length == 0 )
                {
                    EditorUtility.DisplayDialog("Final Mapping Failed!", "Mapping of " + System.IO.Path.GetFileNameWithoutExtension(filename) + " failed!", "OK");
                    EditorUtility.ClearProgressBar();
                    return;
                }
            }
        }
        else
        {
            for ( int i = 0; i < am.Verts.Length; i++ )
            {
                am.Verts[i].indices = oldverts[i].indices;
            }
        }

        oldverts = null;
    }
    void DoUpdate()
    {
        if ( mod == null && modref == null )
        {
            mod = (MegaPointCache)GetComponent<MegaPointCache>();
            modref = (MegaPointCacheRef)GetComponent<MegaPointCacheRef>();
        }

        if ( mod != null || modref != null )
        {
            if ( LinkedUpdate )
            {
                DoLinkedUpdate();
            }
            else
            {
                if ( clips.Count > 0 && current < clips.Count )
                {
                    if ( t >= 0.0f )
                    {
                        t += Time.deltaTime * clips[current].speed;
                        float dt = clips[current].end - clips[current].start;

                        switch ( clips[current].loop )
                        {
                            //case MegaRepeatMode.Loop: at = Mathf.Repeat(t, dt); break;
                            case MegaRepeatMode.Loop:
                                at = Mathf.Repeat(t, Mathf.Abs(dt));
                                if ( dt < 0.0f )
                                    at = clips[current].start - at;
                                break;
                            case MegaRepeatMode.PingPong: at = Mathf.PingPong(t, dt); break;
                            case MegaRepeatMode.Clamp: at = Mathf.Clamp(t, 0.0f, dt); break;
                        }

                        at += clips[current].start;

                        if ( mod )
                            mod.SetAnim(at);
                        else
                            modref.SetAnim(at);
                    }
                }
            }
        }
    }
Beispiel #25
0
    void LoadPC2()
    {
        MegaPointCache am = (MegaPointCache)target;

        mods = am.gameObject.GetComponent <MegaModifiers>();

        string filename = EditorUtility.OpenFilePanel("Point Cache File", lastpath, "pc2");

        if (filename == null || filename.Length < 1)
        {
            return;
        }

        lastpath = filename;

        // Clear what we have
        Verts.Clear();

        FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, System.IO.FileShare.Read);

        BinaryReader br = new BinaryReader(fs);

        string sig = MegaParse.ReadStr(br);

        if (sig != "POINTCACHE2")
        {
            br.Close();
            return;
        }

        int fileVersion = br.ReadInt32();

        if (fileVersion != 1)
        {
            br.Close();
            return;
        }

        int numPoints = br.ReadInt32();

        br.ReadSingle();
        br.ReadSingle();
        int numSamples = br.ReadInt32();

        am.Verts = new MegaPCVert[numPoints];

        for (int i = 0; i < am.Verts.Length; i++)
        {
            am.Verts[i]        = new MegaPCVert();
            am.Verts[i].points = new Vector3[numSamples];
        }

        for (int i = 0; i < numSamples; i++)
        {
            for (int v = 0; v < numPoints; v++)
            {
                am.Verts[v].points[i] = MegaParse.ReadP3(br);
            }
        }
        BuildData(mods, am, filename);
        br.Close();
    }
Beispiel #26
0
	void AdjustVerts(MegaModifiers mods, MegaPointCache am)
	{
		if ( am.Verts != null )
		{
			Vector3[] baseverts = new Vector3[am.Verts.Length];

			for ( int i = 0; i < am.Verts.Length; i++ )
				baseverts[i] = am.Verts[i].points[0];

			Vector3 min1,max1;
			Vector3 min2,max2;

			Vector3 ex1 = Extents(mods.verts, out min1, out max1);
			Vector3 ex2 = Extents(baseverts, out min2, out max2);

			//Debug.Log("mesh extents " + ex1.ToString("0.00000"));
			//Debug.Log("cache extents " + ex2.ToString("0.00000"));

			//Debug.Log("mesh min " + min1.ToString("0.00000"));
			//Debug.Log("cache min " + min2.ToString("0.00000"));

			//Debug.Log("mesh max " + max1.ToString("0.00000"));
			//Debug.Log("cache max " + max2.ToString("0.00000"));

			int largest1 = MegaUtils.LargestComponent(ex1);
			int largest2 = MegaUtils.LargestComponent(ex2);

			//Debug.Log(largest1 + " " + largest2);
			float scl1 = ex1[largest1] / ex2[largest2];
			//Debug.Log("scl " + scl1.ToString("0.0000"));

			//off = verts[0] - (tverts[0] * scl);
			Vector3 off1 = (min2 * scl1) - min1;

			for ( int i = 0; i < am.Verts.Length; i++ )
			{
				for ( int j = 0; j < am.Verts[i].points.Length; j++ )
				{
					Vector3 p = am.Verts[i].points[j] * scl1;

					am.Verts[i].points[j] = p - off1;
				}
			}
		}
	}
Beispiel #27
0
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 void Start()
 {
     serp02.gameObject.SetActive(false);
     megaPointCache = serp01.GetComponent<MegaPointCache>();
     megaPointCache.animated=false;
 }
Beispiel #28
0
 //////////////////////////////////////////////////////////////////////////////////////////////////////////
 void Start()
 {
     megaPointCache1 = m_lluna.GetComponent<MegaPointCache>();
     megaPointCache2 = m_gato.GetComponent<MegaPointCache>();
 }