69 lines
		
	
	
	
		
			2 KiB
		
	
	
	
		
			Ruby
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			69 lines
		
	
	
	
		
			2 KiB
		
	
	
	
		
			Ruby
		
	
	
		
			Executable file
		
	
	
	
	
#!/usr/bin/env ruby
 | 
						|
 | 
						|
require 'json'
 | 
						|
require_relative './../../xrforge.rb'
 | 
						|
 | 
						|
# Check if a filename is provided
 | 
						|
if ARGV.length != 1
 | 
						|
  puts "Usage: #{$0} <path/to/experience/somefile.xxx>"
 | 
						|
  exit 1
 | 
						|
end
 | 
						|
 | 
						|
filename = ARGV[0]
 | 
						|
 | 
						|
begin
 | 
						|
  # Read and parse the JSON file
 | 
						|
  data = JSON.parse(File.read(filename))
 | 
						|
 | 
						|
  logfile = File.join( File.dirname(filename), "log.txt" )
 | 
						|
 | 
						|
  XRForge.log("✅ starting XR fragments check", logfile, true)
 | 
						|
 | 
						|
  # Extract the desired field (assuming the field is named 'model_file')
 | 
						|
  thumb_file = data['image']
 | 
						|
  XRForge.log("✅ thumbnail sidecar-file '#{thumb_file}' detected", logfile)
 | 
						|
  
 | 
						|
  # Get the base name of the thumbnail file without its extension
 | 
						|
  base_name = File.basename(thumb_file, File.extname(thumb_file))
 | 
						|
  
 | 
						|
  model_file = nil # Initialize model_file to nil
 | 
						|
  
 | 
						|
  # Loop over the list of extensions
 | 
						|
  XRForge::MODEL_EXT.each do |ext|
 | 
						|
    # Construct the filename with the current extension
 | 
						|
    filename = "#{base_name}#{ext}"
 | 
						|
  
 | 
						|
    # Check if the file exists
 | 
						|
    if File.exist?(filename)
 | 
						|
      XRForge.log("✅ 3D file '#{filename}' detected", logfile)
 | 
						|
      model_file = filename # Store the found filename
 | 
						|
      break # Stop the loop once a file is found
 | 
						|
    else
 | 
						|
      # Log a message for the file that was not found, but don't stop
 | 
						|
      XRForge.log("⚠️ 3D file '#{filename}' not detected", logfile)
 | 
						|
    end
 | 
						|
  end
 | 
						|
  
 | 
						|
  # Check if a model file was found after the loop
 | 
						|
  if model_file
 | 
						|
    XRForge.log("✅ Final model file: '#{model_file}'", logfile)
 | 
						|
  else
 | 
						|
    XRForge.log("❌ No suitable 3D file found for XR Fragments-compatible experience", logfile)
 | 
						|
  end
 | 
						|
 | 
						|
  # Construct the output filename
 | 
						|
  output_file = "#{File.basename(model_file, File.extname(model_file))}.blend"
 | 
						|
 | 
						|
  # Execute the system call
 | 
						|
  puts("assimp", model_file, output_file)
 | 
						|
  system("assimp", model_file, output_file)
 | 
						|
 | 
						|
  XRForge.log(" ", logfile)
 | 
						|
 | 
						|
rescue Errno::ENOENT
 | 
						|
  puts "File #{filename} not found"
 | 
						|
rescue JSON::ParserError
 | 
						|
  puts "Error parsing JSON from #{filename}"
 | 
						|
rescue => e
 | 
						|
  puts "An error occurred: #{e.message}"
 | 
						|
end
 |