Пример #1
0
    //private int[] getTriangles(TerrainTile terraintile)
    //{

    //    return terraintile.GetTriangles(0);
    //}

    private Vector3WGS TerrainTileCenterWGS(int X, int Y)
    {
        Vector3WGS origin   = new Vector3WGS();
        double     tileSize = 180 / Math.Pow(2, zoomLevel);

        origin.lon = ((X + 0.5) * tileSize) - 180;
        origin.lat = ((Y + 0.5) * tileSize) - 90;
        return(origin);
    }
Пример #2
0
        /// <summary>
        /// Splits an unsupported multidimensional array into a Vector3 array.
        /// </summary>
        /// <param name="coordinates">The string containing the multidimensional array</param>
        /// <returns>An array of unity coordinates</returns>
        private Vector3[] SplitToCoordinatesArray(string coordinates, string startHeight, string endHeight)
        {
            splitArray = coordinates.Split(new string[] { "],[" }, StringSplitOptions.None);
            newVector2Array.Clear();

            //Convert string with RD coordinates into unity coordinates
            for (int i = 0; i < splitArray.Length; i++)
            {
                vector2String = splitArray[i].Split(',');
                Vector3WGS newWGSVector3 = new Vector3WGS(
                    double.Parse(vector2String[0], CultureInfo.InvariantCulture),
                    double.Parse(vector2String[1], CultureInfo.InvariantCulture),
                    (i == 0) ? double.Parse(startHeight, CultureInfo.InvariantCulture) + napOffset : double.Parse(endHeight, CultureInfo.InvariantCulture) + napOffset
                    );

                Vector3 unityCoordinate = CoordConvert.WGS84toUnity(newWGSVector3);
                newVector2Array.Add(unityCoordinate);
            }
            return(newVector2Array.ToArray());
        }
Пример #3
0
    /// <summary>
    /// Write the XML output based on our list of materials and objects+triangles
    /// </summary>
    public void CreateCollada(bool addGeoLocation = false, Vector3WGS geolocationWGS = default)
    {
        if (addGeoLocation)
        {
            generateGeoHeader = true;
            geoCoordinates    = geolocationWGS;
        }

        stringWriter = new StringWriter();
        writer       = new XmlTextWriter(stringWriter);
        WriteDocumentHeader();
        WriteAssetHeader();

        //Library for material Effects
        writer.WriteStartElement("library_effects");
        foreach (Material material in materials)
        {
            WriteMaterialEffects(material);
        }
        writer.WriteEndElement();

        //Library for materials
        writer.WriteStartElement("library_materials");
        foreach (Material material in materials)
        {
            WriteMaterial(material);
        }
        writer.WriteEndElement();

        //Library for geometries
        if (objectsTriangles != null && objectsTriangles.Count > 0)
        {
            writer.WriteStartElement("library_geometries");

            foreach (var mesh in objectsTriangles)
            {
                WriteGeometry(mesh);
            }
            writer.WriteEndElement();             //end library_geometries
        }

        //Library for scenes
        writer.WriteStartElement("library_visual_scenes");
        writer.WriteStartElement("visual_scene");
        writer.WriteAttributeString("id", "DefaultScene");

        if (generateGeoHeader)
        {
            //geolocation (officialy only supported from collada 1.5.1)
            writer.WriteStartElement("asset");
            writer.WriteStartElement("coverage");
            writer.WriteStartElement("geographic_location");
            writer.WriteStartElement("longitude");
            writer.WriteString(geoCoordinates.lon.ToString(CultureInfo.InvariantCulture));
            writer.WriteEndElement();             //end longitude
            writer.WriteStartElement("latitude");
            writer.WriteString(geoCoordinates.lat.ToString(CultureInfo.InvariantCulture));
            writer.WriteEndElement();             //end latitude
            writer.WriteStartElement("altitude");
            writer.WriteAttributeString("mode", "relativeToGround");
            writer.WriteString(geoCoordinates.h.ToString(CultureInfo.InvariantCulture));
            writer.WriteEndElement();             //end altitude
            writer.WriteEndElement();             //end geographic_location
            writer.WriteEndElement();             //end coverage
            writer.WriteEndElement();             //end asset
        }

        if (objectsTriangles != null && objectsTriangles.Count > 0)
        {
            foreach (var mesh in objectsTriangles)
            {
                //Create nodes that reference instanced geometry
                writer.WriteStartElement("node");
                writer.WriteAttributeString("id", mesh.Key);
                writer.WriteStartElement("translate");
                writer.WriteString(" 0 0 0");
                writer.WriteEndElement();                 //end translate
                writer.WriteStartElement("scale");
                writer.WriteString(" 1 1 1");
                writer.WriteEndElement();                 //end scale

                //reference geometry
                writer.WriteStartElement("instance_geometry");
                writer.WriteAttributeString("url", "#" + mesh.Key + "-geometry");
                writer.WriteStartElement("bind_material");
                writer.WriteStartElement("technique_common");
                writer.WriteStartElement("instance_material");
                writer.WriteAttributeString("symbol", mesh.Key + "-symbol");
                writer.WriteAttributeString("target", "#" + mesh.Key);
                writer.WriteEndElement();                 //end instance_material
                writer.WriteEndElement();                 //end technique_common
                writer.WriteEndElement();                 //end bind_material
                writer.WriteEndElement();                 //end instance_geometry
                writer.WriteEndElement();                 //end node
            }
        }
        writer.WriteEndElement();         //end visual_scene
        writer.WriteEndElement();         //end library_visual_scenes

        //Scene
        writer.WriteStartElement("scene");
        writer.WriteStartElement("instance_visual_scene");
        writer.WriteAttributeString("url", "#DefaultScene");
        writer.WriteEndElement();         // end instance_visual_scene
        writer.WriteEndElement();         // end scene

        //Close document
        writer.WriteEndElement();         // COLLADA
        writer.WriteEndDocument();
        writer.Flush();
        writer.Close();
    }