public bool Convert()
        {
            m_reporter.Open();
            m_animClip = new AnimationClip();

            int nchildren = m_root.childCount;

            for (int i = 0; i < nchildren; ++i)
            {
                ConvertRecursive(m_root.GetChild(i), "");
            }

            AssetDatabase.CreateAsset(m_animClip, "Assets/" + m_assetName + ".anim");
            m_controller = AnimatorController.CreateAnimatorControllerAtPathWithClip("Assets/" + m_assetName + ".controller", m_animClip);

            var go       = m_root.gameObject;
            var animator = usdi.GetOrAddComponent <Animator>(go);

            animator.runtimeAnimatorController = m_controller;
            {
                var usd = go.GetComponent <UsdStream>();
                if (usd != null)
                {
                    usd.usdiDetachUsdComponents();
                }
                else
                {
                    var cmps = go.GetComponentsInChildren <UsdIComponent>();
                    foreach (var c in cmps)
                    {
                        Undo.DestroyObjectImmediate(c);
                    }
                }
            }

            {
                // todo: create mesh & material assets
                //PrefabUtility.CreatePrefab("Assets/" + m_assetName + ".prefab", m_root.gameObject);
            }

            m_reporter.Close();
            return(true);
        }
Example #2
0
        void Generate()
        {
            usdi.ProgressReporter reporter = new usdi.ProgressReporter();
            UsdStream             stream   = null;

            int ndone = 0;

            if (m_stream != null)
            {
                reporter.Open();
                stream = m_stream;
                var meshes  = new List <usdi.Mesh>();
                var results = new List <bool>();
                usdi.usdiPreComputeNormalsAll(m_stream.usdiContext, s_genTangents, s_overwrite, (usdi.Mesh mesh, Bool done) => {
                    meshes.Add(mesh);
                    results.Add(done);
                    if (done)
                    {
                        ++ndone;
                        reporter.Write("done: " + usdi.usdiPrimGetNameS(mesh) + "\n");
                    }
                    else
                    {
                        reporter.Write("skipped: " + usdi.usdiPrimGetNameS(mesh) + "\n");
                    }
                });
                for (int i = 0; i < meshes.Count; ++i)
                {
                    var mesh = meshes[i];
                    if (results[i])
                    {
                        Debug.Log("Precompute done: " + usdi.usdiPrimGetNameS(mesh));
                    }
                    else
                    {
                        Debug.Log("Precompute skipped: " + usdi.usdiPrimGetNameS(mesh));
                    }
                }
            }
            else if (m_mesh != null)
            {
                stream = m_mesh.stream;
                var mesh = m_mesh.nativeMeshPtr;
                var ret  = usdi.usdiMeshPreComputeNormals(mesh, s_genTangents, s_overwrite);
                if (ret)
                {
                    Debug.Log("Precompute done: " + usdi.usdiPrimGetPathS(mesh));
                    ++ndone;
                }
                else
                {
                    Debug.Log("Precompute skipped: " + usdi.usdiPrimGetPathS(mesh));
                }
            }

            if (stream != null && ndone > 0)
            {
                reporter.Write("flushing to file ... ");
                stream.usdiSave();
                stream.usdiReload();
                reporter.Write("done.\n");
            }
            reporter.Close();
        }