Ejemplo n.º 1
0
        unsafe void Init(CollisionFilter filter, Material material)
        {
            m_Header.CollisionType = CollisionType.Convex;
            m_Header.Version       = 0;
            m_Header.Magic         = 0xff;
            m_Header.Filter        = filter;
            m_Header.Material      = material;

            ConvexHull.ConvexRadius = 0.0f;

            fixed(PolygonCollider *collider = &this)
            {
                ConvexHull.VerticesBlob.Offset = UnsafeEx.CalculateOffset(ref collider->m_Vertices[0], ref ConvexHull.VerticesBlob);
                ConvexHull.VerticesBlob.Length = 4;

                ConvexHull.FacePlanesBlob.Offset = UnsafeEx.CalculateOffset(ref collider->m_FacePlanes[0], ref ConvexHull.FacePlanesBlob);
                ConvexHull.FacePlanesBlob.Length = 2;

                ConvexHull.FacesBlob.Offset = UnsafeEx.CalculateOffset(ref collider->m_Faces[0], ref ConvexHull.FacesBlob);
                ConvexHull.FacesBlob.Length = 2;

                ConvexHull.FaceVertexIndicesBlob.Offset = UnsafeEx.CalculateOffset(ref collider->m_FaceVertexIndices[0], ref ConvexHull.FaceVertexIndicesBlob);
                ConvexHull.FaceVertexIndicesBlob.Length = 8;

                // No connectivity needed
                ConvexHull.VertexEdgesBlob.Offset = 0;
                ConvexHull.VertexEdgesBlob.Length = 0;
                ConvexHull.FaceLinksBlob.Offset   = 0;
                ConvexHull.FaceLinksBlob.Length   = 0;
            }
        }
Ejemplo n.º 2
0
        // Create a joint asset with the given constraints
        public static unsafe BlobAssetReference <JointData> Create(MTransform aFromJoint, MTransform bFromJoint, Constraint[] constraints)
        {
            // Allocate
            int        totalSize = sizeof(JointData) + sizeof(Constraint) * constraints.Length;
            JointData *jointData = (JointData *)UnsafeUtility.Malloc(totalSize, 16, Allocator.Temp);

            UnsafeUtility.MemClear(jointData, totalSize);

            // Initialize
            {
                jointData->AFromJoint = aFromJoint;
                jointData->BFromJoint = bFromJoint;
                jointData->Version    = 1;

                byte *end = (byte *)jointData + sizeof(JointData);
                jointData->m_ConstraintsBlob.Offset = UnsafeEx.CalculateOffset(end, ref jointData->m_ConstraintsBlob);
                jointData->m_ConstraintsBlob.Length = constraints.Length;

                for (int i = 0; i < constraints.Length; i++)
                {
                    jointData->Constraints[i] = constraints[i];
                }
            }

            var blob = BlobAssetReference <JointData> .Create(jointData, totalSize);

            UnsafeUtility.Free(jointData, Allocator.Temp);

            return(blob);
        }