def intersect_bounding_box_3D(self, bounding_box, DISPLAY=False):
        try:
            if not self.get_prim():
                raise Errors.CantBeNoneError("Prim cant be none", "We need a prim to calculate tbn some steps after")
        except Errors.CantBeNoneError as e:
            Errors.Error.display_exception(e)
            exit()

        if not self.get_points_tangent_space():
            self.create_3D_to_2D_rectangle(self.get_prim())
        this_point_relative = self.get_tbn_class().get_point_which_is_relative()
        this_tbn_inverse_matrix = self.get_tbn_class().get_tbn_inverse()
        param_bounding_box_points_in_this_tangent_space = []
        for point in bounding_box.get_rectangle_object_space():
            point_relative = GeoMath.vecSub(point, this_point_relative)
            this_tbn_inverse_matrix.printAttributes()
            point_tangent_space = this_tbn_inverse_matrix.mulPoint3ToMatrix3(point_relative)
            param_bounding_box_points_in_this_tangent_space.append(point_tangent_space)
        intersections = GeoMath.getIntersectionsBetweenEdges2D(
            GeoMath.getEdgesFromPoints(self.get_rectangle_tangent_space()),
            GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space),
        )
        if DISPLAY:
            # TEMP: exit
            1 / 0
            exit()
            for intersection in intersections:
                this_tbn_matrix = self.get_tbn_class().get_tbn()
                point_object_space = this_tbn_matrix.mulPoint3ToMatrix3(intersection)
                point_absolute = GeoMath.vecPlus(point_object_space, this_point_relative)
                self.to_display_intersections.append(point_absolute)
            self.display_intersections()
        return intersections
示例#2
0
    def intersections_with_crack(self, crack, path_ordered):
        reload(GeoMath)
        intersections = []
        edges_floor = GeoMath.getEdgesFromPoints(self.get_absolute_points())
        prev_intersection = None
        next_intersection = None
        #=======================================================================
        # we group the intersections in pairs, because after we'll have a different
        # destruction in the floor for each pair of intersection
        #=======================================================================

        for infoPrim in path_ordered:
            patterns = crack[infoPrim.getPrim()]
            for pattern in patterns:
                pattern_edges = GeoMath.getEdgesFromPoints(pattern.getPoints())
                may_intersect, pattern_edge_inter, floor_edge_inter = GeoMath.bolzanoIntersectionEdges2_5D(
                    pattern_edges, edges_floor)
                if (may_intersect):
                    # FIXME: HACK: we take one point of the pattern edge and put the y of the floor.
                    # We are assuming the edge is perpendicular to the floor.
                    # TEMP:
                    point_intersection = [
                        pattern_edge_inter[0][0], floor_edge_inter[0][1],
                        pattern_edge_inter[0][2]
                    ]
                    logging.debug("Intersection bef" + str(point_intersection))
                    logging.debug("fllor_edge_inter " + str(floor_edge_inter))
                    #point2DToProjectOntoXZ = [point_intersection[0], 0, point_intersection[2]]
                    #floorEdge2DToCalculateProjectionOntoXZ = [[floor_edge_inter[0][0],0 , floor_edge_inter[0][2]], [floor_edge_inter[1][0], 0, floor_edge_inter[1][2]]]

                    #point_intersection = GeoMath.getPointProjectionOnLine(floorEdge2DToCalculateProjectionOntoXZ, point2DToProjectOntoXZ)
                    #point_intersection = [point_intersection[0], floor_edge_inter[0][1], point_intersection[2]]

                    logging.debug("Intersection " + str(point_intersection))

                    if (not prev_intersection):
                        prev_intersection = point_intersection
                        break
                    elif (not GeoMath.pointEqualPoint(point_intersection,
                                                      prev_intersection)):
                        next_intersection = point_intersection
                        new_intersection = [
                            prev_intersection, next_intersection
                        ]
                        intersections.append(new_intersection)
                        prev_intersection = None
                        next_intersection = None
                        break
        return intersections
