//-------------------------------------------------------------------------
    /// Copy Constructor - creates a deep copy of the src object.
    public ColliderGenTK2DParametersForSprite(ColliderGenTK2DParametersForSprite src)
    {
        mSpriteIndex = src.mSpriteIndex;

        mOutlineVertexCount = src.mOutlineVertexCount;
        // other old unused parameters skipped.

        // deep copy of the following two member variables
        if (src.mRegionIndependentParameters != null)
        {
            mRegionIndependentParameters = new RegionIndependentParametersTK2D(src.mRegionIndependentParameters);
        }
        else
        {
            mRegionIndependentParameters = null;
        }

        if (src.mColliderRegionParameters != null)
        {
            mColliderRegionParameters = new ColliderRegionParametersTK2D[src.mColliderRegionParameters.Length];
            for (int index = 0; index < src.mColliderRegionParameters.Length; ++index)
            {
                mColliderRegionParameters[index] = new ColliderRegionParametersTK2D(src.mColliderRegionParameters[index]);
            }
        }
        else
        {
            src.mColliderRegionParameters = null;
        }

        mVersionID = src.mVersionID;
    }
    //-------------------------------------------------------------------------
    /// Copy Constructor - creates a deep copy of the src object.
    public ColliderGenTK2DParametersForSprite(ColliderGenTK2DParametersForSprite src)
    {
        mSpriteIndex = src.mSpriteIndex;

        mOutlineVertexCount = src.mOutlineVertexCount;
        // other old unused parameters skipped.

        // deep copy of the following two member variables
        if (src.mRegionIndependentParameters != null) {
            mRegionIndependentParameters = new RegionIndependentParametersTK2D(src.mRegionIndependentParameters);
        }
        else {
            mRegionIndependentParameters = null;
        }

        if (src.mColliderRegionParameters != null) {
            mColliderRegionParameters = new ColliderRegionParametersTK2D[src.mColliderRegionParameters.Length];
            for (int index = 0; index < src.mColliderRegionParameters.Length; ++index) {
                mColliderRegionParameters[index] = new ColliderRegionParametersTK2D(src.mColliderRegionParameters[index]);
            }
        }
        else {
            src.mColliderRegionParameters = null;
        }

        mVersionID = src.mVersionID;
    }
