コード例 #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);
        }
コード例 #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);
        }
コード例 #3
0
        /// <summary>
        /// This is called after the Groups were Imported to validate the Content
        /// </summary>
        /// <param name="grps">The imported Groups</param>
        /// <param name="bns">The imported Joints</param>
        /// <returns>true, if the Import should be continued</returns>
        /// <remarks>This Implementation will show the ImportGmdcGroups Dialog to
        /// let the User validate the Content. Override this Method, if you want a
        /// diffrent Import Dialog</remarks>
        protected virtual bool ValidateImportedGroups(ImportedGroups grps, ImportedBones bns)
        {
            foreach (ImportedGroup g in grps)
            {
                //add all populated Element Lists
                for (int k = 0; k < g.Elements.Count; k++)
                {
                    g.Elements[k].Number = g.Elements[k].Values.Count;
                    if (g.Elements[k].Values.Length > 0)
                    {
                        g.Link.ReferencedElement.Add(k);
                    }
                }                 // for k
                                  //if (minct==int.MaxValue) minct=0;
            }

            if (Helper.WindowsRegistry.ShowJointNames)
            {
                foreach (ImportedBone bn in bns)
                {
                    Console.WriteLine(bn.ImportedName + " -- " + bn.ParentName);
                }
            }

            importoptionsresult = ImportGmdcGroupsForm.Execute(gmdc, grps, bns);
            return(importoptionsresult.Result == System.Windows.Forms.DialogResult.OK);
        }
コード例 #4
0
        /// <summary>
        /// Process the Data stored in the passed Stream, and change/replace the passed Gmdc
        /// </summary>
        /// <param name="input">A Stream with the Input Data</param>
        /// <param name="gmdc">The Gmdc that should receive the Data</param>
        /// <param name="animationonly">true, if only the Animation Data should be imported</param>
        public virtual bool Process(System.IO.Stream input, GeometryDataContainer gmdc, bool animationonly)
        {
            animonly = animationonly;

            this.input = new System.IO.StreamReader(input);
            this.gmdc  = gmdc;
            SetUpAnimationData();

            if (gmdc == null || input == null)
            {
                return(false);
            }

            ImportedGroups g = LoadGroups();
            ImportedBones  b = LoadBones();

            if (!animonly)
            {
                if (ValidateImportedGroups(g, b))
                {
                    ChangeGmdc(g, b);
                }
            }
            this.ChangeAnim();

            return(true);
        }
コード例 #5
0
        /// <summary>
        /// This Method is called during the Import to process the input Data and
        /// generate a vaild Groups ArrayList.
        /// </summary>
        /// <returns>A List of all available Groups</returns>
        /// <remarks>You can use the Input and Gmdc Member to acces the Stream and
        /// the Gmdc File that should be changed</remarks>
        protected override ImportedGroups LoadGroups()
        {
            ImportedGroups grps = new ImportedGroups();

            LoadLists();
            ProcessLists(grps);
            return(grps);
        }
コード例 #6
0
        /// <summary>
        /// Create a clone of this Object
        /// </summary>
        /// <returns>The clone</returns>
        public override object Clone()
        {
            ImportedGroups list = new ImportedGroups();

            foreach (ImportedGroup item in this)
            {
                list.Add(item);
            }

            return(list);
        }
コード例 #7
0
        /// <summary>
        /// Use the Members, that wer initialized with LoadLists() to create
        /// the Imported Group Data
        /// </summary>
        /// <param name="grps">The List that should receive the Group Data</param>
        void ProcessLists(ImportedGroups grps)
        {
            foreach (string k in groups.Keys)
            {
                faces = (ArrayList)groups[k];

                //ignore empty groups
                if (faces.Count == 0)
                {
                    continue;
                }

                ImportedGroup g = PrepareGroup();
                g.Group.Name = k;
                BuildGroup(g);

                grps.Add(g);
            }
        }
コード例 #8
0
        /// <summary>
        /// Replace an existing Group with  the passed Group in the current Gmdc
        /// </summary>
        /// <param name="gs">List of all available Groups</param>
        /// <param name="g"></param>
        protected virtual void ReplaceGroup(ImportedGroups gs, ImportedGroup g)
        {
            int index = g.Target.Index;

            if (index < 0 || index >= Gmdc.Groups.Length)
            {
                index = Gmdc.FindGroupByName(g.Target.Name);
            }
            if (index >= 0)
            {
                gmdc.RemoveGroup(index);
            }

            //make sure to update the Groups
            foreach (ImportedGroup ig in gs)
            {
                if (ig.Target.Index > index)
                {
                    ig.Target.Index--;
                }
            }

            RenameGroup(g);
        }
コード例 #9
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);
 }
コード例 #10
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);
        }
コード例 #11
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();
                }
            }
        }