Just a real quick question about Genesis file detection

Issue #1769 closed
Joe Morris @ FAST Animation Studio Toolz created an issue
    def is_character_file(self, file_path):
        try:
            with open(file_path, 'r', errors='ignore') as f:
                content = f.read()
                if 'Genesis' in content:
                    print("This is a Genesis character, choose DBZFILE or MORPHED for MESH FITTING setting on panel!")
                    return True
                else:
                    print("This is an Environment or Prop - Choose 'UNIQUE' or 'SHARED' for MESH FITTING setting on panel!")
                    return False
        except FileNotFoundError:
            print(f"File not found: {file_path}")
            return False

The above code has been working on everything I throw at it every Genesis file comes back true i'm just using this as a test to strengthen my error handling and I was wondering if I could rely on your greater knowledge to let me know if this is good enough for all instances and if it's not maybe give me a proper search term that would be more apt to detect any Genesis character duf that you're at on supports…. just not sure if you notice anomalies where there's any Genesis DUF scene files that don't contain that I know maybe some V4 don't at least the Loretta and Lorenzo Poly kit doesn’t… I spent three hours last night trying to train neural networks on DUF files to get it to detect them and came up with that in a pinch and it works so I'm just kind of going with this until I hear otherwise thanks in advance for any help….. Or if you have a method of detection could you show me where it is

Comments (7)

  1. Joe Morris @ FAST Animation Studio Toolz reporter

    Actually I made a error when I was doing it so this is my final one

        def is_character_file(self, file_path):
            def unzip_and_read_file(file_path):
                temp_dir = tempfile.mkdtemp()
                output_path = os.path.join(temp_dir, os.path.basename(file_path))
                
                with gzip.open(file_path, 'rb') as gzip_file:
                    with open(output_path, 'wb') as out_file:
                        out_file.write(gzip_file.read())
                
                with open(output_path, 'r') as f:
                    content = f.read()
                
                os.remove(output_path)
                return content
            
            def read_directly(file_path):
                with open(file_path, 'r') as f:
                    return f.read()
            
            def get_content_type(file_content):
                if '"type" : "scene",' in file_content:
                    return "scene"
                elif '"type" : "preset_pose",' in file_content:
                    return "pose"
                else:
                    return None
    
            # Determine if it's gzipped
            is_compressed = is_gzip_file(file_path)
            
            if is_compressed:
                content = unzip_and_read_file(file_path)
            else:
                content = read_directly(file_path)
    
            # Determine the type of content (scene or pose)
            content_type = get_content_type(content)
            
            # Check if it's a scene with "Genesis"
            if content_type == "scene":
                if 'Genesis' in content:
                    print_color("AG", "\nThis is a Genesis character, choose", new_line=False)
                    print_color("AR", " DBZFILE", new_line=False)
                    print_color("AG", " or", new_line=False)
                    print_color("AR", " MORPHED ", new_line=False)
                    print_color("AB", "MESH FITTING", new_line=False)
                    print_color("AG", " setting on panel!")
                    return True
                else:
                    print_color("AG", "\nThis is an Environment or Prop - Choose", new_line=False)
                    print_color("AR", " UNIQUE", new_line=False)
                    print_color("AG", " or", new_line=False)
                    print_color("AR", " SHARED ", new_line=False)
                    print_color("AB", "MESH FITTING", new_line=False)
                    print_color("AG", " setting on panel!")
                    return False
            else:
                return False
    

  2. Thomas Larsson repo owner
    • changed status to open

    A duf/dsf file is a json file which is optionally gzipped. The function loadJson in load_json.py reads the file and returns a python dict.

  3. Joe Morris @ FAST Animation Studio Toolz reporter

    no the thing is I'm trying to figure out a foolproof way to testify file is a Genesis DUF and I think I found it in the above it's been working on everything I threw at it I just wanted to ask your opinion on what you thought because I kind of needed in my code so I could cancel out of an operator

  4. Thomas Larsson repo owner

    That might work, but I would prefer to read the file with json to have more control over what’s happening. I added the function that loads gzipped json files to the api: import_daz.load_daz_file(filepath). I also added an example script that reads files and reports the asset type and the first url encountered, if any.: https://bitbucket.org/Diffeomorphic/daz-importer-scripts/src/master/check_file_content.py. Here is the output

    File: /data/DAZ 3D/Genesis 8/Female 8_1/Genesis8_1Female.dsf
    Asset type: figure
    
    File: /People/Genesis 8 Female/Characters/Aiko 8.duf
    Asset type: character
    First URL: /data/DAZ%203D/Genesis%208/Female/Genesis8Female.dsf#Genesis8Female
    
    File: /People/Genesis 3 Female/Poses/Fashion Model Pose 01.duf
    Asset type: preset_pose
    
    File: /People/Genesis 3 Female/Materials/Jeane Eyes 01.duf
    Asset type: preset_material
    
    File: /People/Genesis 3 Female/Clothing/Basic Wear/Basic Wear.duf
    Asset type: wearable
    First URL: /data/DAZ%203D/Genesis%203%20Female%20Starter%20Essentials/Top/Top_2282.dsf#Top_2282
    

  5. Joe Morris @ FAST Animation Studio Toolz reporter

    is there a specific test For environment and prop and if it comes back as asset type character does that mean 100 percent always it's a Genesis character this is really cool I appreciate providing all that information🙂

  6. Log in to comment