2025-11-10 21:25:39 +01:00
|
|
|
#!/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
|
|
|
|
|
|
|
|
|
|
# Change the directory
|
|
|
|
|
dir = File.dirname(filename)
|
|
|
|
|
Dir.chdir( File.dirname(filename) )
|
|
|
|
|
# Read and parse the JSON file
|
|
|
|
|
data = JSON.parse( File.read( "datapackage.json" ) )
|
|
|
|
|
|
|
|
|
|
#if data['keywords'].empty? || data['keywords'].include?('mml')
|
|
|
|
|
|
|
|
|
|
logfile = File.join( File.dirname(filename), ".xrforge/log.txt" )
|
|
|
|
|
|
|
|
|
|
XRForge.log("✅ starting build mml XR scene", logfile)
|
|
|
|
|
|
|
|
|
|
# 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 = "#{dir.gsub("/mnt/","")}/#{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- / MML-compatible experience", logfile)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Get the value of the environment variable FEDERATE_DRIVE_HOST
|
|
|
|
|
federate_drive_host = ENV['FEDERATE_DRIVE_HOST']
|
|
|
|
|
|
|
|
|
|
# https://viewer.mml.io/main/v1/?url=https%3A%2F%2Ffoo.org%2Fbar.mml
|
|
|
|
|
mml = <<~MML
|
|
|
|
|
<m-model src="#{federate_drive_host}/#{model_file.gsub("#","%23")}" anim-loop="true" anim-enabled="true"></m-model>
|
|
|
|
|
MML
|
|
|
|
|
|
|
|
|
|
File.write('.xrforge/scene.mml', mml)
|
|
|
|
|
|
|
|
|
|
XRForge.log("✅ generated scene.mml", logfile)
|
|
|
|
|
XRForge.log(" ", logfile)
|
|
|
|
|
|
|
|
|
|
# tag it!
|
|
|
|
|
if ! data['keywords'].include?('mml')
|
|
|
|
|
data['keywords'].push('mml')
|
2025-11-11 19:11:09 +01:00
|
|
|
File.write("datapackage.json", JSON.pretty_generate(data) )
|
2025-11-10 21:25:39 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
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
|