feat/godot: work in progress [might break]

This commit is contained in:
Leon van Kammen 2024-05-14 09:36:54 +00:00
parent 00d82cf262
commit b265478960
6 changed files with 13 additions and 1341 deletions

1
example/aframe/sandbox/dist Symbolic link
View File

@ -0,0 +1 @@
../../../dist

View File

@ -0,0 +1 @@
/home/leon/projects/projects.usb/2wa.gitlab.io/asset/XR

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -8,7 +8,8 @@ var player:CharacterBody3D
func _ready(): func _ready():
xrf = preload("res://xrfragment.gd").new() xrf = preload("res://xrfragment.gd").new()
add_child(xrf) add_child(xrf)
xrf.to("https://xrfragment.org/other.glb", _onXRF ) #xrf.to("https://xrfragment.org/other.glb", _onXRF )
xrf.to("http://localhost:8080/example/assets/other.glb", _onXRF )
player = find_child("PlayerBody") player = find_child("PlayerBody")
player.enabled = false # optional: turn off gravity player.enabled = false # optional: turn off gravity

View File

@ -127,7 +127,6 @@ func to(url, f:Callable ):
var http_request = HTTPRequest.new() var http_request = HTTPRequest.new()
add_child(http_request) add_child(http_request)
http_request.request_completed.connect(downloadModelSuccess) http_request.request_completed.connect(downloadModelSuccess)
var error = http_request.request(url) var error = http_request.request(url)
if error != OK: if error != OK:
push_error("An error occurred in the HTTP request.") push_error("An error occurred in the HTTP request.")
@ -142,6 +141,9 @@ func downloadModelSuccess(result, response_code, headers, body):
# TODO: here different parsing functions should be called # TODO: here different parsing functions should be called
# based on the filetype (glb,gltf,ade,obj e.g.) # based on the filetype (glb,gltf,ade,obj e.g.)
loadModelFromBufferByGLTFDocument(body) loadModelFromBufferByGLTFDocument(body)
if scene == null:
print('could not load GLTF from HTTP response')
return
_parseXRFMetadata(scene) _parseXRFMetadata(scene)
traverse( scene, _parseXRFMetadata ) traverse( scene, _parseXRFMetadata )
# setup actions & embeds # setup actions & embeds
@ -158,7 +160,8 @@ func loadModelFromBufferByGLTFDocument(body):
var error = doc.append_from_buffer(body, "", state) var error = doc.append_from_buffer(body, "", state)
if error == OK: if error == OK:
scene = doc.generate_scene(state) scene = doc.generate_scene(state)
scene.name = "XRFscene" scene.name = "XRFscene"
_addAnimations(state, scene)
metadata = _parseMetadata(state,scene) metadata = _parseMetadata(state,scene)
add_child(scene) add_child(scene)
print("model added") print("model added")
@ -173,6 +176,10 @@ func _parseXRFMetadata(node:Node):
if typeof(extras[i]) == TYPE_STRING: if typeof(extras[i]) == TYPE_STRING:
XRF[ i ] = parseURL( extras[i] ) XRF[ i ] = parseURL( extras[i] )
node.set_meta("XRF", XRF) node.set_meta("XRF", XRF)
func _addAnimations( state:GLTFState, scene):
for i in state.get_animation_players_count(0):
print(i) #add_child( state.get_animation_player(i) )
func traverse(node, f:Callable ): func traverse(node, f:Callable ):
for N in node.get_children(): for N in node.get_children():