private static void RecursiveCreate(Armature armature, BodyCollisionTree tree, string prefix, List<BodyCollider> result) { foreach (ColliderTemplate collider in armature.Colliders) collider.InsertCollider(tree.GetNode(prefix + armature.Name), result); foreach (Armature child in armature.Children) RecursiveCreate(child, tree, prefix, result); }
/// <summary> /// Match bones with colliders and create primitive nodes. /// </summary> /// <param name="colliderConfiguration">Filename of the collision configuration</param> /// <param name="entity">Entity (model) loaded</param> /// <param name="armaturePrefix">Prefix of the armature name within the model</param> /// <returns>A list of primitive nodes created</returns> public static List<BodyCollider> ParseColliders(string colliderConfiguration, BodyCollisionTree tree, string armaturePrefix) { Armature armature = ColliderCache.GetOrCreate(colliderConfiguration, tree); List<BodyCollider> result = new List<BodyCollider>(); RecursiveCreate(armature, tree, armaturePrefix, result); return result; }
private static Armature GetOrCreate(this Dictionary<string, Armature> cache, string colliderConfiguration, BodyCollisionTree tree) { if (cache.ContainsKey(colliderConfiguration)) return cache[colliderConfiguration]; XElement root = XElement.Load("Assets/Data/Colliders/" + colliderConfiguration); Armature rootArmature = Armature.FromRoot(root, tree); cache.Add(colliderConfiguration, rootArmature); return rootArmature; }
private Armature(XElement element, BodyCollisionTree tree) { Name = element.Attribute("name").Value; var collidersEnumerator = element.Elements("Collider"); Colliders = new ColliderTemplate[collidersEnumerator.Count()]; int i = 0; foreach (XElement colliderElement in collidersEnumerator) Colliders[i++] = CreateColliderTemplate(colliderElement); var childEnumerator = element.Elements("Armature"); Children = new Armature[childEnumerator.Count()]; i = 0; foreach (XElement childElement in childEnumerator) Children[i++] = new Armature(childElement, tree); }
public Character(World world, CharacterConfiguration configuration, string colliderName) : base(world) { this.Configuration = configuration; if (Configuration.EntityNames.Length == 0) throw new ArgumentException("At least one body entity must be provided."); CharacterNode = World.WorldNode.CreateChildSceneNode(); EyeNode = CharacterNode.CreateChildSceneNode(new Vector3(0, 1.7f, 0)); FirstPersonModel = new FirstPersonModel(this, EyeNode); FirstPersonModel.Visible = false; ThirdPersonModel = new ThirdPersonModel(this, CharacterNode, Configuration.EntityNames); BodyCollisionTree = new BodyCollisionTree(ThirdPersonModel.BodyEntities[0], AllLowerBodyAnimations.Concat(AllUpperBodyAnimations)); BodyColliders = ColliderLoader.ParseColliders(colliderName, BodyCollisionTree, "Alpha_").ToArray(); BoundingSphere = new SphereNode(CharacterNode, new Vector3(0, 1, 0), 2); SimpleCollider = new UprightCylinderNode(CharacterNode, Vector3.ZERO, 1.7f, 0.7f); AnimationManagerMapper.Add( AnimationKind.LowerBody, new AnimationManager( AllLowerBodyAnimations, ThirdPersonModel.BodyEntities, "Idle" ) ); AnimationManagerMapper.Add( AnimationKind.UpperBody, new AnimationManager( AllUpperBodyAnimations, ThirdPersonModel.BodyEntities, "Wield_USP" ) ); Camera = World.CreateCamera(Vector3.ZERO, MathHelper.Forward); EyeNode.AttachObject(Camera); ViewFrustum = new FrustumNode(Camera); SpecialMoveHandlers = new SpecialMoveHandler[3]; Reset(); }
public static Armature FromRoot(XElement root, BodyCollisionTree tree) { return new Armature(root.Element("Armature"), tree); }