Ejemplo n.º 1
0
        static Scene.Node NodeFromGLTFScene(glTF.glTF gltf, byte[] bytes, int index)
        {
            var scene = gltf.scenes[index];
            var group = new Scene.Group();

            group.Name     = scene.name;
            group.Children = new List <Scene.Node>();
            for (int i = 0, c = scene.nodes.Length; i < c; ++i)
            {
                group.Children.Add(NodeFromGLTFNode(gltf, bytes, i));
            }
            return(group);
        }
Ejemplo n.º 2
0
        void HandleObject(OpenFlight.Node node, Scene.Node parent)
        {
            var flt_object = Parser.ParseObject(node.Record);
            var group      = new Scene.Group();

            group.Name = flt_object.ID;
            parent.AddChild(group);
            foreach (var child in node.Children)
            {
                HandleNode(child, group);
            }
            if (WorkingGroup != null)
            {
                CloseWorkingGroup();
            }
        }
Ejemplo n.º 3
0
        static Scene.Node NodeFromGLTFNode(glTF.glTF gltf, byte[] bytes, int index)
        {
            var node = gltf.nodes[index];

            Scene.Node result = new Scene.Group();

            /*
             * Scene.Node result = null;
             * if (node.mesh < 0)
             *  result = new Scene.Group();
             * else
             *  result = new Scene.Mesh();
             */

            result.Name = node.name;
            if (node.translation != null)
            {
                result.position = new Vector3(node.translation[0], node.translation[1], node.translation[2]);
            }
            if (node.rotation != null)
            {
                // assign rotation
            }

            // TODO: assign translation to result.Matrix
            // TODO: assign rotation to result.Matrix

            if (node.mesh >= 0)
            {
                result.Children = new List <Scene.Node>();
                var mesh = gltf.meshes[node.mesh];

                foreach (var meshprimitive in gltf.meshes[index].primitives)
                {
                    var meshtoadd = new Scene.Mesh();
                    meshtoadd.Name = gltf.meshes[node.mesh].name;
                    if (meshprimitive.attributes.POSITION != -1)
                    {
                        meshtoadd.Vertices = Vector3FromBinary(gltf, bytes, meshprimitive.attributes.POSITION);
                    }
                    if (meshprimitive.attributes.NORMAL != -1)
                    {
                        meshtoadd.Normals = Vector3FromBinary(gltf, bytes, meshprimitive.attributes.NORMAL);
                    }
                    if (meshprimitive.attributes.TEXCOORD_0 != -1)
                    {
                        meshtoadd.UVs1 = Vector2FromBinary(gltf, bytes, meshprimitive.attributes.TEXCOORD_0);
                    }
                    if (meshprimitive.indices != -1)
                    {
                        meshtoadd.Triangles = TrianglesFromBinary(gltf, bytes, meshprimitive.indices);
                    }
                    if (meshprimitive.material != -1)
                    {
                        meshtoadd.MaterialIndex = meshprimitive.material;
                    }
                    result.Children.Add(meshtoadd);
                }
            }
            if (node.children != null)
            {
                for (int i = 0, c = node.children.Length; i < c; ++i)
                {
                    result.Children.Add(NodeFromGLTFNode(gltf, bytes, i));
                }
            }
            return(result);
        }