Exemplo n.º 1
0
        public void Preview()
        {
            int n = listBox1.SelectedIndex;

            if (n == -1)
            {
                return;
            }
            int idx = objects[n];

            hb1.ByteProvider = new DynamicByteProvider(udk.Exports[idx].data);
            treeView1.Nodes.Clear();
            if (udk.GetClass(udk.Exports[idx].clas) == "SkeletalMesh")
            {
                STM = null;
                SKM = new SkeletalMesh(udk, idx);
                treeView1.Nodes.Add(SKM.ToTree());
            }
            if (udk.GetClass(udk.Exports[idx].clas) == "StaticMesh")
            {
                SKM = null;
                STM = new StaticMesh(udk, idx);
                treeView1.Nodes.Add(STM.ToTree());
            }
        }
Exemplo n.º 2
0
        private void listBox1_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            int n = listBox1.SelectedIndex;

            if (n == -1)
            {
                return;
            }
            n = Objects[n];
            lODToolStripMenuItem.Visible = false;
            UnCheckLODs();
            stm                = null;
            skm                = null;
            skmold             = null;
            Preview3D.SkelMesh = null;
            Preview3D.StatMesh = null;
            if (pcc.getExport(n).ClassName == "StaticMesh")
            {
                LoadStaticMesh(n);
            }
            if (pcc.getExport(n).ClassName == "SkeletalMesh")
            {
                LoadSkeletalMesh(n);
            }
        }
Exemplo n.º 3
0
        private void listBox1_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            int n = listBox1.SelectedIndex;

            if (n == -1)
            {
                return;
            }
            n = Objects[n];
            lODToolStripMenuItem.Visible = false;
            UnCheckLODs();
            stm = null;
            skm = null;
            preview?.Dispose();
            preview                          = null;
            MaterialBox.Visible              = false;
            MaterialApplyButton.Visible      = false;
            MaterialIndexBox.Visible         = false;
            MaterialIndexApplyButton.Visible = false;
            if (Pcc.getExport(n).ClassName == "StaticMesh")
            {
                LoadStaticMesh(n);
            }
            if (Pcc.getExport(n).ClassName == "SkeletalMesh")
            {
                LoadSkeletalMesh(n);
            }
        }
Exemplo n.º 4
0
 public void LoadSkeletalMesh(int index)
 {
     try
     {
         DisableLODs();
         skm                   = new SkeletalMesh(pcc, index);
         skmold                = new SkeletalMeshOld(pcc, pcc.Exports[index].Data);
         hb1.ByteProvider      = new DynamicByteProvider(pcc.Exports[index].Data);
         Preview3D.StatMesh    = null;
         Preview3D.SkelMesh    = skm;
         Preview3D.CamDistance = skm.Bounding.r * 2.0f;
         Preview3D.CamOffset   = skm.Bounding.origin;
         treeView1.Nodes.Clear();
         treeView1.Nodes.Add(skm.ToTree());
         treeView1.Nodes[0].Expand();
         lODToolStripMenuItem.Visible  = true;
         lOD1ToolStripMenuItem.Enabled = true;
         lOD1ToolStripMenuItem.Checked = true;
         if (skm.LODModels.Count > 1)
         {
             lOD2ToolStripMenuItem.Enabled = true;
         }
         if (skm.LODModels.Count > 2)
         {
             lOD3ToolStripMenuItem.Enabled = true;
         }
         if (skm.LODModels.Count > 3)
         {
             lOD4ToolStripMenuItem.Enabled = true;
         }
     }
     catch (Exception)
     {
     }
 }
Exemplo n.º 5
0
        public static void OnBeginPlay()
        {
            Debug.Log(LogLevel.Display, "Hello, Unreal Engine!");
            Debug.AddOnScreenMessage(-1, 3.0f, Color.LightGreen, MethodBase.GetCurrentMethod().DeclaringType + " system started!");

            World.GetFirstPlayerController().SetViewTarget(World.GetActor <Camera>("MainCamera"));

            Actor kachujin = new Actor("Kachujin");
            SkeletalMeshComponent kachujinSkeletalMeshComponent = new SkeletalMeshComponent(kachujin);
            SkeletalMesh          kachujinSkeletalMesh          = SkeletalMesh.Load("/Game/Tests/Characters/Kachujin/SkeletalMesh");

            kachujinSkeletalMeshComponent.SetSkeletalMesh(kachujinSkeletalMesh);
            kachujinSkeletalMeshComponent.SetWorldLocation(new Vector3(-70.0f, -100.0f, -700.0f));
            kachujinSkeletalMeshComponent.SetWorldRotation(Maths.Euler(0.0f, 90.0f, 0.0f));
            kachujinSkeletalMeshComponent.SetAnimationMode(AnimationMode.Asset);
            kachujinSkeletalMeshComponent.PlayAnimation(AnimationSequence.Load("/Game/Tests/Characters/Kachujin/AnimationSequenceSwordSwing"), true);

            Actor ganfault = new Actor("Ganfault");
            SkeletalMeshComponent ganfaultSkeletalMeshComponent = new SkeletalMeshComponent(ganfault);
            SkeletalMesh          ganfaultSkeletalMesh          = SkeletalMesh.Load("/Game/Tests/Characters/Ganfault/SkeletalMesh");

            ganfaultSkeletalMeshComponent.SetSkeletalMesh(ganfaultSkeletalMesh);
            ganfaultSkeletalMeshComponent.SetWorldLocation(new Vector3(70.0f, -100.0f, -700.0f));
            ganfaultSkeletalMeshComponent.SetWorldRotation(Maths.Euler(0.0f, 90.0f, 0.0f));
            ganfaultSkeletalMeshComponent.SetAnimationMode(AnimationMode.Asset);
            ganfaultSkeletalMeshComponent.PlayAnimation(AnimationMontage.Load("/Game/Tests/Characters/Ganfault/AnimationMontage"), true);
        }
Exemplo n.º 6
0
            internal static unsafe void Invoke(IntPtr obj, SkeletalMesh NewMesh, bool bReinitPose)
            {
                long *p = stackalloc long[] { 0L, 0L, 0L };
                byte *b = (byte *)p;

                *((IntPtr *)(b + 0)) = NewMesh;
                *((bool *)(b + 8))   = bReinitPose;
                Main.GetProcessEvent(obj, SetSkeletalMesh_ptr, new IntPtr(p));;
            }
        }