Exemplo n.º 3
0
    //-------------------------------------------------------------------------
    public static void CalculateUnreducedOutlineForAllColliderRegions(ref ColliderRegionData[] colliderRegions, ref PolygonOutlineFromImageFrontend outlineAlgorithm,
                                                                      RegionIndependentParametersTK2D regionIndependentParameters,
                                                                      ColliderRegionParametersTK2D[] colliderRegionParameters,
                                                                      bool[] binaryImage, int binaryImageWidth, int binaryImageHeight,
                                                                      bool ccwVertexOrder)
    {
        Vector3 customOffset = regionIndependentParameters.CustomOffset;
        Vector3 customScale  = regionIndependentParameters.CustomScale;

        for (int count = 0; count < colliderRegions.Length; ++count)
        {
            if (colliderRegionParameters[count].EnableRegion)
            {
                // Calculate polygon bounds
                outlineAlgorithm.VertexReductionDistanceTolerance = regionIndependentParameters.VertexReductionDistanceTolerance;
                outlineAlgorithm.MaxPointCount = colliderRegionParameters[count].MaxPointCount;

                // TODO: replace this with a joint-convex hull implementation, just a workaround for now.
                bool allRegionsConvex = regionIndependentParameters.Convex;
                outlineAlgorithm.Convex = allRegionsConvex ? true : colliderRegionParameters[count].Convex;
                //outlineAlgorithm.Convex = colliderRegionParameters[count].Convex;

                outlineAlgorithm.XOffsetNormalized = 0.0f + customOffset.x + (0.5f - (0.5f * customScale.x));
                outlineAlgorithm.YOffsetNormalized = 1.0f - customOffset.y - (0.5f - (0.5f * customScale.y));
                outlineAlgorithm.XScale            = 1.0f * customScale.x;
                outlineAlgorithm.YScale            = -1.0f * customScale.y;
                bool outputVerticesInNormalizedSpace = false;

                bool regionVertexOrder = ccwVertexOrder;
                if (!colliderRegions[count].mRegionIsIsland)
                {
                    regionVertexOrder = !regionVertexOrder;
                }

                colliderRegions[count].mOutlineVertexOrderIsCCW = regionVertexOrder;
                outlineAlgorithm.UnreducedOutlineFromBinaryImage(ref colliderRegions[count].mIntermediateOutlineVertices, binaryImage, binaryImageWidth, binaryImageHeight, colliderRegions[count].mDetectedRegion.mPointAtBorder, colliderRegions[count].mRegionIsIsland, outputVerticesInNormalizedSpace, regionVertexOrder);
            }
            else
            {
                colliderRegions[count].mIntermediateOutlineVertices = null;
                colliderRegions[count].mResultVertices        = null;
                colliderRegions[count].mResultTriangleIndices = null;
            }
        }
    }
    //-------------------------------------------------------------------------
    public static int ReduceOutlineForAllColliderRegions(ref ColliderRegionData[] colliderRegions, ref PolygonOutlineFromImageFrontend outlineAlgorithm,
                                                         RegionIndependentParametersTK2D regionIndependentParameters,
                                                         ColliderRegionParametersTK2D[] colliderRegionParameters)
    {
        int numRegionsWithData = 0;

        if (colliderRegions == null || colliderRegions.Length == 0 || outlineAlgorithm == null)
        {
            Debug.LogError("Error: Unexpected state in ReduceOutlineForAllColliderRegions(): colliderRegions is empty or null or outlineAlgorithm is null!");
            return(0);
        }

        for (int count = 0; count < colliderRegions.Length; ++count)
        {
            if (colliderRegions[count].mIntermediateOutlineVertices == null)
            {
                colliderRegions[count].mResultVertices        = null;
                colliderRegions[count].mResultTriangleIndices = null;
                continue;
            }
            if (colliderRegions[count].mReducedOutlineVertices != null && !colliderRegionParameters[count].RegionUpdateCalculationNeeded)
            {
                continue;
            }

            outlineAlgorithm.VertexReductionDistanceTolerance = regionIndependentParameters.VertexReductionDistanceTolerance;
            outlineAlgorithm.MaxPointCount = colliderRegionParameters[count].MaxPointCount;
            // TODO: replace this with a joint-convex hull implementation, just a workaround for now.
            bool allRegionsConvex = regionIndependentParameters.Convex;
            outlineAlgorithm.Convex = allRegionsConvex ? true : colliderRegionParameters[count].Convex;

            colliderRegions[count].mReducedOutlineVertices = outlineAlgorithm.ReduceOutline(colliderRegions[count].mIntermediateOutlineVertices, colliderRegions[count].mOutlineVertexOrderIsCCW);
            colliderRegionParameters[count].RegionUpdateCalculationNeeded = false;
            ++numRegionsWithData;
        }
        return(numRegionsWithData);
    }
