예제 #1
0
 public void CopyFrom(dynamic src)
 {
     Clear();
     foreach (dynamic d in src)
     {
         Garment g = new Garment(d, garmentRoot, skeleton, scriptor);
         Add(g);
     }
 }
예제 #2
0
 public void Select(Garment g)
 {
     if (currentGarment != null)
     {
         currentGarment.Hide();
     }
     currentGarment = g;
     g.Show();
 }
예제 #3
0
        public void Select(String garmentName, String url)
        {
            Garment g = Load(garmentName, url);

            if (g != null)
            {
                Select(g);
                return;
            }
        }
예제 #4
0
        /*!
         * @param url		URL to 3D animation file to load.
         * @param target	name of avatar/garment to apply animation to
         *				if null, the current avatar is assumed
         * Load a 3D animation content file (BVH, Havok or Vixen format)
         * and apply it to the named avatar or garment. The name of the
         * animation is the base name of the file without the extension.
         *
         * @see PlayAnimation PauseAnimation
         */
        public virtual void LoadAnimation(String url, String targetname)
        {
            String    ext     = url.Substring(url.LastIndexOf('.')).ToLower();
            SharedObj targobj = null;
            Garment   g       = null;

            if (ext == ".scp")
            {
                scriptor.LoadScript(url);
                return;
            }
            if (ext == ".xml")
            {
                if (targetname != null)
                {
                    g = FindGarment(targetname);
                }
                else
                {
                    g = currentGarment;
                }
                LoadMayaCache(g, url, null, scriptor);
            }
            else
            {
                Puppet p = null;

                if (targetname != null)
                {
                    p = FindAvatar(targetname);
                    g = FindGarment(targetname);
                }
                else
                {
                    if (currentAvatar == null)
                    {
                        return;
                    }
                    p = currentAvatar;
                }
                if (p != null)
                {
                    targetname = p.AnimSkeleton.Name;
                    targetname = targetname.Substring(targetname.IndexOf('.'));
                    targobj    = p.AnimSkeleton;
                }
                else if (g != null)
                {
                    targobj    = g.ClothMesh;
                    targetname = g.ClothMesh.Name;
                }
                scriptor.Load(url, targetname, 0, targobj);
            }
        }
예제 #5
0
        /*!
         * Hides the named garment if it is currently draped on the avatar.
         *
         * @see ShowGarment LoadGarment
         */
        public virtual void HideGarment(String name)
        {
            Garment g = closet.Find(name);

            if (g != null)
            {
                g.Hide();
            }
            else
            {
                SharedWorld.LogError("Cannot find garment " + name);
            }
        }
예제 #6
0
        public Garment Load(String garmentName, String url)
        {
            dynamic g = Find(garmentName);

            if (g != null)
            {
                g.Load(g.filename);
                Select(g);
                return(g);
            }
            g = new Garment(garmentRoot, skeleton, garmentName);
            this.Add(g);
            return(null);
        }
예제 #7
0
        /*!
         * Display the named garment on the avatar. This function will only display the clothing
         * if it has already been loaded.
         *
         * @see LoadGarment HideGarment
         */
        public virtual void ShowGarment(String name)
        {
            Garment g = closet.Find(name);

            if (g != null)
            {
                if (!g.IsLoaded)
                {
                    g.Load(null);
                }
                else
                {
                    g.Show();
                }
                currentGarment = g;
            }
            else
            {
                SharedWorld.LogError("Cannot find garment " + name);
            }
        }
예제 #8
0
        public Garment OnLoad(Scene scene, SharedWorld world, dynamic avatarconfig)
        {
            Garment g   = Find(scene.Name);
            dynamic tmp = g;

            if (g == null)
            {
                SharedWorld.LogError(scene.Name + " not a garment - ignoring this load event");
                return(null);
            }
            if (g.IsLoaded)
            {
                SharedWorld.LogError(scene.Name + " already loaded - ignoring this load event");
                return(g);
            }
            g.Connect(world, scene, avatarconfig);
            if ((scriptor != null) && (tmp.script != null))
            {
                scriptor.LoadScript(tmp.script);
            }
            Select(g);
            return(g);
        }
예제 #9
0
        /*!
         * @param world	current world
         * @param scene	scene which finished loading
         *
         * Called when a 3D content file has finished loading. This event
         * will always come before OnSetScene but this function is not
         * guaranteed to be called before th 3D scene has been replaced.
         * This function always invokes the LoadSceneEvent handler.
         */
        public virtual void OnSceneLoad(SharedWorld world, Scene scene, String scenefile)
        {
            System.String name = scene.Name.ToLower();

            if (name.EndsWith(".scene"))
            {
                name = name.Substring(0, name.Length - 6);
            }
            SharedWorld.Trace("Loaded " + name);
            if (LoadSceneEvent != null)
            {
                LoadSceneEvent(name, scenefile);
            }
            if (scenefile.Contains("avatar"))
            {
                OnAvatarLoad(world, scene);
                return;
            }
            if (name.Contains("hair"))
            {
                ConnectHair(world, scene);
                return;
            }
            else if (!sceneLoaded && (interiorRoot.FileName == scenefile))
            {
                sceneLoaded = true;
                world.SuspendScene();
                Camera mainCam = world.GetScene().Camera;
                Box3   vvol    = scene.Camera.ViewVol;
                float  aspect  = mainCam.Aspect;
                mainCam.Copy(scene.Camera);
                mainCam.Aspect = aspect;
                if (cameraController != null)
                {
                    cameraController.Target = mainCam;
                }
                world.ResumeScene();
                if (scriptor != null)
                {
                    scriptor.LoadScript(scenefile.Substring(0, scenefile.Length - 3) + "scp");
                }
                return;
            }

            /*
             * Not background or avatar, assume it is clothing
             */
            if (closet == null)
            {
                return;
            }
            world.SuspendScene();
            dynamic g = closet.OnLoad(scene, world, config.avatar);

            if (g == null)
            {
                world.ResumeScene();
                return;
            }
            if (g.script != null)
            {
                PlayAnimation(g.script, 0);
            }
            if (g.ClothSim != null)
            {
                if (g.ClothSim.Parent() == null)
                {
                    physics.Append(g.ClothSim);
                }
                if (typeof(ClothSim).IsAssignableFrom(g.ClothSim.GetType()))
                {
                    ((ClothSim)g.ClothSim).GroundPlane = groundPlane;
                }
            }
            currentGarment = g;
            world.ResumeScene();
            if (LoadGarmentEvent != null)
            {
                LoadGarmentEvent(g.name, scenefile);
            }
        }
예제 #10
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);
        }
예제 #11
0
        public void Add(Garment g)
        {
            dynamic tmp = this;

            tmp.items.Add(g);
        }