/* * Event.LOADSCENE handler - comes here when 3D scene loaded. * If a user interface scene is loaded (name contains "ui_") * bind the UI scene to the Selector for picking outfits. */ public override void OnSceneLoad(SharedWorld world, Scene scene, String scenefile) { System.String name = scene.Name.ToLower(); if (name.Contains("ui_")) { Model iconRoot = uiRoot.Find(".selectable", Group.FIND_DESCEND | Group.FIND_END) as Model; SharedWorld.Trace("Loaded " + name); if (iconRoot != null) { RaiseSceneLoadEvent(name, scenefile); if (outfitSelector != null) { outfitSelector.SetTarget(iconRoot); } return; } } base.OnSceneLoad(world, scene, scenefile); }
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 Skeleton ConnectBody(Engine simroot) { if (simroot == null) { return(null); } try { string filebase = Path.GetFileNameWithoutExtension(filename).ToLower() + "."; animSkel = (Skeleton)simroot.Find(filebase + animRig + ".skeleton", Group.FIND_DESCEND | Group.FIND_EXACT); if (usehavok) { Physics physroot = Physics.Get(); Engine skelmapper; BodyPoser = (Skeleton)simroot.Find(filebase + havokRig + ".skeleton", Group.FIND_DESCEND | Group.FIND_EXACT); if ((PhysicsOptions != null)) { if (PhysicsOptions.Contains("ynamic")) { physicsOpts |= RagDoll.DYNAMIC; } if (PhysicsOptions.Contains("ower")) { physicsOpts |= RagDoll.POWERED; } BodyPoser.SetBoneOptions(0, Skeleton.BONE_ANIMATE); } else { if (BodyPoser.GetBoneName(0).StartsWith("Proxy")) { BodyPoser.SetBoneOptions(BodyPoser.GetBoneIndex("Proxy_RightWrist"), Skeleton.BONE_LOCK_ROTATION); BodyPoser.SetBoneOptions(BodyPoser.GetBoneIndex("Proxy_RightAnkle"), Skeleton.BONE_LOCK_ROTATION); BodyPoser.SetBoneOptions(BodyPoser.GetBoneIndex("Proxy_LeftWrist"), Skeleton.BONE_LOCK_ROTATION); BodyPoser.SetBoneOptions(BodyPoser.GetBoneIndex("Proxy_LeftAnkle"), Skeleton.BONE_LOCK_ROTATION); } } BodyPoser.Control |= physicsOpts; BodyPoser.Active = false; skelmapper = (Engine)BodyPoser.Find(".mapper", Group.FIND_END | Group.FIND_CHILD); if (skelmapper != null) { skelmapper.Active = true; } if (physroot != null) { bodySim = (Engine)physroot.Find(filebase + "cloth", Group.FIND_DESCEND | Group.FIND_EXACT); } if (bodySim == null) { bodySim = (Engine)physroot.Find(".skin", Group.FIND_DESCEND | Group.FIND_END); } if (physicsOpts != 0) { physroot.Active = true; } bodySkeleton = (Model)bodyModel.Find(havokRig, Group.FIND_DESCEND | Group.FIND_END); if (bodySkeleton != null) { bodySkeleton.Active = false; RightHand = (Model)bodySkeleton.Find("RightWrist", Group.FIND_DESCEND | Group.FIND_END); LeftHand = (Model)bodySkeleton.Find("LeftWrist", Group.FIND_DESCEND | Group.FIND_END); Head = (Model)bodySkeleton.Find("Head", Group.FIND_DESCEND | Group.FIND_END); } } else { bodySim = (Engine)simroot.Find(".skin", Group.FIND_DESCEND | Group.FIND_END); BodyPoser = animSkel; } Show(); } catch (Exception) { // do nothing, simulation tree does not have SCAPESkin and BodyPoser } return(BodyPoser); }
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); }