Exemple #1
0
        static public List <double> ConvertXForm(Transform xform)
        {
            if (xform == null || xform.IsIdentity)
            {
                return(null);
            }

            var BasisX  = xform.BasisX;
            var BasisY  = xform.BasisY;
            var BasisZ  = xform.BasisZ;
            var Origin  = xform.Origin;
            var OriginX = PointInt.ConvertFeetToMillimetres(Origin.X);
            var OriginY = PointInt.ConvertFeetToMillimetres(Origin.Y);
            var OriginZ = PointInt.ConvertFeetToMillimetres(Origin.Z);

            List <double> glXform = new List <double>(16)
            {
                BasisX.X, BasisX.Y, BasisX.Z, 0,
                BasisY.X, BasisY.Y, BasisY.Z, 0,
                BasisZ.X, BasisZ.Y, BasisZ.Z, 0,
                OriginX, OriginY, OriginZ, 1
            };

            return(glXform);
        }
Exemple #2
0
        public void CloseGeometry()
        {
            Debug.WriteLine(String.Format("{0}  Closing Geometry", formatDebugHeirarchy));
            // Create the new mesh and populate the primitives with GeometryData
            glTFMesh mesh = new glTFMesh();

            mesh.primitives = new List <glTFMeshPrimitive>();

            // transfer ordered vertices from vertex dictionary to vertices list
            foreach (KeyValuePair <string, GeometryData> key_geom in currentGeom)
            {
                string       key  = key_geom.Key;
                GeometryData geom = key_geom.Value;
                foreach (KeyValuePair <PointInt, int> point_index in geom.vertDictionary)
                {
                    PointInt point = point_index.Key;
                    geom.vertices.Add(point.X);
                    geom.vertices.Add(point.Y);
                    geom.vertices.Add(point.Z);
                }

                // convert GeometryData objects into glTFMeshPrimitive
                string material_key = key.Split('_')[1];

                glTFBinaryData bufferMeta = processGeometry(geom, key);
                if (bufferMeta.hashcode != null)
                {
                    binaryFileData.Add(bufferMeta);
                }

                glTFMeshPrimitive primative = new glTFMeshPrimitive();

                primative.attributes.POSITION = bufferMeta.vertexAccessorIndex;
                primative.indices             = bufferMeta.indexAccessorIndex;
                primative.material            = materialDict.GetIndexFromUUID(material_key);
                // TODO: Add normal attribute accessor index here

                mesh.primitives.Add(primative);
            }

            // glTF entity can not be empty
            if (mesh.primitives.Count() > 0)
            {
                // Prevent mesh duplication by hash checking
                string meshHash            = ManagerUtils.GenerateSHA256Hash(mesh);
                ManagerUtils.HashSearch hs = new ManagerUtils.HashSearch(meshHash);
                int idx = meshContainers.FindIndex(hs.EqualTo);

                if (idx != -1)
                {
                    // set the current nodes mesh index to the already
                    // created mesh location.
                    nodeDict[currentNodeId].mesh = idx;
                }
                else
                {
                    // create new mesh and add it's index to the current node.
                    MeshContainer mc = new MeshContainer();
                    mc.hashcode = meshHash;
                    mc.contents = mesh;
                    meshContainers.Add(mc);
                    nodeDict[currentNodeId].mesh = meshContainers.Count - 1;
                }
            }

            geometryStack.Pop();
            return;
        }