Beispiel #1
0
        void RefreshBoneList(object instance)
        {
            var comp = instance as EngineNS.GamePlay.Component.GComponent;

            if (comp == null)
            {
                return;
            }
            var hostMesh = comp.HostContainer as EngineNS.GamePlay.Component.GMeshComponent;

            if (hostMesh != null)
            {
                var modifier = hostMesh.SceneMesh.MdfQueue.FindModifier <EngineNS.Graphics.Mesh.CGfxSkinModifier>();
                if (modifier != null)
                {
                    var skeleton     = EngineNS.CEngine.Instance.SkeletonAssetManager.GetSkeleton(EngineNS.CEngine.Instance.RenderContext, EngineNS.RName.GetRName(modifier.SkeletonAsset));
                    var skeletonPose = skeleton.CreateSkeletonPose();
                    BoneList.Add("None");
                    for (uint i = 0; i < skeletonPose.BoneNumber; ++i)
                    {
                        BoneList.Add(skeletonPose.GetBonePose(i).ReferenceBone.BoneDesc.Name);
                    }
                }
            }
        }
Beispiel #2
0
        public override void Read(BinaryReader b)
        {
            base.Read(b);
            NumBones = b.ReadInt32();

            for (int i = 0; i < NumBones; i++)
            {
                CompiledBone tempBone = new CompiledBone();
                tempBone.ReadCompiledBone_900(b);

                if (RootBone == null)  // First bone read is root bone
                {
                    RootBone = tempBone;
                }

                BoneList.Add(tempBone);
                BoneDictionary[i] = tempBone;
            }

            List <string> boneNames = GetNullSeparatedStrings(NumBones, b);

            // Post bone read setup.  Parents, children, etc.
            // Add the ChildID to the parent bone.  This will help with navigation. Also set up the TransformSoFar
            for (int i = 0; i < NumBones; i++)
            {
                BoneList[i].boneName = boneNames[i];
                SetParentBone(BoneList[i]);
                AddChildIDToParent(BoneList[i]);
                SetBoneLocalTransformMatrix(BoneList[i]);
            }
        }
Beispiel #3
0
        public override void Read(BinaryReader b)
        {
            base.Read(b);
            this.SkipBytes(b, 32);  // Padding between the chunk header and the first bone.
            Vector3  localTranslation;
            Matrix33 localRotation;

            //  Read the first bone with ReadCompiledBone, then recursively grab all the children for each bone you find.
            //  Each bone structure is 584 bytes, so will need to seek childOffset * 584 each time, and go back.
            NumBones = (int)((this.Size - 32) / 584);
            for (int i = 0; i < NumBones; i++)
            {
                CompiledBone tempBone = new CompiledBone();
                tempBone.ReadCompiledBone(b);
                if (RootBone == null)  // First bone read is root bone
                {
                    this.RootBone = tempBone;
                }

                tempBone.LocalTranslation = tempBone.boneToWorld.GetBoneToWorldTranslationVector();      // World positions of the bone
                tempBone.LocalRotation    = tempBone.boneToWorld.GetBoneToWorldRotationMatrix();         // World rotation of the bone.
                //tempBone.ParentBone = BoneMap[i + tempBone.offsetParent];
                tempBone.ParentBone = GetParentBone(tempBone, i);
                if (tempBone.ParentBone != null)
                {
                    tempBone.parentID = tempBone.ParentBone.ControllerID;
                }
                else
                {
                    tempBone.parentID = 0;
                }

                if (tempBone.parentID != 0)
                {
                    localRotation    = GetParentBone(tempBone, i).boneToWorld.GetBoneToWorldRotationMatrix().ConjugateTransposeThisAndMultiply(tempBone.boneToWorld.GetBoneToWorldRotationMatrix());
                    localTranslation = GetParentBone(tempBone, i).LocalRotation *(tempBone.LocalTranslation - GetParentBone(tempBone, i).boneToWorld.GetBoneToWorldTranslationVector());
                }
                else
                {
                    localTranslation = tempBone.boneToWorld.GetBoneToWorldTranslationVector();
                    localRotation    = tempBone.boneToWorld.GetBoneToWorldRotationMatrix();
                }
                tempBone.LocalTransform = GetTransformFromParts(localTranslation, localRotation);

                BoneList.Add(tempBone);
                BoneDictionary[i] = tempBone;
            }

            // Add the ChildID to the parent bone.  This will help with navigation. Also set up the TransformSoFar
            foreach (CompiledBone bone in BoneList)
            {
                AddChildIDToParent(bone);
            }
            SkinningInfo skin = GetSkinningInfo();

            skin.CompiledBones   = new List <CompiledBone>();
            skin.HasSkinningInfo = true;
            skin.CompiledBones   = BoneList;
        }