Exemplo n.º 7
0
        public void OnBeginPlay()
        {
            World.GetFirstPlayerController().SetViewTarget(World.GetActor <Camera>("MainCamera"));

            SkeletalMesh prototypeMesh = SkeletalMesh.Load("/Game/Tests/Characters/Prototype");

            Actor leftPrototype = new("leftPrototype");
            SkeletalMeshComponent leftSkeletalMeshComponent = new(leftPrototype);

            leftSkeletalMeshComponent.SetSkeletalMesh(prototypeMesh);
            leftSkeletalMeshComponent.SetWorldLocation(new(-700.0f, -70.0f, -100.0f));
            leftSkeletalMeshComponent.SetWorldRotation(Maths.Euler(0.0f, 0.0f, 90.0f));
            leftSkeletalMeshComponent.SetAnimationMode(AnimationMode.Asset);
            leftSkeletalMeshComponent.PlayAnimation(AnimationSequence.Load("/Game/Tests/Characters/Animations/IdleAnimationSequence"), true);

            Assert.IsTrue(leftSkeletalMeshComponent.IsPlaying);
            Assert.IsTrue(leftSkeletalMeshComponent.GetBoneName(0) == "root");

            Bounds leftSkeletalMeshComponentBounds = default;

            leftSkeletalMeshComponent.GetBounds(leftSkeletalMeshComponent.GetTransform(), ref leftSkeletalMeshComponentBounds);

            Assert.IsFalse(leftSkeletalMeshComponentBounds == default(Bounds));

            Actor rightPrototype = new("rightPrototype");
            SkeletalMeshComponent rightSkeletalMeshComponent = new(rightPrototype);

            rightSkeletalMeshComponent.SetSkeletalMesh(prototypeMesh);
            rightSkeletalMeshComponent.SetWorldLocation(new(-700.0f, 70.0f, -100.0f));
            rightSkeletalMeshComponent.SetWorldRotation(Maths.Euler(0.0f, 0.0f, 90.0f));
            rightSkeletalMeshComponent.SetAnimationMode(AnimationMode.Asset);

            MaterialInstanceDynamic prototypeMaterial = rightSkeletalMeshComponent.CreateAndSetMaterialInstanceDynamic(0);

            prototypeMaterial.SetVectorParameterValue("AccentColor", new(0.0f, 0.5f, 1.0f));

            Assert.IsNotNull(prototypeMaterial.GetParent());

            AnimationMontage rightPrototypeAnimationMontage = AnimationMontage.Load("/Game/Tests/Characters/Animations/RunAnimationMontage");

            rightSkeletalMeshComponent.PlayAnimation(rightPrototypeAnimationMontage, true);

            AnimationInstance rightPrototypeAnimationInstance = rightSkeletalMeshComponent.GetAnimationInstance();

            Assert.IsTrue(rightPrototypeAnimationInstance.IsPlaying(rightPrototypeAnimationMontage));
            Assert.IsTrue(rightSkeletalMeshComponent.GetBoneName(0) == "root");

            Bounds rightSkeletalMeshComponentBounds = default;

            rightSkeletalMeshComponent.GetBounds(rightSkeletalMeshComponent.GetTransform(), ref rightSkeletalMeshComponentBounds);

            Assert.IsFalse(rightSkeletalMeshComponentBounds == default(Bounds));
        }
Exemplo n.º 8
0
 public USkelMesh(byte[] mem, string[] Names)
 {
     memory         = mem;
     memsize        = memory.Length;
     names          = Names;
     Mesh           = new SkeletalMesh();
     Mesh.OProps    = new List <Property>();
     Mesh.bound     = new Bounding();
     Mesh.materials = new List <int>();
     Mesh.Bones     = new List <Bone>();
     Deserialize();
 }
Exemplo n.º 9
0
        /// <summary>
        /// Spawns a new <see cref="Character" /> for the given player. If the player already has a character it will be destroyed.
        /// </summary>
        public void LoadCharacter()
        {
            if (this != Players.Service.LocalPlayer && RunService.Service.IsServer())
            {
                throw new InvalidOperationException(
                          "LoadCharacter can only be called by the host or on the local player.");
            }

            Character?.Destroy();

            var character = new Character {
                Name = Name, Player = this
            };

            var mesh = new SkeletalMesh
            {
                Parent = character
            };

            var skeleton = new Skeleton
            {
                Parent = character
            };

            var camera = Game.Workspace.CurrentCamera;

            camera.CameraSubject = character;
            camera.CameraType    = CameraType.Custom;

            character.Parent = Game.Workspace;
            character.Teleport(new Vector3(0, 10, 0));
            Character = character;

            // copy guis AFTER character has loaded
            if (Game.StarterGui.ResetGuisOnDeath && IsLocalPlayer)
            {
                PlayerGui.ClearChildren();
                PlayerGui.FetchStarterGuis();
            }

            Character.Died.Event += () =>
            {
                if (Game.Players.CharacterAutoLoads)
                {
                    LoadCharacter();
                }
            };

            Logger.Info("Character loaded.");
        }
Exemplo n.º 10
0
        public void LoadSkeletalMesh(int index)
        {
            DisableLODs();
            UnCheckLODs();
            skm    = new SkeletalMesh(pcc, index);
            skmold = new SkeletalMeshOld(pcc, index);

            // Load preview model
            preview?.Dispose();
            preview = new ModelPreview(view.Device, skm, view.TextureCache);
            RefreshChosenMaterialsList();
            CenterView();

            // Update treeview
            treeView1.BeginUpdate();
            treeView1.Nodes.Clear();
            treeView1.Nodes.Add(skm.ToTree());
            treeView1.Nodes[0].Expand();
            treeView1.EndUpdate();
            lODToolStripMenuItem.Visible  = true;
            lOD0ToolStripMenuItem.Enabled = true;
            lOD0ToolStripMenuItem.Checked = true;
            if (skm.LODModels.Count > 1)
            {
                lOD1ToolStripMenuItem.Enabled = true;
            }
            if (skm.LODModels.Count > 2)
            {
                lOD2ToolStripMenuItem.Enabled = true;
            }
            if (skm.LODModels.Count > 3)
            {
                lOD3ToolStripMenuItem.Enabled = true;
            }
            MaterialBox.Visible              = false;
            MaterialApplyButton.Visible      = false;
            MaterialIndexBox.Visible         = false;
            MaterialIndexApplyButton.Visible = false;
        }
Exemplo n.º 11
0
        public static void OnBeginPlay()
        {
            Debug.AddOnScreenMessage(-1, 3.0f, Color.LightGreen, MethodBase.GetCurrentMethod().DeclaringType + " system started!");

            World.GetFirstPlayerController().SetViewTarget(World.GetActor <Camera>("MainCamera"));

            SkeletalMesh prototypeMesh = SkeletalMesh.Load("/Game/Tests/Characters/Prototype");

            Actor leftPrototype = new Actor("leftPrototype");
            SkeletalMeshComponent leftSkeletalMeshComponent = new SkeletalMeshComponent(leftPrototype);

            leftSkeletalMeshComponent.SetSkeletalMesh(prototypeMesh);
            leftSkeletalMeshComponent.SetWorldLocation(new Vector3(-700.0f, -70.0f, -100.0f));
            leftSkeletalMeshComponent.SetWorldRotation(Maths.Euler(0.0f, 0.0f, 90.0f));
            leftSkeletalMeshComponent.SetAnimationMode(AnimationMode.Asset);
            leftSkeletalMeshComponent.PlayAnimation(AnimationSequence.Load("/Game/Tests/Characters/Animations/IdleAnimationSequence"), true);

            Assert.IsTrue(leftSkeletalMeshComponent.IsPlaying);
            Assert.IsTrue(leftSkeletalMeshComponent.GetBoneName(0) == "root");

            Actor rightPrototype = new Actor("rightPrototype");
            SkeletalMeshComponent rightSkeletalMeshComponent = new SkeletalMeshComponent(rightPrototype);

            rightSkeletalMeshComponent.SetSkeletalMesh(prototypeMesh);
            rightSkeletalMeshComponent.SetWorldLocation(new Vector3(-700.0f, 70.0f, -100.0f));
            rightSkeletalMeshComponent.SetWorldRotation(Maths.Euler(0.0f, 0.0f, 90.0f));
            rightSkeletalMeshComponent.SetAnimationMode(AnimationMode.Asset);
            rightSkeletalMeshComponent.CreateAndSetMaterialInstanceDynamic(0).SetVectorParameterValue("AccentColor", new LinearColor(0.0f, 0.5f, 1.0f));

            AnimationMontage rightPrototypeAnimationMontage = AnimationMontage.Load("/Game/Tests/Characters/Animations/RunAnimationMontage");

            rightSkeletalMeshComponent.PlayAnimation(rightPrototypeAnimationMontage, true);

            AnimationInstance rightPrototypeAnimationInstance = rightSkeletalMeshComponent.GetAnimationInstance();

            Assert.IsTrue(rightPrototypeAnimationInstance.IsPlaying(rightPrototypeAnimationMontage));
            Assert.IsTrue(rightSkeletalMeshComponent.GetBoneName(0) == "root");
        }
