/// <summary> /// Runs all requirements and returns the event index of the code to be executed. /// </summary> /// <returns></returns> public int Run() { int index = 0; foreach (List <RequirementInfo> list in _requirements) { bool failed = false; foreach (RequirementInfo req in list) { bool isTrue = Scriptor.ApplyRequirement(req); if (!isTrue) { failed = true; break; } } if (!failed) { return(_reqIndices[index]); } index++; } if (_elseIndex >= 0) { return(_elseIndex); } return(_endIndex); }
protected virtual Engine MakeEngines() { simRoot = new Engine(); simRoot.Name = "magicmirror.simroot"; physics = new Physics(); physics.Name = "magicmirrot.physics"; physics.Active = false; simRoot.Append(physics); scriptor = new Scriptor(); scriptor.Name = "magicmirror.scriptor"; simRoot.Append(scriptor); cameraController = new Transformer(); cameraController.Name = "magicmirror.camera.xform"; simRoot.Append(cameraController); if (!SuppressNavigation) { navigator = new Flyer(); if (typeof(Flyer).IsAssignableFrom(navigator.GetType())) { navigator.DegreesOfFreedom = Flyer.Y_ROT | Flyer.X_TRANS | Flyer.Y_TRANS | Flyer.Z_TRANS; navigator.Speed = 15.0f; } else { navigator.Speed = 0.1f; navigator.TurnSpeed *= 0.05f; } navigator.Name = "magicmirror.navigator"; navigator.SetFlags((uint)SharedObj.DOEVENTS); cameraController.Append(navigator); } return(simRoot); }
public bool Evaluate() { foreach (RequirementInfo i in _requirements) { if (!Scriptor.ApplyRequirement(i)) { return(false); } } return(true); }
public Garment(dynamic src, Model root, Skeleton skel, Scriptor scp) : base(new Dictionary <string, object>() { { "name", src.name }, { "filename", src.filename }, { "iconfile", src.iconfile }, { "script", src.script }, { "animation", src.animation } }) { closetRoot = root; skeleton = skel; scriptor = scp; clothRoot = new ExtModel(); clothRoot.Options |= ExtModel.REMOVE; clothRoot.Active = false; root.Append(clothRoot); }
/*! * @param url URL to 3D animation file to load. * Load a 3D animation content file (BVH or Vixen format) * and apply it to the current skeleton. * * @see PlayAnimation PauseAnimation */ public void LoadAnimation(string url) { Viewer3D viewer = Viewer as Viewer3D; Scriptor scriptor = AnimScriptor; String ext = url.Substring(url.LastIndexOf('.')).ToLower(); string skelname = ConnectSkeleton(); AnimScriptor.Directory = Path.GetDirectoryName(url); AnimScriptor.Target = _skeleton; if (ext == ".scp") { scriptor.LoadScript(url); } else { _animName = Path.GetFileNameWithoutExtension(url) + skelname; scriptor.Load(url, skelname, Animator.AUTO_PLAY, _skeleton); } }
/*! * Pauses the currently playing animation. * * @see LoadAnimation PlayAnimation */ public void PauseAnimation(string name) { try { Viewer3D viewer = Viewer as Viewer3D; string skelname = ConnectSkeleton(); Scriptor scp = AnimScriptor; if (skelname != null) { if (name != null) { scp.End(name + skelname); } else { scp.End(_animName); } } } catch (Exception ex) { SharedWorld.LogError("PauseAnimation EXCEPTION " + ex.Message); } }
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 Script() { _forceBuild = false; _scriptor = new Scriptor(this); }
public Script(ArticleNode article) { _forceBuild = false; _scriptor = new Scriptor(this); }
protected virtual Skeleton ConnectAvatar(SharedWorld world, Scene scene) { Skeleton skeleton = null; Scene displayScene = world.GetScene(); try { if (currentAvatar.IsActive) { return(currentAvatar.BodyPoser); } if (currentAvatar.IsHavokFile) { skeleton = currentAvatar.ConnectBody(physics); } else { skeleton = currentAvatar.ConnectBody(scene.Engines); skeleton.Remove(false); physics.Append(skeleton); } world.Observe(Event.LOAD_SCENE, skeleton); if (skeleton != null) { if (scriptor != null) { scriptor.Directory = config.mediadir; scriptor.Target = currentAvatar.AnimSkeleton; if (!currentAvatar.AnimSkeleton.Name.Contains("amy")) { currentAvatar.AnimSkeleton.GetBone(0).SetOptions(Transformer.RELATIVE); } if (config.script != null) { scriptor.LoadScript(config.script); } currentAvatar.IsActive = true; if (config.animation != null) { dynamic animinfo = config.animation; if (animinfo.scale != null) { string s = animinfo.scale; double d = Double.Parse(s); if (d > 0) { Scriptor.SetAnimationScale((float)d); } } } } } else { return(null); } } catch (Exception) { // do nothing for now } return(skeleton); }
/*! * 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); }
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); }
public Script() { _build = false; _scriptor = new Scriptor(this); }