public void SetBoneData(UniformBuffer bonesBuffer, ref int offset)
 {
     for (int i = 0; i < starts.Count; i++)
     {
         starts[i].Update(Matrix4x4.Identity);
     }
     for (int i = 0; i < boneMatrices.Length; i++)
     {
         if (instanceArray[i] != null)
         {
             boneMatrices[i] = instanceArray[i].BoneMatrix;
         }
     }
     BufferOffset = offset;
     bonesBuffer.SetData(boneMatrices, offset);
     offset += boneMatrices.Length;
 }
Esempio n. 2
0
        public CharacterSkinning(DfmFile dfm)
        {
            this.dfm = dfm;
            int length = (dfm.Parts.Keys.Max() + 1);

            boneMatrices  = new Matrix4[length];
            instanceArray = new BoneInstance[length];

            foreach (var kv in dfm.Parts)
            {
                var inst = new BoneInstance();
                inst.Name             = kv.Value.objectName;
                inst.InvBindPose      = kv.Value.Bone.BoneToRoot.Inverted();
                instanceArray[kv.Key] = inst;
                boneInstances.Add(inst.Name, inst);
            }

            foreach (var con in dfm.Constructs.Constructs)
            {
                if (!boneInstances.ContainsKey(con.ChildName))
                {
                    continue;
                }
                var inst = boneInstances[con.ChildName];
                if (!string.IsNullOrEmpty(con.ParentName))
                {
                    var parent = boneInstances[con.ParentName];
                    inst.Parent = parent;
                }

                inst.OriginalRotation = con.Rotation;
                inst.Origin           = con.Origin;
            }
            for (int j = 0; j < boneMatrices.Length; j++)
            {
                boneMatrices[j] = Matrix4.Identity;
            }
            BonesBuffer = new UniformBuffer(200, 64, typeof(Matrix4));
            BonesBuffer.SetData(boneMatrices);
        }
Esempio n. 3
0
 public CommandBuffer()
 {
     //TODO: This needs to be managed a lot better, leaks memory right now
     BonesBuffer = new UniformBuffer(800, 64, typeof(Matrix4x4));
     WorldBuffer = new WorldMatrixBuffer();
 }