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
112 changes: 109 additions & 3 deletions doc/HomagGroup.Blazor3D.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/dotnet/Blazor3D/Blazor3D/Enums/ImportModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public enum Import3DFormats
/// <summary>
/// <a target="_blank" href="https://en.wikipedia.org/wiki/STL_(file_format)">Stl</a> format.
/// </summary>
Stl
Stl,
/// <summary>
/// <a target="_blank" href="https://en.wikipedia.org/wiki/Point_Cloud_Library#PCD_File_Format">Pcd</a> format.
/// </summary>
Pcd
}
}
41 changes: 41 additions & 0 deletions src/dotnet/Blazor3D/Blazor3D/Geometires/PointsGeometry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using HomagGroup.Blazor3D.Core;
using HomagGroup.Blazor3D.Maths;

namespace HomagGroup.Blazor3D.Geometires
{
/// <summary>
/// <para>Geometry for a point cloud.</para>
/// <para>This class inherits from <see cref="BufferGeometry"/></para>
/// </summary>
/// <inheritdoc><see cref="BufferGeometry"/></inheritdoc>
public sealed class PointsGeometry : BufferGeometry
{
public PointsGeometry() : base("PointsGeometry")
{ }

/// <summary>
/// Positions of each point. Defaults to empty list.
/// </summary>
public List<Vector3> Points { get; set; } = new List<Vector3>();

/// <summary>
/// Normal vectors for each point. Defaults to empty list. Optional, leave empty if not used.
/// </summary>
public List<Vector3> Normals { get; set; } = new List<Vector3>();

/// <summary>
/// RGB colors for each point. Defaults to empty list. Optional, leave empty if not used.
/// </summary>
public List<Vector3> Colors { get; set; } = new List<Vector3>();

/// <summary>
/// Intensities for each point. Defaults to empty list. Optional, leave empty if not used.
/// </summary>
public List<double> Intensities{ get; set; } = new List<double>();

/// <summary>
/// Numeric labels for each point. Defaults to empty list. Optional, leave empty if not used.
/// </summary>
public List<int> Labels{ get; set; } = new List<int>();
}
}
6 changes: 6 additions & 0 deletions src/dotnet/Blazor3D/Blazor3D/Materials/Material.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,11 @@ protected Material(string type)
/// When drawing 2D overlays it can be useful to disable the depth writing in order to layer several things together without creating z-index artifacts.
/// </summary>
public bool DepthWrite { get; set; } = true;

/// <summary>
/// Defines whether vertex coloring is used. Default is false. The engine supports RGB and RGBA vertex colors depending on
/// whether a three (RGB) or four (RGBA) component color buffer attribute is used.
/// </summary>
public bool VertexColors { get; set; } = false;
}
}
49 changes: 49 additions & 0 deletions src/dotnet/Blazor3D/Blazor3D/Materials/PointsMaterial.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using HomagGroup.Blazor3D.Textures;

namespace HomagGroup.Blazor3D.Materials
{
/// <summary>
/// <para>The default material used by <see cref="Objects.Points"/>.</para>
/// <para>This class inherits from <see cref="Material"/></para>
/// <para>Wrapper for three.js <a target="_blank" href="https://threejs.org/docs/index.html#api/en/materials/PointsMaterial">PointsMaterial</a></para>
/// <para>The documentation comments for this class have been copied from <a target="_blank" href="https://threejs.org/docs/index.html#api/en/materials/PointsMaterial">threejs.org</a>.</para>
/// </summary>
/// <inheritdoc><see cref="Material"/></inheritdoc>
public sealed class PointsMaterial : Material
{
public PointsMaterial() : base("PointsMaterial")
{ }

/// <summary>
/// Sets the color of the points using data from a Texture. May optionally include an alpha channel, typically combined with Transparent (todo) or AlphaTest(todo).
/// Default is null. The texture map color is modulated by the diffuse Color.
/// </summary>
public Texture Map { get; set; } = null!;

/// <summary>
/// The alpha map is a grayscale texture that controls the opacity across the surface (black: fully transparent; white: fully opaque). Default is null.
///
/// Only the color of the texture is used, ignoring the alpha channel if one exists.For RGB and RGBA textures, the
/// <a target="_blank" href="https://threejs.org/docs/index.html#api/en/renderers/WebGLRenderer">WebGL renderer</a> will use the green channel
/// when sampling this texture due to the extra bit of precision provided for green in DXT-compressed and uncompressed RGB 565 formats.
/// Luminance-only and luminance/alpha textures will also still work as expected.
/// </summary>
public Texture AlphaMap { get; set; } = null!;

/// <summary>
/// Whether the material is affected by fog. Default is true.
/// </summary>
public bool Fog { get; set; } = true;

/// <summary>
/// Defines the size of the points in pixels. Default is 1.0.
/// Will be capped if it exceeds the hardware dependent parameter <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/getParameter">gl.ALIASED_POINT_SIZE_RANGE</a>.
/// </summary>
public double Size { get; set; } = 1.0;

/// <summary>
/// Specify whether points' size is attenuated by the camera depth. (Perspective camera only.) Default is true.
/// </summary>
public bool SizeAttenuation { get; set; } = true;
}
}
35 changes: 35 additions & 0 deletions src/dotnet/Blazor3D/Blazor3D/Objects/Points.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using HomagGroup.Blazor3D.Core;
using HomagGroup.Blazor3D.Geometires;
using HomagGroup.Blazor3D.Materials;

