コード例 #1
0
    def findBestPatternDynamic(self, curPoint, nextPoint, setClass, prim, patternCrack, tbn, tbnInverse, pointWhichIsRelative, texture, texturePrim):
        '''
        Get the best dynamic pattern
        
        @param curPoint:
        @type curPoint:
        @param nextPoint:
        @type nextPoint:
        @param setClass:
        @type setClass:
        @param prim:
        @type prim:
        @param patternCrack:
        @type patternCrack:
        @param tbn:
        @type tbn:
        @param tbnInverse:
        @type tbnInverse:
        @param pointWhichIsRelative:
        @type pointWhichIsRelative:
        @param texture:
        @type texture:
        @param texturePrim:
        @type texturePrim:
        '''
        logging.debug('Class AutoPattern, method findBestPatternDinamically')
        logging.debug('cur_point: ' + str(curPoint) + "next_point: " + str(nextPoint))

        # Direction of the crack
        vector = GeoMath.vecSub(nextPoint, curPoint)
        vector_rotated = tbnInverse.mulPoint3ToMatrix3(vector)
        logging.debug("vector_rotated: " + str(vector_rotated))
        # Number of attemps to try to find a good pattern
        attempts = 2
        # Get a pattern generated dynamically
        # TODO: wavelength now only 0, but it can be any number
        wavelenght = 0
        first_point = [0, 0, 0]
        # Calculate normal of pattern
        direction = GeoMath.vecNormalize(GeoMath.vecSub(vector_rotated, first_point))
        normal_of_pattern = GeoMath.vecCrossProduct(list(prim.normal()), direction)
        pattern = setClass.getRandomPattern(wavelenght, first_point, vector_rotated, normal_of_pattern)
        validatedPattern = self.validateAndAdjustPatterns(curPoint, nextPoint, setClass, prim, patternCrack, tbn, pointWhichIsRelative, texture, texturePrim, pattern)

        if(not validatedPattern):
            # Try 10 times variing random offset(seed) in the noise function to get a valid pattern
            for _ in range(attempts):
                pattern = setClass.getRandomPattern(wavelenght, first_point, vector_rotated, normal_of_pattern)
                validatedPattern = self.validateAndAdjustPatterns(curPoint, nextPoint, setClass, prim, patternCrack, tbn, pointWhichIsRelative, texture, texturePrim, pattern)
                if(validatedPattern):
                    break

        if(not validatedPattern):
            # Try "attemps" times varying the random offset(seed) of the noise funcion and do the height little to
            # increase posibilities to get a valid pattern
            height = setClass.getSizey() / 2
            reduction_height = 2
            for _ in range(attempts):
                pattern = setClass.getRandomPattern(wavelenght, first_point, vector_rotated, normal_of_pattern, height)

                validatedPattern = self.validateAndAdjustPatterns(curPoint, nextPoint, setClass, prim, patternCrack, tbn, pointWhichIsRelative, texture, texturePrim, pattern)
                # Make the height half, for get more possibilities to do a good pattern
                height = height / reduction_height
                if(validatedPattern):
                    break
        if(not validatedPattern):
            # Apply the joker pattern!
            vecH, vecV = DetermineVectors.DetermineVectors.detVec(prim, GeoMath.vecSub(nextPoint, curPoint), [0, 0, 1])
            validatedPattern = setClass.applyJoker(curPoint, nextPoint, vecH, vecV)
            logging.debug("End method finBestPatternDynamic, class Autopattern. State: Joker applied")
        else:
            logging.debug("End method finBestPatternDynamic, class Autopattern. State: good")

        return validatedPattern