Beispiel #1
0
        public void AddEntity(EntityShotBase entity, out ShotModelData data)
        {
            if (!IsUpdated)
            {
                Update();
            }

            int hash = GetPropertyHashCode(entity.Property, entity.Parent);

            ShotGroup group = null;

            if (ReusableGroupDict.ContainsKey(hash))
            {
                var groupList = ReusableGroupDict[hash];

                group = groupList.FirstOrDefault();

                if (groupList.Count == 1)
                {
                    ReusableGroupDict.Remove(hash);
                }
                else
                {
                    groupList.RemoveAt(0);
                }
            }
            group = group ?? new ShotGroup(entity);

            group.SetEntity(entity);
            data = group.Data;

            GroupList.Add(group);
        }
        public ShotGroup(EntityShot entity, World world)
        {
            ParentEntity = entity.ParentEntity;
            Property     = entity.Property;
            World        = world;

            Data = new ShotModelData(World, Property);
        }
Beispiel #3
0
 public override bool Spawn()
 {
     if (base.Spawn())
     {
         ModelData = World.AddShot(this);
         Property.Type.InitEntity(this);
         RootBone.ParentId = Parent is EntityShotBase entity ? entity.RootBone.BoneId : RootBone.ParentId;
         return(true);
     }
     return(false);
 }
Beispiel #4
0
 public void InitShotModelData(ShotModelData data)
 {
     if (data.Property.Type.HasMmdData)
     {
         SetupShotModelData(data);
     }
     else
     {
         SetupBone(data, data.Bones[0]);
     }
 }
Beispiel #5
0
        public void InitShotModelData(ShotModelData data)
        {
            if (data.Property.Type.HasMesh)
            {
                data.BoneIndexOffset = Bones.BoneList.Count;
                ModelDataEachPropertyDict[data.Property].Add(data);
            }
            Bones.SetupBone(data.Bones);

            data.IsInitialized = true;
        }
        public ShotModelData AddEntity(EntityShot entity)
        {
            if (!TypeGroupDict.ContainsKey(entity.Property.Type))
            {
                TypeGroupDict[entity.Property.Type] = new ShotTypeGroup(entity.Property.Type, World);
            }

            ShotTypeGroup typeGroup = TypeGroupDict[entity.Property.Type];

            ShotModelData data = typeGroup.AddEntityToGroup(entity);

            if (data == null)
            {
                data = typeGroup.CreateGroup(entity);
                World.PmxModel.InitShotModelData(data);
            }

            return(data);
        }
Beispiel #7
0
        private void SetupBone(ShotModelData data, params PmxBoneData[] bones)
        {
            for (int i = 0; i < bones.Length; i++)
            {
                PmxBoneData bone = bones[i];

                bone.BoneName = data.Property.Type.Name[0] + (BoneList.Count - 1).ToString();
                bone.Flag     = 0x0002 | 0x0004 | 0x0010;
                bone.BoneId   = BoneList.Count + i;

                if (-1 < bone.ParentId && bone.ParentId < bones.Length)
                {
                    bone.ParentId = BoneList.IndexOf(bones[bone.ParentId]);
                }
                else
                {
                    bone.ParentId = 0;
                }
                BoneList.Add(bone);
            }
        }
Beispiel #8
0
        private void SetupShotModelData(ShotModelData data)
        {
            int[] indices = Array.ConvertAll(data.Indices, i => i + VertexList.Count);
            IndexList.AddRange(indices);

            PmxVertexData[] vertices = data.Vertices;
            foreach (var vertex in vertices)
            {
                vertex.VertexId = VertexList.Count;
                vertex.BoneId   = Array.ConvertAll(vertex.BoneId, i => i + BoneList.Count);
                VertexList.Add(vertex);
            }

            PmxMaterialData[] materials = data.Materials;
            PmxMorphData      morph     = data.MaterialMorph;

            morph.MorphName  = data.Property.Type.Name[0] + MorphList.Count.ToString();
            morph.Type       = 4;
            morph.MorphArray = ArrayUtil.Set(new PmxMorphMaterialData[materials.Length], i => new PmxMorphMaterialData());

            for (int i = 0; i < materials.Length; i++)
            {
                morph.MorphArray[i].Index = MaterialList.Count + i;
                morph.MorphId             = MorphList.Count + i;
            }
            MorphList.Add(morph);

            string[] textures = data.Textures;
            foreach (var texture in textures)
            {
                if (!TextureList.Contains(texture))
                {
                    TextureList.Add(texture);
                }
            }

            foreach (PmxMaterialData material in materials)
            {
                material.MaterialName = data.Property.Type.Name[0] + MaterialList.Count.ToString();

                if (0 <= material.TextureId && material.TextureId < textures.Length)
                {
                    material.TextureId = TextureList.IndexOf(textures[material.TextureId]);
                }
                else
                {
                    material.TextureId = -1;
                }

                if (0 <= material.SphereId && material.SphereId < textures.Length)
                {
                    material.SphereId = TextureList.IndexOf(textures[material.SphereId]);
                }
                else
                {
                    material.SphereId = -1;
                }
                material.MaterialId = MaterialList.Count;
                MaterialList.Add(material);
            }
            SetupBone(data, data.Bones);

            ModelDataList.Add(data);
        }
Beispiel #9
0
 public ShotGroup(EntityShotBase entity)
 {
     Data         = new ShotModelData(entity.World, entity.Property);
     ParentEntity = entity.Parent;
 }