; LoadGLTFScene Example ; --------------------- ; Requires Extended mode. Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,1.5,-6 light=CreateLight() RotateEntity light,45,45,0 ; A pivot to hang the imported scene on, so we can scale and spin it as one holder=CreatePivot() ; The whole file arrives as one entity tree, parented to our pivot scene=LoadGLTFScene("../../../samples/glTF/assets/ToyCar/ToyCar.glb",holder) If scene=0 Then RuntimeError "Could not load ToyCar.glb: "+ModelLoadError() ; The car is authored at real-world scale, about 20cm long ScaleEntity holder,30,30,30 ; Every node of the file became a child entity you can address by yourself parts=CountChildren(scene) pick=1 While Not KeyDown(1) TurnEntity holder,0,0.4,0 ; Space steps through the parts the file was built from If KeyHit(57) And parts>0 ; Put the old selection back to full opacity old=GetChild(scene,pick) If EntityClass(old)="Mesh" Then EntityAlpha old,1 pick=pick+1 If pick>parts Then pick=1 EndIf ; Describe whichever part is selected, and fade it so you can spot it part=GetChild(scene,pick) name$=EntityName$(part) cls$=EntityClass(part) surfs=0 If cls$="Mesh" surfs=CountSurfaces(part) EntityAlpha part,0.3 EndIf ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld Text 0,0,"Space: step through the imported parts Arrows: camera Esc: exit" Text 0,20,"LoadGLTFScene(...,holder) gave one root entity with "+parts+" children" Text 0,40,"Part "+pick+" of "+parts+": "+Chr$(34)+name$+Chr$(34)+" class "+cls$+" surfaces "+surfs Text 0,60,"The faded part is the selected one. Helper nodes carry no geometry at all" Flip Wend End