Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Examples/Blazor3D.Examples.Server/Controllers/FileController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Mvc;

namespace Blazor3D.Examples.Server.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class FileController : Controller
{
/// <summary>
/// Addition as a controller for accessing local files
/// </summary>
/// <param name="link">Full path local file</param>
/// <returns></returns>
[HttpGet("[action]")]
public IActionResult FileDownload([FromQuery] string link)
{
var saveFileName = link.Substring(link.LastIndexOf('\\') + 1);
try
{
var fileBytes = System.IO.File.ReadAllBytes(link);

var contentType = "APPLICATION/octet-stream";
var fileName = saveFileName;
return File(fileBytes, contentType, fileName);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, "Error download: " + ex.Message);
}
}
}
}
23 changes: 22 additions & 1 deletion Examples/Blazor3D.Examples.Server/Pages/Example02.razor
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<div class="col-6">
<p><button class="btn btn-primary" @onclick="OnLoadObjButtonClick">Load OBJ</button> </p>
<p><button class="btn btn-primary" @onclick="OnLoadObjNoTexturesButtonClick">Load OBJ w/o texture</button> </p>
<p>
<input @bind="PathToLocalDisk" placeholder="Enter the full path to the file on your local drive" size="50" /><br/>
<button class="btn btn-primary" @onclick="OnLoadObjNoTexturesLocalFilesButtonClick">Load OBJ w/o texture local disk</button>
</p>
<p><button class="btn btn-primary" @onclick="OnLoadColladaButtonClick">Load Collada</button> </p>
<p><button class="btn btn-primary" @onclick="OnLoadFbxButtonClick">Load Fbx</button> </p>
<p><button class="btn btn-primary" @onclick="OnLoadGltfButtonClick">Load Gltf</button> </p>
Expand All @@ -38,6 +42,7 @@
private Scene scene = new Scene();
private Guid loadedObjectGuid = Guid.NewGuid();
private string msg = string.Empty;
private string PathToLocalDisk { get; set; }

public void Dispose()
{
Expand All @@ -51,7 +56,8 @@
return base.OnInitializedAsync();
}

private void AddLights(){
private void AddLights()
{
scene.Add(new AmbientLight());
scene.Add(new PointLight()
{
Expand Down Expand Up @@ -119,6 +125,21 @@
await View3D1.SetCameraPositionAsync(new Vector3(0, 100, 250), new Vector3(0, 50, 0));
}

private async Task OnLoadObjNoTexturesLocalFilesButtonClick()
{
var settings = new ImportSettings
{
Format = Import3DFormats.Obj,
//The path is processed without quotes
FileURL = $"api/File/FileDownload?link={PathToLocalDisk}"
};

loadedObjectGuid = await View3D1.Import3DModelAsync(settings);
await View3D1.SetCameraPositionAsync(
new Vector3(0, 100, 250),
new Vector3(0, 50, 0));
}

private async Task OnLoadColladaButtonClick()
{
var settings = new ImportSettings
Expand Down
5 changes: 5 additions & 0 deletions Examples/Blazor3D.Examples.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddControllers();

var app = builder.Build();

Expand All @@ -30,6 +31,10 @@

app.UseRouting();

app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");

app.MapBlazorHub();
app.MapFallbackToPage("/_Host");

Expand Down