示例#3
0
    def intersect_bounding_box_with_limits_3D(self,
                                              bounding_box,
                                              DISPLAY=False):
        try:
            if (not self.get_prim()):
                raise Errors.CantBeNoneError(
                    'Prim cant be none',
                    'We need a prim to calculate tbn some steps after')
        except Errors.CantBeNoneError as e:
            Errors.Error.display_exception(e)
            exit()

        if (not self.get_points_tangent_space()):
            self.convert_3D_to_2D(self.get_prim())
        this_point_relative = self.get_tbn_class().get_point_which_is_relative(
        )
        this_tbn_inverse_matrix = self.get_tbn_class().get_tbn_inverse()
        param_bounding_box_points_in_this_tangent_space = []
        for point in bounding_box.get_rectangle_object_space():
            point_relative = GeoMath.vecSub(point, this_point_relative)
            point_tangent_space = this_tbn_inverse_matrix.mulPoint3ToMatrix3(
                point_relative)
            param_bounding_box_points_in_this_tangent_space.append(
                point_tangent_space)
        intersections = GeoMath.getIntersectionsBetweenEdges2D(self.get_edges_tangent_space(), \
                       GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space))

        #=======================================================================
        # work in object space because we only has to know if the bounding boxes
        # share some edge between
        #=======================================================================
        edges_shared_between_bounding_boxes = \
        GeoMath.getEdgesBetweenEdges(self.get_edges_tangent_space(), \
        GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space))

        if (DISPLAY):
            # TEMP: exit
            1 / 0
            exit()
            for intersection in intersections:
                this_tbn_matrix = self.get_tbn_class().get_tbn()
                point_object_space = this_tbn_matrix.mulPoint3ToMatrix3(
                    intersection)
                point_absolute = GeoMath.vecPlus(point_object_space,
                                                 this_point_relative)
                self.to_display_intersections.append(point_absolute)
            self.display_intersections()
        return intersections, edges_shared_between_bounding_boxes
示例#4
0
    def create_3D_to_2D_rectangle(self, prim):
        try:
            if (not prim):
                raise Errors.CantBeNoneError(
                    'Prim cant be none', 'We need a' +
                    ' prim to calculate tbn some' + ' steps after')
        except Errors.CantBeNoneError as e:
            Errors.Error.display_exception(e)
            exit()
        tbn_class = CreateTBN.CreateTBN(prim)
        tbn_class.do(scale=True)
        tbn_matrix = tbn_class.get_tbn()
        tbn_inverse_matrix = tbn_class.get_tbn_inverse()
        temporary_list = []
        for point in self.get_points_object_space():
            point_relative = GeoMath.vecSub(
                point, tbn_class.get_point_which_is_relative())
            point_tangent_space = tbn_inverse_matrix.mulPoint3ToMatrix3(
                point_relative)
            temporary_list.append(point_tangent_space)

        self.set_points_tangent_space(temporary_list)
        self.calculate_bounding_box_tangent_space()
        #=======================================================================
        # Tranform to object space
        #=======================================================================
        rectangle_tangent_space = self.create_rectangle('tangent')
        rectangle_object_space = []
        for point_tangent_space in rectangle_tangent_space:
            point_object_space_relative = tbn_matrix.mulPoint3ToMatrix3(
                point_tangent_space)
            point_object_space = GeoMath.vecPlus(
                point_object_space_relative,
                tbn_class.get_point_which_is_relative())
            rectangle_object_space.append(point_object_space)

        self.set_rectangle_object_space(rectangle_object_space)
        bounding_box_object_space_size = GeoMath.vecSub(
            rectangle_object_space[2], rectangle_object_space[0])
        self.set_vector_size_object_space(bounding_box_object_space_size)
        self.set_rectangle_tangent_space(rectangle_tangent_space)
        self.set_edges_object_space(
            GeoMath.getEdgesFromPoints(rectangle_object_space))
        self.set_edges_tangent_space(
            GeoMath.getEdgesFromPoints(rectangle_tangent_space))
        self.tbn_class = tbn_class
