File size: 1,616 Bytes
0e805d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""GLB file validation."""

import os
from pathlib import Path
from typing import Tuple


class AssetValidator:
    """Validates GLB files for correctness."""
    
    @staticmethod
    def validate_glb(glb_path: Path) -> Tuple[bool, str]:
        """Validate GLB file exists and is not corrupt."""
        if not glb_path.exists():
            return False, f"GLB file not found: {glb_path}"
        
        file_size = glb_path.stat().st_size
        if file_size < 1000:  # Less than 1KB = corrupt
            return False, f"GLB file is corrupt (size: {file_size} bytes)"
        
        print(f"[Validator] GLB file valid: {file_size / 1e6:.2f} MB")
        
        # Optional: Deep validation with pygltflib
        try:
            import pygltflib
            gltf = pygltflib.GLTF2().load(str(glb_path))
            if not gltf.meshes:
                return False, "GLB contains no meshes"
            print(f"[Validator] GLB contains {len(gltf.meshes)} meshes")
        except ImportError:
            print("[Validator] pygltflib not installed, skipping deep validation")
        except Exception as e:
            return False, f"GLB validation failed: {e}"
        
        return True, "Valid"
    
    @staticmethod
    def get_file_info(glb_path: Path) -> dict:
        """Get information about GLB file."""
        if not glb_path.exists():
            return {"exists": False}
        
        stat = glb_path.stat()
        return {
            "exists": True,
            "size_mb": stat.st_size / 1e6,
            "size_bytes": stat.st_size,
            "modified": stat.st_mtime,
        }