namespace HomagGroup.Blazor3D.Objects
{
/// <summary>
/// <para>A class for displaying points. The points are rendered by the
/// <a target="_blank" href="https://threejs.org/docs/index.html#api/en/renderers/WebGLRenderer">WebGLRenderer</a> using
/// <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements">gl.POINTS</a>.
/// </para>
/// <para>This object inherits from <see cref="Object3D"/></para>
/// <para>Wrapper for three.js <a target="_blank" href="https://threejs.org/docs/index.html#api/en/objects/Points">Points</a></para>
/// <para>The documentation comments for this class have been copied from <a target="_blank" href="https://threejs.org/docs/index.html#api/en/objects/Points">threejs.org</a>.</para>
/// </summary>
/// <inheritdoc><see cref="Object3D"/></inheritdoc>
public class Points : Object3D
{
public Points() : base("Points")
{ }

protected Points(string type) : base(type)
{ }

/// <summary>
/// <para>An instance of <see cref="Materials.Material"/>, defining the object's appearance. Default is a <see cref="PointsMaterial"/>.</para>
/// </summary>
public Material Material { get; set; } = new PointsMaterial();

/// <summary>
/// <para>An instance of <see cref="BufferGeometry"/> (or derived classes), defining the object's structure.</para>
/// </summary>
public BufferGeometry Geometry { get; set; } = new PointsGeometry();
}
}
8 changes: 4 additions & 4 deletions src/dotnet/Blazor3D/Blazor3D/Settings/ImportSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public class ImportSettings
/// </summary>
public Guid? Uuid { get; set; } = null;
/// <summary>
/// <para>Material that will be applied to all loaded meshes.</para>
/// <para>Currently works only for <see cref="Import3DFormats.Stl"/> STL format.</para>
/// <para>If not specified, the default <see cref="MeshStandardMaterial"/> is applied to the imported objects.</para>
/// <para>Material that will be applied to all loaded models.</para>
/// <para>Currently works only for <see cref="Import3DFormats.Stl"/> and <see cref="Import3DFormats.Pcd"/> formats.</para>
/// <para>If not specified, the default <see cref="Materials.Material"/> is applied to the imported objects.</para>
/// </summary>
public MeshStandardMaterial Material { get; set; } = null!;
public Material Material { get; set; } = null!;
}
}
22 changes: 16 additions & 6 deletions src/dotnet/Blazor3D/Blazor3D/Viewers/Viewer.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,10 @@ private List<Object3D> ParseChildren(JToken? children)
private async Task OnObjectLoadedPrivate(Object3DArgs e)
{
var json = await bundleModule.InvokeAsync<string>("getSceneItemByGuid", e.UUID);
if (json.Contains("\"type\":\"Group\""))

var type = JsonConvert.DeserializeAnonymousType(json, new { Type="" })?.Type;

if (type == "Group")
{
var jobject = JObject.Parse(json);
var name = jobject.Property("name")?.Value.ToString() ?? string.Empty;
Expand All @@ -381,8 +384,7 @@ private async Task OnObjectLoadedPrivate(Object3DArgs e)
Scene.Children.Add(group);
ObjectLoaded?.Invoke(new Object3DArgs() { UUID = e.UUID });
}

if (json.Contains("\"type\":\"Mesh\""))
else if (type == "Mesh")
{
var mesh = JsonConvert.DeserializeObject<Mesh>(json);
if (mesh != null)
Expand All @@ -391,14 +393,22 @@ private async Task OnObjectLoadedPrivate(Object3DArgs e)
ObjectLoaded?.Invoke(new Object3DArgs() { UUID = e.UUID });
}
}

if (json.Contains("\"type\":\"Sprite\""))
else if (type == "Sprite")
{
var sprite = JsonConvert.DeserializeObject<Sprite>(json);
if (sprite != null)
{
Scene.Children.Add(sprite);
ObjectLoaded?.Invoke(new Object3DArgs() { UUID= e.UUID });
ObjectLoaded?.Invoke(new Object3DArgs() { UUID = e.UUID });
}
}
else if (type == "Points")
{
var points = JsonConvert.DeserializeObject<Points>(json);
if (points != null)
{
Scene.Children.Add(points);
ObjectLoaded?.Invoke(new Object3DArgs() { UUID = e.UUID });
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/dotnet/Blazor3D/Blazor3D/wwwroot/js/bundle.js

Large diffs are not rendered by default.

Loading