示例#5
0
    def intersections_with_crack(self, crack, path_ordered):
        reload(GeoMath)
        intersections = []
        edges_floor = GeoMath.getEdgesFromPoints(self.get_absolute_points())
        prev_intersection = None
        next_intersection = None
        #=======================================================================
        # we group the intersections in pairs, because after we'll have a different
        # destruction in the floor for each pair of intersection
        #=======================================================================

        for infoPrim in path_ordered:
            patterns = crack[infoPrim.getPrim()]
            for pattern in patterns:
                pattern_edges = GeoMath.getEdgesFromPoints(pattern.getPoints())
                may_intersect, pattern_edge_inter, floor_edge_inter = GeoMath.bolzanoIntersectionEdges2_5D(pattern_edges, edges_floor)
                if(may_intersect):
                    # FIXME: HACK: we take one point of the pattern edge and put the y of the floor.
                    # We are assuming the edge is perpendicular to the floor.
                    # TEMP:
                    point_intersection = [pattern_edge_inter[0][0], floor_edge_inter[0][1], pattern_edge_inter[0][2]]
                    logging.debug("Intersection bef" + str(point_intersection))
                    logging.debug("fllor_edge_inter " + str(floor_edge_inter))
                    #point2DToProjectOntoXZ = [point_intersection[0], 0, point_intersection[2]]
                    #floorEdge2DToCalculateProjectionOntoXZ = [[floor_edge_inter[0][0],0 , floor_edge_inter[0][2]], [floor_edge_inter[1][0], 0, floor_edge_inter[1][2]]]

                    #point_intersection = GeoMath.getPointProjectionOnLine(floorEdge2DToCalculateProjectionOntoXZ, point2DToProjectOntoXZ)
                    #point_intersection = [point_intersection[0], floor_edge_inter[0][1], point_intersection[2]]

                    logging.debug("Intersection " + str(point_intersection))
                    
                    if(not prev_intersection):
                        prev_intersection = point_intersection
                        break
                    elif(not GeoMath.pointEqualPoint(point_intersection, prev_intersection)):
                        next_intersection = point_intersection
                        new_intersection = [prev_intersection, next_intersection]
                        intersections.append(new_intersection)
                        prev_intersection = None
                        next_intersection = None
                        break
        return intersections
