I want to add text on 3d boxes but i cant see them

Viewed 36

I want to add text on 3d boxes but i cant see them, when i rotate camera, i can see but, it looks like remains inside of box. how can see show them front of box? should i make boxes transparent or something?

you can see "li" on left.

enter image description here

but it should shown like this : enter image description here

( stopped creation of box when create 1st)

summary is:

  xz_sizes = np.array(boyutlar)
        
        xz_sizes[:,1] = 0
        
        print(xz_sizes)
        label_pos = (np.array(pozisyon) + xz_sizes/2 ).tolist()
        labels = ["limegreen","blue","1","1","1","1","1","1","1"]

        # labels = ['12', '24']
        for pos, label in zip(label_pos, labels):
            axGlob.text( *pos, label, 'x', ha='center', va='center') 
            counter2 += 2
            if counter2 == 100:
                break ```


Fullcode=class Painter:

def __init__(self,bins):
    self.items = bins.items
    self.width = bins.width
    self.height = bins.height
    self.depth = bins.depth

def _plotCube(self, ax, x, y, z, dx, dy, dz, color='red',mode=2):
    # stoppause = 5
    """ Auxiliary function to plot a cube. code taken somewhere from the web.  """
    xx = [x, x, x+dx, x+dx, x]
    yy = [y, y+dy, y+dy, y, y]
    
    kwargs = {'alpha': 1, 'color': color,'linewidth':1 }
    if mode == 1 :
        ax.plot3D(xx, yy, [z]*5, **kwargs)
        ax.plot3D(xx, yy, [z+dz]*5, **kwargs)
        ax.plot3D([x, x], [y, y], [z, z+dz], **kwargs)
        ax.plot3D([x, x], [y+dy, y+dy], [z, z+dz], **kwargs)
        ax.plot3D([x+dx, x+dx], [y+dy, y+dy], [z, z+dz], **kwargs)
        ax.plot3D([x+dx, x+dx], [y, y], [z, z+dz], **kwargs)
    else :
        text='sadsadas'
        p = Rectangle((x,y),dx,dy,fc=color,ec='black')
       
        p2 = Rectangle((x,y),dx,dy,fc=color,ec='black',label = 'adad')
        p3 = Rectangle((y,z),dy,dz,fc=color,ec='black')
        p4 = Rectangle((y,z),dy,dz,fc=color,ec='black')
        p5 = Rectangle((x,z),dx,dz,fc=color,ec='black')
        p6 = Rectangle((x,z),dx,dz,fc=color,ec='black')
        ax.add_patch(p)
       # ax.annotate(text, (x+dx/2,y))
        ax.add_patch(p2)
       # ax.annotate(text, (x+dx/2,y))
        ax.add_patch(p3)
        ax.add_patch(p4)
        ax.add_patch(p5)
        ax.add_patch(p6)
       # ax.text(x+dx, y+dy/2, z, "red", color='red',rotation_mode= None,verticalalignment = 'top',animated = 'b')
        # ax.text
        ax.annotate(text, (x,y))
        art3d.pathpatch_2d_to_3d(p, z=z, zdir="z")
        # art3d.text(x+0.8,y+0.8,z+0.8, 'label', zdir="x")
        art3d.pathpatch_2d_to_3d(p2, z=z+dz, zdir="z")
        art3d.pathpatch_2d_to_3d(p3, z=x, zdir="x")
        art3d.pathpatch_2d_to_3d(p4, z=x + dx, zdir="x")
        art3d.pathpatch_2d_to_3d(p5, z=y, zdir="y")
        art3d.pathpatch_2d_to_3d(p6, z=y + dy, zdir="y")


    
def plotBoxAndItems(self,title=""):
    counter2 = 0
    with open('boyutlar.csv', newline='') as f:
        reader = csv.reader(f)
        boyutlar = list(reader)
      
    boyutlar = [e for e in boyutlar if e]

    # boyutlar = [[float(value) for value in sublist] for sublist in boyutlar]      
    boyutlar = [list(map(float, y)) for y in boyutlar]         
          
    with open('pozisyon.csv', newline='') as f:
        reader2 = csv.reader(f)
        pozisyon = list(reader2)
    pozisyon = [e for e in pozisyon if e]
    # print(pozisyon)

    # pozisyon = [[float(value) for value in sublist] for sublist in pozisyon]   
    pozisyon = [[float(value) for value in sublist] for sublist in pozisyon]
    print(pozisyon)
    
    """ side effective. Plot the Bin and the items it contains. """
    fig = plt.figure()
    axGlob = plt.axes(projection='3d')
    stoppause = 1
    counter=0
    # fit rotation type
    for item in self.items:
        rt = item.rotation_type  
        x,y,z = item.position
        [w,h,d] = item.getDimension()
        color = item.color
        # countt=countt+1
        if item.typeof == 'cube':
             # plot item of cube
            self._plotCube(axGlob, float(x), float(y), float(z), float(w),float(h),float(d),color=color,mode=2)
        elif item.typeof == 'cylinder':
            # plot item of cylinder
            self._plotCylinder(axGlob, float(x), float(y), float(z), float(w),float(h),float(d),color=color,mode=2)
        
        counter = counter + 1 
        if counter == stoppause:
            break
    # plot bin 
    self._plotCube(axGlob,0, 0, 0, float(self.width), float(self.height), float(self.depth),color='black',mode=1)
    
    plt.title('result')
    self.setAxesEqual(axGlob)
    xz_sizes = np.array(boyutlar)
    
    xz_sizes[:,1] = 0
    
    print(xz_sizes)
    label_pos = (np.array(pozisyon) + xz_sizes/2 ).tolist()
    labels = ["limegreen","blue","1","1","1","1","1","1","1"]

    # labels = ['12', '24']
    for pos, label in zip(label_pos, labels):
        axGlob.text( *pos, label, 'x', ha='center', va='center') 
        counter2 += 1
        if counter2 == 1:
            break
    
        
                  
        
        
    plt.show()

0 Answers
Related