public Scene[] LoadScenes (out int defaultScene) { defaultScene = -1; if (gltf.Scene == null) return new Scene[] {}; List<Scene> scenes = new List<Scene> (); defaultScene = (int)gltf.Scene; for (int i = 0; i < gltf.Scenes.Length; i++) { GL.Scene scene = gltf.Scenes[i]; Debug.WriteLine ("Loading Scene {0}", scene.Name); scenes.Add (new Scene { Name = scene.Name, }); if (scene.Nodes.Length == 0) continue; scenes[i].Root = new Node { localMatrix = Matrix4x4.Identity, Children = new List<Node> () }; foreach (int nodeIdx in scene.Nodes) loadNode (scenes[i].Root, gltf.Nodes[nodeIdx]); } return scenes.ToArray (); }
private void InitScene() { _scene = new gltf.Scene(); _scene.Nodes = new[] { 0 }; _topNode = new gltf.Node(); _topNode.Name = "Z_UP"; _topNode.Matrix = new[] { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; _nodes.Add(_topNode); }
public Scene[] LoadScenes(out int defaultScene) { defaultScene = -1; if (gltf.Scene == null) { return new Scene[] {} } ; List <Scene> scenes = new List <Scene> (); defaultScene = (int)gltf.Scene; for (int i = 0; i < gltf.Scenes.Length; i++) { GL.Scene scene = gltf.Scenes[i]; Debug.WriteLine("Loading Scene {0}", scene.Name); scenes.Add(new Scene { Name = scene.Name, }); if (scene.Nodes.Length == 0) { continue; } scenes[i].Root = new Node { localMatrix = Matrix4x4.Identity, Children = new List <Node> () }; foreach (int nodeIdx in scene.Nodes) { loadNode(scenes[i].Root, gltf.Nodes[nodeIdx]); } } return(scenes.ToArray()); } void loadNode(Node parentNode, GL.Node gltfNode) { Debug.WriteLine("Loading node {0}", gltfNode.Name); Vector3 translation = new Vector3(); Quaternion rotation = Quaternion.Identity; Vector3 scale = new Vector3(1); Matrix4x4 localTransform = Matrix4x4.Identity; if (gltfNode.Matrix != null) { float[] M = gltfNode.Matrix; localTransform = new Matrix4x4( M[0], M[1], M[2], M[3], M[4], M[5], M[6], M[7], M[8], M[9], M[10], M[11], M[12], M[13], M[14], M[15]); } if (gltfNode.Translation != null) { FromFloatArray(ref translation, gltfNode.Translation); } if (gltfNode.Translation != null) { FromFloatArray(ref rotation, gltfNode.Rotation); } if (gltfNode.Translation != null) { FromFloatArray(ref scale, gltfNode.Scale); } localTransform *= Matrix4x4.CreateScale(scale) * Matrix4x4.CreateFromQuaternion(rotation) * Matrix4x4.CreateTranslation(translation); //localTransform = Matrix4x4.Identity; Node node = new Node { localMatrix = localTransform, Parent = parentNode, Name = gltfNode.Name }; parentNode.Children.Add(node); if (gltfNode.Children != null) { node.Children = new List <Node> (); for (int i = 0; i < gltfNode.Children.Length; i++) { loadNode(node, gltf.Nodes[gltfNode.Children[i]]); } } if (gltfNode.Mesh != null) { node.Mesh = meshes[(int)gltfNode.Mesh]; } }