JoseConseco / GoB

Fork of original GoB script (I just added some fixes)
GNU General Public License v3.0
648 stars 78 forks source link

zbrush2024 goz blender4.0 #465

Closed kyoumado closed 1 month ago

kyoumado commented 8 months ago

When using zbrush2024 goz to Blender 4.0, whether clicking all or visible, only the first subtool will be transferred to Blender

jbvendamme commented 8 months ago

Ihave the same problem, and the polypaint is absent too.. Any solution so far ?

razhar1980 commented 8 months ago

Same Here! Zbrush 2024.0.1, Blender 4.0.2 and gob 4.0.2 as well Sometimes, (could not reproduce constantly) when you open the softwares the first time, maybe the import works... but it doesn't import the polypaint

kyoumado commented 8 months ago

Yes, I haven't found a solution yet, so I'm still using zbrush2023

thironaka0716 commented 8 months ago

Hi, actually I just fix the ploblem in my case.

I had an error in the polypaint section and used ChatGPT to temporarily fix the error. It happened to work in my case, but it may not be a common fix for all. Replacing #Polypaint with the following code around line 338 of GoB.py in GoB-4_0_2 successfully imported with polypaint

Fixed_GoB.zip

            # Polypainting
            elif tag == b'\xb9\x88\x00\x00': 
                if prefs().debug_output:
                    print("Import Polypaint: ", prefs().import_polypaint)  

                if prefs().import_polypaint:     
                    if bpy.app.version < (3,4,0): 
                        goz_file.seek(4, 1)
                        cnt = unpack('<Q', goz_file.read(8))[0] 
                        polypaintData = []

                        for i in range(cnt): 
                            data = goz_file.read(3)
                            if len(data) < 3:
                                break
                            colordata = unpack('<3B', data) # Color
                            unpack('<B', goz_file.read(1))  # Alpha
                            alpha = 1  

                            # convert color to vector                         
                            rgb = [x / 255.0 for x in colordata]    
                            rgb.reverse()                    
                            rgba = rgb + [alpha]                                          
                            polypaintData.append(tuple(rgba))                      

                        if prefs().performance_profiling: 
                            start_time = profiler(start_time, "Polypaint Unpack")

                        if polypaintData:                   
                            bm = bmesh.new()
                            bm.from_mesh(me)
                            bm.faces.ensure_lookup_table()
                            if me.vertex_colors:                            
                                if prefs().import_polypaint_name in me.vertex_colors: 
                                    color_layer = bm.loops.layers.color.get(prefs().import_polypaint_name)
                                else:
                                    color_layer = bm.loops.layers.color.new(prefs().import_polypaint_name)                                    
                            else:
                                color_layer = bm.loops.layers.color.new(prefs().import_polypaint_name)                

                            for face in bm.faces:
                                for loop in face.loops:
                                    if loop.vert.index < len(polypaintData):
                                        loop[color_layer] = polypaintData[loop.vert.index]

                            bm.to_mesh(me)                        
                            me.update(calc_edges=True, calc_edges_loose=True)  
                            bm.free()                            
                        polypaintData.clear()

                    else:      
                        if not me.color_attributes:
                            me.color_attributes.new(prefs().import_polypaint_name, 'BYTE_COLOR', 'POINT')  

                        goz_file.seek(4, 1)
                        cnt = unpack('<Q', goz_file.read(8))[0] 
                        alpha = 1   
                        for i in range(cnt): 
                            data = goz_file.read(3)
                            if len(data) < 3:
                                break
                            colordata = unpack('<3B', data) # Color
                            unpack('<B', goz_file.read(1))  # Alpha 
                            # convert color to vector                         
                            rgb = [x / 255.0 for x in colordata]
                            rgb.reverse()                   
                            rgba = rgb + [alpha]                           
                            if i < len(me.attributes.active_color.data):
                                me.attributes.active_color.data[i].color_srgb = rgba

                    if prefs().performance_profiling: 
                        start_time = profiler(start_time, "Polypaint Assign")
jbvendamme commented 8 months ago

Hi thanks, for this, I ll give it a try! Le mercredi 13 mars 2024 à 07:30:04 UTC, thironaka0716 @.***> a écrit :

Hi, actually I just fix the ploblem in my case. I am Japanese so please translate them below

I had an error in the polypaint section and used ChatGPT to temporarily fix the error. It happened to work in my case, but it may not be a common fix for all. Replacing #Polypaint with the following code around line 338 of GoB.py in GoB-4_0_2 successfully imported with polypaint

Fixed_GoB.zip

Polypainting

        elif tag == b'\xb9\x88\x00\x00': 
            if prefs().debug_output:
                print("Import Polypaint: ", prefs().import_polypaint)  

            if prefs().import_polypaint:     
                if bpy.app.version < (3,4,0): 
                    goz_file.seek(4, 1)
                    cnt = unpack('<Q', goz_file.read(8))[0] 
                    polypaintData = []

                    for i in range(cnt): 
                        data = goz_file.read(3)
                        if len(data) < 3:
                            break
                        colordata = unpack('<3B', data) # Color
                        unpack('<B', goz_file.read(1))  # Alpha
                        alpha = 1  

                        # convert color to vector                         
                        rgb = [x / 255.0 for x in colordata]    
                        rgb.reverse()                    
                        rgba = rgb + [alpha]                                          
                        polypaintData.append(tuple(rgba))                      

                    if prefs().performance_profiling: 
                        start_time = profiler(start_time, "Polypaint Unpack")

                    if polypaintData:                   
                        bm = bmesh.new()
                        bm.from_mesh(me)
                        bm.faces.ensure_lookup_table()
                        if me.vertex_colors:                            
                            if prefs().import_polypaint_name in me.vertex_colors: 
                                color_layer = bm.loops.layers.color.get(prefs().import_polypaint_name)
                            else:
                                color_layer = bm.loops.layers.color.new(prefs().import_polypaint_name)                                    
                        else:
                            color_layer = bm.loops.layers.color.new(prefs().import_polypaint_name)                

                        for face in bm.faces:
                            for loop in face.loops:
                                if loop.vert.index < len(polypaintData):
                                    loop[color_layer] = polypaintData[loop.vert.index]

                        bm.to_mesh(me)                        
                        me.update(calc_edges=True, calc_edges_loose=True)  
                        bm.free()                            
                    polypaintData.clear()

                else:      
                    if not me.color_attributes:
                        me.color_attributes.new(prefs().import_polypaint_name, 'BYTE_COLOR', 'POINT')  

                    goz_file.seek(4, 1)
                    cnt = unpack('<Q', goz_file.read(8))[0] 
                    alpha = 1   
                    for i in range(cnt): 
                        data = goz_file.read(3)
                        if len(data) < 3:
                            break
                        colordata = unpack('<3B', data) # Color
                        unpack('<B', goz_file.read(1))  # Alpha 
                        # convert color to vector                         
                        rgb = [x / 255.0 for x in colordata]
                        rgb.reverse()                   
                        rgba = rgb + [alpha]                           
                        if i < len(me.attributes.active_color.data):
                            me.attributes.active_color.data[i].color_srgb = rgba

                if prefs().performance_profiling: 
                    start_time = profiler(start_time, "Polypaint Assign")

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

razhar1980 commented 7 months ago

the fix really helped with the polypaint, but Blender still imports only the first subtool, sometimes 2 subtools... that's really weird. Alternatively you can turn off and on the import button on blender, and then click goz on zbrush to send the active subtool. But that's annoying. (updated blender to 4.1, same issue)