/// <summary> /// Sets this avatar's head outfit. /// </summary> public void SetHead(Outfit HeadOutfit, SkinType Type) { Appearance Apr; switch (Type) { case SkinType.Light: Apr = FileManager.GetAppearance(HeadOutfit.LightAppearance.UniqueID); break; case SkinType.Medium: Apr = FileManager.GetAppearance(HeadOutfit.MediumAppearance.UniqueID); break; case SkinType.Dark: Apr = FileManager.GetAppearance(HeadOutfit.DarkAppearance.UniqueID); break; default: Apr = FileManager.GetAppearance(HeadOutfit.LightAppearance.UniqueID); break; } AccessoryMesh = null; AccessoryTexture = null; //I think that heads are always 0... Binding Bnd = FileManager.GetBinding(Apr.BindingIDs[0].UniqueID); HeadMesh = FileManager.GetMesh(Bnd.MeshID.UniqueID); HeadTexture = FileManager.GetTexture(Bnd.TextureID.UniqueID); if(Apr.BindingIDs.Count > 1) //This head has accessories. Bnd = FileManager.GetBinding(Apr.BindingIDs[1].UniqueID); }
/// <summary> /// Transforms all vertices in a given mesh to their correct positions. /// </summary> /// <param name="Msh">The mesh to transform.</param> /// <param name="bone">The bone to transform to.</param> private void TransformVertices(Mesh Msh, Bone bone, MeshType MshType) { switch (MshType) { case MeshType.Head: for (int i = 0; i < Msh.TotalVertexCount; i++) { //Transform the head vertices' position by the absolute transform //for the headbone (which is always bone 17) to render the head in place. Msh.TransformedVertices[i].Position = Vector3.Transform(Msh.RealVertices[i].Position, Skel.Bones[16].AbsoluteMatrix); Msh.TransformedVertices[i].TextureCoordinate = Msh.RealVertices[i].TextureCoordinate; //Transform the head normals' position by the absolute transform //for the headbone (which is always bone 17) to render the head in place. Msh.TransformedVertices[i].Normal = Vector3.Transform(Msh.RealVertices[i].Normal, Skel.Bones[16].AbsoluteMatrix); } return; case MeshType.Body: BoneBinding boneBinding = Msh.BoneBindings.FirstOrDefault(x => Msh.Bones[(int)x.BoneIndex] == bone.Name); if (boneBinding != null) { for (int i = 0; i < boneBinding.RealVertexCount; i++) { int vertexIndex = (int)boneBinding.FirstRealVertexIndex + i; VertexPositionNormalTexture relativeVertex = Msh.RealVertices[vertexIndex]; Matrix translatedMatrix = Matrix.CreateTranslation(new Vector3(relativeVertex.Position.X, relativeVertex.Position.Y, relativeVertex.Position.Z)) * bone.AbsoluteMatrix; Msh.TransformedVertices[vertexIndex].Position = Vector3.Transform(Vector3.Zero, translatedMatrix); Msh.TransformedVertices[vertexIndex].TextureCoordinate = relativeVertex.TextureCoordinate; //Normals... translatedMatrix = Matrix.CreateTranslation(new Vector3(relativeVertex.Normal.X, relativeVertex.Normal.Y, relativeVertex.Normal.Z)) * bone.AbsoluteMatrix; Msh.TransformedVertices[vertexIndex].Normal = Vector3.Transform(Vector3.Zero, translatedMatrix); } } foreach (var child in bone.Children) TransformVertices(Msh, child, MshType); break; case MeshType.LHand: for (int i = 0; i < Msh.TotalVertexCount; i++) { //Transform the left hand vertices' position by the absolute transform //for the left handbone (which is always bone 10) to render the left hand in place. Msh.TransformedVertices[i].Position = Vector3.Transform(Msh.RealVertices[i].Position, Skel.Bones[9].AbsoluteMatrix); //Transform the left hand normals' position by the absolute transform //for the left handbone (which is always bone 10) to render the left hand in place. Msh.TransformedVertices[i].Normal = Vector3.Transform(Msh.RealVertices[i].Normal, Skel.Bones[9].AbsoluteMatrix); } return; case MeshType.RHand: for (int i = 0; i < Msh.TotalVertexCount; i++) { //Transform the right hand vertices' position by the absolute transform //for the right handbone (which is always bone 15) to render the right hand in place. Msh.TransformedVertices[i].Position = Vector3.Transform(Msh.RealVertices[i].Position, Skel.Bones[14].AbsoluteMatrix); //Transform the right hand normals' position by the absolute transform //for the right handbone (which is always bone 15) to render the right hand in place. Msh.TransformedVertices[i].Normal = Vector3.Transform(Msh.RealVertices[i].Normal, Skel.Bones[14].AbsoluteMatrix); } return; } }
/// <summary> /// Changes this avatar's outfit. /// </summary> public void ChangeOutfit(Outfit Oft, SkinType Type) { Binding[] Bindings; AccessoryMesh = null; AccessoryTexture = null; if (Oft.HandgroupID.FileID != 0) { HandGroup Hag = FileManager.GetHandgroup(Oft.HandgroupID.UniqueID); Appearance LeftHandApr, RightHandApr; switch (Type) { case SkinType.Light: LeftHandApr = FileManager.GetAppearance(Hag.Light.Left.Idle.AppearanceID.UniqueID); RightHandApr = FileManager.GetAppearance(Hag.Light.Right.Idle.AppearanceID.UniqueID); break; case SkinType.Medium: LeftHandApr = FileManager.GetAppearance(Hag.Medium.Left.Idle.AppearanceID.UniqueID); RightHandApr = FileManager.GetAppearance(Hag.Medium.Right.Idle.AppearanceID.UniqueID); break; case SkinType.Dark: LeftHandApr = FileManager.GetAppearance(Hag.Dark.Left.Idle.AppearanceID.UniqueID); RightHandApr = FileManager.GetAppearance(Hag.Dark.Right.Idle.AppearanceID.UniqueID); break; default: LeftHandApr = FileManager.GetAppearance(Hag.Light.Left.Idle.AppearanceID.UniqueID); RightHandApr = FileManager.GetAppearance(Hag.Light.Right.Idle.AppearanceID.UniqueID); break; } Bindings = FileManager.GetBindings(LeftHandApr.BindingIDs); foreach (Binding Bnd in Bindings) { switch (Bnd.Bone) { case "L_HAND": LeftHandMesh = FileManager.GetMesh(Bnd.MeshID.UniqueID); LeftHandTexture = FileManager.GetTexture(Bnd.TextureID.UniqueID); break; } } Bindings = FileManager.GetBindings(RightHandApr.BindingIDs); foreach (Binding Bnd in Bindings) { switch (Bnd.Bone) { case "R_HAND": RightHandMesh = FileManager.GetMesh(Bnd.MeshID.UniqueID); RightHandTexture = FileManager.GetTexture(Bnd.TextureID.UniqueID); break; } } } Appearance Apr; switch (Type) { case SkinType.Light: Apr = FileManager.GetAppearance(Oft.LightAppearance.UniqueID); break; case SkinType.Medium: Apr = FileManager.GetAppearance(Oft.MediumAppearance.UniqueID); break; case SkinType.Dark: Apr = FileManager.GetAppearance(Oft.DarkAppearance.UniqueID); break; default: Apr = FileManager.GetAppearance(Oft.LightAppearance.UniqueID); break; } Bindings = FileManager.GetBindings(Apr.BindingIDs); if(Oft.Region == OutfitRegion.Head) HeadMesh = null; //IMPORTANT: Reset the head mesh before loading a new one. foreach (Binding Bnd in Bindings) { switch (Bnd.Bone) { case "PELVIS": BodyMesh = FileManager.GetMesh(Bnd.MeshID.UniqueID); BodyTexture = FileManager.GetTexture(Bnd.TextureID.UniqueID); break; case "HEAD": if (HeadMesh == null) { HeadMesh = FileManager.GetMesh(Bnd.MeshID.UniqueID); HeadTexture = FileManager.GetTexture(Bnd.TextureID.UniqueID); } else { AccessoryMesh = FileManager.GetMesh(Bnd.MeshID.UniqueID); AccessoryTexture = FileManager.GetTexture(Bnd.TextureID.UniqueID); } break; } } }