示例#6
0
    def intersect_bounding_box_3D(self, bounding_box, DISPLAY=False):
        try:
            if (not self.get_prim()):
                raise Errors.CantBeNoneError(
                    'Prim cant be none',
                    'We need a prim to calculate tbn some steps after')
        except Errors.CantBeNoneError as e:
            Errors.Error.display_exception(e)
            exit()

        if (not self.get_points_tangent_space()):
            self.create_3D_to_2D_rectangle(self.get_prim())
        this_point_relative = self.get_tbn_class().get_point_which_is_relative(
        )
        this_tbn_inverse_matrix = self.get_tbn_class().get_tbn_inverse()
        param_bounding_box_points_in_this_tangent_space = []
        for point in bounding_box.get_rectangle_object_space():
            point_relative = GeoMath.vecSub(point, this_point_relative)
            this_tbn_inverse_matrix.printAttributes()
            point_tangent_space = this_tbn_inverse_matrix.mulPoint3ToMatrix3(
                point_relative)
            param_bounding_box_points_in_this_tangent_space.append(
                point_tangent_space)
        intersections = GeoMath.getIntersectionsBetweenEdges2D(
            GeoMath.getEdgesFromPoints(self.get_rectangle_tangent_space()),
            GeoMath.getEdgesFromPoints(
                param_bounding_box_points_in_this_tangent_space))
        if (DISPLAY):
            # TEMP: exit
            1 / 0
            exit()
            for intersection in intersections:
                this_tbn_matrix = self.get_tbn_class().get_tbn()
                point_object_space = this_tbn_matrix.mulPoint3ToMatrix3(
                    intersection)
                point_absolute = GeoMath.vecPlus(point_object_space,
                                                 this_point_relative)
                self.to_display_intersections.append(point_absolute)
            self.display_intersections()
        return intersections
    def intersect_bounding_box_with_limits_3D(self, bounding_box, DISPLAY=False):
        try:
            if not self.get_prim():
                raise Errors.CantBeNoneError("Prim cant be none", "We need a prim to calculate tbn some steps after")
        except Errors.CantBeNoneError as e:
            Errors.Error.display_exception(e)
            exit()

        if not self.get_points_tangent_space():
            self.convert_3D_to_2D(self.get_prim())
        this_point_relative = self.get_tbn_class().get_point_which_is_relative()
        this_tbn_inverse_matrix = self.get_tbn_class().get_tbn_inverse()
        param_bounding_box_points_in_this_tangent_space = []
        for point in bounding_box.get_rectangle_object_space():
            point_relative = GeoMath.vecSub(point, this_point_relative)
            point_tangent_space = this_tbn_inverse_matrix.mulPoint3ToMatrix3(point_relative)
            param_bounding_box_points_in_this_tangent_space.append(point_tangent_space)
        intersections = GeoMath.getIntersectionsBetweenEdges2D(
            self.get_edges_tangent_space(), GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space)
        )

        # =======================================================================
        # work in object space because we only has to know if the bounding boxes
        # share some edge between
        # =======================================================================
        edges_shared_between_bounding_boxes = GeoMath.getEdgesBetweenEdges(
            self.get_edges_tangent_space(), GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space)
        )

        if DISPLAY:
            # TEMP: exit
            1 / 0
            exit()
            for intersection in intersections:
                this_tbn_matrix = self.get_tbn_class().get_tbn()
                point_object_space = this_tbn_matrix.mulPoint3ToMatrix3(intersection)
                point_absolute = GeoMath.vecPlus(point_object_space, this_point_relative)
                self.to_display_intersections.append(point_absolute)
            self.display_intersections()
        return intersections, edges_shared_between_bounding_boxes
    def create_3D_to_2D_rectangle(self, prim):
        try:
            if not prim:
                raise Errors.CantBeNoneError(
                    "Prim cant be none", "We need a" + " prim to calculate tbn some" + " steps after"
                )
        except Errors.CantBeNoneError as e:
            Errors.Error.display_exception(e)
            exit()
        tbn_class = CreateTBN.CreateTBN(prim)
        tbn_class.do(scale=True)
        tbn_matrix = tbn_class.get_tbn()
        tbn_inverse_matrix = tbn_class.get_tbn_inverse()
        temporary_list = []
        for point in self.get_points_object_space():
            point_relative = GeoMath.vecSub(point, tbn_class.get_point_which_is_relative())
            point_tangent_space = tbn_inverse_matrix.mulPoint3ToMatrix3(point_relative)
            temporary_list.append(point_tangent_space)

        self.set_points_tangent_space(temporary_list)
        self.calculate_bounding_box_tangent_space()
        # =======================================================================
        # Tranform to object space
        # =======================================================================
        rectangle_tangent_space = self.create_rectangle("tangent")
        rectangle_object_space = []
        for point_tangent_space in rectangle_tangent_space:
            point_object_space_relative = tbn_matrix.mulPoint3ToMatrix3(point_tangent_space)
            point_object_space = GeoMath.vecPlus(point_object_space_relative, tbn_class.get_point_which_is_relative())
            rectangle_object_space.append(point_object_space)

        self.set_rectangle_object_space(rectangle_object_space)
        bounding_box_object_space_size = GeoMath.vecSub(rectangle_object_space[2], rectangle_object_space[0])
        self.set_vector_size_object_space(bounding_box_object_space_size)
        self.set_rectangle_tangent_space(rectangle_tangent_space)
        self.set_edges_object_space(GeoMath.getEdgesFromPoints(rectangle_object_space))
        self.set_edges_tangent_space(GeoMath.getEdgesFromPoints(rectangle_tangent_space))
        self.tbn_class = tbn_class