Exemplo n.º 12
0
        private void importLODToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int n = MeshListBox.SelectedIndex;

            if (n == -1)
            {
                return;
            }
            int m = LODListBox.SelectedIndex;

            if (m == -1)
            {
                return;
            }
            SkeletalMesh skm = new SkeletalMesh(pcc, SelectedObject);

            SkeletalMesh.LODModelStruct          lodpcc = skm.LODModels[SelectedLOD];
            UDKExplorer.UDK.Classes.SkeletalMesh skmudk = new UDKExplorer.UDK.Classes.SkeletalMesh(udk, Objects[n]);
            if (skm.Bones.Count != skmudk.Bones.Count)
            {
                if (MessageBox.Show("Your imported mesh has a different count of Bones! This would crash your game, proceed?", "UDK Skeleton Import", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }
            }
            UDKExplorer.UDK.Classes.SkeletalMesh.LODModelStruct lodudk = skmudk.LODModels[m];
            lodpcc.Sections = new List <SkeletalMesh.SectionStruct>();
            foreach (UDKExplorer.UDK.Classes.SkeletalMesh.SectionStruct secudk in lodudk.Sections)
            {
                SkeletalMesh.SectionStruct secpcc = new SkeletalMesh.SectionStruct();
                secpcc.BaseIndex     = secudk.BaseIndex;
                secpcc.ChunkIndex    = secudk.ChunkIndex;
                secpcc.MaterialIndex = secudk.MaterialIndex;
                secpcc.NumTriangles  = secudk.NumTriangles;
                lodpcc.Sections.Add(secpcc);
            }
            lodpcc.IndexBuffer            = new SkeletalMesh.MultiSizeIndexContainerStruct();
            lodpcc.IndexBuffer.IndexCount = lodudk.IndexBuffer.IndexCount;
            lodpcc.IndexBuffer.IndexSize  = lodudk.IndexBuffer.IndexSize;
            lodpcc.IndexBuffer.Indexes    = new List <ushort>();
            foreach (ushort Idx in lodudk.IndexBuffer.Indexes)
            {
                lodpcc.IndexBuffer.Indexes.Add(Idx);
            }
            List <int> BoneMap = new List <int>();

            for (int i = 0; i < skmudk.Bones.Count; i++)
            {
                string udkb  = udk.GetName(skmudk.Bones[i].Name);
                bool   found = false;
                for (int j = 0; j < skm.Bones.Count; j++)
                {
                    string pccb = pcc.getNameEntry(skm.Bones[j].Name);
                    if (pccb == udkb)
                    {
                        found = true;
                        BoneMap.Add(j);
                        if (MPOpt.SKM_importbones)
                        {
                            SkeletalMesh.BoneStruct bpcc = skm.Bones[j];
                            UDKExplorer.UDK.Classes.SkeletalMesh.BoneStruct budk = skmudk.Bones[i];
                            bpcc.Orientation = budk.Orientation;
                            bpcc.Position    = budk.Position;
                            skm.Bones[j]     = bpcc;
                        }
                    }
                }
                if (!found)
                {
                    DebugOutput.PrintLn("ERROR: Cant Match Bone \"" + udkb + "\"");
                    BoneMap.Add(0);
                }
            }

            lodpcc.ActiveBones = new List <ushort>();
            foreach (ushort Idx in lodudk.ActiveBones)
            {
                lodpcc.ActiveBones.Add((ushort)BoneMap[Idx]);
            }
            lodpcc.Chunks = new List <SkeletalMesh.SkelMeshChunkStruct>();
            foreach (UDKExplorer.UDK.Classes.SkeletalMesh.SkelMeshChunkStruct chunkudk in lodudk.Chunks)
            {
                SkeletalMesh.SkelMeshChunkStruct chunkpcc = new SkeletalMesh.SkelMeshChunkStruct();
                chunkpcc.BaseVertexIndex   = chunkudk.BaseVertexIndex;
                chunkpcc.MaxBoneInfluences = chunkudk.MaxBoneInfluences;
                chunkpcc.NumRigidVertices  = chunkudk.NumRigidVertices;
                chunkpcc.NumSoftVertices   = chunkudk.NumSoftVertices;
                chunkpcc.BoneMap           = new List <ushort>();
                chunkpcc.RiginSkinVertices = new List <SkeletalMesh.RigidSkinVertexStruct>();
                chunkpcc.SoftSkinVertices  = new List <SkeletalMesh.SoftSkinVertexStruct>();
                foreach (ushort Idx in chunkudk.BoneMap)
                {
                    chunkpcc.BoneMap.Add((ushort)BoneMap[Idx]);
                }
                lodpcc.Chunks.Add(chunkpcc);
            }
            lodpcc.Size          = lodudk.Size;
            lodpcc.NumVertices   = lodudk.NumVertices;
            lodpcc.RequiredBones = new List <byte>();
            foreach (byte b in lodudk.RequiredBones)
            {
                lodpcc.RequiredBones.Add(b);
            }
            lodpcc.VertexBufferGPUSkin = new SkeletalMesh.VertexBufferGPUSkinStruct();
            lodpcc.VertexBufferGPUSkin.NumTexCoords = lodudk.VertexBufferGPUSkin.NumTexCoords;
            lodpcc.VertexBufferGPUSkin.Extension    = lodudk.VertexBufferGPUSkin.Extension;
            lodpcc.VertexBufferGPUSkin.Origin       = lodudk.VertexBufferGPUSkin.Origin;
            lodpcc.VertexBufferGPUSkin.VertexSize   = lodudk.VertexBufferGPUSkin.VertexSize;
            lodpcc.VertexBufferGPUSkin.Vertices     = new List <SkeletalMesh.GPUSkinVertexStruct>();
            foreach (UDKExplorer.UDK.Classes.SkeletalMesh.GPUSkinVertexStruct vudk in lodudk.VertexBufferGPUSkin.Vertices)
            {
                SkeletalMesh.GPUSkinVertexStruct vpcc = new SkeletalMesh.GPUSkinVertexStruct();
                vpcc.TangentX         = vudk.TangentX;
                vpcc.TangentZ         = vudk.TangentZ;
                vpcc.Position         = vudk.Position;
                vpcc.InfluenceBones   = vudk.InfluenceBones;
                vpcc.InfluenceWeights = vudk.InfluenceWeights;
                vpcc.U = vudk.U;
                vpcc.V = vudk.V;
                lodpcc.VertexBufferGPUSkin.Vertices.Add(vpcc);
            }
            skm.LODModels[SelectedLOD] = lodpcc;
            SerializingContainer con = new SerializingContainer();

            con.Memory    = new MemoryStream();
            con.isLoading = false;
            skm.Serialize(con);
            int          end = skm.GetPropertyEnd();
            MemoryStream mem = new MemoryStream();

            mem.Write(pcc.Exports[SelectedObject].Data, 0, end);
            mem.Write(con.Memory.ToArray(), 0, (int)con.Memory.Length);
            pcc.Exports[SelectedObject].Data = mem.ToArray();
            MessageBox.Show("Done");
            Close();
        }
