Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CameraController for sample scene #127

Merged
merged 2 commits into from
Oct 27, 2022
Merged
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
2 changes: 1 addition & 1 deletion Assets/3rdparty/Nifti.NET/Nifti.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public class Nifti<T> : Nifti
{
public new T[] Data { get { return ((Nifti)this).Data as T[]; } set { ((Nifti)this).Data = value; } }

public new T this[params int[] idx]
public T this[params int[] idx]
{
get { return Data[DataIndexFor(idx)]; }
set { Data[DataIndexFor(idx)] = value; }
Expand Down
28 changes: 24 additions & 4 deletions Assets/Scenes/TestScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 11
serializedVersion: 12
m_GIWorkflowMode: 1
m_GISettings:
serializedVersion: 2
Expand Down Expand Up @@ -96,8 +96,10 @@ LightmapSettings:
m_PVRFilteringAtrousPositionSigmaAO: 1
m_ExportTrainingData: 0
m_TrainingDataDestination: TrainingData
m_LightProbeSampleCountMultiplier: 4
m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 1
m_LightingSettings: {fileID: 4890085278179872738, guid: e6dba3b7d410a0aa284708a584885877,
type: 2}
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
Expand All @@ -117,6 +119,8 @@ NavMeshSettings:
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
maxJobWorkers: 0
preserveTilesOutsideBounds: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
Expand Down Expand Up @@ -188,8 +192,9 @@ Light:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 812574417}
m_Enabled: 1
serializedVersion: 9
serializedVersion: 10
m_Type: 1
m_Shape: 0
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
m_Intensity: 1
m_Range: 10
Expand Down Expand Up @@ -238,6 +243,7 @@ Light:
m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_UseBoundingSphereOverride: 0
m_UseViewFrustumForShadowCasterCull: 1
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &812574419
Expand Down Expand Up @@ -265,6 +271,7 @@ GameObject:
- component: {fileID: 1753173007}
- component: {fileID: 1753173006}
- component: {fileID: 1753173005}
- component: {fileID: 1753173008}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
Expand Down Expand Up @@ -337,3 +344,16 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 15.23, y: 20.92, z: 0}
--- !u!114 &1753173008
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1753173004}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4539fba9185c180bb9a68b796d0f5353, type: 3}
m_Name:
m_EditorClassIdentifier:
movementSpeed: 1
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ public void ReadCoordinates()
// Reads whether system is in Direct or Cartesian
public void ReadCoordinateSystemType()
{
string molecule = null;
string compare = "Direct";

var line = ParseLine();
Expand Down
6 changes: 0 additions & 6 deletions Assets/Scripts/Importing/RawImporter/RawDatasetImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,16 @@ private int GetSampleFormatSize(DataContentFormat format)
{
case DataContentFormat.Int8:
return 1;
break;
case DataContentFormat.Uint8:
return 1;
break;
case DataContentFormat.Int16:
return 2;
break;
case DataContentFormat.Uint16:
return 2;
break;
case DataContentFormat.Int32:
return 4;
break;
case DataContentFormat.Uint32:
return 4;
break;
}
throw new NotImplementedException();
}
Expand Down
54 changes: 54 additions & 0 deletions Assets/Scripts/SampleScene/CameraController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using UnityEngine;

namespace UnityVolumeRendering
{
/// <summary>
/// Camera controller for sample scene.
/// </summary>
public class CameraController : MonoBehaviour
{
// Normal movement speed
public float movementSpeed = 1.2f;
// Rotation speed
public float rotationSpeed = 2.0f;
// Mouse wheel scroll speed
public float scrollSpeed = 100.0f;
// Multiplied applied to movement speed shen shift key is held down
public float shiftSpeedMultiplier = 3.0f;
// Speed at which to interpolate between movement positions and directions
public float smoothingSpeed = 15.0f;

private Vector3 positionDelta = Vector3.zero;
private Vector2 rotationDelta = Vector3.zero;

private void Update()
{
float actualMovementSpeed = movementSpeed * (Input.GetKey(KeyCode.LeftShift) ? shiftSpeedMultiplier : 1.0f);

Vector3 movementDir = Vector3.zero;
movementDir.z += Input.GetKey(KeyCode.W) ? actualMovementSpeed : 0.0f;
movementDir.z -= Input.GetKey(KeyCode.S) ? actualMovementSpeed : 0.0f;
movementDir.x += Input.GetKey(KeyCode.D) ? actualMovementSpeed : 0.0f;
movementDir.x -= Input.GetKey(KeyCode.A) ? actualMovementSpeed : 0.0f;
movementDir.y += Input.GetKey(KeyCode.E) ? actualMovementSpeed : 0.0f;
movementDir.y -= Input.GetKey(KeyCode.Q) ? actualMovementSpeed : 0.0f;
movementDir.z += Input.mouseScrollDelta.y * scrollSpeed;

Vector3 worldMovementDir = transform.TransformDirection(movementDir);
Vector3 targetPositionDelta = worldMovementDir * movementSpeed * Time.deltaTime;
this.positionDelta = Vector3.Lerp(this.positionDelta, targetPositionDelta, Time.deltaTime * smoothingSpeed);
transform.position += this.positionDelta;

Vector2 mousePosition = Input.mousePosition;
if (Input.GetMouseButton(1))
{
Vector2 targetRotationDelta = new Vector2(Input.GetAxis("Mouse X") * rotationSpeed, -Input.GetAxis("Mouse Y") * rotationSpeed);
this.rotationDelta = Vector2.Lerp(this.rotationDelta, targetRotationDelta, Time.deltaTime * smoothingSpeed);
transform.Rotate(new Vector3(this.rotationDelta.y, 0.0f, 0.0f), Space.Self);
transform.Rotate(new Vector3(0.0f, this.rotationDelta.x, 0.0f), Space.World);
}

}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/SampleScene/CameraController.cs.meta

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

2 changes: 1 addition & 1 deletion Assets/Scripts/VolumeData/VolumeDataset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private Texture3D CreateGradientTextureInternal()
{
cols = new Color[data.Length];
}
catch (OutOfMemoryException ex)
catch (OutOfMemoryException)
{
cols = null;
}
Expand Down