def test_reserveFaceAndVertexCount():
    builder = MeshBuilder()
    builder.addVertex(1, 2, 3)

    builder.reserveFaceAndVertexCount(200, 20)
    # Reserving face count should reset the verts
    assert builder.getVertexCount() == 0
Exemple #2
0
    def createMeshOrJumps(self, make_mesh):
        builder = MeshBuilder()

        line_count = 0
        if make_mesh:
            for polygon in self._polygons:
                line_count += polygon.meshLineCount
        else:
            for polygon in self._polygons:
                line_count += polygon.jumpCount

        # Reserve the neccesary space for the data upfront
        builder.reserveFaceAndVertexCount(2 * line_count, 4 * line_count)

        for polygon in self._polygons:
            # Filter out the types of lines we are not interesed in depending on whether we are drawing the mesh or the jumps.
            index_mask = numpy.logical_not(
                polygon.jumpMask) if make_mesh else polygon.jumpMask

            # Create an array with rows [p p+1] and only keep those we whant to draw based on make_mesh
            points = numpy.concatenate((polygon.data[:-1], polygon.data[1:]),
                                       1)[index_mask.ravel()]
            # Line types of the points we want to draw
            line_types = polygon.types[index_mask]

            # Shift the z-axis according to previous implementation.
            if make_mesh:
                points[polygon.isInfillOrSkinType(line_types), 1::3] -= 0.01
            else:
                points[:, 1::3] += 0.01

            # Create an array with normals and tile 2 copies to match size of points variable
            normals = numpy.tile(polygon.getNormals()[index_mask.ravel()],
                                 (1, 2))

            # Scale all normals by the line width of the current line so we can easily offset.
            normals *= (polygon.lineWidths[index_mask.ravel()] / 2)

            # Create 4 points to draw each line segment, points +- normals results in 2 points each.
            # After this we reshape to one point per line.
            f_points = numpy.concatenate((points - normals, points + normals),
                                         1).reshape((-1, 3))

            # __index_pattern defines which points to use to draw the two faces for each lines egment, the following linesegment is offset by 4
            f_indices = (self.__index_pattern + numpy.arange(
                0, 4 * len(normals), 4, dtype=numpy.int32).reshape(
                    (-1, 1))).reshape((-1, 3))
            f_colors = numpy.repeat(polygon.mapLineTypeToColor(line_types), 4,
                                    0)

            builder.addFacesWithColor(f_points, f_indices, f_colors)

        return builder.build()
Exemple #3
0
    def createMeshOrJumps(self, make_mesh):
        builder = MeshBuilder()
        
        line_count = 0
        if make_mesh:
            for polygon in self._polygons:
                line_count += polygon.meshLineCount
        else:
            for polygon in self._polygons:
                line_count += polygon.jumpCount

        # Reserve the neccesary space for the data upfront
        builder.reserveFaceAndVertexCount(2 * line_count, 4 * line_count)
        
        for polygon in self._polygons:
            # Filter out the types of lines we are not interesed in depending on whether we are drawing the mesh or the jumps.
            index_mask = numpy.logical_not(polygon.jumpMask) if make_mesh else polygon.jumpMask

            # Create an array with rows [p p+1] and only keep those we whant to draw based on make_mesh
            points = numpy.concatenate((polygon.data[:-1], polygon.data[1:]), 1)[index_mask.ravel()]
            # Line types of the points we want to draw
            line_types = polygon.types[index_mask]
            
            # Shift the z-axis according to previous implementation.
            if make_mesh:
                points[polygon.isInfillOrSkinType(line_types), 1::3] -= 0.01
            else:
                points[:, 1::3] += 0.01

            # Create an array with normals and tile 2 copies to match size of points variable
            normals = numpy.tile( polygon.getNormals()[index_mask.ravel()], (1, 2))

            # Scale all normals by the line width of the current line so we can easily offset.
            normals *= (polygon.lineWidths[index_mask.ravel()] / 2)

            # Create 4 points to draw each line segment, points +- normals results in 2 points each.
            # After this we reshape to one point per line.
            f_points = numpy.concatenate((points-normals, points+normals), 1).reshape((-1, 3))

            # __index_pattern defines which points to use to draw the two faces for each lines egment, the following linesegment is offset by 4
            f_indices = ( self.__index_pattern + numpy.arange(0, 4 * len(normals), 4, dtype=numpy.int32).reshape((-1, 1)) ).reshape((-1, 3))
            f_colors = numpy.repeat(polygon.mapLineTypeToColor(line_types), 4, 0)

            builder.addFacesWithColor(f_points, f_indices, f_colors)
        
        return builder.build()