Beispiel #1
0
        /*
         * void LoadAnimations(dynamic avatarconfig)
         * Load the mesh animations associated with this garment.
         * @param avatarconfig	"avatar" section of the config file
         *
         */
        public void LoadAnimations(dynamic avatarconfig)
        {
            dynamic anims = (this as dynamic).animation;

            char[]  delims       = { (char)'/', (char)'\\', (char)'.' };
            dynamic g            = this;
            String  garment_name = g.name;

            if (anims == null)
            {
                return;
            }
            String avatar_name = avatarconfig.rig + ".skeleton.anim";

            foreach (string s in anims)
            {
                String base_name = Path.GetFileNameWithoutExtension(s);
                String script    = "";

                if (s.IndexOfAny(delims) < 0)
                {
                    continue;
                }
                if (!base_name.EndsWith("_" + garment_name))
                {
                    throw new FileLoadException("Incorrect animation naming in closet file, animation names must end with garment name suffix", s);
                }
                String anim_name     = base_name.Substring(0, base_name.Length - garment_name.Length - 1);
                String meshanim_name = g.name + ".meshanim";
                String anim_eng_name = base_name + '.' + meshanim_name + ".anim";

                enableAnims  += "enable " + anim_eng_name + "\n";
                disableAnims += "disable " + anim_eng_name + "\n";
                if (s.EndsWith("xml"))
                {
                    Animator anim = scriptor.MakeAnim(anim_eng_name, clothMesh, false);
                    anim.SetEngineName(meshanim_name);
                    anim.SetFileName(s);
                    SharedWorld.Get().Observe(Event.LOAD_SCENE, anim);
                    AvatarScene.LoadMayaCache(g, s, null, scriptor);
                }
                else
                {
                    script += "load " + s + " " + meshanim_name + " -s  -t " + garment_name + "." + garment_name + "\n";
                }
                script += "onevent loadscene " + anim_eng_name + ", begin " + anim_eng_name + " -with " + anim_name + "." + avatar_name;
                scriptor.Exec(script);
                Console.WriteLine("LoadAnimations: " + script);
            }
        }
Beispiel #2
0
        /*!
         * Loads a Maya geometry cache for cloth presimulation.
         * @param	g			Garment which is being simulated by the cache
         * @param	url			URL or path to the cache description file (XML)
         * @param	text		if not null, this parameter is used as the XML cache description
         * @param	scriptor	Scriptor object to add this animation to
         *
         * @returns true if cache successfully loaded and connected, else false
         */
        public static bool LoadMayaCache(Garment g, String url, String text, Scriptor scriptor)
        {
            dynamic d = g;

            if (g == null)
            {
                return(false);
            }
            if ((g.ClothSim == null) || !g.ClothSim.IsClass((uint)SerialID.VX_MeshAnimator))
            {
                return(false);
            }

            LoadSceneEvent loadevent;
            string         name     = Path.GetFileNameWithoutExtension(url);
            MeshAnimator   clothsim = g.ClothSim.Clone() as MeshAnimator;
            Animator       anim;

            MayaIO.MayaCacheFile import = new MayaIO.MayaCacheFile(clothsim);
            String engname = d.name + ".meshanim";
            String animname;

            /*
             * Make a MeshAnimator to control the cloth vertices in the cloth mesh.
             * The mesh sequence will be loaded into this engine.
             */
            clothsim.Name = name;
            if (clothsim.Target == null)
            {
                clothsim.Target = g.ClothMesh;
            }

            /*
             * Make an Animator to control the mesh animation we are loading.
             * It is attached to the Scriptor that should control it.
             */
            name    += "." + engname;
            animname = name + ".anim";
            anim     = scriptor.MakeAnim(name, g.ClothMesh, false);
            anim.SetEngineName(engname);
            anim.SetFileName(url);
            SharedWorld.Get().Observe(Event.LOAD_SCENE, anim);

            /*
             * Make a load event to signal the mesh animation has been loaded.
             * The event will come from the Animator and will contain the
             * MeshAnimator with the mesh sequences loaded.
             */
            loadevent        = new LoadSceneEvent(Event.LOAD_SCENE);
            loadevent.Sender = anim;
            if (loadevent.Sender == null)
            {
                loadevent.Sender = clothsim;
            }
            loadevent.Object   = clothsim;
            loadevent.FileName = url;

            /*
             * Start the import of the Maya me4sh sequence.
             * This occurs asynchronously in a separate thread.
             */
            if (text != null)
            {
                import.FileName = url;
                import.LoadString(text, loadevent);
            }
            else
            {
                import.LoadFile(url, loadevent);
            }
            return(true);
        }