Exemplo n.º 13
0
        private void ImportMeshToolStripMenuItem_Click(object sender, System.EventArgs e)
        {
            if (MeshListBox.SelectedIndex == -1)
            {
                return;
            }

            SkeletalMesh newMesh = new SkeletalMesh();
            SkeletalMesh oldMesh = new SkeletalMesh(pcc, SelectedObject);

            UDKExplorer.UDK.Classes.SkeletalMesh sourceMesh = new UDKExplorer.UDK.Classes.SkeletalMesh(udk, Objects[MeshListBox.SelectedIndex]);

            // Fill out data in newMesh
            newMesh.MyIndex = SelectedObject;
            newMesh.Owner   = pcc;
            newMesh.Flags   = (int)(pcc.Exports[SelectedObject].ObjectFlags >> 32); // Keep the flags from the overwritten mesh

            // Bounding
            newMesh.Bounding = new SkeletalMesh.BoundingStruct(sourceMesh.Bounding);

            // Materials
            newMesh.Materials = new List <int>();
            foreach (int materialObjectIndex in sourceMesh.Materials)
            {
                newMesh.Materials.Add(0); // Don't bother copying IDs that will be invalid anyways.
            }
            // The materials are all entered as zero, nothing we can do now.

            /*for (int i = 0; i < newMesh.Materials.Count; i++)
             * {
             *  newMesh.MatInsts.Add(new MaterialInstanceConstant(pcc, newMesh.Materials[i] - 1));
             * }*/

            // OrgRot
            newMesh.Origin   = sourceMesh.Origin;
            newMesh.Rotation = sourceMesh.Rotation;

            // Bones
            newMesh.Bones = new List <SkeletalMesh.BoneStruct>();
            foreach (UDKExplorer.UDK.Classes.SkeletalMesh.BoneStruct bone in sourceMesh.Bones)
            {
                newMesh.Bones.Add(SkeletalMesh.BoneStruct.ImportFromUDK(bone, udk, pcc));
            }
            newMesh.SkeletonDepth = sourceMesh.SkeletonDepth;

            // LODs
            newMesh.LODModels = new List <SkeletalMesh.LODModelStruct>();
            foreach (UDKExplorer.UDK.Classes.SkeletalMesh.LODModelStruct lod in sourceMesh.LODModels)
            {
                SkeletalMesh.LODModelStruct newLOD = new SkeletalMesh.LODModelStruct();

                newLOD.Sections = new List <SkeletalMesh.SectionStruct>();
                foreach (UDKExplorer.UDK.Classes.SkeletalMesh.SectionStruct secudk in lod.Sections)
                {
                    SkeletalMesh.SectionStruct secpcc = new SkeletalMesh.SectionStruct();
                    secpcc.BaseIndex     = secudk.BaseIndex;
                    secpcc.ChunkIndex    = secudk.ChunkIndex;
                    secpcc.MaterialIndex = secudk.MaterialIndex;
                    secpcc.NumTriangles  = secudk.NumTriangles;
                    newLOD.Sections.Add(secpcc);
                }
                newLOD.IndexBuffer            = new SkeletalMesh.MultiSizeIndexContainerStruct();
                newLOD.IndexBuffer.IndexCount = lod.IndexBuffer.IndexCount;
                newLOD.IndexBuffer.IndexSize  = lod.IndexBuffer.IndexSize;
                newLOD.IndexBuffer.Indexes    = new List <ushort>();
                foreach (ushort Idx in lod.IndexBuffer.Indexes)
                {
                    newLOD.IndexBuffer.Indexes.Add(Idx);
                }
                // TODO: Unk1
                newLOD.Unk1 = 0;

                /* We don't need to change bone indexes, because the skeleton is coming along for the ride.
                 *
                 * List<int> BoneMap = new List<int>(); // Maps source bone i to existing bone index BoneMap[i]
                 * for (int i = 0; i < sourceMesh.Bones.Count; i++)
                 * {
                 *  string sourceName = udk.GetName(sourceMesh.Bones[i].Name);
                 *  bool found = false;
                 *  for (int j = 0; j < skm.Bones.Count; j++)
                 *  {
                 *      string pccb = pcc.getNameEntry(skm.Bones[j].Name);
                 *      if (pccb == sourceName)
                 *      {
                 *          found = true;
                 *          BoneMap.Add(j);
                 *          if (MPOpt.SKM_importbones)
                 *          {
                 *              SkeletalMesh.BoneStruct bpcc = skm.Bones[j];
                 *              UDKExplorer.UDK.Classes.SkeletalMesh.BoneStruct budk = sourceMesh.Bones[i];
                 *              bpcc.Orientation = budk.Orientation;
                 *              bpcc.Position = budk.Position;
                 *              skm.Bones[j] = bpcc;
                 *          }
                 *      }
                 *  }
                 *  if (!found)
                 *  {
                 *      DebugOutput.PrintLn("ERROR: Cant Match Bone \"" + sourceName + "\"");
                 *      BoneMap.Add(0);
                 *  }
                 * }*/

                newLOD.ActiveBones = new List <ushort>();
                foreach (ushort Idx in lod.ActiveBones)
                {
                    newLOD.ActiveBones.Add(/*(ushort)BoneMap[Idx]*/ Idx);
                }
                // TODO: Unk2
                newLOD.Unk2   = 0;
                newLOD.Chunks = new List <SkeletalMesh.SkelMeshChunkStruct>();
                foreach (UDKExplorer.UDK.Classes.SkeletalMesh.SkelMeshChunkStruct chunkudk in lod.Chunks)
                {
                    SkeletalMesh.SkelMeshChunkStruct chunkpcc = new SkeletalMesh.SkelMeshChunkStruct();
                    chunkpcc.BaseVertexIndex   = chunkudk.BaseVertexIndex;
                    chunkpcc.MaxBoneInfluences = chunkudk.MaxBoneInfluences;
                    chunkpcc.NumRigidVertices  = chunkudk.NumRigidVertices;
                    chunkpcc.NumSoftVertices   = chunkudk.NumSoftVertices;
                    chunkpcc.BoneMap           = new List <ushort>();
                    chunkpcc.RiginSkinVertices = new List <SkeletalMesh.RigidSkinVertexStruct>();
                    chunkpcc.SoftSkinVertices  = new List <SkeletalMesh.SoftSkinVertexStruct>();
                    foreach (ushort Idx in chunkudk.BoneMap)
                    {
                        chunkpcc.BoneMap.Add(/*(ushort)BoneMap[Idx]*/ Idx);
                    }
                    newLOD.Chunks.Add(chunkpcc);
                }
                newLOD.Size        = lod.Size;
                newLOD.NumVertices = lod.NumVertices;
                // TODO: Unk3
                newLOD.Unk3          = 0;
                newLOD.RequiredBones = new List <byte>();
                foreach (byte b in lod.RequiredBones)
                {
                    newLOD.RequiredBones.Add(b);
                }
                newLOD.RawPointIndicesFlag   = lod.RawPointIndicesFlag;
                newLOD.RawPointIndicesCount  = lod.RawPointIndicesCount;
                newLOD.RawPointIndicesSize   = lod.RawPointIndicesSize;
                newLOD.RawPointIndicesOffset = lod.RawPointIndicesOffset;
                newLOD.RawPointIndices       = new List <int>();
                foreach (int i in lod.RawPointIndices)
                {
                    newLOD.RawPointIndices.Add(i);
                }
                newLOD.NumTexCoords        = lod.NumTexCoords;
                newLOD.VertexBufferGPUSkin = new SkeletalMesh.VertexBufferGPUSkinStruct();
                newLOD.VertexBufferGPUSkin.NumTexCoords = lod.VertexBufferGPUSkin.NumTexCoords;
                newLOD.VertexBufferGPUSkin.Extension    = lod.VertexBufferGPUSkin.Extension;
                newLOD.VertexBufferGPUSkin.Origin       = lod.VertexBufferGPUSkin.Origin;
                newLOD.VertexBufferGPUSkin.VertexSize   = lod.VertexBufferGPUSkin.VertexSize;
                newLOD.VertexBufferGPUSkin.Vertices     = new List <SkeletalMesh.GPUSkinVertexStruct>();
                foreach (UDKExplorer.UDK.Classes.SkeletalMesh.GPUSkinVertexStruct vudk in lod.VertexBufferGPUSkin.Vertices)
                {
                    SkeletalMesh.GPUSkinVertexStruct vpcc = new SkeletalMesh.GPUSkinVertexStruct();
                    vpcc.TangentX         = vudk.TangentX;
                    vpcc.TangentZ         = vudk.TangentZ;
                    vpcc.Position         = vudk.Position;
                    vpcc.InfluenceBones   = vudk.InfluenceBones;
                    vpcc.InfluenceWeights = vudk.InfluenceWeights;
                    vpcc.U = vudk.U;
                    vpcc.V = vudk.V;
                    newLOD.VertexBufferGPUSkin.Vertices.Add(vpcc);
                }
                // TODO: Unk4
                newLOD.Unk4 = 0;
                //skm.LODModels[SelectedLOD] = newLOD;
                newMesh.LODModels.Add(newLOD);
            }

            // Tail
            newMesh.TailNames = new List <SkeletalMesh.TailNamesStruct>();
            for (int i = 0; i < newMesh.Bones.Count; i++)
            {
                newMesh.TailNames.Add(new SkeletalMesh.TailNamesStruct(newMesh.Bones[i].Name, i));
            }
            newMesh.Unk1 = oldMesh.Unk1;
            newMesh.Unk2 = oldMesh.Unk2;
            newMesh.Unk3 = new List <int>();
            foreach (int i in oldMesh.Unk3)
            {
                newMesh.Unk3.Add(i);
            }

            // Write mesh data to temporary buffer
            SerializingContainer serializer = new SerializingContainer();

            serializer.Memory    = new MemoryStream();
            serializer.isLoading = false;
            newMesh.Serialize(serializer);

            // Copy in the properties from the old mesh
            int          propertyEnd = newMesh.GetPropertyEnd();
            MemoryStream finalData   = new MemoryStream();

            finalData.Write(pcc.Exports[SelectedObject].Data, 0, propertyEnd);

            // Copy in the data from the new mesh
            finalData.Write(serializer.Memory.ToArray(), 0, (int)serializer.Memory.Length);

            // Upload final data
            pcc.Exports[SelectedObject].Data = finalData.ToArray();
            MessageBox.Show("Mesh replaced.");
            Close();
        }
 public void SetSkeletalMesh(SkeletalMesh skeletalMesh)
 {
     CreateRenderProxies();
 }