示例#9
0
    def findUpperTextureContainingPoint(self, point):

        if(not self.reverseListOfTextures):
            # Get ordered layers
            layers = list(self.getLayers())
            # We want to start from the upper texture, so we inverse the list
            layers.reverse()
            self.reverseListOfTextures = layers

        layerInPoint = None
        for layer in self.reverseListOfTextures:
            if(layer.pointInTexture(point)):
                if(GeoMath.pointInEdges(point, GeoMath.getEdgesFromPoints(layer.get_absolute_points()))):
                    # Warning!!! point are in the edge of a texture, so if you call this method to know
                    # the next texture be careful, it will be error
                    logging.warning('Method findUpperTextureContainingPoint, Point lie in a edge of texture')
                layerInPoint = layer
                break
        if(not layerInPoint):
            layerInPoint = self.getDefaultTexture()
        return layerInPoint
示例#10
0
    def apply_noise(cls, points, normal, height, for_edge, frequency="little",):
        logging.debug("Class Add_noise, method apply_noise")
        if(not cls.curve_node):
            logging.debug("Class GlassDynamicPatternGenerator, creating new nodes")
            # Create nodes to generate a pattern
            curve_node = cls.node_geo.createNode('curve')
            edge_divide_node = cls.node_geo.createNode('edgedivide')
            point_node = cls.node_geo.createNode('point')
            mountain_node = cls.node_geo.createNode('mountain')

            # connect it
            edge_divide_node.setNextInput(curve_node)
            point_node.setNextInput(edge_divide_node)
            mountain_node.setNextInput(point_node)

            # The first group, if we don't put the value, it doesnt work
            edge_divide_node.parm('group').set('0')


        else:
            curve_node = cls.curve_node
            edge_divide_node = cls.edge_divide_node
            point_node = cls.point_node
            mountain_node = cls.mountain_node
        final_points = []

        if (for_edge):
            # If we want a noise for each edge, we can get all edges from points
            edges = GeoMath.getEdgesFromPoints(points)
            # Delete last edge, because we are working with no closed pattern
            edges.pop()
        else:
            # If not, we apply noise to all points at the same time
            edges = [points]
        logging.debug("Class add noise")
        logging.debug("points" + str(points))
        logging.debug("normal" + str(normal))
        logging.debug("height" + str(height))
        logging.debug("for_edge" + str(for_edge))
        for points_for_iteration in edges:
            '''
            pointI = points_for_iteration[0]
            pointF = points_for_iteration[len(points_for_iteration) - 1]
            points_for_iteration = [pointI, pointF]
            '''
            pointsString = ""
            for point in points_for_iteration:
                pointsString = pointsString + str(point[0]) + "," + str(point[1]) + "," + str(point[2]) + " "
            curve_node.parm('coords').set(pointsString)

            # Set edge divisions, we set for a constant of 50, but it may to be any number
            # Only if we apply noise for each edge
            if(for_edge):
                multiplier_number_of_points = 1
                edge_divide_node.parm('numdivs').set(int(cls.calculate_frequency(frequency) * multiplier_number_of_points))
            else:
                point_node.setInput(0, curve_node)

            # Put the parameters
            point_node.parm('donml').set('on')
            point_node.parm('nx').deleteAllKeyframes()
            point_node.parm('ny').deleteAllKeyframes()
            point_node.parm('nz').deleteAllKeyframes()
            point_node.parm('nx').set(normal[0])
            point_node.parm('ny').set(normal[1])
            point_node.parm('nz').set(normal[2])

            # Set parameters to mountain node
            # self.sizex*50=number of points_for_iteration in the curve

            mountain_node.parm('height').set(height)
            frequency_number = cls.calculate_frequency(frequency)
            mountain_node.parm('freq1').set(frequency_number)
            mountain_node.parm('freq2').set(frequency_number)
            mountain_node.parm('freq3').set(frequency_number)
            # Put random offset to get random points_for_iteration
            mountain_node.parm('offset1').set(random.random() * 100)
            mountain_node.parm('offset2').set(random.random() * 100)
            mountain_node.parm('offset3').set(random.random() * 100)
            # We get the generate pattern
            pointI = points_for_iteration[0]
            pointF = points_for_iteration[len(points_for_iteration) - 1]
            mountain_node.cook()
            generated_pattern = [list(p.position()) for p in mountain_node.geometry().points()]
            #===================================================================
            # Important: If we do a division of edges, the points are numered in
            # this manner:
            # We get a edge numered as first point with number 0 and last point
            # with number 1. when we do a division, each division are numered from
            # point 0 to ndivision, but the point number 1 is still the number one
            # so for example, in a edge [0,1] with 5 divions the number are
            # [0,2,3,4,1].
            #===================================================================
            if(for_edge):
                #===============================================================
                # fix the above issue
                #===============================================================
                last_point = generated_pattern[1]
                del generated_pattern[1]
                generated_pattern.append(last_point)
            # Return initial point and final point to his original positions
            generated_pattern[0] = pointI
            generated_pattern[len(generated_pattern) - 1] = pointF

            final_points.extend(generated_pattern)
            logging.debug("Add noise points_for_iteration finish: " + str(points_for_iteration))

        if(not cls.curve_node):
            cls.curve_node = curve_node
            cls.edge_divide_node = edge_divide_node
            cls.point_node = point_node
            cls.mountain_node = mountain_node

        if(not for_edge):
            # Back to connect the nodes as before
            point_node.setInput(0, edge_divide_node)
        return final_points
