Esempio n. 1
0
        public EntityModel Convert()
        {
            if (Bones.All(x => x.Cubes == null))
            {
                return(null);
            }

            EntityModel model = new EntityModel();

            model.Name          = Description.Identifier;
            model.Textureheight = Description.TextureHeight;
            model.Texturewidth  = Description.TextureWidth;

            var scale = Vector3.One;

            if (VisibleBoundsHeight.HasValue && VisibleBoundsWidth.HasValue)
            {
                /*  scale.X = 0.0625F * VisibleBoundsWidth.Value;
                 * scale.Z = 0.0625F * VisibleBoundsWidth.Value;
                 *
                 * scale.Y = 0.0625F * VisibleBoundsHeight.Value;*/
            }

            Dictionary <string, EntityModelBone> bones = new Dictionary <string, EntityModelBone>();

            foreach (var bone in Bones)
            {
                if (bone.Cubes == null)
                {
                    continue;
                }

                EntityModelBone newBone;
                if (!bones.TryGetValue(bone.Name, out newBone))
                {
                    newBone = new EntityModelBone();
                    bones.TryAdd(bone.Name, newBone);
                }
                else
                {
                    Log.Warn($"Overwriting bone...");
                }

                newBone.Parent   = bone.Parent;
                newBone.Name     = bone.Name;
                newBone.Pivot    = bone.Pivot;
                newBone.Rotation = new Vector3(bone.Rotation.X, bone.Rotation.Y, bone.Rotation.Z);

                if (bone.Cubes == null)
                {
                    newBone.NeverRender = true;
                }
                else
                {
                    newBone.Cubes = bone.Cubes.Select(x => new EntityModelCube()
                    {
                        Mirror  = x.Mirror,
                        Origin  = x.Origin * scale,
                        Size    = x.Size * scale,
                        Uv      = x.Uv,
                        Inflate = x.Inflate
                    }).ToArray();
                }

                bones[bone.Name] = newBone;
                // newBone.
            }

            model.Bones = bones.Values.ToArray();
            return(model);
        }
 protected override bool SaveCanExecute()
 {
     return(HasChanges && Bones.All(p => !p.HasErrors));
 }