Exemplo n.º 5
0
	//-------------------------------------------------------------------------
	public static int ReduceOutlineForAllColliderRegions(ref ColliderRegionData[] colliderRegions, ref PolygonOutlineFromImageFrontend outlineAlgorithm,
														  RegionIndependentParametersTK2D regionIndependentParameters,
														  ColliderRegionParametersTK2D[] colliderRegionParameters) {
		
		int numRegionsWithData = 0;
		if (colliderRegions == null || colliderRegions.Length == 0 || outlineAlgorithm == null) {
			Debug.LogError("Error: Unexpected state in ReduceOutlineForAllColliderRegions(): colliderRegions is empty or null or outlineAlgorithm is null!");
			return 0;
		}
		
		for (int count = 0; count < colliderRegions.Length; ++count) {
			
			if (colliderRegions[count].mIntermediateOutlineVertices == null) {
				colliderRegions[count].mResultVertices = null;
				colliderRegions[count].mResultTriangleIndices = null;
				continue;
			}
			if (colliderRegions[count].mReducedOutlineVertices != null && !colliderRegionParameters[count].RegionUpdateCalculationNeeded) {
				continue;
			}
			
			outlineAlgorithm.VertexReductionDistanceTolerance = regionIndependentParameters.VertexReductionDistanceTolerance;
			outlineAlgorithm.MaxPointCount = colliderRegionParameters[count].MaxPointCount;
			// TODO: replace this with a joint-convex hull implementation, just a workaround for now.
			bool allRegionsConvex = regionIndependentParameters.Convex;
			outlineAlgorithm.Convex = allRegionsConvex ? true : colliderRegionParameters[count].Convex;
			
			colliderRegions[count].mReducedOutlineVertices = outlineAlgorithm.ReduceOutline(colliderRegions[count].mIntermediateOutlineVertices, colliderRegions[count].mOutlineVertexOrderIsCCW);
			colliderRegionParameters[count].RegionUpdateCalculationNeeded = false;
			++numRegionsWithData;
		}
		return numRegionsWithData;
	}
Exemplo n.º 6
0
	//-------------------------------------------------------------------------
	public static void CalculateUnreducedOutlineForAllColliderRegions(ref ColliderRegionData[] colliderRegions, ref PolygonOutlineFromImageFrontend outlineAlgorithm,
																	  RegionIndependentParametersTK2D regionIndependentParameters,
																	  ColliderRegionParametersTK2D[] colliderRegionParameters, bool [,] binaryImage,
																	  bool ccwVertexOrder) {
		
		Vector3 customOffset = regionIndependentParameters.CustomOffset;
		Vector3 customScale = regionIndependentParameters.CustomScale;
		
		for (int count = 0; count < colliderRegions.Length; ++count) {
        
			if (colliderRegionParameters[count].EnableRegion) {
				// Calculate polygon bounds
	            outlineAlgorithm.VertexReductionDistanceTolerance = regionIndependentParameters.VertexReductionDistanceTolerance;
			    outlineAlgorithm.MaxPointCount = colliderRegionParameters[count].MaxPointCount;
				
				// TODO: replace this with a joint-convex hull implementation, just a workaround for now.
				bool allRegionsConvex = regionIndependentParameters.Convex;
				outlineAlgorithm.Convex = allRegionsConvex ? true : colliderRegionParameters[count].Convex;
			    //outlineAlgorithm.Convex = colliderRegionParameters[count].Convex;
			    
				outlineAlgorithm.XOffsetNormalized = 0.0f + customOffset.x + (0.5f - (0.5f * customScale.x));
	            outlineAlgorithm.YOffsetNormalized = 1.0f - customOffset.y - (0.5f - (0.5f * customScale.y));
				outlineAlgorithm.XScale = 1.0f * customScale.x;
	            outlineAlgorithm.YScale = -1.0f * customScale.y;
			    bool outputVerticesInNormalizedSpace = false;
				
				bool regionVertexOrder = ccwVertexOrder;
				if (!colliderRegions[count].mRegionIsIsland) {
					regionVertexOrder = !regionVertexOrder;
				}
	
				colliderRegions[count].mOutlineVertexOrderIsCCW = regionVertexOrder;
	            outlineAlgorithm.UnreducedOutlineFromBinaryImage(out colliderRegions[count].mIntermediateOutlineVertices, binaryImage, colliderRegions[count].mDetectedRegion.mPointAtBorder, colliderRegions[count].mRegionIsIsland, outputVerticesInNormalizedSpace, regionVertexOrder);
			}
			else {
				colliderRegions[count].mIntermediateOutlineVertices = null;
				colliderRegions[count].mResultVertices = null;
				colliderRegions[count].mResultTriangleIndices = null;
			}
        }
	}
 // Deep-copy constructor.
 public RegionIndependentParametersTK2D(RegionIndependentParametersTK2D src) : base(src)
 {
 }