Beispiel #4
0
        public void InitializeBone()
        {
            BoneList.Clear();
            PmxBone pmxBone = new PmxBone();

            pmxBone.Name   = "センター";
            pmxBone.NameE  = "center";
            pmxBone.Parent = -1;
            pmxBone.SetFlag(PmxBone.BoneFlags.Translation, val: true);
            BoneList.Add(pmxBone);
        }
Beispiel #5
0
        public CurtainFireModel(World world)
        {
            World = world;

            PmxBoneData centerBone = new PmxBoneData()
            {
                BoneName = "センター",
                ParentId = -1,
                Flag     = 0x0002 | 0x0004 | 0x0008 | 0x0010
            };

            BoneList.Add(centerBone);
        }
        public ModelBoneCollection(World world)
        {
            World = world;

            PmxBoneData centerBone = new PmxBoneData()
            {
                BoneName = "センター",
                ParentId = -1,
                Flag     = BoneFlags.ROTATE | BoneFlags.MOVE | BoneFlags.VISIBLE | BoneFlags.OP,
            };

            BoneList.Add(centerBone);
        }
Beispiel #7
0
        public void SetupBone(params PmxBoneData[] bones)
        {
            foreach (var bone in bones)
            {
                bone.BoneName = "B" + (BoneList.Count - 1);
                bone.BoneId   = BoneList.Count;
                bone.Flag     = BoneFlags.ROTATE | BoneFlags.MOVE | BoneFlags.OP;

                if (-1 < bone.ParentId && bone.ParentId < bones.Length - 1)
                {
                    bone.ParentId = bones[bone.ParentId].BoneId;
                }
                else
                {
                    bone.ParentId = 0;
                }
                BoneList.Add(bone);
            }
        }
