janusXR works
This commit is contained in:
parent
fe779a9a97
commit
24c747dda3
3 changed files with 104 additions and 34 deletions
100
manyfold/root/hook.d/experience_updated/300-package_janusxr.rb
Executable file
100
manyfold/root/hook.d/experience_updated/300-package_janusxr.rb
Executable file
|
|
@ -0,0 +1,100 @@
|
||||||
|
#!/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" ) )
|
||||||
|
|
||||||
|
logfile = File.join( File.dirname(filename), ".xrforge/log.txt" )
|
||||||
|
|
||||||
|
XRForge.log("✅ starting build janusXR 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- / JanusXR-compatible experience", logfile)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Get the value of the environment variable FEDERATE_DRIVE_HOST
|
||||||
|
federate_drive_host = ENV['FEDERATE_DRIVE_HOST']
|
||||||
|
|
||||||
|
# Define the HTML content using a multi-line string (heredoc)
|
||||||
|
# Ruby's heredoc allows for variable interpolation (using #{})
|
||||||
|
jml = <<~HTML
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>janusxr room</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script src="https://web.janusvr.com/janusweb.js"></script>
|
||||||
|
<janus-viewer>
|
||||||
|
<FireBoxRoom>
|
||||||
|
<Assets>
|
||||||
|
<assetobject id="experience" src="#{federate_drive_host}/#{model_file.gsub("#","%23")}"/>
|
||||||
|
</Assets>
|
||||||
|
<Room>
|
||||||
|
<object pos="0 0 0" collision_id="experience" id="experience" />
|
||||||
|
</Room>
|
||||||
|
</FireBoxRoom>
|
||||||
|
</janus-viewer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
HTML
|
||||||
|
|
||||||
|
# Write the content to the specified file
|
||||||
|
# File.write is the concise equivalent of 'echo "$jml" > filename'
|
||||||
|
File.write('.xrforge/janusxr.html', jml)
|
||||||
|
|
||||||
|
XRForge.log("✅ written janusxr.html", logfile)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
dir="$(dirname $1)"
|
|
||||||
cd "$dir"
|
|
||||||
echo "[package_janusxr.sh] packing janusxr.html"
|
|
||||||
|
|
||||||
glb=$(ls *.glb | head -n1) # todo: check datapackage.json instead of first match
|
|
||||||
|
|
||||||
jml='
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>janusxr room</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<script src="https://web.janusvr.com/janusweb.js"></script>
|
|
||||||
<janus-viewer>
|
|
||||||
<FireBoxRoom>
|
|
||||||
<Assets>
|
|
||||||
<assetobject id="experience" src="'${FEDERATE_DRIVE_HOST}/$1'"/>
|
|
||||||
</Assets>
|
|
||||||
<Room>
|
|
||||||
<object pos="0 0 0" collision_id="experience" id="experience" />
|
|
||||||
</Room>
|
|
||||||
</FireBoxRoom>
|
|
||||||
</janus-viewer>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
'
|
|
||||||
|
|
||||||
echo "$jml" > .xrforge/janusxr.html
|
|
||||||
|
|
@ -12,12 +12,12 @@ end
|
||||||
filename = ARGV[0]
|
filename = ARGV[0]
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
# Change the directory
|
||||||
|
Dir.chdir( File.dirname(filename) )
|
||||||
# Read and parse the JSON file
|
# Read and parse the JSON file
|
||||||
data = JSON.parse(File.read(filename))
|
data = JSON.parse( File.read( "datapackage.json" ) )
|
||||||
|
|
||||||
logfile = File.join( File.dirname(filename), ".xrforge/log.txt" )
|
XRForge.log("✅ starting XR fragments check", logfile)
|
||||||
|
|
||||||
XRForge.log("✅ starting XR fragments check", logfile, true)
|
|
||||||
|
|
||||||
# Extract the desired field (assuming the field is named 'model_file')
|
# Extract the desired field (assuming the field is named 'model_file')
|
||||||
thumb_file = data['image']
|
thumb_file = data['image']
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue