Beispiel #1
0
        /// <summary>
        /// Replace an exiting bone with the passed one
        /// </summary>
        /// <param name="grps">List of all Imported Groups (needed to fix the UseBone Indices)</param>
        /// <param name="bns">List of all Bones</param>
        /// <param name="b"></param>
        /// <param name="index">The Number of the Bone that should be added</param>
        /// <returns>the real Bone Index</returns>
        protected virtual int ReplaceBone(ImportedGroups grps, ImportedBones bns, ImportedBone b, int index)
        {
            int nindex = b.TargetIndex;

            gmdc.Joints[nindex] = b.Bone;

            VectorTransformation t = new VectorTransformation(VectorTransformation.TransformOrder.RotateTranslate);

            gmdc.Model.Transformations[nindex] = t;

            //Change the TransformNode for the New Bone
            if (Options.UpdateCres)
            {
                if (gmdc.ParentResourceNode != null)
                {
                    TransformNode tn = gmdc.Joints[nindex].AssignedTransformNode;
                    tn.ObjectGraphNode.FileName = b.ImportedName;
                    if (tn != null)
                    {
                        tn.Transformation = b.Transformation.Clone();
                    }
                }
            }

            return(nindex);
        }
Beispiel #2
0
        /// <summary>
        /// Add the passed Bone to the Gmdc and Fix the UseBone Indices to apropriate Values
        /// </summary>
        /// <param name="grps">List of all Imported Groups (needed to fix the UseBone Indices)</param>
        /// <param name="bns">List of all Bones</param>
        /// <param name="b"></param>
        /// <param name="index">The Number of the Bone that should be added</param>
        /// <returns>the real Bone Index</returns>
        protected virtual int AddBone(ImportedGroups grps, ImportedBones bns, ImportedBone b, int index)
        {
            int nindex = gmdc.Joints.Length;

            gmdc.Joints.Add(b.Bone);

            VectorTransformation t = new VectorTransformation(VectorTransformation.TransformOrder.RotateTranslate);

            gmdc.Model.Transformations.Add(t);

            //Create a TransformNode for the New Bone
            if (Options.UpdateCres)
            {
                if ((gmdc.ParentResourceNode != null) && (IsLocalCres()))
                {
                    TransformNode tn = new TransformNode(gmdc.ParentResourceNode.Parent);
                    tn.ObjectGraphNode.FileName = b.ImportedName;
                    tn.Transformation           = b.Transformation.Clone();
                    tn.JointReference           = nindex;

                    gmdc.ParentResourceNode.Parent.Blocks = (SimPe.Interfaces.Scenegraph.IRcolBlock[])Helper.Add(
                        gmdc.ParentResourceNode.Parent.Blocks,
                        tn,
                        typeof(SimPe.Interfaces.Scenegraph.IRcolBlock)
                        );
                }
            }


            return(nindex);
        }
Beispiel #3
0
 /// <summary>
 /// Checks wether or not the object is already stored in the List
 /// </summary>
 /// <param name="item">The Object you are looking for</param>
 /// <returns>true, if it was found</returns>
 public bool Contains(ImportedBone item)
 {
     return(base.Contains(item));
 }
Beispiel #4
0
 /// <summary>
 /// remove an Element
 /// </summary>
 /// <param name="item">The object that should be removed</param>
 public void Remove(ImportedBone item)
 {
     base.Remove(item);
 }
Beispiel #5
0
 /// <summary>
 /// insert a new Element
 /// </summary>
 /// <param name="index">The Index where the Element should be stored</param>
 /// <param name="item">The object that should be inserted</param>
 public void Insert(int index, ImportedBone item)
 {
     base.Insert(index, item);
 }
Beispiel #6
0
 /// <summary>
 /// add a new Element
 /// </summary>
 /// <param name="item">The object you want to add</param>
 /// <returns>The index it was added on</returns>
 public int Add(ImportedBone item)
 {
     return(base.Add(item));
 }
Beispiel #7
0
 /// <summary>
 /// Remove the Links to the NothingBones
 /// </summary>
 /// <param name="grps">List of all Imported Groups (needed to fix the UseBone Indices)</param>
 /// <param name="b"></param>
 /// <param name="index">The Number of the Bone that should be added</param>
 /// <returns>the real Bone Index</returns>
 protected virtual int NothingBone(ImportedGroups grps, ImportedBone b, int index)
 {
     return(-1);
 }
Beispiel #8
0
        /// <summary>
        /// Replace an exiting bone with the passed one
        /// </summary>
        /// <param name="grps">List of all Imported Groups (needed to fix the UseBone Indices)</param>
        /// <param name="b"></param>
        /// <param name="index">The Number of the Bone that should be added</param>
        /// <returns>the real Bone Index</returns>
        protected virtual int UpdateBone(ImportedGroups grps, ImportedBone b, int index)
        {
            int nindex = b.TargetIndex;

            return(nindex);
        }
Beispiel #9
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();
                }
            }
        }