Skip to content

Instantly share code, notes, and snippets.

@PierceLBrooks
Created February 5, 2024 23:27
Show Gist options
  • Save PierceLBrooks/b99ea234a265e822d2933041fcf2b57c to your computer and use it in GitHub Desktop.
Save PierceLBrooks/b99ea234a265e822d2933041fcf2b57c to your computer and use it in GitHub Desktop.
extends Node3D
# Called when the node enters the scene tree for the first time.
func _ready():
var state = GLTFState.new()
var document = GLTFDocument.new()
var error = document.append_from_file("res://untitled.gltf", state)
if (error != OK):
print(str(error))
return
var nodes = state.get_nodes()
for i in range(len(nodes)):
var node = nodes[i]
if (node.get_skeleton() >= 0):
var skeleton = state.get_skeletons()[node.get_skeleton()]
var roots = skeleton.get_roots()
if not (roots.has(i)):
continue
print(str(i)+" = "+node.resource_name)
print("\t"+str(node.get_mesh()))
print("\t"+str(node.get_skin()))
print("\t"+str(node.get_skeleton()))
if (node.get_skeleton() >= 0):
var skeleton = state.get_skeletons()[node.get_skeleton()]
var roots = skeleton.get_roots()
var joints = skeleton.get_joints()
for j in range(len(roots)):
print("\t\t"+str(roots[j]))
for j in range(len(joints)):
print("\t\t"+str(joints[j])+" = "+nodes[joints[j]].resource_name)
if (node.get_mesh() >= 0):
var mesh = state.get_meshes()[node.get_mesh()].get_mesh()
print("\t\t"+str(mesh.get_surface_count()))
for j in range(mesh.get_surface_count()):
var surface = mesh.get_surface_arrays(j)
print("\t\t\t"+str(j)+" = "+str(len(surface[Mesh.ARRAY_WEIGHTS])))
var scene = document.generate_scene(state)
add_child(scene)
print(str(get_world_3d()))
print(str(scene.get_world_3d()))
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment