-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NUI.Scene3D] Add Capture for SceneView
Signed-off-by: Seungho Baek <[email protected]>
- Loading branch information
Showing
5 changed files
with
325 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/Tizen.NUI.Scene3D/src/public/Controls/CaptureFinishedEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright(c) 2024 Samsung Electronics Co., Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
using System; | ||
using System.ComponentModel; | ||
|
||
namespace Tizen.NUI.Scene3D | ||
{ | ||
/// <summary> | ||
/// Event arguments of SceneView capture finished event. | ||
/// </summary> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public class CaptureFinishedEventArgs : EventArgs | ||
{ | ||
/// <summary> | ||
/// Integer ID of the capture request. | ||
/// </summary> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public int CaptureId | ||
{ | ||
get; set; | ||
} | ||
|
||
/// <summary> | ||
/// ImageUrl of the captured result | ||
/// If the capture is failed, it is null. | ||
/// </summary> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public ImageUrl CapturedImageUrl | ||
{ | ||
get; set; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/Scene3DCaptureTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
using System.Numerics; | ||
using System.Reflection.Metadata.Ecma335; | ||
using System.Threading.Tasks; | ||
using global::System; | ||
using Tizen.NUI; | ||
using Tizen.NUI.BaseComponents; | ||
using Tizen.NUI.Scene3D; | ||
|
||
namespace Tizen.NUI.Samples | ||
{ | ||
using log = Tizen.Log; | ||
public class Scene3DCaptureTest : IExample | ||
{ | ||
private Window window; | ||
private SceneView sceneView; | ||
private static readonly string resourcePath = Tizen.Applications.Application.Current.DirectoryInfo.Resource; | ||
private Tizen.NUI.Scene3D.Camera[] cameras; | ||
private string[] cameraName; | ||
private int cameraIndex; | ||
int captureId; | ||
ImageView imageView; | ||
ImageUrl imageUrl; | ||
bool inCapture = false; | ||
|
||
Animation rotAnimation; | ||
public void Activate() | ||
{ | ||
window = NUIApplication.GetDefaultWindow(); | ||
Size2D windowSize = window.Size; | ||
|
||
sceneView = new SceneView() | ||
{ | ||
Size = new Size(windowSize.Width, windowSize.Height), | ||
PivotPoint = PivotPoint.TopLeft, | ||
ParentOrigin = ParentOrigin.TopLeft, | ||
PositionUsesPivotPoint = true, | ||
BackgroundColor = new Color(0.85f, 0.85f, 0.85f, 1.0f), | ||
UseFramebuffer = true, | ||
}; | ||
window.Add(sceneView); | ||
|
||
Light light = new Light() | ||
{ | ||
Color = new Vector4(0.4f, 0.4f, 0.4f, 1.0f), | ||
Position = new Vector3(-1.0f, 0.0f, 1.1f), | ||
PositionUsesPivotPoint = true, | ||
}; | ||
light.LookAt(new Vector3(0.0f, 0.0f, 0.0f)); | ||
sceneView.Add(light); | ||
|
||
cameras = new Scene3D.Camera[2]; | ||
cameraName = new string[]{"camera1", "camera2"}; | ||
Vector3[] cameraPosition = new Vector3[]{new Vector3(1.5f, 0.0f, 1.5f), new Vector3(-1.5f, -1.5f, 1.5f)}; | ||
Vector3 modelPosition = new Vector3(-1.5f, 0.0f, 0.0f); | ||
|
||
cameraIndex = 0; | ||
for(uint i = 0; i<2; ++i) | ||
{ | ||
cameras[i] = new Scene3D.Camera() | ||
{ | ||
Name = cameraName[i], | ||
Position = cameraPosition[i], | ||
NearPlaneDistance = 1.0f, | ||
FarPlaneDistance = 10.0f, | ||
}; | ||
sceneView.AddCamera(cameras[i]); | ||
} | ||
cameras[1].FieldOfView = new Radian(new Degree(70.0f)); | ||
|
||
Model model = new Model(resourcePath + "models/BoxAnimated.glb") | ||
{ | ||
PositionUsesPivotPoint = true, | ||
Position = modelPosition, | ||
Size = new Size(0.5f, 0.5f, 0.5f), | ||
}; | ||
sceneView.Add(model); | ||
model.Add(cameras[0]); | ||
sceneView.SelectCamera(cameraName[0]); | ||
model.ResourcesLoaded += (s, e) => | ||
{ | ||
SceneCapture(1); | ||
}; | ||
sceneView.Add(cameras[1]); | ||
|
||
cameras[0].LookAt(modelPosition); | ||
cameras[1].LookAt(modelPosition); | ||
|
||
rotAnimation = new Animation(3000); | ||
KeyFrames keyFrames = new KeyFrames(); | ||
keyFrames.Add(0.0f, new Rotation(new Radian(new Degree(0.0f)), Vector3.YAxis)); | ||
keyFrames.Add(0.25f, new Rotation(new Radian(new Degree(90.0f)), Vector3.YAxis)); | ||
keyFrames.Add(0.5f, new Rotation(new Radian(new Degree(180.0f)), Vector3.YAxis)); | ||
keyFrames.Add(0.75f, new Rotation(new Radian(new Degree(270.0f)), Vector3.YAxis)); | ||
keyFrames.Add(1.0f, new Rotation(new Radian(new Degree(360.0f)), Vector3.YAxis)); | ||
rotAnimation.AnimateBetween(model, "Orientation", keyFrames); | ||
rotAnimation.Looping = true; | ||
rotAnimation.Play(); | ||
|
||
|
||
sceneView.CaptureFinished += (s, e) => | ||
{ | ||
Tizen.Log.Error("NUI", $"Finished Capture ID : {e.CaptureId}\n"); | ||
if(e.CapturedImageUrl == null) | ||
{ | ||
Tizen.Log.Error("NUI", $"Capture Failed\n"); | ||
return; | ||
} | ||
CreateImageView(e.CapturedImageUrl); | ||
}; | ||
|
||
window.KeyEvent += WindowKeyEvent; | ||
} | ||
|
||
private void WindowKeyEvent(object sender, Window.KeyEventArgs e) | ||
{ | ||
if (e.Key.State == Key.StateType.Down) | ||
{ | ||
if (e.Key.KeyPressedName == "1") | ||
{ | ||
SceneCapture(1); | ||
} | ||
else | ||
{ | ||
return; | ||
} | ||
} | ||
} | ||
|
||
void SceneCapture(int captureCameraIndex) | ||
{ | ||
captureId = sceneView.Capture(cameras[captureCameraIndex], new Vector2(300, 300)); | ||
Tizen.Log.Error("NUI", $"Requestd Capture ID : {captureId}\n"); | ||
} | ||
|
||
void CreateImageView(ImageUrl capturedImageUrl) | ||
{ | ||
if (imageView != null) | ||
{ | ||
imageView.Dispose(); | ||
} | ||
if (imageUrl != null) | ||
{ | ||
imageUrl.Dispose(); | ||
} | ||
imageUrl = capturedImageUrl; | ||
|
||
imageView = new ImageView(imageUrl.ToString()) | ||
{ | ||
Size = new Size(300, 300), | ||
PositionUsesPivotPoint = true, | ||
ParentOrigin = ParentOrigin.BottomLeft, | ||
PivotPoint = PivotPoint.BottomLeft | ||
}; | ||
window.Add(imageView); | ||
} | ||
|
||
public void Deactivate() | ||
{ | ||
window.KeyEvent -= WindowKeyEvent; | ||
sceneView?.Dispose(); | ||
} | ||
} | ||
} |
Binary file not shown.