Example #1
0
 public static void CollectInstances(Va3cObject obj, Dictionary <string, int> geoLookup, Matrix4x4 transform, List <VimInstanceData> r)
 {
     transform *= ToMath3d(obj.matrix);
     if (geoLookup.ContainsKey(obj.geometry))
     {
         var inst = new VimInstanceData
         {
             WorldTransform = transform,
             MeshIndex      = geoLookup[obj.geometry]
         };
         r.Add(inst);
     }
     foreach (var c in obj.children)
     {
         CollectInstances(c, geoLookup, transform, r);
     }
 }
Example #2
0
        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);
        }