/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <summary> /// Create a clone of this Object /// </summary> /// <returns>The clone</returns> public override object Clone() { ImportedBones list = new ImportedBones(); foreach (ImportedBone item in this) { list.Add(item); } return(list); }
/// <summary> /// Returns the PArent Bone or null if none was found /// </summary> /// <param name="bones">List of Bones, where we should look for Parents</param> /// <returns>null if no Parent is available or the Parent Bone</returns> public ImportedBone GetParentFrom(ImportedBones bones) { parentname = parentname.Trim(); if (parentname.Trim() == "") { return(null); } foreach (ImportedBone b in bones) { if (b.ImportedName.Trim() == parentname) { return(b); } } return(null); }
/// <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(); } } }