Exemple #1
0
        protected GenericRcol FindDefiningCRES(SimPe.Interfaces.Files.IPackedFileDescriptor pfd, SimPe.Interfaces.Files.IPackageFile pkg)
        {
            GenericRcol rcol = new GenericRcol();

            rcol.ProcessData(pfd, pkg);

            ResourceNode rn = (ResourceNode)rcol.Blocks[0];

            foreach (int i in rn.ChildBlocks)
            {
                SimPe.Interfaces.Scenegraph.ICresChildren icc = rn.GetBlock(i);

                if (icc != null)
                {
                    if (icc.StoredTransformNode != null)
                    {
                        if (icc.StoredTransformNode.ObjectGraphNode.FileName == this.Name)
                        {
                            return(rcol);
                        }
                    }
                }
            }
            return(null);
        }
Exemple #2
0
        void AddJoint(ListedMeshBlocks lmb, SimPe.Interfaces.Scenegraph.ICresChildren bl, Ambertation.Graphics.MeshList parent, System.Windows.Forms.TreeNodeCollection nodes)
        {
            SimPe.Plugin.TransformNode tn = bl.StoredTransformNode;


            if (tn != null)
            {
                Ambertation.Graphics.MeshBox mb = new Ambertation.Graphics.MeshBox(
                    Microsoft.DirectX.Direct3D.Mesh.Sphere(dx.Device, 0.02f, 12, 24),
                    1,
                    Ambertation.Graphics.DirectXPanel.GetMaterial(Color.Wheat)
                    );
                mb.Wire = false;

                Ambertation.Scenes.Transformation trans = new Ambertation.Scenes.Transformation();
                trans.Rotation.X = tn.Rotation.GetEulerAngles().X;
                trans.Rotation.Y = tn.Rotation.GetEulerAngles().Y;
                trans.Rotation.Z = tn.Rotation.GetEulerAngles().Z;

                trans.Translation.X = tn.TransformX;
                trans.Translation.Y = tn.TransformY;
                trans.Translation.Z = tn.TransformZ;

                mb.Transform = Ambertation.Scenes.Converter.ToDx(trans);

                TreeNode tnode = new TreeNode(tn.ToString());
                tnode.Tag = mb;
                nodes.Add(tnode);
                jointmap[bl.GetName()] = mb;

                parent.Add(mb);

                foreach (SimPe.Interfaces.Scenegraph.ICresChildren cld in bl)
                {
                    AddJoint(lmb, cld, mb, tnode.Nodes);
                }
            }
            else
            {
                foreach (SimPe.Interfaces.Scenegraph.ICresChildren cld in bl)
                {
                    AddJoint(lmb, cld, parent, nodes);
                }
            }
        }
Exemple #3
0
        void AddJoint(Ambertation.Scenes.Joint parent, int index, Hashtable jointmap, ElementOrder component)
        {
            if (!joints)
            {
                return;
            }
            if (index < 0 || index >= gmdc.Joints.Count)
            {
                return;
            }

            GmdcJoint j = gmdc.Joints[index];

            Ambertation.Scenes.Joint nj = parent.CreateChild(j.Name);
            jointmap[index] = nj;

            if (j.AssignedTransformNode != null)
            {
                Vector3f tmp = j.AssignedTransformNode.Transformation.Translation;
                tmp = component.TransformScaled(tmp);
                //tmp = component.ScaleMatrix * tmp;

                nj.Translation.X = tmp.X; nj.Translation.Y = tmp.Y; nj.Translation.Z = tmp.Z;

                Quaternion q = component.TransformRotation(j.AssignedTransformNode.Transformation.Rotation);
                tmp = q.GetEulerAngles();

                //Console.WriteLine("        "+q.ToLinedString());
                nj.Rotation.X = tmp.X; nj.Rotation.Y = tmp.Y; nj.Rotation.Z = tmp.Z;

                IntArrayList li = j.AssignedTransformNode.ChildBlocks;
                foreach (int i in li)
                {
                    SimPe.Interfaces.Scenegraph.ICresChildren cld = j.AssignedTransformNode.GetBlock(i);
                    if (cld is TransformNode)
                    {
                        TransformNode tn = cld as TransformNode;
                        if (tn.JointReference != TransformNode.NO_JOINT)
                        {
                            AddJoint(nj, tn.JointReference, jointmap, component);
                        }
                    }
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Build the Parent Map
        /// </summary>
        /// <param name="parentmap">Hasttable that will contain the Child (key) -> Parent (value) Relation</param>
        /// <param name="parent">the current Parent id (-1=none)</param>
        /// <param name="c">the current Block we process</param>
        protected void LoadJointRelationRec(System.Collections.Hashtable parentmap, int parent, SimPe.Interfaces.Scenegraph.ICresChildren c)
        {
            if (c == null)
            {
                return;
            }

            if (c.GetType() == typeof(TransformNode))
            {
                TransformNode tn = (TransformNode)c;
                if (tn.JointReference != TransformNode.NO_JOINT)
                {
                    parentmap[tn.JointReference] = parent;
                    parent = tn.JointReference;
                }
            }

            //process the childs of this Block
            foreach (int i in c.ChildBlocks)
            {
                SimPe.Interfaces.Scenegraph.ICresChildren cl = c.GetBlock(i);
                LoadJointRelationRec(parentmap, parent, cl);
            }
        }
Exemple #5
0
        /// <summary>
        /// Add a ChildNode (and all it's subChilds) to a TreeNode
        /// </summary>
        /// <param name="parent">The parent TreeNode</param>
        /// <param name="index">The Index of the Child Block in the Parent</param>
        /// <param name="child">The ChildBlock (can be null)</param>
        protected void AddChildNode(System.Windows.Forms.TreeNodeCollection parent, int index, SimPe.Interfaces.Scenegraph.ICresChildren child)
        {
            //Make the user aware, that a Node was left out!
            if (child == null)
            {
                System.Windows.Forms.TreeNode unode = new System.Windows.Forms.TreeNode("[Error: Unsupported Child on Index " + index.ToString() + "]");
                unode.Tag                = index;
                unode.ImageIndex         = 4;
                unode.SelectedImageIndex = 4;
                parent.Add(unode);
                return;
            }

            System.Windows.Forms.TreeNode node = new System.Windows.Forms.TreeNode("0x" + index.ToString("X") + ": " + child.ToString());
            node.Tag                = index;
            node.ImageIndex         = child.ImageIndex;
            node.SelectedImageIndex = node.ImageIndex;
            parent.Add(node);

            foreach (int i in child.ChildBlocks)
            {
                AddChildNode(node.Nodes, i, child.GetBlock(i));
            }
        }
Exemple #6
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();
                }
            }
        }