added clients/webxr
This commit is contained in:
		
							parent
							
								
									7c173d8436
								
							
						
					
					
						commit
						936c29d121
					
				
					 6 changed files with 207 additions and 1 deletions
				
			
		
							
								
								
									
										2
									
								
								.gitmodules
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitmodules
									
										
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -1,3 +1,3 @@
 | 
			
		|||
[submodule "godot"]
 | 
			
		||||
	path = godot
 | 
			
		||||
	path = clients/godot
 | 
			
		||||
	url = ../xrforge-godot.git
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										93
									
								
								clients/webxr/viewer/index.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										93
									
								
								clients/webxr/viewer/index.html
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,93 @@
 | 
			
		|||
<!DOCTYPE html>
 | 
			
		||||
<html>
 | 
			
		||||
	<head>
 | 
			
		||||
		<style type="text/css">
 | 
			
		||||
 | 
			
		||||
				body{ 
 | 
			
		||||
					background: #555; 
 | 
			
		||||
				  height: 100%;
 | 
			
		||||
				  margin: 0;
 | 
			
		||||
				  overflow: hidden;
 | 
			
		||||
				  padding: 0;
 | 
			
		||||
				  width: 100%;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				img#btn_play:hover {
 | 
			
		||||
					opacity: 1.0;
 | 
			
		||||
				}
 | 
			
		||||
				img#btn_play {
 | 
			
		||||
					position: fixed;
 | 
			
		||||
					top: 50%;
 | 
			
		||||
					left: 50%;
 | 
			
		||||
          width:30%;
 | 
			
		||||
          max-width:400px;
 | 
			
		||||
					transform: translate(-50%,-50%);
 | 
			
		||||
					cursor: pointer;
 | 
			
		||||
					opacity: 0.6;
 | 
			
		||||
					transition: 0.3s;
 | 
			
		||||
					z-index: 999;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
		</style>
 | 
			
		||||
	</head>
 | 
			
		||||
	<body>
 | 
			
		||||
 | 
			
		||||
	  <img id="btn_play" src="play.svg"/>
 | 
			
		||||
 | 
			
		||||
	  <a-scene>
 | 
			
		||||
	  	<a-entity id="player" animation-mixer_disabled gltf-model></a-entity>
 | 
			
		||||
	  </a-scene>
 | 
			
		||||
 | 
			
		||||
		<script type="module">
 | 
			
		||||
			import * as xrforge from './plugin.xrforge.js';
 | 
			
		||||
			import * as level0  from './xrf.level0.js';
 | 
			
		||||
 | 
			
		||||
			const widget = new Proxy({
 | 
			
		||||
 | 
			
		||||
				backend: null,
 | 
			
		||||
			  player:  document.querySelector("#player"),
 | 
			
		||||
			  src:     document.location.search.substr(1),
 | 
			
		||||
				ext:     {},
 | 
			
		||||
 | 
			
		||||
				init(opts){ 
 | 
			
		||||
					for( var i in opts) this[i] = opts[i]
 | 
			
		||||
				},
 | 
			
		||||
 | 
			
		||||
				play(){
 | 
			
		||||
     			// set URL
 | 
			
		||||
			    player.setAttribute("gltf-model", `url(${widget.src})` )
 | 
			
		||||
 | 
			
		||||
          document.querySelector("#btn_play").style.display = 'none'
 | 
			
		||||
 | 
			
		||||
			    let script = document.createElement("script")
 | 
			
		||||
			    script.src = "https://aframe.io/releases/1.7.0/aframe.min.js"
 | 
			
		||||
			    document.head.appendChild(script)
 | 
			
		||||
 | 
			
		||||
			    script = document.createElement("script")
 | 
			
		||||
			    script.src = "backend.xrforge.js"
 | 
			
		||||
			    document.head.appendChild(script)
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
			},
 | 
			
		||||
			{
 | 
			
		||||
				get(me,k){ return me[k] },
 | 
			
		||||
 | 
			
		||||
				set(me,k,v){ 
 | 
			
		||||
					me[k] = v
 | 
			
		||||
					return true 
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
			})
 | 
			
		||||
 | 
			
		||||
			xrforge.init(widget)
 | 
			
		||||
			level0.init(widget)
 | 
			
		||||
 | 
			
		||||
			document.querySelector("#btn_play").addEventListener("click", () => widget.play() )
 | 
			
		||||
 | 
			
		||||
			//document.body.style.background = `url(${src.replace( /\.(glb|usdz|gltf|obj|col)$/ , ".png")})`
 | 
			
		||||
           	
 | 
			
		||||
 | 
			
		||||
		</script>
 | 
			
		||||
 | 
			
		||||
	</body>
 | 
			
		||||
</html>
 | 
			
		||||
							
								
								
									
										43
									
								
								clients/webxr/viewer/play.svg
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								clients/webxr/viewer/play.svg
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,43 @@
 | 
			
		|||
<?xml version="1.0" encoding="iso-8859-1"?>
 | 
			
		||||
<!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
 | 
			
		||||
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
 | 
			
		||||
	 viewBox="0 0 58.752 58.752" style="enable-background:new 0 0 58.752 58.752;" xml:space="preserve">
 | 
			
		||||
<g>
 | 
			
		||||
	<path stroke="#CCC" stroke-opacity="0.5" fill="white" d="M52.524,23.925L12.507,0.824c-1.907-1.1-4.376-1.097-6.276,0C4.293,1.94,3.088,4.025,3.088,6.264v46.205
 | 
			
		||||
		c0,2.24,1.204,4.325,3.131,5.435c0.953,0.555,2.042,0.848,3.149,0.848c1.104,0,2.192-0.292,3.141-0.843l40.017-23.103
 | 
			
		||||
		c1.936-1.119,3.138-3.203,3.138-5.439C55.663,27.134,54.462,25.05,52.524,23.925z M49.524,29.612L9.504,52.716
 | 
			
		||||
		c-0.082,0.047-0.18,0.052-0.279-0.005c-0.084-0.049-0.137-0.142-0.137-0.242V6.263c0-0.1,0.052-0.192,0.14-0.243
 | 
			
		||||
		c0.042-0.025,0.09-0.038,0.139-0.038c0.051,0,0.099,0.013,0.142,0.038l40.01,23.098c0.089,0.052,0.145,0.147,0.145,0.249
 | 
			
		||||
		C49.663,29.47,49.611,29.561,49.524,29.612z"/>
 | 
			
		||||
</g>
 | 
			
		||||
<g>
 | 
			
		||||
</g>
 | 
			
		||||
<g>
 | 
			
		||||
</g>
 | 
			
		||||
<g>
 | 
			
		||||
</g>
 | 
			
		||||
<g>
 | 
			
		||||
</g>
 | 
			
		||||
<g>
 | 
			
		||||
</g>
 | 
			
		||||
<g>
 | 
			
		||||
</g>
 | 
			
		||||
<g>
 | 
			
		||||
</g>
 | 
			
		||||
<g>
 | 
			
		||||
</g>
 | 
			
		||||
<g>
 | 
			
		||||
</g>
 | 
			
		||||
<g>
 | 
			
		||||
</g>
 | 
			
		||||
<g>
 | 
			
		||||
</g>
 | 
			
		||||
<g>
 | 
			
		||||
</g>
 | 
			
		||||
<g>
 | 
			
		||||
</g>
 | 
			
		||||
<g>
 | 
			
		||||
</g>
 | 
			
		||||
<g>
 | 
			
		||||
</g>
 | 
			
		||||
</svg>
 | 
			
		||||
| 
		 After Width: | Height: | Size: 1.2 KiB  | 
							
								
								
									
										44
									
								
								clients/webxr/viewer/plugin.xrforge.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								clients/webxr/viewer/plugin.xrforge.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,44 @@
 | 
			
		|||
 | 
			
		||||
function init(widget){
 | 
			
		||||
  inferSource(widget.src)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function inferSource(src){
 | 
			
		||||
 response = await fetch(src, {
 | 
			
		||||
    method: 'HEAD'
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  if (!response.ok) {
 | 
			
		||||
    throw new Error(`HTTP error! status: ${response.status}`);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // 1. Get the Content-Disposition header value
 | 
			
		||||
  contentDisposition = response.headers.get('Content-Disposition');
 | 
			
		||||
  
 | 
			
		||||
  // 2. Process the value to extract the filename
 | 
			
		||||
	console.log(widget.src)
 | 
			
		||||
  widget.src = extractFilename(contentDisposition)
 | 
			
		||||
	console.log("detected: "+widget.src)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function extractFilename(contentDispositionHeader) {
 | 
			
		||||
  // Check for the preferred 'filename*' (UTF-8 encoded)
 | 
			
		||||
  // This looks for 'filename*=' followed by the encoding and the filename
 | 
			
		||||
  const utf8Match = contentDispositionHeader.match(/filename\*=(?:utf-8|UTF-8)''(.+?)(?:;|$)/i);
 | 
			
		||||
  if (utf8Match && utf8Match[1]) {
 | 
			
		||||
    // The filename might be URL-encoded, so decode it
 | 
			
		||||
    // The value in your example is 'website.jpg' which is not encoded, 
 | 
			
		||||
    // but a proper implementation should decode.
 | 
			
		||||
    return decodeURIComponent(utf8Match[1].trim());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Fallback to the simpler 'filename'
 | 
			
		||||
  const basicMatch = contentDispositionHeader.match(/filename="(.+?)"/i);
 | 
			
		||||
  if (basicMatch && basicMatch[1]) {
 | 
			
		||||
    return basicMatch[1].trim();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return null;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export { init };
 | 
			
		||||
							
								
								
									
										26
									
								
								clients/webxr/viewer/shell.nix
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								clients/webxr/viewer/shell.nix
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,26 @@
 | 
			
		|||
#let 
 | 
			
		||||
#  pkgs = import (builtins.fetchGit {
 | 
			
		||||
#      name = "nixos-23.05";
 | 
			
		||||
#    url = "https://github.com/nixos/nixpkgs/";
 | 
			
		||||
#    ref = "refs/heads/nixos-unstable";
 | 
			
		||||
#    rev = "ef99fa5c5ed624460217c31ac4271cfb5cb2502c";
 | 
			
		||||
#  }) {};
 | 
			
		||||
{ pkgs ? import <nixpkgs> {} }:
 | 
			
		||||
 | 
			
		||||
  pkgs.mkShell {
 | 
			
		||||
    # nativeBuildInputs is usually what you want -- tools you need to run
 | 
			
		||||
    nativeBuildInputs = with pkgs.buildPackages; [ 
 | 
			
		||||
 | 
			
		||||
      nodejs_20
 | 
			
		||||
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    shellHook = ''
 | 
			
		||||
      
 | 
			
		||||
      # install bun
 | 
			
		||||
      alias bun="steam-run ~/.bun/bin/bun"
 | 
			
		||||
      test -f ~/.bun/bin/bun || curl -fsSL https://bun.com/install | bash -s "bun-v1.2.22"
 | 
			
		||||
 | 
			
		||||
      export NIX_SHELL_DEV=1
 | 
			
		||||
    '';
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		
		Reference in a new issue