/*! * @param ev Vixen event to handle. * @param world current world * Handles vixen events - content loading and animation. * This function also calls event handlers for AvatarEvents. */ protected override void OnVixen(VixenEventArgs vargs) { Event ev = vargs.VixEvent; int code = ev.Code; if (code == Event.STOP) { if (StopEvent != null) { StopEvent(ev.Sender.Name); } } else if (code == Event.LOAD_SCENE) { try { LoadSceneEvent le = ev as LoadSceneEvent; String fname = le.FileName; SharedObj obj = le.Object; if (obj != null) { string name = obj.Name; int p = name.IndexOf('.'); if (p > 0) { name = name.Substring(0, p); } if (obj.IsClass((uint)SerialID.VX_Scene)) { Scene scene = obj as Scene; OnSceneLoad(scene, fname); if (LoadSceneEvent != null) { LoadSceneEvent(name, fname); } } else if (obj.IsClass((uint)SerialID.VX_Skeleton)) { if (LoadAnimEvent != null) { LoadAnimEvent(name, fname); } } } } catch (Exception) { } } else if (code == Event.SCENE_CHANGE) { try { SceneEvent se = ev as SceneEvent; if (SetSceneEvent != null) { string name = se.Target.Name; int p = name.IndexOf('.'); if (p > 0) { name = name.Substring(0, p); } SetSceneEvent(name); } } catch (Exception) { } } }
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); }