public glTF MakeGltf() { float scale = 1.0f; glTF gltf = new glTF(); glTFNode rootNode = new glTFNode(); rootNode.name = "rootNode"; rootNode.matrix = new List <float>() { scale, 0, 0, 0, 0, scale, 0, 0, 0, 0, scale, 0, 0, 0, 0, scale }; rootNode.children = new List <int>(); gltf.nodes.Add(rootNode); gltf = RecursivelyAddChilren(gltf, _container.obj, 0); return(gltf); }
public glTF RecursivelyAddChilren(glTF gltf, Va3cObject obj, int parentIndex) { foreach (var child in obj.children) { glTFNode childNode = new glTFNode(); childNode.name = child.name; foreach (double coord in child.matrix) { childNode.matrix.Add((float)coord); } int childIndex = gltf.AddChildNode(childNode, parentIndex); if (child.geometry != null) { Va3cGeometry geom = _geometries[child.geometry]; // make an accessor, buffer, and bufferView glTFBinaryData dataContainer = gltf.AddGeometryMeta(geom, child.uuid); binaryFileData.Add(dataContainer); // add geometry to meshes array glTFMesh mesh = new glTFMesh(); glTFMeshPrimitive primative = new glTFMeshPrimitive(); primative.attributes.POSITION = dataContainer.vertexAccessorIndex; primative.attributes.NORMAL = dataContainer.normalsAccessorIndex; primative.indices = dataContainer.indexAccessorIndex; mesh.primitives = new List <glTFMeshPrimitive>() { primative }; int meshIndex = gltf.AddMesh(mesh); gltf.nodes[childIndex].mesh = meshIndex; } if (child.children != null && child.children.Count > 0) { return(RecursivelyAddChilren(gltf, child, childIndex)); } } return(gltf); }
public int AddChildNode(glTFNode node, int parentIndex) { this.nodes.Add(node); this.nodes[parentIndex].children.Add(this.nodes.Count - 1); return(this.nodes.Count - 1); }