Beispiel #8
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);
            }
        }
        public void SetupBone(ShotModelData data, params PmxBoneData[] bones)
        {
            for (int i = 0; i < bones.Length; i++)
            {
                PmxBoneData bone = bones[i];

                bone.BoneName = $"B_{(BoneList.Count - 1).ToString()}";
                bone.Flag     = BoneFlags.ROTATE | BoneFlags.MOVE | BoneFlags.OP;
                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 #10
0
        protected override void Parse(Stream s)
        {
            BinaryReader br  = new BinaryReader(s);
            string       tag = FOURCC(br.ReadUInt32());

            if (tag != Tag)
            {
                throw new InvalidDataException(string.Format("Invalid Tag read: '{0}'; expected: '{1}'; at 0x{1:X8}", tag, Tag, s.Position));
            }
            mVersion = br.ReadUInt32();
            mBones   = new BoneList(handler);
            int count = br.ReadInt32();

            uint[] names = new uint[count];
            for (int i = 0; i < count; i++)
            {
                names[i] = br.ReadUInt32();
            }
            for (int i = 0; i < count; i++)
            {
                mBones.Add(new Bone(handler, names[i], new Matrix43(handler, s)));
            }
        }
Beispiel #11
0
        public virtual void FromStream(Stream s, bool id)
        {
            Action <Action> action = delegate(Action a)
            {
                try
                {
                    a();
                }
                catch (Exception)
                {
                    LoadErrCount++;
                }
            };
            PmxHeader head = new PmxHeader();

            head.FromStreamEx(s);
            Header.FromHeader(head);
            head.ElementFormat.WithID = id;
            action(delegate
            {
                ModelInfo.FromStreamEx(s, head.ElementFormat);
            });
            int count = 0;

            action(delegate
            {
                count = PmxStreamHelper.ReadElement_Int32(s);
            });
            VertexList.Clear();
            VertexList.Capacity = count;
            for (int k = 0; k < count; k++)
            {
                PmxVertex v = new PmxVertex();
                action(delegate
                {
                    v.FromStreamEx(s, head.ElementFormat);
                });
                VertexList.Add(v);
            }
            action(delegate
            {
                count = PmxStreamHelper.ReadElement_Int32(s);
            });
            FaceList.Clear();
            FaceList.Capacity = count;
            for (int l = 0; l < count; l++)
            {
                int ix = 0;
                action(delegate
                {
                    ix = PmxStreamHelper.ReadElement_Int32(s, head.ElementFormat.VertexSize, signed: false);
                });
                FaceList.Add(ix);
            }
            PmxTextureTable tx = new PmxTextureTable();

            action(delegate
            {
                tx.FromStreamEx(s, head.ElementFormat);
            });
            action(delegate
            {
                count = PmxStreamHelper.ReadElement_Int32(s);
            });
            MaterialList.Clear();
            MaterialList.Capacity = count;
            for (int m = 0; m < count; m++)
            {
                PmxMaterial j = new PmxMaterial();
                action(delegate
                {
                    j.FromStreamEx_TexTable(s, tx, head.ElementFormat);
                });
                MaterialList.Add(j);
            }
            action(delegate
            {
                count = PmxStreamHelper.ReadElement_Int32(s);
            });
            BoneList.Clear();
            BoneList.Capacity = count;
            for (int n = 0; n < count; n++)
            {
                PmxBone b = new PmxBone();
                action(delegate
                {
                    b.FromStreamEx(s, head.ElementFormat);
                });
                BoneList.Add(b);
            }
            action(delegate
            {
                count = PmxStreamHelper.ReadElement_Int32(s);
            });
            MorphList.Clear();
            MorphList.Capacity = count;
            for (int num = 0; num < count; num++)
            {
                PmxMorph morph = new PmxMorph();
                action(delegate
                {
                    morph.FromStreamEx(s, head.ElementFormat);
                });
                MorphList.Add(morph);
            }
            action(delegate
            {
                count = PmxStreamHelper.ReadElement_Int32(s);
            });
            NodeList.Clear();
            NodeList.Capacity = count;
            for (int num2 = 0; num2 < count; num2++)
            {
                PmxNode node = new PmxNode();
                action(delegate
                {
                    node.FromStreamEx(s, head.ElementFormat);
                });
                NodeList.Add(node);
                if (NodeList[num2].SystemNode)
                {
                    if (NodeList[num2].Name == "Root")
                    {
                        RootNode = NodeList[num2];
                    }
                    else if (NodeList[num2].Name == "表情")
                    {
                        ExpNode = NodeList[num2];
                    }
                }
            }
            action(delegate
            {
                count = PmxStreamHelper.ReadElement_Int32(s);
            });
            BodyList.Clear();
            BodyList.Capacity = count;
            for (int num3 = 0; num3 < count; num3++)
            {
                PmxBody b2 = new PmxBody();
                action(delegate
                {
                    b2.FromStreamEx(s, head.ElementFormat);
                });
                BodyList.Add(b2);
            }
            action(delegate
            {
                count = PmxStreamHelper.ReadElement_Int32(s);
            });
            JointList.Clear();
            JointList.Capacity = count;
            for (int num4 = 0; num4 < count; num4++)
            {
                PmxJoint i = new PmxJoint();
                action(delegate
                {
                    i.FromStreamEx(s, head.ElementFormat);
                });
                JointList.Add(i);
            }
            if (head.Ver >= 2.1f)
            {
                action(delegate
                {
                    count = PmxStreamHelper.ReadElement_Int32(s);
                });
                SoftBodyList.Clear();
                SoftBodyList.Capacity = count;
                for (int num5 = 0; num5 < count; num5++)
                {
                    PmxSoftBody b3 = new PmxSoftBody();
                    action(delegate
                    {
                        b3.FromStreamEx(s, head.ElementFormat);
                    });
                    SoftBodyList.Add(b3);
                }
            }
            if (id)
            {
                action(delegate
                {
                    FilePath = PmxStreamHelper.ReadString(s, head.ElementFormat);
                });
            }
            head.ElementFormat.WithID = false;
        }
Beispiel #12
0
        public void FromPmx(Pmx pmx)
        {
            Clear();
            FilePath     = pmx.FilePath;
            LoadErrCount = pmx.LoadErrCount;
            Header       = pmx.Header.Clone();
            ModelInfo    = pmx.ModelInfo.Clone();
            int count = pmx.VertexList.Count;

            VertexList.Capacity = count;
            for (int i = 0; i < count; i++)
            {
                VertexList.Add(pmx.VertexList[i].Clone());
            }
            count             = pmx.FaceList.Count;
            FaceList.Capacity = count;
            for (int j = 0; j < count; j++)
            {
                FaceList.Add(pmx.FaceList[j]);
            }
            count = pmx.MaterialList.Count;
            MaterialList.Capacity = count;
            for (int k = 0; k < count; k++)
            {
                MaterialList.Add(pmx.MaterialList[k].Clone());
            }
            count             = pmx.BoneList.Count;
            BoneList.Capacity = count;
            for (int l = 0; l < count; l++)
            {
                BoneList.Add(pmx.BoneList[l].Clone());
            }
            count = pmx.MorphList.Count;
            MorphList.Capacity = count;
            for (int m = 0; m < count; m++)
            {
                MorphList.Add(pmx.MorphList[m].Clone());
            }
            count = pmx.NodeList.Count;
            NodeList.Clear();
            NodeList.Capacity = count;
            for (int n = 0; n < count; n++)
            {
                NodeList.Add(pmx.NodeList[n].Clone());
                if (NodeList[n].SystemNode)
                {
                    if (NodeList[n].Name == "Root")
                    {
                        RootNode = NodeList[n];
                    }
                    else if (NodeList[n].Name == "表情")
                    {
                        ExpNode = NodeList[n];
                    }
                }
            }
            count             = pmx.BodyList.Count;
            BodyList.Capacity = count;
            for (int num = 0; num < count; num++)
            {
                BodyList.Add(pmx.BodyList[num].Clone());
            }
            count = pmx.JointList.Count;
            JointList.Capacity = count;
            for (int num2 = 0; num2 < count; num2++)
            {
                JointList.Add(pmx.JointList[num2].Clone());
            }
            count = pmx.SoftBodyList.Count;
            SoftBodyList.Capacity = count;
            for (int num3 = 0; num3 < count; num3++)
            {
                SoftBodyList.Add(pmx.SoftBodyList[num3].Clone());
            }
        }
Beispiel #13
0
        private void IconTextBtn_SubmenuOpened(object sender, RoutedEventArgs e)
        {
            BoneList.Clear();
            var enumrableInterface = BindInstance.GetType().GetInterface(typeof(System.Collections.IEnumerable).FullName, false);

            if (enumrableInterface != null)
            {
                // 显示多个对象
                int count = 0;
                foreach (var objIns in (System.Collections.IEnumerable)BindInstance)
                {
                    if (objIns == null)
                    {
                        continue;
                    }
                    count++;
                }
                if (count == 0)
                {
                }
                else if (count == 1)
                {
                    foreach (var objIns in (System.Collections.IEnumerable)BindInstance)
                    {
                        if (objIns == null)
                        {
                            continue;
                        }
                        RefreshBoneList(objIns);
                    }
                }
                else
                {
                    string skeletonName     = null;
                    bool   haveSameSkeleton = true;
                    foreach (var objIns in (System.Collections.IEnumerable)BindInstance)
                    {
                        if (objIns == null)
                        {
                            continue;
                        }
                        var comp = objIns as EngineNS.GamePlay.Component.GComponent;
                        if (comp == null)
                        {
                            continue;
                        }
                        var hostMesh = comp.HostContainer as EngineNS.GamePlay.Component.GMeshComponent;
                        if (hostMesh != null)
                        {
                            var modifier = hostMesh.SceneMesh.MdfQueue.FindModifier <EngineNS.Graphics.Mesh.CGfxSkinModifier>();
                            if (modifier != null)
                            {
                                if (skeletonName == null)
                                {
                                    skeletonName = modifier.SkeletonAsset;
                                }
                                if (skeletonName != modifier.SkeletonAsset)
                                {
                                    haveSameSkeleton = false;
                                    return;
                                }
                            }
                        }
                    }
                    if (haveSameSkeleton && !string.IsNullOrEmpty(skeletonName))
                    {
                        var skeleton     = EngineNS.CEngine.Instance.SkeletonAssetManager.GetSkeleton(EngineNS.CEngine.Instance.RenderContext, EngineNS.RName.GetRName(skeletonName));
                        var skeletonPose = skeleton.CreateSkeletonPose();
                        BoneList.Add("None");
                        for (uint i = 0; i < skeletonPose.BoneNumber; ++i)
                        {
                            BoneList.Add(skeletonPose.GetBonePose(i).ReferenceBone.BoneDesc.Name);
                        }
                    }
                }
            }
            else
            {
                RefreshBoneList(BindInstance);
            }
            SearchBoxCtrl.FocusInput();
        }