示例#11
0
    def intersect_bounding_box_without_limits_3D(self,
                                                 bounding_box,
                                                 DISPLAY=False):
        global littleEpsilon
        try:
            if (not self.get_prim()):
                raise Errors.CantBeNoneError(
                    'Prim cant be none',
                    'We need a prim to calculate tbn some steps after')
        except Errors.CantBeNoneError as e:
            Errors.Error.display_exception(e)
            exit()

        if (not self.get_points_tangent_space()):
            self.convert_3D_to_2D(self.get_prim())
        this_point_relative = self.get_tbn_class().get_point_which_is_relative(
        )
        this_tbn_inverse_matrix = self.get_tbn_class().get_tbn_inverse()
        param_bounding_box_points_in_this_tangent_space = []
        for point in bounding_box.get_rectangle_object_space():
            point_relative = GeoMath.vecSub(point, this_point_relative)
            point_tangent_space = this_tbn_inverse_matrix.mulPoint3ToMatrix3(
                point_relative)
            param_bounding_box_points_in_this_tangent_space.append(
                point_tangent_space)
        intersections = GeoMath.getIntersectionsBetweenEdges2D(self.get_edges_tangent_space(), \
                       GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space))
        if (intersections):
            #===============================================================
            # Check if the limits are touching and if it are touching it,
            # check if the intersection is in there. If it is in there,
            # the intersection lie in the limit, so we dont consider an
            # intersection
            #===============================================================
            edges_shared_between_bounding_boxes = \
            GeoMath.getEdgesBetweenEdges(self.get_edges_tangent_space(), \
            GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space))
            inside = False
            print "Edges shared between"
            print edges_shared_between_bounding_boxes
            for intersection in intersections:
                inside = GeoMath.pointInEdges(
                    intersection, edges_shared_between_bounding_boxes)
                if (not inside):
                    break
            #===============================================================
            # If all intersections lie in the edges shared between bounding
            # boxes we discart its
            #===============================================================
            if (inside):
                intersections = []
            else:
                # check if intersections are in the corner, because we consider corner as limit
                shared_points_between_bounding_boxes = GeoMath.getSharedPoints(
                    self.get_rectangle_tangent_space(),
                    param_bounding_box_points_in_this_tangent_space)
                # If all intersections lie in the corner we doen't consider intersections as intersections
                true_intersections = list(intersections)
                for intersection in intersections:
                    for corner in shared_points_between_bounding_boxes:
                        if (GeoMath.vecModul(
                                GeoMath.vecSub(corner, intersection)) <=
                                littleEpsilon):
                            true_intersections.remove(intersection)
                            break
                intersections = true_intersections

        if (DISPLAY):
            # TEMP: exit
            1 / 0
            exit()
            for intersection in intersections:
                this_tbn_matrix = self.get_tbn_class().get_tbn()
                point_object_space = this_tbn_matrix.mulPoint3ToMatrix3(
                    intersection)
                point_absolute = GeoMath.vecPlus(point_object_space,
                                                 this_point_relative)
                self.to_display_intersections.append(point_absolute)
            self.display_intersections()
        return intersections
    def intersect_bounding_box_without_limits_3D(self, bounding_box, DISPLAY=False):
        global littleEpsilon
        try:
            if not self.get_prim():
                raise Errors.CantBeNoneError("Prim cant be none", "We need a prim to calculate tbn some steps after")
        except Errors.CantBeNoneError as e:
            Errors.Error.display_exception(e)
            exit()

        if not self.get_points_tangent_space():
            self.convert_3D_to_2D(self.get_prim())
        this_point_relative = self.get_tbn_class().get_point_which_is_relative()
        this_tbn_inverse_matrix = self.get_tbn_class().get_tbn_inverse()
        param_bounding_box_points_in_this_tangent_space = []
        for point in bounding_box.get_rectangle_object_space():
            point_relative = GeoMath.vecSub(point, this_point_relative)
            point_tangent_space = this_tbn_inverse_matrix.mulPoint3ToMatrix3(point_relative)
            param_bounding_box_points_in_this_tangent_space.append(point_tangent_space)
        intersections = GeoMath.getIntersectionsBetweenEdges2D(
            self.get_edges_tangent_space(), GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space)
        )
        if intersections:
            # ===============================================================
            # Check if the limits are touching and if it are touching it,
            # check if the intersection is in there. If it is in there,
            # the intersection lie in the limit, so we dont consider an
            # intersection
            # ===============================================================
            edges_shared_between_bounding_boxes = GeoMath.getEdgesBetweenEdges(
                self.get_edges_tangent_space(),
                GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space),
            )
            inside = False
            print "Edges shared between"
            print edges_shared_between_bounding_boxes
            for intersection in intersections:
                inside = GeoMath.pointInEdges(intersection, edges_shared_between_bounding_boxes)
                if not inside:
                    break
            # ===============================================================
            # If all intersections lie in the edges shared between bounding
            # boxes we discart its
            # ===============================================================
            if inside:
                intersections = []
            else:
                # check if intersections are in the corner, because we consider corner as limit
                shared_points_between_bounding_boxes = GeoMath.getSharedPoints(
                    self.get_rectangle_tangent_space(), param_bounding_box_points_in_this_tangent_space
                )
                # If all intersections lie in the corner we doen't consider intersections as intersections
                true_intersections = list(intersections)
                for intersection in intersections:
                    for corner in shared_points_between_bounding_boxes:
                        if GeoMath.vecModul(GeoMath.vecSub(corner, intersection)) <= littleEpsilon:
                            true_intersections.remove(intersection)
                            break
                intersections = true_intersections

        if DISPLAY:
            # TEMP: exit
            1 / 0
            exit()
            for intersection in intersections:
                this_tbn_matrix = self.get_tbn_class().get_tbn()
                point_object_space = this_tbn_matrix.mulPoint3ToMatrix3(intersection)
                point_absolute = GeoMath.vecPlus(point_object_space, this_point_relative)
                self.to_display_intersections.append(point_absolute)
            self.display_intersections()
        return intersections
