示例#1
0
文件: Bone.cs 项目: Deus0/zoxel
        public float3 GetInfluenceOffset()
        {
            float3 midPoint        = (GetInfluenceSizeBase() / 2f);
            float3 influenceOffset = (influenceMax.ToFloat3() / 32f - midPoint);

            return(influenceOffset);
        }
示例#2
0
        public void SetBones(EntityManager EntityManager, Entity skeleton, int3[] bodyPositions, VoxData[] voxes, int3[] positions, int[] parents, byte[] axes)
        {
            Dispose(EntityManager);
            List <Entity> boneList         = new List <Entity>();
            float3        skeletonPosition = EntityManager.GetComponentData <Translation>(skeleton).Value;

            if (boneArchtype.Valid == false)
            {
                boneArchtype = EntityManager.CreateArchetype(
                    typeof(Parent),
                    typeof(LocalToParent),
                    typeof(LocalToWorld),
                    typeof(Translation),
                    typeof(Rotation),
                    typeof(NonUniformScale),
                    typeof(Bone)
                    );
            }
            float3     totalSize = size.ToFloat3() / 32f;
            Quaternion rot2      = Quaternion.Euler(0, 180, 0);
            quaternion rot3      = rot2;

            for (int i = 0; i < positions.Length; i++)
            {
                Entity bone     = EntityManager.CreateEntity(boneArchtype);
                float3 position = positions[i].ToFloat3() / 32f;
                position -= totalSize / 2f;
                position  = math.rotate(rot3, position);
                var  vox           = voxes[i];
                int3 halfSize      = new int3((vox.size.x / 2), (vox.size.y / 2), (vox.size.z / 2));
                int3 minusHalfSize = new int3(-vox.size.x / 2, -vox.size.y / 2, -vox.size.z / 2);
                int3 bodyMidpoint  = bodyPositions[i] + halfSize;
                int3 boneOffset    = bodyMidpoint - positions[i];
                //minusHalfSize = new int3(minusHalfSize.x - (vox.size.x % 2), minusHalfSize.y, minusHalfSize.z - (vox.size.z % 2));
                //halfSize = new int3(halfSize.x + 1, halfSize.y + 1, halfSize.z + 1);
                //minusHalfSize = new int3(minusHalfSize.x - 1, minusHalfSize.y - 1, minusHalfSize.z - 1);
                //halfSize = new int3(halfSize.x + 1, halfSize.y, halfSize.z + 1);
                if ((SlotAxis)axes[i] == SlotAxis.Left || (SlotAxis)axes[i] == SlotAxis.Right)
                {
                    boneOffset = new int3(-boneOffset.x, -boneOffset.y, -boneOffset.z);
                    //minusHalfSize.x--;
                }
                minusHalfSize.x -= (vox.size.x % 2);
                //boneOffset.x -=  (vox.size.x % 2);
                Bone newBone = new Bone
                {
                    position     = position,
                    skeleton     = skeleton,
                    influenceMin = (boneOffset + minusHalfSize),
                    influenceMax = (boneOffset + halfSize)
                };
                EntityManager.SetComponentData(bone, newBone);
                EntityManager.SetComponentData(bone, new Parent {
                    Value = skeleton
                });
                EntityManager.SetComponentData(bone, new Translation {
                    Value = position
                });
                EntityManager.SetComponentData(bone, new Rotation {
                    Value = quaternion.identity
                });
                EntityManager.SetComponentData(bone, new NonUniformScale {
                    Value = new float3(1, 1, 1)
                });
                boneList.Add(bone);
            }
            bones = new BlitableArray <Entity>(boneList.Count, Unity.Collections.Allocator.Persistent);
            for (int i = 0; i < bones.Length; i++)
            {
                bones[i] = boneList[i];
            }
            if (Bootstrap.instance.isAddAnimations)
            {
                AddAnimations(EntityManager);
            }
        }