Exemplo n.º 15
0
        private void importLODToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int n = listBox1.SelectedIndex;

            if (n == -1)
            {
                return;
            }
            int m = listBox2.SelectedIndex;

            if (m == -1)
            {
                return;
            }
            TreeNode t1 = treeView1.SelectedNode;

            if (t1 == null || t1.Parent == null || t1.Name == "")
            {
                return;
            }
            PCCObject    pcc = new PCCObject();
            SkeletalMesh skm = new SkeletalMesh();
            EntryStruct  en;
            string       loc = Path.GetDirectoryName(Application.ExecutablePath) + "\\exec\\";

            if (DisplayStyle == 0)
            {
                int o = 0;
                if (!Int32.TryParse(t1.Name, out o))
                {
                    return;
                }
                en = Entries[o];
                if (!en.isDLC)
                {
                    pcc = new PCCObject(ME3Directory.cookedPath + en.Filename);
                    if (en.isSkeletal)
                    {
                        skm = new SkeletalMesh(pcc, en.Index);
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    string dirDLC = ME3Directory.DLCPath;
                    dirDLC += en.DLCName;
                    dirDLC += "\\CookedPCConsole\\Default.sfar";
                    DLCBase dlc = new DLCBase(dirDLC);
                    foreach (sfarFile file in dlc.fileList)
                    {
                        try
                        {
                            string filename = Path.GetFileName(file.fileName);
                            if (Path.GetExtension(filename).ToLower().EndsWith(".pcc") && filename == en.Filename)
                            {
                                if (File.Exists(loc + "dlc.pcc"))
                                {
                                    File.Delete(loc + "dlc.pcc");
                                }
                                using (Stream input = File.OpenRead(dirDLC), output = File.Create(loc + "dlc.pcc"))
                                {
                                    AmaroK86.MassEffect3.DLCUnpack.DecompressEntry(file, input, output, dlc.CompressionScheme);
                                }
                                if (File.Exists(loc + "dlc.pcc"))
                                {
                                    try
                                    {
                                        pcc = new PCCObject(loc + "dlc.pcc");
                                        if (en.isSkeletal)
                                        {
                                            skm = new SkeletalMesh(pcc, en.Index);
                                            break;
                                        }
                                        else
                                        {
                                            return;
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        return;
                                    }
                                }
                            }
                        }
                        catch (Exception)
                        {
                            return;
                        }
                    }
                }
            }
            else
            {
                return;
            }
            if (!skm.Loaded || !pcc.Loaded)
            {
                return;
            }
            SkeletalMesh.LODModelStruct          lodpcc = skm.LODModels[0];
            UDKExplorer.UDK.Classes.SkeletalMesh skmudk = new UDKExplorer.UDK.Classes.SkeletalMesh(udk, Objects[n]);
            UDKExplorer.UDK.Classes.SkeletalMesh.LODModelStruct lodudk = skmudk.LODModels[m];
            lodpcc.Sections = new List <SkeletalMesh.SectionStruct>();
            foreach (UDKExplorer.UDK.Classes.SkeletalMesh.SectionStruct secudk in lodudk.Sections)
            {
                SkeletalMesh.SectionStruct secpcc = new SkeletalMesh.SectionStruct();
                secpcc.BaseIndex     = secudk.BaseIndex;
                secpcc.ChunkIndex    = secudk.ChunkIndex;
                secpcc.MaterialIndex = secudk.MaterialIndex;
                secpcc.NumTriangles  = secudk.NumTriangles;
                lodpcc.Sections.Add(secpcc);
            }
            lodpcc.IndexBuffer            = new SkeletalMesh.MultiSizeIndexContainerStruct();
            lodpcc.IndexBuffer.IndexCount = lodudk.IndexBuffer.IndexCount;
            lodpcc.IndexBuffer.IndexSize  = lodudk.IndexBuffer.IndexSize;
            lodpcc.IndexBuffer.Indexes    = new List <ushort>();
            foreach (ushort Idx in lodudk.IndexBuffer.Indexes)
            {
                lodpcc.IndexBuffer.Indexes.Add(Idx);
            }
            List <int> BoneMap = new List <int>();

            for (int i = 0; i < skmudk.Bones.Count; i++)
            {
                string udkb  = udk.GetName(skmudk.Bones[i].Name);
                bool   found = false;
                for (int j = 0; j < skm.Bones.Count; j++)
                {
                    string pccb = pcc.getNameEntry(skm.Bones[j].Name);
                    if (pccb == udkb)
                    {
                        found = true;
                        BoneMap.Add(j);
                        if (importBonesToolStripMenuItem.Checked)
                        {
                            SkeletalMesh.BoneStruct bpcc = skm.Bones[j];
                            UDKExplorer.UDK.Classes.SkeletalMesh.BoneStruct budk = skmudk.Bones[i];
                            bpcc.Orientation = budk.Orientation;
                            bpcc.Position    = budk.Position;
                            skm.Bones[j]     = bpcc;
                        }
                    }
                }
                if (!found)
                {
                    DebugOutput.PrintLn("ERROR: Cant Match Bone \"" + udkb + "\"");
                    BoneMap.Add(0);
                }
            }

            lodpcc.ActiveBones = new List <ushort>();
            foreach (ushort Idx in lodudk.ActiveBones)
            {
                lodpcc.ActiveBones.Add((ushort)BoneMap[Idx]);
            }
            lodpcc.Chunks = new List <SkeletalMesh.SkelMeshChunkStruct>();
            foreach (UDKExplorer.UDK.Classes.SkeletalMesh.SkelMeshChunkStruct chunkudk in lodudk.Chunks)
            {
                SkeletalMesh.SkelMeshChunkStruct chunkpcc = new SkeletalMesh.SkelMeshChunkStruct();
                chunkpcc.BaseVertexIndex   = chunkudk.BaseVertexIndex;
                chunkpcc.MaxBoneInfluences = chunkudk.MaxBoneInfluences;
                chunkpcc.NumRigidVertices  = chunkudk.NumRigidVertices;
                chunkpcc.NumSoftVertices   = chunkudk.NumSoftVertices;
                chunkpcc.BoneMap           = new List <ushort>();
                chunkpcc.RiginSkinVertices = new List <SkeletalMesh.RigidSkinVertexStruct>();
                chunkpcc.SoftSkinVertices  = new List <SkeletalMesh.SoftSkinVertexStruct>();
                foreach (ushort Idx in chunkudk.BoneMap)
                {
                    chunkpcc.BoneMap.Add((ushort)BoneMap[Idx]);
                }
                lodpcc.Chunks.Add(chunkpcc);
            }
            lodpcc.Size          = lodudk.Size;
            lodpcc.NumVertices   = lodudk.NumVertices;
            lodpcc.RequiredBones = new List <byte>();
            foreach (byte b in lodudk.RequiredBones)
            {
                lodpcc.RequiredBones.Add(b);
            }
            lodpcc.VertexBufferGPUSkin = new SkeletalMesh.VertexBufferGPUSkinStruct();
            lodpcc.VertexBufferGPUSkin.NumTexCoords = lodudk.VertexBufferGPUSkin.NumTexCoords;
            lodpcc.VertexBufferGPUSkin.Extension    = lodudk.VertexBufferGPUSkin.Extension;
            lodpcc.VertexBufferGPUSkin.Origin       = lodudk.VertexBufferGPUSkin.Origin;
            lodpcc.VertexBufferGPUSkin.VertexSize   = lodudk.VertexBufferGPUSkin.VertexSize;
            lodpcc.VertexBufferGPUSkin.Vertices     = new List <SkeletalMesh.GPUSkinVertexStruct>();
            foreach (UDKExplorer.UDK.Classes.SkeletalMesh.GPUSkinVertexStruct vudk in lodudk.VertexBufferGPUSkin.Vertices)
            {
                SkeletalMesh.GPUSkinVertexStruct vpcc = new SkeletalMesh.GPUSkinVertexStruct();
                vpcc.TangentX         = vudk.TangentX;
                vpcc.TangentZ         = vudk.TangentZ;
                vpcc.Position         = vudk.Position;
                vpcc.InfluenceBones   = vudk.InfluenceBones;
                vpcc.InfluenceWeights = vudk.InfluenceWeights;
                vpcc.U = vudk.U;
                vpcc.V = vudk.V;
                lodpcc.VertexBufferGPUSkin.Vertices.Add(vpcc);
            }
            for (int i = 0; i < skm.LODModels.Count; i++)
            {
                skm.LODModels[i] = lodpcc;
            }
            SerializingContainer con = new SerializingContainer();

            con.Memory    = new MemoryStream();
            con.isLoading = false;
            skm.Serialize(con);
            int          end = skm.GetPropertyEnd();
            MemoryStream mem = new MemoryStream();

            mem.Write(pcc.Exports[en.Index].Data, 0, end);
            mem.Write(con.Memory.ToArray(), 0, (int)con.Memory.Length);
            pcc.Exports[en.Index].Data = mem.ToArray();
            pcc.altSaveToFile(pcc.pccFileName, true);
            if (!en.isDLC)
            {
                MessageBox.Show("Done");
            }
            else
            {
                MessageBox.Show("Done. The file is now in following folder, please replace it back to DLC :\n" + loc + "dlc.pcc");
            }
            globalTreeToolStripMenuItem.Visible       =
                optionsToolStripMenuItem.Visible      =
                    transferToolStripMenuItem.Visible =
                        splitContainer1.Visible       = true;
            fileToolStripMenuItem.Visible             =
                importLODToolStripMenuItem.Visible    =
                    splitContainer3.Visible           = false;
        }
Exemplo n.º 16
0
        public override void handleUpdate(List <PackageUpdate> updates)
        {
            IEnumerable <PackageUpdate> relevantUpdates = updates.Where(x => x.change != PackageChange.Import &&
                                                                        x.change != PackageChange.ImportAdd &&
                                                                        x.change != PackageChange.Names);
            List <int> updatedExports = relevantUpdates.Select(x => x.index).ToList();

            if (skm != null && updatedExports.Contains(skm.MyIndex))
            {
                int index = skm.MyIndex;
                //loaded SkeletalMesh is no longer a SkeletalMesh
                if (Pcc.getExport(index).ClassName != "SkeletalMesh")
                {
                    skm = null;
                    preview?.Dispose();
                    preview = null;
                    treeView1.Nodes.Clear();
                    RefreshMeshList();
                }
                else
                {
                    LoadSkeletalMesh(index);
                }
                updatedExports.Remove(index);
            }
            else if (stm != null && updatedExports.Contains(stm.index))
            {
                int index = stm.index;
                //loaded SkeletalMesh is no longer a SkeletalMesh
                if (Pcc.getExport(index).ClassName != "StaticMesh")
                {
                    stm = null;
                    preview?.Dispose();
                    preview = null;
                    treeView1.Nodes.Clear();
                    RefreshMeshList();
                }
                else
                {
                    LoadStaticMesh(index);
                }
                updatedExports.Remove(index);
            }
            if (updatedExports.Intersect(Materials).Count() > 0)
            {
                RefreshMaterialList();
            }
            else
            {
                foreach (var i in updatedExports)
                {
                    string className = Pcc.getExport(i).ClassName;
                    if (className == "MaterialInstanceConstant" || className == "Material")
                    {
                        RefreshMaterialList();
                        break;
                    }
                }
            }
            if (updatedExports.Intersect(Objects).Count() > 0)
            {
                RefreshMeshList();
            }
            else
            {
                foreach (var i in updatedExports)
                {
                    string className = Pcc.getExport(i).ClassName;
                    if (className == "SkeletalMesh" || className == "StaticMesh")
                    {
                        RefreshMeshList();
                        break;
                    }
                }
            }
        }
Exemplo n.º 17
0
 public void LoadSkeletalMesh(int index)
 {
     try
     {
         DisableLODs();
         UnCheckLODs();
         skm              = new SkeletalMesh(pcc as ME3Package, index);
         skmold           = new SkeletalMeshOld(pcc as ME3Package, index);
         hb1.ByteProvider = new DynamicByteProvider(pcc.Exports[index].Data);
         bool foundTex = false;
         try
         {
             for (int i = 0; i < skm.MatInsts.Count; i++)
             {
                 for (int j = 0; j < skm.MatInsts[i].Textures.Count; j++)
                 {
                     if (skm.MatInsts[i].Textures[j].Desc.Contains("Diffuse"))
                     {
                         Preview3D.setTex(skm.MatInsts[i].Textures[j].Texture);
                         foundTex = true;
                         break;
                     }
                 }
             }
         }
         catch
         {
         }
         if (!foundTex)
         {
             Preview3D.setTex();
         }
         Preview3D.StatMesh    = null;
         Preview3D.SkelMesh    = skm;
         Preview3D.CamDistance = skm.Bounding.r * 2.0f;
         Preview3D.CamOffset   = skm.Bounding.origin;
         treeView1.BeginUpdate();
         treeView1.Nodes.Clear();
         treeView1.Nodes.Add(skm.ToTree());
         treeView1.Nodes[0].Expand();
         treeView1.EndUpdate();
         lODToolStripMenuItem.Visible  = true;
         lOD0ToolStripMenuItem.Enabled = true;
         lOD0ToolStripMenuItem.Checked = true;
         if (skm.LODModels.Count > 1)
         {
             lOD1ToolStripMenuItem.Enabled = true;
         }
         if (skm.LODModels.Count > 2)
         {
             lOD2ToolStripMenuItem.Enabled = true;
         }
         if (skm.LODModels.Count > 3)
         {
             lOD3ToolStripMenuItem.Enabled = true;
         }
     }
     catch
     {
         return;
     }
 }
Exemplo n.º 18
0
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode t = treeView1.SelectedNode;

            if (DisplayStyle == 0)
            {
                if (t.Parent == null || t.Name == "")
                {
                    return;
                }
                preview?.Dispose();
                preview = null;
                try
                {
                    if (int.TryParse(t.Name, out int i))
                    {
                        EntryStruct en = Entries[i];
                        if (!en.isDLC)
                        {
                            using (ME3Package pcc = MEPackageHandler.OpenME3Package(ME3Directory.cookedPath + en.Filename))
                            {
                                if (en.isSkeletal)
                                {
                                    SkeletalMesh skmesh = new SkeletalMesh(pcc, en.Index); // TODO: pass device
                                    preview = new ModelPreview(view.Device, skmesh, view.TextureCache);
                                    CenterView();
                                    treeView2.Nodes.Clear();
                                    if (previewWithTreeToolStripMenuItem.Checked)
                                    {
                                        treeView2.Visible = false;
                                        Application.DoEvents();
                                        treeView2.Nodes.Add(skmesh.ToTree());
                                        treeView2.Visible = true;
                                    }
                                }
                                else
                                {
                                }
                            }
                        }
                        else
                        {
                            string loc    = Path.GetDirectoryName(Application.ExecutablePath) + "\\exec\\";
                            string dirDLC = ME3Directory.DLCPath;
                            dirDLC += en.DLCName;
                            dirDLC += "\\CookedPCConsole\\Default.sfar";
                            DLCUnpack dlc = new DLCUnpack(dirDLC);
                            foreach (DLCUnpack.DLCEntry file in dlc.filesList)
                            {
                                try
                                {
                                    string filename = Path.GetFileName(file.filenamePath);
                                    if (Path.GetExtension(filename).ToLower().EndsWith(".pcc") && filename == en.Filename)
                                    {
                                        using (Stream input = File.OpenRead(dirDLC), output = File.Create(loc + filename))
                                        {
                                            dlc.ExtractEntry(file, input, output);
                                        }
                                        if (File.Exists(loc + filename))
                                        {
                                            try
                                            {
                                                if (en.isSkeletal)
                                                {
                                                    using (ME3Package pcc = MEPackageHandler.OpenME3Package(loc + filename))
                                                    {
                                                        SkeletalMesh skmesh = new SkeletalMesh(pcc, en.Index);
                                                        CenterView();
                                                        treeView2.Nodes.Clear();
                                                        if (previewWithTreeToolStripMenuItem.Checked)
                                                        {
                                                            treeView2.Visible = false;
                                                            Application.DoEvents();
                                                            treeView2.Nodes.Add(skmesh.ToTree());
                                                            treeView2.Visible = true;
                                                        }
                                                    }
                                                }
                                            }
                                            catch (Exception)
                                            {
                                            }
                                            File.Delete(loc + filename);
                                        }
                                    }
                                }
                                catch (Exception)
                                {
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
Exemplo n.º 19
0
 ///<summary>Retrieves Bone Pose data for the given Bone Names at the specified Time from the given Animation Sequence</summary>
 public static IReadOnlyCollection <Transform> GetBonePosesForTime(AnimSequence AnimationSequence, byte BoneNames /*TODO: array TArray */, float Time, bool bExtractRootMotion, SkeletalMesh PreviewMesh) =>
 AnimationBlueprintLibrary_methods.GetBonePosesForTime_method.Invoke(AnimationSequence, BoneNames, Time, bExtractRootMotion, PreviewMesh);
Exemplo n.º 20
0
 public SkeletalMeshRenderProxy(SkeletalMesh setSkeletalMesh)
 {
     SkeletalMesh = setSkeletalMesh;
 }
        private static List <SkeletalMesh> LoadMesh(Package packageToSaveIn, Gltf model, List <byte[]> rawBuffers, Mesh mesh)
        {
            List <SkeletalMesh> meshes = new List <SkeletalMesh>();

            for (int p = 0; p < mesh.Primitives.Length; p++)
            {
                var prim = mesh.Primitives[p];

                if (prim.Mode != MeshPrimitive.ModeEnum.TRIANGLES)
                {
                    throw new NotImplementedException("Modes other than TRIANGLES are not implemented (yet)");
                }

                Accessor positionAccessor = GetAccessorByType("POSITION", model, prim);
                if (positionAccessor.Type != Accessor.TypeEnum.VEC3)
                {
                    throw new InvalidDataException("POSITION accessor must have type VEC3");
                }

                Accessor normalAccessor = GetAccessorByType("NORMAL", model, prim);
                if (normalAccessor != null &&
                    normalAccessor.Type != Accessor.TypeEnum.VEC3)
                {
                    throw new InvalidDataException("NORMAL accessor must have type VEC3");
                }

                Accessor texcoordAccessor = GetAccessorByType("TEXCOORD_0", model, prim);
                if (texcoordAccessor != null &&
                    texcoordAccessor.Type != Accessor.TypeEnum.VEC2)
                {
                    throw new InvalidDataException("TEXCOORD accessor must have type VEC2");
                }

                Accessor tangentAccessor = GetAccessorByType("TANGENT", model, prim);
                if (tangentAccessor != null &&
                    tangentAccessor.Type != Accessor.TypeEnum.VEC4)
                {
                    throw new InvalidDataException("TANGENT accessor must have type VEC4");
                }

                Accessor weightsAccessor = GetAccessorByType("WEIGHTS_0", model, prim);
                if (weightsAccessor != null &&
                    weightsAccessor.Type != Accessor.TypeEnum.VEC4)
                {
                    throw new InvalidDataException("WEIGHTS_0 accessor must have type VEC4");
                }

                Accessor jointsAccessor = GetAccessorByType("JOINTS_0", model, prim);
                if (jointsAccessor != null &&
                    jointsAccessor.Type != Accessor.TypeEnum.VEC4)
                {
                    throw new InvalidDataException("JOINTS_0 accessor must have type VEC4");
                }

                SkinnedTangentVertex[] vertices           = new SkinnedTangentVertex[positionAccessor.Count];
                BufferView             positionBufferView = model.BufferViews[positionAccessor.BufferView.Value];
                BufferView             normalsBufferView  = null;
                if (normalAccessor != null)
                {
                    normalsBufferView = model.BufferViews[normalAccessor.BufferView.Value];
                }
                BufferView texCoordBufferView = null;
                if (texcoordAccessor != null)
                {
                    texCoordBufferView = model.BufferViews[texcoordAccessor.BufferView.Value];
                }
                BufferView tangentBufferView = null;
                if (tangentAccessor != null)
                {
                    tangentBufferView = model.BufferViews[tangentAccessor.BufferView.Value];
                }
                BufferView weightsBufferView = null;
                if (weightsAccessor != null)
                {
                    weightsBufferView = model.BufferViews[weightsAccessor.BufferView.Value];
                }
                BufferView jointsBufferView = null;
                if (jointsAccessor != null)
                {
                    jointsBufferView = model.BufferViews[jointsAccessor.BufferView.Value];
                }

                ReadOnlySpan <Vector3> positionSpan = MemoryMarshal.Cast <byte, Vector3>(
                    new ReadOnlySpan <byte>(rawBuffers[positionBufferView.Buffer], positionBufferView.ByteOffset + positionAccessor.ByteOffset, positionAccessor.Count * 12));
                ReadOnlySpan <Vector3> normalsSpan = null;
                if (normalsBufferView != null)
                {
                    normalsSpan = MemoryMarshal.Cast <byte, Vector3>(
                        new ReadOnlySpan <byte>(rawBuffers[normalsBufferView.Buffer], normalsBufferView.ByteOffset + normalAccessor.ByteOffset, normalAccessor.Count * 12));
                }
                ReadOnlySpan <Vector2> texCoordSpan = null;
                if (texCoordBufferView != null)
                {
                    texCoordSpan = MemoryMarshal.Cast <byte, Vector2>(
                        new ReadOnlySpan <byte>(rawBuffers[texCoordBufferView.Buffer], texCoordBufferView.ByteOffset + texcoordAccessor.ByteOffset, texcoordAccessor.Count * 8));
                }
                ReadOnlySpan <Vector4> tangentSpan = null;
                if (tangentBufferView != null)
                {
                    tangentSpan = MemoryMarshal.Cast <byte, Vector4>(
                        new ReadOnlySpan <byte>(rawBuffers[tangentBufferView.Buffer], tangentBufferView.ByteOffset + tangentAccessor.ByteOffset, tangentAccessor.Count * 16));
                }
                ReadOnlySpan <Vector4> weightsSpan = null;
                if (weightsBufferView != null)
                {
                    weightsSpan = MemoryMarshal.Cast <byte, Vector4>(
                        new ReadOnlySpan <byte>(rawBuffers[weightsBufferView.Buffer], weightsBufferView.ByteOffset + weightsAccessor.ByteOffset, weightsAccessor.Count * 16));
                }
                ReadOnlySpan <Vector4> jointsSpan = null;
                if (jointsBufferView != null)
                {
                    jointsSpan = MemoryMarshal.Cast <byte, Vector4>(
                        new ReadOnlySpan <byte>(rawBuffers[jointsBufferView.Buffer], jointsBufferView.ByteOffset + jointsAccessor.ByteOffset, jointsAccessor.Count * 16));
                }

                for (int v = 0; v < vertices.Length; v++)
                {
                    vertices[v].Position = positionSpan[v];

                    if (normalsSpan != null)
                    {
                        vertices[v].Normal = normalsSpan[v];
                    }

                    if (texCoordSpan != null)
                    {
                        vertices[v].TexCoord = texCoordSpan[v];
                    }

                    if (tangentSpan != null)
                    {
                        vertices[v].Tangent = new Vector3(tangentSpan[v].X, tangentSpan[v].Y, tangentSpan[v].Z);
                        if (normalsSpan != null)
                        {
                            vertices[v].BiTangent = Vector3.Cross(normalsSpan[v], vertices[v].Tangent) * tangentSpan[v].W;
                        }
                    }
                }

                SkeletalMesh skeletalMesh = new SkeletalMesh();

                if (prim.Indices == null)
                {
                    skeletalMesh = SkeletalMesh.FromVertices(vertices);
                }
                else
                {
                    int      primIndex     = prim.Indices.Value;
                    Accessor indexAccessor = GetAccessorByIndex(primIndex, model);
                    if (indexAccessor != null)
                    {
                        if (indexAccessor.Type != Accessor.TypeEnum.SCALAR)
                        {
                            throw new InvalidDataException("Index accessor must have type SCALAR");
                        }

                        uint[] indices = new uint[indexAccessor.Count];

                        BufferView indexBufferView = model.BufferViews[indexAccessor.BufferView.Value];
                        switch (indexAccessor.ComponentType)
                        {
                        case Accessor.ComponentTypeEnum.UNSIGNED_BYTE:
                        {
                            ReadOnlySpan <byte> indexSpan =
                                new ReadOnlySpan <byte>(rawBuffers[indexBufferView.Buffer], indexBufferView.ByteOffset + indexAccessor.ByteOffset, indexAccessor.Count);

                            for (int idx = 0; idx < indices.Length; idx++)
                            {
                                indices[idx] = (uint)indexSpan[idx];
                            }
                        }
                        break;

                        case Accessor.ComponentTypeEnum.UNSIGNED_SHORT:
                        {
                            ReadOnlySpan <ushort> indexSpan = MemoryMarshal.Cast <byte, ushort>(
                                new ReadOnlySpan <byte>(rawBuffers[indexBufferView.Buffer], indexBufferView.ByteOffset + indexAccessor.ByteOffset, indexAccessor.Count * 2));

                            for (int idx = 0; idx < indices.Length; idx++)
                            {
                                indices[idx] = (uint)indexSpan[idx];
                            }
                        }
                        break;

                        case Accessor.ComponentTypeEnum.UNSIGNED_INT:
                        {
                            ReadOnlySpan <uint> indexSpan = MemoryMarshal.Cast <byte, uint>(
                                new ReadOnlySpan <byte>(rawBuffers[indexBufferView.Buffer], indexBufferView.ByteOffset + indexAccessor.ByteOffset, indexAccessor.Count * 4));

                            indices = indexSpan.ToArray();
                        }
                        break;

                        default:
                            throw new NotImplementedException("ComponentType " + indexAccessor.ComponentType + " not implemented.");
                        }

                        skeletalMesh = SkeletalMesh.FromVertices(vertices, indices);
                    }
                }

                skeletalMesh.Name = mesh.Name + "_" + p + ".skeletalMesh";
                packageToSaveIn.StoreAsset(skeletalMesh);
                meshes.Add(skeletalMesh);

                Materials.Material material = CreateMaterialForMesh(prim, model);
                skeletalMesh.Material = material;
            }

            return(meshes);
        }