Exemple #1
0
        /// <summary>
        /// This Method is called when the Imported Data should be written to the
        /// passed Gmdc File
        /// </summary>
        /// <param name="grps">The imported Groups</param>
        /// <param name="bns">The imported Joints</param>
        /// <remarks>
        /// Override This Method if you want a diffrent Behaviour when writing the Data
        /// to the Gmdc. Override AddGroup(), ReplaceGroup() or RenameGroup() if you just
        /// want to alter a specific Behaviuour.
        /// </remarks>
        protected virtual void ChangeGmdc(ImportedGroups grps, ImportedBones bns)
        {
            //remove all existing Groups and Elements
            if (this.Options.CleanGroups)
            {
                for (int i = Gmdc.Groups.Length - 1; i >= 0; i--)
                {
                    Gmdc.RemoveGroup(i);
                }
            }

            //Add the Joints
            Hashtable boneIndexMap = new Hashtable();

            for (int i = 0; i < bns.Length; i++)
            {
                ImportedBone b = bns[i];
                if (b.Action == GmdcImporterAction.Add)
                {
                    boneIndexMap[i] = AddBone(grps, bns, b, i);
                }
                else if (b.Action == GmdcImporterAction.Rename)
                {
                    boneIndexMap[i] = AddBone(grps, bns, b, i);
                }
                else if (b.Action == GmdcImporterAction.Replace)
                {
                    boneIndexMap[i] = ReplaceBone(grps, bns, b, i);
                }
                else if (b.Action == GmdcImporterAction.Update)
                {
                    boneIndexMap[i] = UpdateBone(grps, b, i);
                }
                else
                {
                    boneIndexMap[i] = NothingBone(grps, b, i);
                }

                //make sure the Target Index is set correct, and the parrent is set up
                b.TargetIndex = (int)boneIndexMap[i];
                b.Bone.Parent = Gmdc;
            }

            //Update the Bone Indices
            foreach (ImportedGroup g in grps)
            {
                for (int i = 0; i < g.Group.UsedJoints.Length; i++)
                {
                    int index = g.Group.UsedJoints[i];
                    if (boneIndexMap.ContainsKey(index))
                    {
                        g.Group.UsedJoints[i] = (int)boneIndexMap[index];
                    }
                }
            }

            bool clearbmesh = false;

            //Add the Groups
            foreach (ImportedGroup g in grps)
            {
                if (g.Action == GmdcImporterAction.Add)
                {
                    AddGroup(g);
                }
                else if (g.Action == GmdcImporterAction.Rename)
                {
                    RenameGroup(g);
                }
                else if (g.Action == GmdcImporterAction.Replace)
                {
                    ReplaceGroup(grps, g);
                }
                else if (g.Action == GmdcImporterAction.Update)
                {
                    UpdateGroup(g);
                }

                if (g.Action != GmdcImporterAction.Nothing)
#if DEBUG
                { if (!Helper.WindowsRegistry.HiddenMode)
#endif
                { g.Link.Flatten(); }

                if (g.UseInBoundingMesh)
                {
                    clearbmesh = true;
                }
            }

            //Now Update the BoundingMesh if needed
            if (gmdc.Joints.Count != 0)
            {
                gmdc.Model.ClearBoundingMesh();
            }
            else
            {
                if (clearbmesh)
                {
                    gmdc.Model.ClearBoundingMesh();
                    foreach (ImportedGroup g in grps)
                    {
                        if (g.UseInBoundingMesh)
                        {
                            gmdc.Model.AddGroupToBoundingMesh(g.Group);
                        }
                    }
                }
            }

            //Make sure the Elements are assigned to the correct Bones
            for (int i = 0; i < bns.Length; i++)
            {
                ImportedBone b = bns[i];
                if (b.Action == GmdcImporterAction.Add || b.Action == GmdcImporterAction.Rename || b.Action == GmdcImporterAction.Replace)
                {
                    b.Bone.CollectVertices();

                    //Update the Hirarchy if wanted
                    if (Options.UpdateCres)
                    {
                        //Update the effective Transformation
                        TransformNode tn = gmdc.Joints[b.TargetIndex].AssignedTransformNode;
                        if (tn != null)
                        {
                            gmdc.Model.Transformations[b.TargetIndex] = tn.GetEffectiveTransformation();
                        }

                        if (gmdc.ParentResourceNode != null && tn != null && IsLocalCres())
                        {
                            //first delete the reference to this Node from the current parent
                            SimPe.Interfaces.Scenegraph.ICresChildren icc = tn.GetFirstParent();
                            if (icc != null)
                            {
                                if (icc.StoredTransformNode != null)
                                {
                                    icc.StoredTransformNode.RemoveChild(tn.Index);
                                }
                            }


                            //second, add this Joint to it's new Parent (if one is available)
                            if (b.GetParentFrom(bns) != null)
                            {
                                TransformNode np = b.GetParentFrom(bns).Bone.AssignedTransformNode;
                                if (np != null)
                                {
                                    np.AddChild(tn.Index);
                                }
                            }
                        }
                    }
                }
            }

            if (this.Options.CleanBones)
            {
                Gmdc.CleanupBones();
            }
            if (this.Options.UpdateCres)
            {
                if (!IsLocalCres())
                {
                    this.error += "\n\nThe referenced CRES and this GMDC are not in the same Package File. For security reasons, SimPE did not Update the Bone Hirarchy and locations!";
                }
                else
                {
                    gmdc.ParentResourceNode.Parent.SynchronizeUserData();
                }
            }
        }