/*! * Plays the named animation on the current avatar. * The animation will not be played if it has not already been loaded. * @param name name of animation to play * @param blend time in seconds to blend to this animation (0 = no blending) * * @see LoadAnimation PauseAnimation */ public virtual void PlayAnimation(String name, float blend) { SharedWorld world = SharedWorld.Get(); if (nowPlaying != null) { return; } try { Group g = scriptor.Find(name + '.', Group.FIND_START | Group.FIND_CHILD); world.SuspendScene(); if (g != null) { scriptor.End(); nowPlaying = g as Engine; scriptor.Begin(g.Name); } else { nowPlaying = null; } } catch (Exception ex) { SharedWorld.LogError("PlayAnimation EXCEPTION " + ex.Message); nowPlaying = null; } world.ResumeScene(); }
public Skeleton ConnectHair(Engine simroot) { if (simroot == null) { return(null); } try { /* * find the hair simulation skeleton. If using Havok, * enable the skeleton mapper to map the rigid body motion * onto the hair skeleton. * * Find the hair simulation root - either Havok cloth or a skin. */ System.String filebase = Path.GetFileNameWithoutExtension(hairModel.FileName).ToLower(); String skelname = filebase + ".proxy_" + filebase; String ext = Path.GetExtension(hairModel.FileName).ToLower(); if (usehavok && (ext != ".vix")) { RagDoll ragdoll; Physics physroot = Physics.Get(); Engine skelmapper; Model hairBones = (Model)hairModel.Find(skelname, Group.FIND_DESCEND | Group.FIND_END); //if (hairBones != null) // hairBones.Active = false; skelname += ".skeleton"; ragdoll = (RagDoll)Scriptor.Find(skelname); hairSimSkel = ragdoll; hairSimSkel.Control |= RagDoll.DYNAMIC; hairSimSkel.SetBoneOptions(0, Skeleton.BONE_ANIMATE); skelmapper = (Engine)ragdoll.Find(".mapper", Group.FIND_END | Group.FIND_CHILD); if (skelmapper != null) { skelmapper.Active = true; hairAnimSkel = skelmapper.Target as Skeleton; } if (physroot != null) { hairSim = (Engine)physroot.Find(filebase + ".cloth", Group.FIND_DESCEND | Group.FIND_EXACT); if (hairSim == null) { hairSim = (Engine)physroot.Find(".skin", Group.FIND_DESCEND | Group.FIND_END); } physroot.Active = true; } } else { skelname = filebase + "." + filebase + ".skeleton"; hairSimSkel = (Skeleton)Scriptor.Find(skelname); hairSim = (Engine)simroot.Find(".skin", Group.FIND_DESCEND | Group.FIND_END); } /* * Find the head bone in the animation skeleton and connect the hair to it. */ if (animSkel != null) { int headindex = animSkel.GetBoneIndex("center_head"); if (headindex > 0) { Transformer head = animSkel.GetBone(headindex); head.SetOptions(Transformer.WORLD); if (hairSimSkel != null) { head.Target = animSkel.GetBone(0); } else { head.Target = hairModel; } } } Show(); } catch (Exception) { // do nothing } return(hairSimSkel); }
public Engine Connect(SharedWorld world, Scene scene, dynamic avatarconfig) { Engine simroot = Physics.Get(); Model mod; string baseName = null; string animrig = "hip"; string havokrig = null; if (avatarconfig != null) { if (avatarconfig.rig != null) { animrig = avatarconfig.rig; } if (avatarconfig.havokrig != null) { havokrig = avatarconfig.havokrig; } } if (simroot == null) { simroot = scene.Engines; if (simroot == null) { return(null); } } world.SuspendScene(); try { baseName = ((dynamic)this).name; string skelname = null; Skeleton clothskel = null; if (havokrig != null) { skelname += baseName + "." + havokrig + ".skeleton"; clothskel = (Skeleton)Scriptor.Find(skelname); if (clothskel != null) { mod = (Model)clothskel.Target; clothskel.Remove(true); } else { mod = (Model)clothRoot.Find(baseName + "." + havokrig, Group.FIND_DESCEND | Group.FIND_EXACT); } if (mod != null) { mod.Remove(true); } } skelname = baseName + "." + animrig + ".skeleton"; clothskel = (Skeleton)Scriptor.Find(skelname); if (clothskel != null) { Engine e = clothskel.First(); Engine skin = null; clothMesh = (Model)clothskel.Target; if (clothMesh == null) { clothMesh = (Model)clothRoot.Find(baseName + "." + baseName, Group.FIND_DESCEND | Group.FIND_EXACT); } /* * Grab all the skins under this skeleton and group them * under a single Engine. */ while (e != null) { Engine next = e.Next(); if (e.IsClass((uint)SerialID.VX_Skin)) { Skin s = e as Skin; e.Remove(false); // unlink from skeleton s.Skeleton = skeleton; if (skin != null) // more than one skin? { if (clothSim == null) // group them { clothSim = new Engine(); clothSim.Control = Engine.CONTROL_CHILDREN; clothSim.Name = baseName + ".skin"; clothSim.Append(skin); clothSim.Target = clothMesh; } clothSim.Append(s); } skin = e; } e = next; } if (clothSim == null) { clothSim = skin; } clothskel.Remove(true); } if (clothSim == null) { clothSim = (Engine)Scriptor.Find(baseName + ".cloth"); } if (clothSim == null) { clothSim = (Engine)Scriptor.Find(baseName + ".skin"); } if (clothSim == null) { simroot = scene.Engines; if (simroot != null) { clothSim = (Engine)Scriptor.Find(baseName + ".meshanim"); if (clothSim != null) { clothSim.Remove(false); } } } if ((clothMesh == null) && (clothSim != null)) { SharedObj tmp = clothSim.Target; if ((tmp != null) && (typeof(Model).IsAssignableFrom(tmp.GetType()))) { clothMesh = tmp as Model; } } if (clothMesh == null) { clothMesh = (Model)clothRoot.Find(baseName + "." + baseName, Group.FIND_DESCEND | Group.FIND_EXACT); } } catch (Exception) { // do nothing, simulation tree does not have the skeleton } world.ResumeScene(); if (scriptor != null) { LoadAnimations(avatarconfig); } if (clothSim == null) { SharedWorld.LogError("No cloth simulation found for " + baseName); } if (clothMesh == null) { SharedWorld.LogError("No cloth mesh found for " + baseName); } return(clothSim); }