示例#13
0
    def apply_noise(
        cls,
        points,
        normal,
        height,
        for_edge,
        frequency="little",
    ):
        logging.debug("Class Add_noise, method apply_noise")
        if (not cls.curve_node):
            logging.debug(
                "Class GlassDynamicPatternGenerator, creating new nodes")
            # Create nodes to generate a pattern
            curve_node = cls.node_geo.createNode('curve')
            edge_divide_node = cls.node_geo.createNode('edgedivide')
            point_node = cls.node_geo.createNode('point')
            mountain_node = cls.node_geo.createNode('mountain')

            # connect it
            edge_divide_node.setNextInput(curve_node)
            point_node.setNextInput(edge_divide_node)
            mountain_node.setNextInput(point_node)

            # The first group, if we don't put the value, it doesnt work
            edge_divide_node.parm('group').set('0')

        else:
            curve_node = cls.curve_node
            edge_divide_node = cls.edge_divide_node
            point_node = cls.point_node
            mountain_node = cls.mountain_node
        final_points = []

        if (for_edge):
            # If we want a noise for each edge, we can get all edges from points
            edges = GeoMath.getEdgesFromPoints(points)
            # Delete last edge, because we are working with no closed pattern
            edges.pop()
        else:
            # If not, we apply noise to all points at the same time
            edges = [points]
        logging.debug("Class add noise")
        logging.debug("points" + str(points))
        logging.debug("normal" + str(normal))
        logging.debug("height" + str(height))
        logging.debug("for_edge" + str(for_edge))
        for points_for_iteration in edges:
            '''
            pointI = points_for_iteration[0]
            pointF = points_for_iteration[len(points_for_iteration) - 1]
            points_for_iteration = [pointI, pointF]
            '''
            pointsString = ""
            for point in points_for_iteration:
                pointsString = pointsString + str(point[0]) + "," + str(
                    point[1]) + "," + str(point[2]) + " "
            curve_node.parm('coords').set(pointsString)

            # Set edge divisions, we set for a constant of 50, but it may to be any number
            # Only if we apply noise for each edge
            if (for_edge):
                multiplier_number_of_points = 1
                edge_divide_node.parm('numdivs').set(
                    int(
                        cls.calculate_frequency(frequency) *
                        multiplier_number_of_points))
            else:
                point_node.setInput(0, curve_node)

            # Put the parameters
            point_node.parm('donml').set('on')
            point_node.parm('nx').deleteAllKeyframes()
            point_node.parm('ny').deleteAllKeyframes()
            point_node.parm('nz').deleteAllKeyframes()
            point_node.parm('nx').set(normal[0])
            point_node.parm('ny').set(normal[1])
            point_node.parm('nz').set(normal[2])

            # Set parameters to mountain node
            # self.sizex*50=number of points_for_iteration in the curve

            mountain_node.parm('height').set(height)
            frequency_number = cls.calculate_frequency(frequency)
            mountain_node.parm('freq1').set(frequency_number)
            mountain_node.parm('freq2').set(frequency_number)
            mountain_node.parm('freq3').set(frequency_number)
            # Put random offset to get random points_for_iteration
            mountain_node.parm('offset1').set(random.random() * 100)
            mountain_node.parm('offset2').set(random.random() * 100)
            mountain_node.parm('offset3').set(random.random() * 100)
            # We get the generate pattern
            pointI = points_for_iteration[0]
            pointF = points_for_iteration[len(points_for_iteration) - 1]
            mountain_node.cook()
            generated_pattern = [
                list(p.position()) for p in mountain_node.geometry().points()
            ]
            #===================================================================
            # Important: If we do a division of edges, the points are numered in
            # this manner:
            # We get a edge numered as first point with number 0 and last point
            # with number 1. when we do a division, each division are numered from
            # point 0 to ndivision, but the point number 1 is still the number one
            # so for example, in a edge [0,1] with 5 divions the number are
            # [0,2,3,4,1].
            #===================================================================
            if (for_edge):
                #===============================================================
                # fix the above issue
                #===============================================================
                last_point = generated_pattern[1]
                del generated_pattern[1]
                generated_pattern.append(last_point)
            # Return initial point and final point to his original positions
            generated_pattern[0] = pointI
            generated_pattern[len(generated_pattern) - 1] = pointF

            final_points.extend(generated_pattern)
            logging.debug("Add noise points_for_iteration finish: " +
                          str(points_for_iteration))

        if (not cls.curve_node):
            cls.curve_node = curve_node
            cls.edge_divide_node = edge_divide_node
            cls.point_node = point_node
            cls.mountain_node = mountain_node

        if (not for_edge):
            # Back to connect the nodes as before
            point_node.setInput(0, edge_divide_node)
        return final_points