Exemplo n.º 1
0
        public static unsafe BlobAssetReference <Collider> CreateQuad(float3 vertex0, float3 vertex1, float3 vertex2, float3 vertex3, CollisionFilter filter, Material material)
        {
            SafetyChecks.CheckFiniteAndThrow(vertex0, nameof(vertex0));
            SafetyChecks.CheckFiniteAndThrow(vertex1, nameof(vertex1));
            SafetyChecks.CheckFiniteAndThrow(vertex2, nameof(vertex2));
            SafetyChecks.CheckFiniteAndThrow(vertex3, nameof(vertex3));
            SafetyChecks.CheckCoplanarAndThrow(vertex0, vertex1, vertex2, vertex3, nameof(vertex3));

            PolygonCollider collider = default;

            collider.InitAsQuad(vertex0, vertex1, vertex2, vertex3, filter, material);
            return(BlobAssetReference <Collider> .Create(&collider, UnsafeUtility.SizeOf <PolygonCollider>()));
        }
Exemplo n.º 2
0
        public static unsafe BlobAssetReference <Collider> CreateQuad(float3 vertex0, float3 vertex1, float3 vertex2, float3 vertex3, CollisionFilter filter, Material material)
        {
            if (math.any(!math.isfinite(vertex0)) || math.any(!math.isfinite(vertex1)) || math.any(!math.isfinite(vertex2)) || math.any(!math.isfinite(vertex3)))
            {
                throw new ArgumentException("Tried to create triangle collider with nan/inf vertex");
            }

            // check if vertices are co-planar
            float3 normal = math.normalize(math.cross(vertex1 - vertex0, vertex2 - vertex0));

            if (math.abs(math.dot(normal, vertex3 - vertex0)) > 1e-3f)
            {
                throw new ArgumentException("Vertices for quad creation are not co-planar");
            }

            PolygonCollider collider = default;

            collider.InitAsQuad(vertex0, vertex1, vertex2, vertex3, filter, material);
            return(BlobAssetReference <Collider> .Create(&collider, UnsafeUtility.SizeOf <PolygonCollider>()));
        }