bool LoadTexture()
    {
        byte[] file = File.ReadAllBytes(Program.Root + "/floor.png");
        Tex    tex  = Tex.FromMemory(file);

        return(tex != null);
    }
Exemple #2
0
    bool LoadTexture()
    {
        byte[] file = File.ReadAllBytes(SK.Settings.assetsFolder + "/floor.png");
        Tex    tex  = Tex.FromMemory(file);

        return(tex != null);
    }
Exemple #3
0
    ///////////////////////////////////////////

    static async Task RequestColor(BoundingBox regionBounds)
    {
        var request = new ImageryRequest()
        {
            MapArea     = regionBounds,
            MapWidth    = 1024,
            MapHeight   = 1024,
            ImagerySet  = ImageryType.Aerial,
            BingMapsKey = _ApiKey
        };
        Task <Response> metaTask  = ServiceManager.GetResponseAsync(request);
        Task <Stream>   colorTask = ServiceManager.GetImageAsync(request);
        await Task.WhenAll(metaTask, colorTask);

        Response meta  = await metaTask;
        Stream   color = await colorTask;

        if (meta.StatusCode != 200)
        {
            Log.Warn("Bing Maps API error:\n" + string.Join('\n', meta.ErrorDetails));
            return;
        }

        MemoryStream stream = null;

        if (color is MemoryStream)
        {
            stream = color as MemoryStream;
        }
        else
        {
            color.CopyTo(stream);
        }

        mapColor             = Tex.FromMemory(stream.ToArray());
        mapColor.AddressMode = TexAddress.Clamp;

        BoundingBox bounds = new BoundingBox(meta.ResourceSets[0].Resources[0].BoundingBox);

        Geo.BoundsToWorld(regionBounds, bounds, out mapColorSize, out mapColorCenter);
        terrain.SetColorData(mapColor, mapColorSize.XZ * worldScale, mapColorCenter * worldScale);

        if (mapColor == null)
        {
            Log.Warn(Encoding.ASCII.GetString(stream.ToArray()));
        }
    }
 private void UpdateImage(Shared <EncodedImage> image)
 {
     this.Material[MatParamName.DiffuseTex] = Tex.FromMemory(image.Resource.GetBuffer());
 }
    ///////////////////////////////////////////

    public static async Task RequestColor(string apiKey, ImageryType imageryType, BoundingBox regionBounds, Action <Tex, Vec3, Vec2> OnReceivedColor)
    {
        // Request an image from the maps API! This is the request package
        // that gets sent to the server, details about the arguments can be
        // found here:
        // https://github.com/microsoft/BingMapsRESTToolkit/blob/master/Docs/API%20Reference.md#ImageryRequest
        ImageryRequest request = new ImageryRequest()
        {
            MapArea     = regionBounds,
            MapWidth    = 1024,
            MapHeight   = 1024,
            ImagerySet  = imageryType,
            BingMapsKey = apiKey
        };
        // We need the meta response as well as the image response, since the
        // image API doesn't care too much about what we actually request!
        // The results it sends back can differ in size, bounds, image format,
        // so we need to know what we got!
        Task <Response> metaTask  = ServiceManager.GetResponseAsync(request);
        Task <Stream>   colorTask = ServiceManager.GetImageAsync(request);
        await Task.WhenAll(metaTask, colorTask);

        Response meta   = await metaTask;
        Stream   stream = await colorTask;

        // StatusCode is a web response status code, where 200-299 means
        // success. Details here:
        // https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
        if (meta.StatusCode < 200 || meta.StatusCode >= 300)
        {
            Log.Warn("Bing Maps API error:\n" + string.Join('\n', meta.ErrorDetails));
            return;
        }

        // We need the result as a MemoryStream so we can grab the result as
        // an array of bytes.
        MemoryStream memStream = null;

        if (stream is MemoryStream)
        {
            memStream = (MemoryStream)stream;
        }
        else
        {
            stream.CopyTo(memStream);
        }

        // Send the image over to StereoKit, and turn it into a texture!
        Tex texture = Tex.FromMemory(memStream.ToArray());

        texture.AddressMode = TexAddress.Mirror;

        // Convert the image's bounds from lat/lon information into our
        // world's meters.
        BoundingBox bounds = new BoundingBox(meta.ResourceSets[0].Resources[0].BoundingBox);

        Geo.BoundsToWorld(regionBounds, bounds, out Vec3 size, out Vec2 center);

        // Done! Pass the results back.
        OnReceivedColor(texture, size, center);
    }