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
6 changes: 6 additions & 0 deletions doc/HomagGroup.Blazor3D.xml

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

30 changes: 30 additions & 0 deletions src/dotnet/Blazor3D/Blazor3D/Viewers/Viewer.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,36 @@ public async Task RemoveByUuidAsync(Guid uuid)
}
}

/// <summary>
/// Move object with the given id to new position from scene.
/// </summary>
/// <returns>Task</returns>
public async Task MoveObjectByUuidAsync(Guid uuid, Vector3? position = null, Euler? rotation = null, Vector3? scale = null)
{
var json = JsonConvert.SerializeObject(
new { position = position, rotation = rotation, scale = scale },
SerializationHelper.GetSerializerSettings()
);
await bundleModule.InvokeVoidAsync("moveObjectByUuid", json, uuid);

var obj = Viewer.GetObjectByUuid(uuid, this.Scene.Children);
if (obj is not null)
{
if (position is not null)
{
obj.Position = position;
}
if (rotation is not null)
{
obj.Rotation = rotation;
}
if (scale is not null)
{
obj.Scale = scale;
}
}
}

/// <summary>
/// <para>Selects object in scene by it's unique identifier</para>
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/dotnet/Blazor3D/Blazor3D/wwwroot/js/bundle.js

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions src/javascript/Viewer/Viewer3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,26 @@ class Viewer3D {
return null;
}

moveObjectByUuid(positionOptions, uuid) {
let obj = this.scene.getObjectByProperty("uuid", uuid);
if (obj) {
if(positionOptions.position != null)
{
Transforms.setPosition(obj, positionOptions.position);
}
if(positionOptions.rotation != null)
{
Transforms.setRotation(obj, positionOptions.rotation);
}
if(positionOptions.scale != null)
{
Transforms.setScale(obj, positionOptions.scale);
}
return true;
}
return false;
}

removeByUuid(uuid) {
let obj = this.scene.getObjectByProperty("uuid", uuid);
if (obj) {
Expand Down
5 changes: 5 additions & 0 deletions src/javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export function updateScene(json) {
viewer3d.updateScene(sceneOptions);
}

export function moveObjectByUuid(json, guid) {
const positionOptions = JSON.parse(json);
viewer3d.moveObjectByUuid(positionOptions, guid);
}

export function removeByUuid(guid) {
return viewer3d.removeByUuid(guid);
}
Expand Down